Add packages for zip and use them.

* remove zip Jamfile from the build and from the tree
* clean up image and package definitions.
* added zip in regular builds.
This commit is contained in:
Jérôme Duval 2015-03-02 21:27:26 +01:00
parent 1f68e420cc
commit 22d29642fb
50 changed files with 8 additions and 17477 deletions

View File

@ -29,7 +29,7 @@ AddHaikuImagePackages [ FFilterByBuildFeatures
bzip2 ctags ffmpeg findutils gawk glu grep gutenprint jasper jpeg
less libicns libpng libpng16 libwebp mesa mesa_devel mesa_swrast
sed sharutils
tar tiff unzip wget which
tar tiff unzip wget which zip
}@
] ;
if $(HAIKU_PACKAGING_ARCHS[1]) != x86_gcc2 {

View File

@ -34,7 +34,7 @@ SYSTEM_BIN = [ FFilterByBuildFeatures
uptime urlwrapper useradd userdel
version vmstat
waitfor watch writembr@x86,x86_64 xres
zdiff zforce zgrep zip zipcloak zipnote zipsplit zmore znew
zdiff zforce zgrep zmore znew
] ;
SYSTEM_APPS = [ FFilterByBuildFeatures

View File

@ -206,6 +206,7 @@ RemotePackageRepository HaikuPorts
xml_parser-2.36-1
xz_utils-5.0.4-1
yasm-1.2.0-3
zip-3.0-1
zlib-1.2.8-4
zlib_devel-1.2.8-4
@ -408,6 +409,7 @@ RemotePackageRepository HaikuPorts
yasm
xml_parser
xz_utils
zip
zlib
:
# debuginfo packages

View File

@ -218,6 +218,7 @@ RemotePackageRepository HaikuPorts
xz_utils-5.0.6-1
xz_utils_devel-5.0.6-1
yasm-1.2.0-3
zip-3.0-1
zlib-1.2.8-4
zlib_devel-1.2.8-4
@ -348,6 +349,7 @@ RemotePackageRepository HaikuPorts
yasm
xml_parser
xz_utils
zip
zlib
:
# debuginfo packages

View File

@ -391,6 +391,7 @@ RemotePackageRepository HaikuPorts
yab-1.7.02-2
yab_ide-2.2.2-1
yasm-1.2.0-3
zip-3.0-1
zlib-1.2.8-4
zlib_devel-1.2.8-4
zsh-5.0.7-1
@ -1032,6 +1033,7 @@ RemotePackageRepository HaikuPorts
xproto
xrick
xz_utils_x86
zip
zlib
zsh
:

View File

@ -297,7 +297,6 @@ SubInclude HAIKU_TOP src bin debug ;
SubInclude HAIKU_TOP src bin network ;
# Compression command line tools
SubInclude HAIKU_TOP src bin zip ;
SubInclude HAIKU_TOP src bin gzip ;
# Other stuff

View File

@ -1,56 +0,0 @@
SubDir HAIKU_TOP src bin zip ;
local zip_rsrc = [ FGristFiles zip.rsrc ] ;
ResComp $(zip_rsrc) : [ FGristFiles zip.rdef ] ;
local common_files =
globals.c
;
local common_files2 =
crctab.c
ttyio.c
;
local util_files =
beos_.c
fileio_.c
util_.c
zipfile_.c
;
Objects $(common_files) $(common_files2) $(util_files) ;
BinCommand zip :
[ FGristFiles $(common_files:S=.o) $(common_files2:S=.o) ]
beos.c
crc32.c
crypt.c
deflate.c
fileio.c
trees.c
util.c
zip.c
zipfile.c
zipup.c
: be : zip.rsrc
;
BinCommand zipcloak :
crypt_.c
zipcloak.c
[ FGristFiles $(common_files:S=.o) $(common_files2:S=.o) $(util_files:S=.o) ]
: be : zip.rsrc
;
BinCommand zipnote :
zipnote.c
[ FGristFiles $(common_files:S=.o) $(util_files:S=.o) ]
: be : zip.rsrc
;
BinCommand zipsplit :
zipsplit.c
[ FGristFiles $(common_files:S=.o) $(util_files:S=.o) ]
: be : zip.rsrc
;

View File

@ -1,49 +0,0 @@
This is version 1999-Oct-05 of the Info-ZIP copyright and license.
The definitive version of this document should be available at
ftp://ftp.cdrom.com/pub/infozip/license.html indefinitely.
Copyright (c) 1990-1999 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.

View File

@ -1,494 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2004-May-22 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of 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 a Zip dll engine for use directly from C/C++
programs.
The entry points are:
ZpVer *ZpVersion(void);
int EXPENTRY ZpInit(LPZIPUSERFUNCTIONS lpZipUserFunc);
BOOL EXPENTRY ZpSetOptions(LPZPOPT Opts);
ZPOPT EXPENTRY ZpGetOptions(void);
int EXPENTRY ZpArchive(ZCL C);
This module is currently only used by the Windows dll, and is not used at
all by any of the other platforms, although it should be easy enough to
implement this on most platforms.
---------------------------------------------------------------------------*/
#define __API_C
#ifdef WINDLL
# include <windows.h>
# include "windll/windll.h"
#endif
#ifdef OS2
# define INCL_DOSMEMMGR
# include <os2.h>
#endif
#ifdef __BORLANDC__
#include <dir.h>
#endif
#include <direct.h>
#include <ctype.h>
#include "api.h" /* this includes zip.h */
#include "crypt.h"
#include "revision.h"
#ifdef USE_ZLIB
# include "zlib.h"
#endif
DLLPRNT *lpZipPrint;
DLLPASSWORD *lpZipPassword;
extern DLLCOMMENT *lpComment;
ZIPUSERFUNCTIONS ZipUserFunctions, far * lpZipUserFunctions;
int ZipRet;
/* ------------------------------------------------- */
/* Visual Basic converts strings from VB native Unicode to
byte strings when passing to dlls. It seems that any
strings pointed to in structures are converted and the
conversion passed to the dll, but when the dll call
returns the converted strings are garbage collected
unless the debugger prevents it. This leaves the
pointers going to memory that may have been reused
by the time the following dll call is made. This
affects the strings in the Options stucture.
The following kluge stores the strings locally in
the dll between calls. A better fix is to redesign
the api interface so that strings in structures are
removed or are passed in the same call they are used. EG
/* oversized to be sure */
#define MAX_ZIP_DATE_LEN 50
#define MAX_ZIP_DIR_PATH_LEN 4098
char szDate[MAX_ZIP_DATE_LEN + 1];
char szRootDir[MAX_ZIP_DIR_PATH_LEN + 1];
char szTempDir[MAX_ZIP_DIR_PATH_LEN + 1];
/* ------------------------------------------------- */
/* Local forward declarations */
extern int zipmain OF((int, char **));
int AllocMemory(int, char *, char *);
ZPOPT Options;
char **argVee;
int argCee;
/*---------------------------------------------------------------------------
Local functions
---------------------------------------------------------------------------*/
int AllocMemory(int i, char *cmd, char *str)
{
int j;
if ((argVee[i] = (char *) malloc( sizeof(char) * strlen(cmd)+1 )) == NULL)
{
for (j = 0; j < i; j++)
{
free (argVee[j]);
argVee[j] = NULL;
}
free(argVee);
fprintf(stdout, "Unable to allocate memory in zip library at %s\n", str);
return ZE_MEM;
}
strcpy( argVee[i], cmd );
return ZE_OK;
}
/*---------------------------------------------------------------------------
Documented API entry points
---------------------------------------------------------------------------*/
int EXPENTRY ZpInit(LPZIPUSERFUNCTIONS lpZipUserFunc)
{
ZipUserFunctions = *lpZipUserFunc;
lpZipUserFunctions = &ZipUserFunctions;
if (!lpZipUserFunctions->print ||
!lpZipUserFunctions->comment)
return FALSE;
return TRUE;
}
BOOL EXPENTRY ZpSetOptions(LPZPOPT Opts)
{
/* copy the structure including pointers to strings */
Options = *Opts;
/* fix for calling dll from VB - 2002-11-25 */
/* make copies of strings in structure if not NULL passed for empty string */
if (Options.Date) {
szDate[0] = '\0';
strncat(szDate, Options.Date, MAX_ZIP_DATE_LEN);
Options.Date = szDate;
}
if (Options.szRootDir) {
szRootDir[0] = '\0';
strncat(szRootDir, Options.szRootDir, MAX_ZIP_DIR_PATH_LEN);
Options.szRootDir = szRootDir;
}
if (Options.szTempDir) {
szTempDir[0] = '\0';
strncat(szTempDir, Options.szTempDir, MAX_ZIP_DIR_PATH_LEN);
Options.szTempDir = szTempDir;
}
return TRUE;
}
ZPOPT EXPENTRY ZpGetOptions(void)
{
#if CRYPT
Options.fEncryption = TRUE;
#else
Options.fEncryption = FALSE;
#endif
return Options;
}
int EXPENTRY ZpArchive(ZCL C)
/* Add, update, freshen, or delete zip entries in a zip file. See the
command help in help() zip.c */
{
int i, k, j, m;
char szOrigDir[PATH_MAX];
argCee = 0;
/* malloc additional 26 to allow for additional command line arguments */
if ((argVee = (char **)malloc((C.argc+26)*sizeof(char *))) == NULL)
{
fprintf(stdout, "Unable to allocate memory in zip dll\n");
return ZE_MEM;
}
if ((argVee[argCee] = (char *) malloc( sizeof(char) * strlen("wiz.exe")+1 )) == NULL)
{
free(argVee);
fprintf(stdout, "Unable to allocate memory in zip dll\n");
return ZE_MEM;
}
strcpy( argVee[argCee], "wiz.exe" );
argCee++;
/* Set compression level efficacy -0...-9 */
if (AllocMemory(argCee, "-0", "Compression") != ZE_OK)
return ZE_MEM;
argVee[argCee][1] = Options.fLevel;
argCee++;
if (Options.fOffsets) /* Update offsets for SFX prefix */
{
if (AllocMemory(argCee, "-A", "Offsets") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fDeleteEntries) /* Delete files from zip file -d */
{
if (AllocMemory(argCee, "-d", "Delete") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fNoDirEntries) /* Do not add directory entries -D */
{
if (AllocMemory(argCee, "-D", "No Dir Entries") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fFreshen) /* Freshen zip file--overwrite only -f */
{
if (AllocMemory(argCee, "-f", "Freshen") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fRepair) /* Fix archive -F or -FF */
{
if (Options.fRepair == 1)
{
if (AllocMemory(argCee, "-F", "Repair") != ZE_OK)
return ZE_MEM;
}
else
{
if (AllocMemory(argCee, "-FF", "Repair") != ZE_OK)
return ZE_MEM;
}
argCee++;
}
if (Options.fGrow) /* Allow appending to a zip file -g */
{
if (AllocMemory(argCee, "-g", "Appending") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fJunkDir) /* Junk directory names -j */
{
if (AllocMemory(argCee, "-j", "Junk Dir Names") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fEncrypt) /* encrypt -e */
{
if (AllocMemory(argCee, "-e", "Encrypt") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fJunkSFX) /* Junk sfx prefix */
{
if (AllocMemory(argCee, "-J", "Junk SFX") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fForce) /* Make entries using DOS names (k for Katz) -k */
{
if (AllocMemory(argCee, "-k", "Force DOS") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fLF_CRLF) /* Translate LF_CRLF -l */
{
if (AllocMemory(argCee, "-l", "LF-CRLF") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fCRLF_LF) /* Translate CR/LF to LF -ll */
{
if (AllocMemory(argCee, "-ll", "CRLF-LF") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fMove) /* Delete files added to or updated in zip file -m */
{
if (AllocMemory(argCee, "-m", "Move") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fLatestTime) /* Set zip file time to time of latest file in it -o */
{
if (AllocMemory(argCee, "-o", "Time") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fComment) /* Add archive comment "-z" */
{
if (AllocMemory(argCee, "-z", "Comment") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fQuiet) /* quiet operation -q */
{
if (AllocMemory(argCee, "-q", "Quiet") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fSystem) /* include system and hidden files -S */
{
if (AllocMemory(argCee, "-S", "System") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fExcludeDate) /* Exclude files newer than specified date -tt */
{
if ((Options.Date != NULL) && (Options.Date[0] != '\0'))
{
if (AllocMemory(argCee, "-tt", "Date") != ZE_OK)
return ZE_MEM;
argCee++;
if (AllocMemory(argCee, Options.Date, "Date") != ZE_OK)
return ZE_MEM;
argCee++;
}
}
if (Options.fIncludeDate) /* include files newer than specified date -t */
{
if ((Options.Date != NULL) && (Options.Date[0] != '\0'))
{
if (AllocMemory(argCee, "-t", "Date") != ZE_OK)
return ZE_MEM;
argCee++;
if (AllocMemory(argCee, Options.Date, "Date") != ZE_OK)
return ZE_MEM;
argCee++;
}
}
if (Options.fUpdate) /* Update zip file--overwrite only if newer -u */
{
if (AllocMemory(argCee, "-u", "Update") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fVerbose) /* Mention oddities in zip file structure -v */
{
if (AllocMemory(argCee, "-v", "Verbose") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (Options.fVolume) /* Include volume label -$ */
{
if (AllocMemory(argCee, "-$", "Volume") != ZE_OK)
return ZE_MEM;
argCee++;
}
#ifdef NTSD_EAS /* was WIN32 1/22/2005 EG */
if (Options.fPrivilege) /* Use privileges -! */
{
if (AllocMemory(argCee, "-!", "Privileges") != ZE_OK)
return ZE_MEM;
argCee++;
}
#endif
if (Options.fExtra) /* Exclude extra attributes -X */
{
if (AllocMemory(argCee, "-X", "Extra") != ZE_OK)
return ZE_MEM;
argCee++;
}
if ((Options.szTempDir != NULL) && (Options.szTempDir[0] != '\0')
&& Options.fTemp) /* Use temporary directory -b */
{
if (AllocMemory(argCee, "-b", "Temp dir switch command") != ZE_OK)
return ZE_MEM;
argCee++;
if (AllocMemory(argCee, Options.szTempDir, "Temporary directory") != ZE_OK)
return ZE_MEM;
argCee++;
}
/* -r and -R moved down here to avoid VB problem 1/31/2005 EG */
if (Options.fRecurse == 1) /* recurse into subdirectories -r */
{
if (AllocMemory(argCee, "-r", "Recurse -r") != ZE_OK)
return ZE_MEM;
argCee++;
}
else if (Options.fRecurse == 2) /* recurse into subdirectories -R */
{
if (AllocMemory(argCee, "-R", "Recurse -R") != ZE_OK)
return ZE_MEM;
argCee++;
}
if (AllocMemory(argCee, C.lpszZipFN, "Zip file name") != ZE_OK)
return ZE_MEM;
argCee++;
getcwd(szOrigDir, PATH_MAX); /* Save current drive and directory */
if ((Options.szRootDir != NULL) && (Options.szRootDir[0] != '\0'))
{
chdir(Options.szRootDir);
#ifdef __BORLANDC__
setdisk(toupper(Options.szRootDir[0]) - 'A');
#endif
lstrcat(Options.szRootDir, "\\"); /* append trailing \\ */
if (C.FNV != NULL)
{
for (k = 0; k < C.argc; k++)
{
if (AllocMemory(argCee, C.FNV[k], "Making argv") != ZE_OK)
return ZE_MEM;
if ((strncmp(Options.szRootDir, C.FNV[k], lstrlen(Options.szRootDir))) == 0)
{
m = 0;
for (j = lstrlen(Options.szRootDir); j < lstrlen(C.FNV[k]); j++)
argVee[argCee][m++] = C.FNV[k][j];
argVee[argCee][m] = '\0';
}
argCee++;
}
}
}
else
if (C.FNV != NULL)
for (k = 0; k < C.argc; k++)
{
if (AllocMemory(argCee, C.FNV[k], "Making argv") != ZE_OK)
return ZE_MEM;
argCee++;
}
argVee[argCee] = NULL;
ZipRet = zipmain(argCee, argVee);
chdir(szOrigDir);
#ifdef __BORLANDC__
setdisk(toupper(szOrigDir[0]) - 'A');
#endif
/* Free the arguments in the array */
for (i = 0; i < argCee; i++)
{
free (argVee[i]);
argVee[i] = NULL;
}
/* Then free the array itself */
free(argVee);
return ZipRet;
}
#if CRYPT
int encr_passwd(int modeflag, char *pwbuf, int size, const char *zfn)
{
return (*lpZipUserFunctions->password)(pwbuf, size, ((modeflag == ZP_PW_VERIFY) ?
"Verify password: " : "Enter password: "),
(char *)zfn);
}
#endif /* CRYPT */
void EXPENTRY ZpVersion(ZpVer far * p) /* should be pointer to const struct */
{
p->structlen = ZPVER_LEN;
#ifdef BETA
p->flag = 1;
#else
p->flag = 0;
#endif
lstrcpy(p->betalevel, Z_BETALEVEL);
lstrcpy(p->date, REVDATE);
#ifdef ZLIB_VERSION
lstrcpy(p->zlib_version, ZLIB_VERSION);
p->flag |= 2;
#else
p->zlib_version[0] = '\0';
#endif
p->zip.major = Z_MAJORVER;
p->zip.minor = Z_MINORVER;
p->zip.patchlevel = Z_PATCHLEVEL;
p->os2dll.major = D2_MAJORVER;
p->os2dll.minor = D2_MINORVER;
p->os2dll.patchlevel = D2_PATCHLEVEL;
p->windll.major = DW_MAJORVER;
p->windll.minor = DW_MINORVER;
p->windll.patchlevel = DW_PATCHLEVEL;
}

View File

@ -1,152 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2004-May-22 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/* Only the Windows DLL is currently supported */
#ifndef _ZIPAPI_H
#define _ZIPAPI_H
#include "zip.h"
#ifdef WIN32
# ifndef PATH_MAX
# define PATH_MAX 260
# endif
#else
# ifndef PATH_MAX
# define PATH_MAX 128
# endif
#endif
#if defined(WINDLL) || defined(API)
#include <windows.h>
/* Porting definations between Win 3.1x and Win32 */
#ifdef WIN32
# define far
# define _far
# define __far
# define near
# define _near
# define __near
#endif
/*---------------------------------------------------------------------------
Prototypes for public Zip API (DLL) functions.
---------------------------------------------------------------------------*/
#define ZPVER_LEN sizeof(ZpVer)
/* These defines are set to zero for now, until OS/2 comes out
with a dll.
*/
#define D2_MAJORVER 0
#define D2_MINORVER 0
#define D2_PATCHLEVEL 0
/* intended to be a private struct: */
typedef struct _zip_ver {
uch major; /* e.g., integer 5 */
uch minor; /* e.g., 2 */
uch patchlevel; /* e.g., 0 */
uch not_used;
} _zip_version_type;
typedef struct _ZpVer {
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 */
_zip_version_type zip;
_zip_version_type os2dll;
_zip_version_type windll;
} ZpVer;
# ifndef EXPENTRY
# define EXPENTRY WINAPI
# endif
#ifndef DEFINED_ONCE
#define DEFINED_ONCE
typedef int (WINAPI DLLPRNT) (LPSTR, unsigned long);
typedef int (WINAPI DLLPASSWORD) (LPSTR, int, LPCSTR, LPCSTR);
typedef int (WINAPI DLLSERVICE) (LPCSTR, unsigned long);
#endif
typedef int (WINAPI DLLCOMMENT)(LPSTR);
/* Structures */
typedef struct { /* zip options */
LPSTR Date; /* Date to include after */
LPSTR szRootDir; /* Directory to use as base for zipping */
LPSTR szTempDir; /* Temporary directory used during zipping */
BOOL fTemp; /* Use temporary directory '-b' during zipping */
BOOL fSuffix; /* include suffixes (not implemented) */
BOOL fEncrypt; /* encrypt files */
BOOL fSystem; /* include system and hidden files */
BOOL fVolume; /* Include volume label */
BOOL fExtra; /* Exclude extra attributes */
BOOL fNoDirEntries; /* Do not add directory entries */
BOOL fExcludeDate; /* Exclude files newer than specified date */
BOOL fIncludeDate; /* Include only files newer than specified date */
BOOL fVerbose; /* Mention oddities in zip file structure */
BOOL fQuiet; /* Quiet operation */
BOOL fCRLF_LF; /* Translate CR/LF to LF */
BOOL fLF_CRLF; /* Translate LF to CR/LF */
BOOL fJunkDir; /* Junk directory names */
BOOL fGrow; /* Allow appending to a zip file */
BOOL fForce; /* Make entries using DOS names (k for Katz) */
BOOL fMove; /* Delete files added or updated in zip file */
BOOL fDeleteEntries; /* Delete files from zip file */
BOOL fUpdate; /* Update zip file--overwrite only if newer */
BOOL fFreshen; /* Freshen zip file--overwrite only */
BOOL fJunkSFX; /* Junk SFX prefix */
BOOL fLatestTime; /* Set zip file time to time of latest file in it */
BOOL fComment; /* Put comment in zip file */
BOOL fOffsets; /* Update archive offsets for SFX files */
BOOL fPrivilege; /* Use privileges (WIN32 only) */
BOOL fEncryption; /* TRUE if encryption supported, else FALSE.
this is a read only flag */
int fRecurse; /* Recurse into subdirectories. 1 => -r, 2 => -R */
int fRepair; /* Repair archive. 1 => -F, 2 => -FF */
char fLevel; /* Compression level (0 - 9) */
} ZPOPT, _far *LPZPOPT;
typedef struct {
int argc; /* Count of files to zip */
LPSTR lpszZipFN; /* name of archive to create/update */
char **FNV; /* array of file names to zip up */
} ZCL, _far *LPZCL;
typedef struct {
DLLPRNT *print;
DLLCOMMENT *comment;
DLLPASSWORD *password;
DLLSERVICE *ServiceApplication;
} ZIPUSERFUNCTIONS, far * LPZIPUSERFUNCTIONS;
extern LPZIPUSERFUNCTIONS lpZipUserFunctions;
void EXPENTRY ZpVersion(ZpVer far *);
int EXPENTRY ZpInit(LPZIPUSERFUNCTIONS lpZipUserFunc);
BOOL EXPENTRY ZpSetOptions(LPZPOPT Opts);
ZPOPT EXPENTRY ZpGetOptions(void);
int EXPENTRY ZpArchive(ZCL C);
#if defined(ZIPLIB) || defined(COM_OBJECT)
# define ydays zp_ydays
#endif
/* Functions not yet supported */
#if 0
int EXPENTRY ZpMain (int argc, char **argv);
int EXPENTRY ZpAltMain (int argc, char **argv, ZpInit *init);
#endif
#endif /* WINDLL? || API? */
#endif /* _ZIPAPI_H */

View File

@ -1,959 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2004-May-22 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
*/
/*
This BeOS-specific file is based on unix.c in the unix directory; changes
by Chris Herborth (chrish@pobox.com).
*/
#include <OS.h>
#include "zip.h"
#ifndef UTIL /* the companion #endif is a bit of ways down ... */
#include <time.h>
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <kernel/fs_attr.h>
#include <storage/Mime.h>
#include <support/ByteOrder.h>
#define PAD 0
#define PATH_END '/'
/* Library functions not in (most) header files */
#ifdef _POSIX_VERSION
# include <utime.h>
#else
int utime OF((char *, time_t *));
#endif
#if !defined(__BEOS__) && !defined(__HAIKU__)
# define open(path, openMode) _kern_open(-1, (path), (openMode), 0)
extern int _kern_open(int fd, const char *path, int openMode, int perms);
#endif
extern char *label;
local ulg label_time = 0;
local ulg label_mode = 0;
local time_t label_utim = 0;
/* Local functions */
local char *readd OF((DIR *));
local int get_attr_dir( const char *, char **, off_t * );
local int add_UT_ef( struct zlist far * );
local int add_Ux_ef( struct zlist far * );
local int add_Be_ef( struct zlist far * );
#ifdef NO_DIR /* for AT&T 3B1 */
#include <sys/dir.h>
#ifndef dirent
# define dirent direct
#endif
typedef FILE DIR;
/*
** Apparently originally by Rich Salz.
** Cleaned up and modified by James W. Birdsall.
*/
#define opendir(path) fopen(path, "r")
struct dirent *readdir(dirp)
DIR *dirp;
{
static struct dirent entry;
if (dirp == NULL)
return NULL;
for (;;)
if (fread (&entry, sizeof (struct dirent), 1, dirp) == 0)
return NULL;
else if (entry.d_ino)
return (&entry);
} /* end of readdir() */
#define closedir(dirp) fclose(dirp)
#endif /* NO_DIR */
local char *readd(d)
DIR *d; /* directory stream to read from */
/* Return a pointer to the next name in the directory stream d, or NULL if
no more entries or an error occurs. */
{
struct dirent *e;
e = readdir(d);
return e == NULL ? (char *) NULL : e->d_name;
}
int procname(n, caseflag)
char *n; /* name to process */
int caseflag; /* true to force case-sensitive match */
/* Process a name or sh expression to operate on (or exclude). Return
an error code in the ZE_ class. */
{
char *a; /* path and name for recursion */
DIR *d; /* directory stream from opendir() */
char *e; /* pointer to name from readd() */
int m; /* matched flag */
char *p; /* path for recursion */
struct stat s; /* result of stat() */
struct zlist far *z; /* steps through zfiles list */
if (strcmp(n, "-") == 0) /* if compressing stdin */
return newname(n, 0, caseflag);
else if (LSSTAT(n, &s))
{
/* Not a file or directory--search for shell expression in zip file */
p = ex2in(n, 0, (int *)NULL); /* shouldn't affect matching chars */
m = 1;
for (z = zfiles; z != NULL; z = z->nxt) {
if (MATCH(p, z->iname, caseflag))
{
z->mark = pcount ? filter(z->zname, caseflag) : 1;
if (verbose)
fprintf(mesg, "zip diagnostic: %scluding %s\n",
z->mark ? "in" : "ex", z->name);
m = 0;
}
}
free((zvoid *)p);
return m ? ZE_MISS : ZE_OK;
}
/* Live name--use if file, recurse if directory */
if ((s.st_mode & S_IFDIR) == 0)
{
/* add or remove name of file */
if ((m = newname(n, 0, caseflag)) != ZE_OK)
return m;
} else {
/* Add trailing / to the directory name */
if ((p = malloc(strlen(n)+2)) == NULL)
return ZE_MEM;
if (strcmp(n, ".") == 0) {
*p = '\0'; /* avoid "./" prefix and do not create zip entry */
} else {
strcpy(p, n);
a = p + strlen(p);
if (a[-1] != '/')
strcpy(a, "/");
if (dirnames && (m = newname(p, 1, caseflag)) != ZE_OK) {
free((zvoid *)p);
return m;
}
}
/* recurse into directory */
if (recurse && (d = opendir(n)) != NULL)
{
while ((e = readd(d)) != NULL) {
if (strcmp(e, ".") && strcmp(e, ".."))
{
if ((a = malloc(strlen(p) + strlen(e) + 1)) == NULL)
{
closedir(d);
free((zvoid *)p);
return ZE_MEM;
}
strcat(strcpy(a, p), e);
if ((m = procname(a, caseflag)) != ZE_OK) /* recurse on name */
{
if (m == ZE_MISS)
zipwarn("name not matched: ", a);
else
ziperr(m, a);
}
free((zvoid *)a);
}
}
closedir(d);
}
free((zvoid *)p);
} /* (s.st_mode & S_IFDIR) == 0) */
return ZE_OK;
}
char *ex2in(x, isdir, pdosflag)
char *x; /* external file name */
int isdir; /* input: x is a directory */
int *pdosflag; /* output: force MSDOS file attributes? */
/* Convert the external file name to a zip file name, returning the malloc'ed
string or NULL if not enough memory. */
{
char *n; /* internal file name (malloc'ed) */
char *t; /* shortened name */
int dosflag;
dosflag = dosify; /* default for non-DOS and non-OS/2 */
/* Find starting point in name before doing malloc */
for (t = x; *t == '/'; t++)
; /* strip leading '/' chars to get a relative path */
while (*t == '.' && t[1] == '/')
t += 2; /* strip redundant leading "./" sections */
/* Make changes, if any, to the copied name (leave original intact) */
if (!pathput)
t = last(t, PATH_END);
/* Malloc space for internal name and copy it */
if ((n = malloc(strlen(t) + 1)) == NULL)
return NULL;
strcpy(n, t);
if (isdir == 42) return n; /* avoid warning on unused variable */
if (dosify)
msname(n);
/* Returned malloc'ed name */
if (pdosflag)
*pdosflag = dosflag;
return n;
}
char *in2ex(n)
char *n; /* internal file name */
/* Convert the zip file name to an external file name, returning the malloc'ed
string or NULL if not enough memory. */
{
char *x; /* external file name */
if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)
return NULL;
strcpy(x, n);
return x;
}
/*
* XXX use ztimbuf in both POSIX and non POSIX cases ?
*/
void stamp(f, d)
char *f; /* name of file to change */
ulg d; /* dos-style time to change it to */
/* Set last updated and accessed time of file f to the DOS time d. */
{
#ifdef _POSIX_VERSION
struct utimbuf u; /* argument for utime() const ?? */
#else
time_t u[2]; /* argument for utime() */
#endif
/* Convert DOS time to time_t format in u */
#ifdef _POSIX_VERSION
u.actime = u.modtime = dos2unixtime(d);
utime(f, &u);
#else
u[0] = u[1] = dos2unixtime(d);
utime(f, u);
#endif
}
ulg filetime(f, a, n, t)
char *f; /* name of file to get info on */
ulg *a; /* return value: file attributes */
long *n; /* return value: file size */
iztimes *t; /* return value: access, modific. and creation times */
/* If file *f does not exist, return 0. Else, return the file's last
modified date and time as an MSDOS date and time. The date and
time is returned in a long with the date most significant to allow
unsigned integer comparison of absolute times. Also, if a is not
a NULL pointer, store the file attributes there, with the high two
bytes being the Unix attributes, and the low byte being a mapping
of that to DOS attributes. If n is not NULL, store the file size
there. If t is not NULL, the file's access, modification and creation
times are stored there as UNIX time_t values.
If f is "-", use standard input as the file. If f is a device, return
a file size of -1 */
{
struct stat s; /* results of stat() */
char *name;
unsigned int len = strlen(f);
if (f == label) {
if (a != NULL)
*a = label_mode;
if (n != NULL)
*n = -2L; /* convention for a label name */
if (t != NULL)
t->atime = t->mtime = t->ctime = label_utim;
return label_time;
}
if ((name = malloc(len + 1)) == NULL) {
ZIPERR(ZE_MEM, "filetime");
}
strcpy(name, f);
if (name[len - 1] == '/')
name[len - 1] = '\0';
/* not all systems allow stat'ing a file with / appended */
if (strcmp(f, "-") == 0) {
if (fstat(fileno(stdin), &s) != 0) {
free(name);
error("fstat(stdin)");
}
} else if (LSSTAT(name, &s) != 0) {
/* Accept about any file kind including directories
* (stored with trailing / with -r option)
*/
free(name);
return 0;
}
if (a != NULL) {
*a = ((ulg)s.st_mode << 16) | !(s.st_mode & S_IWRITE);
if ((s.st_mode & S_IFMT) == S_IFDIR) {
*a |= MSDOS_DIR_ATTR;
}
}
if (n != NULL)
*n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L;
if (t != NULL) {
t->atime = s.st_atime;
t->mtime = s.st_mtime;
t->ctime = s.st_mtime; /* best guess (s.st_ctime: last status change!) */
}
free(name);
return unix2dostime(&s.st_mtime);
}
/* ----------------------------------------------------------------------
Return a malloc()'d buffer containing all of the attributes and their names
for the file specified in name. You have to free() this yourself. The length
of the buffer is also returned.
If get_attr_dir() fails, the buffer will be NULL, total_size will be 0,
and an error will be returned:
0 - no errors occurred
EINVAL - attr_buff was pointing at a buffer
ENOMEM - insufficient memory for attribute buffer
Other errors are possible (whatever is returned by the fs_attr.h functions).
PROBLEMS:
- pointers are 32-bits; attributes are limited to off_t in size so it's
possible to overflow... in practice, this isn't too likely... your
machine will thrash like hell before that happens
*/
#define INITIAL_BUFF_SIZE 65536
int get_attr_dir( const char *name, char **attr_buff, off_t *total_size )
{
int retval = 0;
int fd;
DIR *fa_dir;
struct dirent *fa_ent;
off_t attrs_size;
off_t this_size;
char *ptr;
struct attr_info fa_info;
struct attr_info big_fa_info;
retval = 0;
attrs_size = 0; /* gcc still says this is used uninitialized... */
*total_size = 0;
/* ----------------------------------------------------------------- */
/* Sanity-check. */
if( *attr_buff != NULL ) {
return EINVAL;
}
/* ----------------------------------------------------------------- */
/* Can we open the file/directory? */
/* */
/* linkput is a zip global; it's set to 1 if we're storing symbolic */
/* links as symbolic links (instead of storing the thing the link */
/* points to)... if we're storing the symbolic link as a link, we'll */
/* want the link's file attributes, otherwise we want the target's. */
if( linkput ) {
fd = open( name, O_RDONLY | O_NOTRAVERSE );
} else {
fd = open( name, O_RDONLY );
}
if( fd < 0 ) {
return errno;
}
/* ----------------------------------------------------------------- */
/* Allocate an initial buffer; 64k should usually be enough. */
*attr_buff = (char *)malloc( INITIAL_BUFF_SIZE );
ptr = *attr_buff;
if( ptr == NULL ) {
close( fd );
return ENOMEM;
}
/* ----------------------------------------------------------------- */
/* Open the attributes directory for this file. */
fa_dir = fs_fopen_attr_dir( fd );
if( fa_dir == NULL ) {
close( fd );
free( ptr );
*attr_buff = NULL;
return retval;
}
/* ----------------------------------------------------------------- */
/* Read all the attributes; the buffer could grow > 64K if there are */
/* many and/or they are large. */
fa_ent = fs_read_attr_dir( fa_dir );
while( fa_ent != NULL ) {
retval = fs_stat_attr( fd, fa_ent->d_name, &fa_info );
/* TODO: check retval != 0 */
this_size = strlen( fa_ent->d_name ) + 1;
this_size += sizeof( struct attr_info );
this_size += fa_info.size;
attrs_size += this_size;
if( attrs_size > INITIAL_BUFF_SIZE ) {
unsigned long offset = ptr - *attr_buff;
*attr_buff = (char *)realloc( *attr_buff, attrs_size );
if( *attr_buff == NULL ) {
retval = fs_close_attr_dir( fa_dir );
/* TODO: check retval != 0 */
close( fd );
return ENOMEM;
}
ptr = *attr_buff + offset;
}
/* Now copy the data for this attribute into the buffer. */
strcpy( ptr, fa_ent->d_name );
ptr += strlen( fa_ent->d_name );
*ptr++ = '\0';
/* We need to put a big-endian version of the fa_info data into */
/* the archive. */
big_fa_info.type = B_HOST_TO_BENDIAN_INT32( fa_info.type );
big_fa_info.size = B_HOST_TO_BENDIAN_INT64( fa_info.size );
memcpy( ptr, &big_fa_info, sizeof( struct attr_info ) );
ptr += sizeof( struct attr_info );
if( fa_info.size > 0 ) {
ssize_t read_bytes;
read_bytes = fs_read_attr( fd, fa_ent->d_name, fa_info.type, 0,
ptr, fa_info.size );
if( read_bytes != fa_info.size ) {
/* print a warning about mismatched sizes */
char buff[80];
sprintf( buff, "read %ld, expected %ld",
(long)read_bytes, (long)fa_info.size );
zipwarn( "attribute size mismatch: ", buff );
}
/* Wave my magic wand... this swaps all the Be types to big- */
/* endian automagically. */
(void)swap_data( fa_info.type, ptr, fa_info.size,
B_SWAP_HOST_TO_BENDIAN );
ptr += fa_info.size;
}
fa_ent = fs_read_attr_dir( fa_dir );
}
/* ----------------------------------------------------------------- */
/* Close the attribute directory. */
retval = fs_close_attr_dir( fa_dir );
/* TODO: check retval != 0 */
/* ----------------------------------------------------------------- */
/* If the buffer is too big, shrink it. */
if( attrs_size < INITIAL_BUFF_SIZE ) {
*attr_buff = (char *)realloc( *attr_buff, attrs_size );
if( *attr_buff == NULL ) {
/* This really shouldn't happen... */
close( fd );
return ENOMEM;
}
}
*total_size = attrs_size;
close( fd );
return 0;
}
/* ---------------------------------------------------------------------- */
/* Add a 'UT' extra field to the zlist data pointed to by z. */
#define EB_L_UT_SIZE (EB_HEADSIZE + EB_UT_LEN(2))
#define EB_C_UT_SIZE (EB_HEADSIZE + EB_UT_LEN(1))
local int add_UT_ef( struct zlist far *z )
{
char *l_ef = NULL;
char *c_ef = NULL;
struct stat s;
#ifdef IZ_CHECK_TZ
if (!zp_tz_is_valid)
return ZE_OK; /* skip silently if no valid TZ info */
#endif
/* We can't work if there's no entry to work on. */
if( z == NULL ) {
return ZE_LOGIC;
}
/* Check to make sure we've got enough room in the extra fields. */
if( z->ext + EB_L_UT_SIZE > USHRT_MAX ||
z->cext + EB_C_UT_SIZE > USHRT_MAX ) {
return ZE_MEM;
}
/* stat() the file (or the symlink) to get the data; if we can't get */
/* the data, there's no point in trying to fill out the fields. */
if(LSSTAT( z->name, &s ) ) {
return ZE_OPEN;
}
/* Allocate memory for the local and central extra fields. */
if( z->extra && z->ext != 0 ) {
l_ef = (char *)realloc( z->extra, z->ext + EB_L_UT_SIZE );
} else {
l_ef = (char *)malloc( EB_L_UT_SIZE );
z->ext = 0;
}
if( l_ef == NULL ) {
return ZE_MEM;
}
z->extra = l_ef;
l_ef += z->ext;
if( z->cextra && z->cext != 0 ) {
c_ef = (char *)realloc( z->cextra, z->cext + EB_C_UT_SIZE );
} else {
c_ef = (char *)malloc( EB_C_UT_SIZE );
z->cext = 0;
}
if( c_ef == NULL ) {
return ZE_MEM;
}
z->cextra = c_ef;
c_ef += z->cext;
/* Now add the local version of the field. */
*l_ef++ = 'U';
*l_ef++ = 'T';
*l_ef++ = (char)(EB_UT_LEN(2)); /* length of data in local EF */
*l_ef++ = (char)0;
*l_ef++ = (char)(EB_UT_FL_MTIME | EB_UT_FL_ATIME);
*l_ef++ = (char)(s.st_mtime);
*l_ef++ = (char)(s.st_mtime >> 8);
*l_ef++ = (char)(s.st_mtime >> 16);
*l_ef++ = (char)(s.st_mtime >> 24);
*l_ef++ = (char)(s.st_atime);
*l_ef++ = (char)(s.st_atime >> 8);
*l_ef++ = (char)(s.st_atime >> 16);
*l_ef++ = (char)(s.st_atime >> 24);
z->ext += EB_L_UT_SIZE;
/* Now add the central version. */
memcpy(c_ef, l_ef-EB_L_UT_SIZE, EB_C_UT_SIZE);
c_ef[EB_LEN] = (char)(EB_UT_LEN(1)); /* length of data in central EF */
z->cext += EB_C_UT_SIZE;
return ZE_OK;
}
/* ---------------------------------------------------------------------- */
/* Add a 'Ux' extra field to the zlist data pointed to by z. */
#define EB_L_UX2_SIZE (EB_HEADSIZE + EB_UX2_MINLEN)
#define EB_C_UX2_SIZE (EB_HEADSIZE)
local int add_Ux_ef( struct zlist far *z )
{
char *l_ef = NULL;
char *c_ef = NULL;
struct stat s;
/* Check to make sure we've got enough room in the extra fields. */
if( z->ext + EB_L_UX2_SIZE > USHRT_MAX ||
z->cext + EB_C_UX2_SIZE > USHRT_MAX ) {
return ZE_MEM;
}
/* stat() the file (or the symlink) to get the data; if we can't get */
/* the data, there's no point in trying to fill out the fields. */
if(LSSTAT( z->name, &s ) ) {
return ZE_OPEN;
}
/* Allocate memory for the local and central extra fields. */
if( z->extra && z->ext != 0 ) {
l_ef = (char *)realloc( z->extra, z->ext + EB_L_UX2_SIZE );
} else {
l_ef = (char *)malloc( EB_L_UX2_SIZE );
z->ext = 0;
}
if( l_ef == NULL ) {
return ZE_MEM;
}
z->extra = l_ef;
l_ef += z->ext;
if( z->cextra && z->cext != 0 ) {
c_ef = (char *)realloc( z->cextra, z->cext + EB_C_UX2_SIZE );
} else {
c_ef = (char *)malloc( EB_C_UX2_SIZE );
z->cext = 0;
}
if( c_ef == NULL ) {
return ZE_MEM;
}
z->cextra = c_ef;
c_ef += z->cext;
/* Now add the local version of the field. */
*l_ef++ = 'U';
*l_ef++ = 'x';
*l_ef++ = (char)(EB_UX2_MINLEN);
*l_ef++ = (char)(EB_UX2_MINLEN >> 8);
*l_ef++ = (char)(s.st_uid);
*l_ef++ = (char)(s.st_uid >> 8);
*l_ef++ = (char)(s.st_gid);
*l_ef++ = (char)(s.st_gid >> 8);
z->ext += EB_L_UX2_SIZE;
/* Now add the central version of the field. */
*c_ef++ = 'U';
*c_ef++ = 'x';
*c_ef++ = 0;
*c_ef++ = 0;
z->cext += EB_C_UX2_SIZE;
return ZE_OK;
}
/* ---------------------------------------------------------------------- */
/* Add a 'Be' extra field to the zlist data pointed to by z. */
#define EB_L_BE_SIZE (EB_HEADSIZE + EB_L_BE_LEN) /* + attr size */
#define EB_C_BE_SIZE (EB_HEADSIZE + EB_C_BE_LEN)
/* maximum memcompress overhead is the sum of the compression header length */
/* (6 = ush compression type, ulg CRC) and the worstcase deflate overhead */
/* when uncompressible data are kept in 2 "stored" blocks (5 per block = */
/* byte blocktype + 2 * ush blocklength) */
#define MEMCOMPRESS_OVERHEAD (EB_MEMCMPR_HSIZ + EB_DEFLAT_EXTRA)
local int add_Be_ef( struct zlist far *z )
{
char *l_ef = NULL;
char *c_ef = NULL;
char *attrbuff = NULL;
off_t attrsize = 0;
char *compbuff = NULL;
ush compsize = 0;
uch flags = 0;
/* Check to make sure we've got enough room in the extra fields. */
if( z->ext + EB_L_BE_SIZE > USHRT_MAX ||
z->cext + EB_C_BE_SIZE > USHRT_MAX ) {
return ZE_MEM;
}
/* Attempt to load up a buffer full of the file's attributes. */
{
int retval;
retval = get_attr_dir( z->name, &attrbuff, &attrsize );
if( retval != 0 ) {
return ZE_OPEN;
}
if( attrsize == 0 ) {
return ZE_OK;
}
if( attrbuff == NULL ) {
return ZE_LOGIC;
}
/* Check for way too much data. */
if( attrsize > (off_t)ULONG_MAX ) {
zipwarn( "uncompressed attributes truncated", "" );
attrsize = (off_t)(ULONG_MAX - MEMCOMPRESS_OVERHEAD);
}
}
if( verbose ) {
printf( "\t[in=%lu]", (unsigned long)attrsize );
}
/* Try compressing the data */
compbuff = (char *)malloc( (size_t)attrsize + MEMCOMPRESS_OVERHEAD );
if( compbuff == NULL ) {
return ZE_MEM;
}
compsize = memcompress( compbuff,
(size_t)attrsize + MEMCOMPRESS_OVERHEAD,
attrbuff,
(size_t)attrsize );
if( verbose ) {
printf( " [out=%u]", compsize );
}
/* Attempt to optimise very small attributes. */
if( compsize > attrsize ) {
free( compbuff );
compsize = (ush)attrsize;
compbuff = attrbuff;
flags = EB_BE_FL_NATURAL;
} else {
free( attrbuff );
}
/* Check to see if we really have enough room in the EF for the data. */
if( ( z->ext + compsize + EB_L_BE_LEN ) > USHRT_MAX ) {
compsize = USHRT_MAX - EB_L_BE_LEN - z->ext;
}
/* Allocate memory for the local and central extra fields. */
if( z->extra && z->ext != 0 ) {
l_ef = (char *)realloc( z->extra, z->ext + EB_L_BE_SIZE + compsize );
} else {
l_ef = (char *)malloc( EB_L_BE_SIZE + compsize );
z->ext = 0;
}
if( l_ef == NULL ) {
free( compbuff );
return ZE_MEM;
}
z->extra = l_ef;
l_ef += z->ext;
if( z->cextra && z->cext != 0 ) {
c_ef = (char *)realloc( z->cextra, z->cext + EB_C_BE_SIZE );
} else {
c_ef = (char *)malloc( EB_C_BE_SIZE );
z->cext = 0;
}
if( c_ef == NULL ) {
free( compbuff );
return ZE_MEM;
}
z->cextra = c_ef;
c_ef += z->cext;
/* Now add the local version of the field. */
*l_ef++ = 'B';
*l_ef++ = 'e';
*l_ef++ = (char)(compsize + EB_L_BE_LEN);
*l_ef++ = (char)((compsize + EB_L_BE_LEN) >> 8);
*l_ef++ = (char)((unsigned long)attrsize);
*l_ef++ = (char)((unsigned long)attrsize >> 8);
*l_ef++ = (char)((unsigned long)attrsize >> 16);
*l_ef++ = (char)((unsigned long)attrsize >> 24);
*l_ef++ = flags;
memcpy( l_ef, compbuff, (size_t)compsize );
z->ext += EB_L_BE_SIZE + compsize;
/* And the central version. */
*c_ef++ = 'B';
*c_ef++ = 'e';
*c_ef++ = (char)(EB_C_BE_LEN);
*c_ef++ = (char)(EB_C_BE_LEN >> 8);
*c_ef++ = (char)compsize;
*c_ef++ = (char)(compsize >> 8);
*c_ef++ = (char)(compsize >> 16);
*c_ef++ = (char)(compsize >> 24);
*c_ef++ = flags;
z->cext += EB_C_BE_SIZE;
free( compbuff );
return ZE_OK;
}
/* Extra field info:
- 'UT' - UNIX time extra field
- 'Ux' - UNIX uid/gid extra field
- 'Be' - BeOS file attributes extra field
This is done the same way ../unix/unix.c stores the 'UT'/'Ux' fields
(full data in local header, only modification time in central header),
with the 'Be' field added to the end and the size of the 'Be' field
in the central header.
See the end of beos/osdep.h for a simple explanation of the 'Be' EF
layout.
*/
int set_extra_field(z, z_utim)
struct zlist far *z;
iztimes *z_utim;
/* store full data in local header but just modification time stamp info
in central header */
{
int retval;
/* Tell picky compilers to shut up about unused variables. */
z_utim = z_utim;
/* Check to make sure z is valid. */
if( z == NULL ) {
return ZE_LOGIC;
}
/* This function is much simpler now that I've moved the extra fields */
/* out... it simplified the 'Be' code, too. */
retval = add_UT_ef( z );
if( retval != ZE_OK ) {
return retval;
}
retval = add_Ux_ef( z );
if( retval != ZE_OK ) {
return retval;
}
retval = add_Be_ef( z );
if( retval != ZE_OK ) {
return retval;
}
return ZE_OK;
}
/* ---------------------------------------------------------------------- */
/* Set a file's MIME type. */
void setfiletype( const char *file, const char *type )
{
int fd;
attr_info fa;
ssize_t wrote_bytes;
fd = open( file, O_RDWR );
if( fd < 0 ) {
zipwarn( "can't open zipfile to write file type", "" );
return;
}
fa.type = B_MIME_STRING_TYPE;
fa.size = (off_t)(strlen( type ) + 1);
wrote_bytes = fs_write_attr( fd, BE_FILE_TYPE_NAME, fa.type, 0,
type, fa.size );
if( wrote_bytes != (ssize_t)fa.size ) {
zipwarn( "couldn't write complete file type", "" );
}
close( fd );
}
int deletedir(d)
char *d; /* directory to delete */
/* Delete the directory *d if it is empty, do nothing otherwise.
Return the result of rmdir(), delete(), or system().
For VMS, d must be in format [x.y]z.dir;1 (not [x.y.z]).
*/
{
# ifdef NO_RMDIR
/* code from Greg Roelofs, who horked it from Mark Edwards (unzip) */
int r, len;
char *s; /* malloc'd string for system command */
len = strlen(d);
if ((s = malloc(len + 34)) == NULL)
return 127;
sprintf(s, "IFS=\" \t\n\" /bin/rmdir %s 2>/dev/null", d);
r = system(s);
free(s);
return r;
# else /* !NO_RMDIR */
return rmdir(d);
# endif /* ?NO_RMDIR */
}
#endif /* !UTIL */
/******************************/
/* Function version_local() */
/******************************/
void version_local()
{
static ZCONST char CompiledWith[] = "Compiled with %s%s for %s%s%s%s.\n\n";
printf(CompiledWith,
#ifdef __MWERKS__
"Metrowerks CodeWarrior", "",
#else
# ifdef __GNUC__
"gcc ", __VERSION__,
# endif
#endif
"BeOS",
#ifdef __POWERPC__
" (PowerPC)",
#else
# ifdef __INTEL__
" (x86)",
# else
" (UNKNOWN!)",
# endif
#endif
#ifdef __DATE__
" on ", __DATE__
#else
"", ""
#endif
);
} /* end function version_local() */

View File

@ -1,59 +0,0 @@
/*
Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 1999-Oct-05 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <support/Errors.h> /* for B_NO_ERROR */
#define USE_EF_UT_TIME /* Enable use of "UT" extra field time info */
#define EB_L_BE_LEN 5 /* min size is an unsigned long and flag */
#define EB_C_BE_LEN 5 /* Length of data in local EF and flag. */
#define EB_BE_FL_NATURAL 0x01 /* data is 'natural' (not compressed) */
#define EB_BE_FL_BADBITS 0xfe /* bits currently undefined */
#ifndef ZP_NEED_MEMCOMPR
# define ZP_NEED_MEMCOMPR
#endif
/* Set a file's MIME type. */
#define BE_FILE_TYPE_NAME "BEOS:TYPE"
void setfiletype( const char *file, const char *type );
/*
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_NATURAL = 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_NATURAL, 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 (big-endian)
attr_data (length in attr_info.size)
*/

View File

@ -1,19 +0,0 @@
/*
Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 1999-Oct-05 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
*/
#ifndef O_RDONLY
# include <fcntl.h>
#endif
#define fhow O_RDONLY
#define fbad (-1)
typedef int ftype;
#define zopen(n,p) open(n,p)
#define zread(f,b,n) read(f,b,n)
#define zclose(f) close(f)
#define zerr(f) (k == (extent)(-1L))
#define zstdin 0

View File

@ -1,2 +0,0 @@
#define UTIL
#include "beos.c"

View File

@ -1,64 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2004-May-22 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of 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 22782 2007-11-01 01:27:31Z korli $ */
#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

@ -1,232 +0,0 @@
/*
Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 1999-Oct-05 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.cdrom.com/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, ulg 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 */

View File

@ -1,227 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2004-May-22 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of 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 22782 2007-11-01 01:27:31Z korli $ */
/*
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 */

View File

@ -1,598 +0,0 @@
/*
Copyright (c) 1990-2006 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 or later
(the contents of which are also included in (un)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]
The main encryption/decryption source code for Info-Zip software was
originally written in Europe. To the best of our knowledge, it can
be freely distributed in both source and object forms from any country,
including the USA under License Exception TSU of the U.S. Export
Administration Regulations (section 740.13(e)) of 6 June 2002.
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;
/* Update number of bytes written to output file */
tempzn += (4 + LOCHEAD) + z->nam + z->ext + z->siz;
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 */
{
#ifdef ZIP10
int c0 /* byte preceding the last input byte */
#endif
int c1; /* last input byte */
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--) {
#ifdef ZIP10
c0 = c1;
#endif
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
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;
/* Update number of bytes written to output file */
tempzn += (4 + LOCHEAD) + z->nam + z->ext + z->siz;
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.
*
* A bug has been found when encrypting large files. See trees.c
* for details and the fix.
*/
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 */

View File

@ -1,178 +0,0 @@
/*
Copyright (c) 1990-2006 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 or later
(the contents of which are also included in (un)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]
The main encryption/decryption source code for Info-Zip software was
originally written in Europe. To the best of our knowledge, it can
be freely distributed in both source and object forms from any country,
including the USA under License Exception TSU of the U.S. Export
Administration Regulations (section 740.13(e)) of 6 June 2002.
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 compiling UnZipSFX stub, to minimize size
- full crypt code when used to compile Zip, 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(SFX)
# define CRYPT 1 /* full version for zip and main unzip */
#else
# define CRYPT 0 /* dummy version for unzip sfx */
#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 91
#ifdef CR_BETA
# define CR_BETA_VER "a BETA"
# define CR_VERSION "2.91a BETA"
# define CR_VERSION_DATE "31 May 2006" /* last real code change */
#else
# define CR_BETA_VER ""
# define CR_VERSION "2.91"
# define CR_VERSION_DATE "31 May 2006" /* 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 */

View File

@ -1,2 +0,0 @@
#define UTIL
#include "crypt.c"

View File

@ -1,908 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 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
*/
/*
* deflate.c by Jean-loup Gailly.
*
* PURPOSE
*
* Identify new text as repetitions of old text within a fixed-
* length sliding window trailing behind the new text.
*
* DISCUSSION
*
* The "deflation" process depends on being able to identify portions
* of the input text which are identical to earlier input (within a
* sliding window trailing behind the input currently being processed).
*
* The most straightforward technique turns out to be the fastest for
* most input files: try all possible matches and select the longest.
* The key feature of this algorithm is that insertions into the string
* dictionary are very simple and thus fast, and deletions are avoided
* completely. Insertions are performed at each input character, whereas
* string matches are performed only when the previous match ends. So it
* is preferable to spend more time in matches to allow very fast string
* insertions and avoid deletions. The matching algorithm for small
* strings is inspired from that of Rabin & Karp. A brute force approach
* is used to find longer strings when a small match has been found.
* A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
* (by Leonid Broukhis).
* A previous version of this file used a more sophisticated algorithm
* (by Fiala and Greene) which is guaranteed to run in linear amortized
* time, but has a larger average cost, uses more memory and is patented.
* However the F&G algorithm may be faster for some highly redundant
* files if the parameter max_chain_length (described below) is too large.
*
* ACKNOWLEDGEMENTS
*
* The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
* I found it in 'freeze' written by Leonid Broukhis.
* Thanks to many info-zippers for bug reports and testing.
*
* REFERENCES
*
* APPNOTE.TXT documentation file in PKZIP 1.93a distribution.
*
* A description of the Rabin and Karp algorithm is given in the book
* "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
*
* Fiala,E.R., and Greene,D.H.
* Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
*
* INTERFACE
*
* void lm_init (int pack_level, ush *flags)
* Initialize the "longest match" routines for a new file
*
* ulg deflate (void)
* Processes a new input file and return its compressed length. Sets
* the compressed length, crc, deflate flags and internal file
* attributes.
*/
#define __DEFLATE_C
#include "zip.h"
#ifndef USE_ZLIB
/* ===========================================================================
* Configuration parameters
*/
/* Compile with MEDIUM_MEM to reduce the memory requirements or
* with SMALL_MEM to use as little memory as possible. Use BIG_MEM if the
* entire input file can be held in memory (not possible on 16 bit systems).
* Warning: defining these symbols affects HASH_BITS (see below) and thus
* affects the compression ratio. The compressed output
* is still correct, and might even be smaller in some cases.
*/
#ifdef SMALL_MEM
# define HASH_BITS 13 /* Number of bits used to hash strings */
#endif
#ifdef MEDIUM_MEM
# define HASH_BITS 14
#endif
#ifndef HASH_BITS
# define HASH_BITS 15
/* For portability to 16 bit machines, do not use values above 15. */
#endif
#define HASH_SIZE (unsigned)(1<<HASH_BITS)
#define HASH_MASK (HASH_SIZE-1)
#define WMASK (WSIZE-1)
/* HASH_SIZE and WSIZE must be powers of two */
#define NIL 0
/* Tail of hash chains */
#define FAST 4
#define SLOW 2
/* speed options for the general purpose bit flag */
#ifndef TOO_FAR
# define TOO_FAR 4096
#endif
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
#if (defined(ASMV) && !defined(MSDOS16) && defined(DYN_ALLOC))
error: DYN_ALLOC not yet supported in match.S or match32.asm
#endif
#ifdef MEMORY16
# define MAXSEG_64K
#endif
/* ===========================================================================
* Local data used by the "longest match" routines.
*/
#if defined(MMAP) || defined(BIG_MEM)
typedef unsigned Pos; /* must be at least 32 bits */
#else
typedef ush Pos;
#endif
typedef unsigned IPos;
/* A Pos is an index in the character window. We use short instead of int to
* save space in the various tables. IPos is used only for parameter passing.
*/
#ifndef DYN_ALLOC
uch window[2L*WSIZE];
/* Sliding window. Input bytes are read into the second half of the window,
* and move to the first half later to keep a dictionary of at least WSIZE
* bytes. With this organization, matches are limited to a distance of
* WSIZE-MAX_MATCH bytes, but this ensures that IO is always
* performed with a length multiple of the block size. Also, it limits
* the window size to 64K, which is quite useful on MSDOS.
* To do: limit the window size to WSIZE+CBSZ if SMALL_MEM (the code would
* be less efficient since the data would have to be copied WSIZE/CBSZ times)
*/
Pos prev[WSIZE];
/* Link to older string with same hash index. To limit the size of this
* array to 64K, this link is maintained only for the last 32K strings.
* An index in this array is thus a window index modulo 32K.
*/
Pos head[HASH_SIZE];
/* Heads of the hash chains or NIL. If your compiler thinks that
* HASH_SIZE is a dynamic value, recompile with -DDYN_ALLOC.
*/
#else
uch far * near window = NULL;
Pos far * near prev = NULL;
Pos far * near head;
#endif
ulg window_size;
/* window size, 2*WSIZE except for MMAP or BIG_MEM, where it is the
* input file length plus MIN_LOOKAHEAD.
*/
long block_start;
/* window position at the beginning of the current output block. Gets
* negative when the window is moved backwards.
*/
local int sliding;
/* Set to false when the input file is already in memory */
local unsigned ins_h; /* hash index of string to be inserted */
#define H_SHIFT ((HASH_BITS+MIN_MATCH-1)/MIN_MATCH)
/* Number of bits by which ins_h and del_h must be shifted at each
* input step. It must be such that after MIN_MATCH steps, the oldest
* byte no longer takes part in the hash key, that is:
* H_SHIFT * MIN_MATCH >= HASH_BITS
*/
unsigned int near prev_length;
/* Length of the best match at previous step. Matches not greater than this
* are discarded. This is used in the lazy match evaluation.
*/
unsigned near strstart; /* start of string to insert */
unsigned near match_start; /* start of matching string */
local int eofile; /* flag set at end of input file */
local unsigned lookahead; /* number of valid bytes ahead in window */
unsigned near max_chain_length;
/* To speed up deflation, hash chains are never searched beyond this length.
* A higher limit improves compression ratio but degrades the speed.
*/
local unsigned int max_lazy_match;
/* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression
* levels >= 4.
*/
#define max_insert_length max_lazy_match
/* Insert new strings in the hash table only if the match length
* is not greater than this length. This saves time but degrades compression.
* max_insert_length is used only for compression levels <= 3.
*/
unsigned near good_match;
/* Use a faster search when the previous match is longer than this */
#ifdef FULL_SEARCH
# define nice_match MAX_MATCH
#else
int near nice_match; /* Stop searching when current match exceeds this */
#endif
/* Values for max_lazy_match, good_match, nice_match and max_chain_length,
* depending on the desired pack level (0..9). The values given below have
* been tuned to exclude worst case performance for pathological files.
* Better values may be found for specific files.
*/
typedef struct config {
ush good_length; /* reduce lazy search above this match length */
ush max_lazy; /* do not perform lazy search above this match length */
ush nice_length; /* quit search above this match length */
ush max_chain;
} config;
local config configuration_table[10] = {
/* good lazy nice chain */
/* 0 */ {0, 0, 0, 0}, /* store only */
/* 1 */ {4, 4, 8, 4}, /* maximum speed, no lazy matches */
/* 2 */ {4, 5, 16, 8},
/* 3 */ {4, 6, 32, 32},
/* 4 */ {4, 4, 16, 16}, /* lazy matches */
/* 5 */ {8, 16, 32, 32},
/* 6 */ {8, 16, 128, 128},
/* 7 */ {8, 32, 128, 256},
/* 8 */ {32, 128, 258, 1024},
/* 9 */ {32, 258, 258, 4096}}; /* maximum compression */
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
* meaning.
*/
#define EQUAL 0
/* result of memcmp for equal strings */
/* ===========================================================================
* Prototypes for local functions.
*/
local void fill_window OF((void));
local ulg deflate_fast OF((void));
int longest_match OF((IPos cur_match));
#if defined(ASMV) && !defined(RISCOS)
void match_init OF((void)); /* asm code initialization */
#endif
#ifdef DEBUG
local void check_match OF((IPos start, IPos match, int length));
#endif
/* ===========================================================================
* Update a hash value with the given input byte
* IN assertion: all calls to to UPDATE_HASH are made with consecutive
* input characters, so that a running hash key can be computed from the
* previous key instead of complete recalculation each time.
*/
#define UPDATE_HASH(h,c) (h = (((h)<<H_SHIFT) ^ (c)) & HASH_MASK)
/* ===========================================================================
* Insert string s in the dictionary and set match_head to the previous head
* of the hash chain (the most recent string with same hash key). Return
* the previous length of the hash chain.
* IN assertion: all calls to to INSERT_STRING are made with consecutive
* input characters and the first MIN_MATCH bytes of s are valid
* (except for the last MIN_MATCH-1 bytes of the input file).
*/
#define INSERT_STRING(s, match_head) \
(UPDATE_HASH(ins_h, window[(s) + (MIN_MATCH-1)]), \
prev[(s) & WMASK] = match_head = head[ins_h], \
head[ins_h] = (s))
/* ===========================================================================
* Initialize the "longest match" routines for a new file
*
* IN assertion: window_size is > 0 if the input file is already read or
* mmap'ed in the window[] array, 0 otherwise. In the first case,
* window_size is sufficient to contain the whole input file plus
* MIN_LOOKAHEAD bytes (to avoid referencing memory beyond the end
* of window[] when looking for matches towards the end).
*/
void lm_init (pack_level, flags)
int pack_level; /* 0: store, 1: best speed, 9: best compression */
ush *flags; /* general purpose bit flag */
{
register unsigned j;
if (pack_level < 1 || pack_level > 9) error("bad pack level");
/* Do not slide the window if the whole input is already in memory
* (window_size > 0)
*/
sliding = 0;
if (window_size == 0L) {
sliding = 1;
window_size = (ulg)2L*WSIZE;
}
/* Use dynamic allocation if compiler does not like big static arrays: */
#ifdef DYN_ALLOC
if (window == NULL) {
window = (uch far *) zcalloc(WSIZE, 2*sizeof(uch));
if (window == NULL) ziperr(ZE_MEM, "window allocation");
}
if (prev == NULL) {
prev = (Pos far *) zcalloc(WSIZE, sizeof(Pos));
head = (Pos far *) zcalloc(HASH_SIZE, sizeof(Pos));
if (prev == NULL || head == NULL) {
ziperr(ZE_MEM, "hash table allocation");
}
}
#endif /* DYN_ALLOC */
/* Initialize the hash table (avoiding 64K overflow for 16 bit systems).
* prev[] will be initialized on the fly.
*/
head[HASH_SIZE-1] = NIL;
memset((char*)head, NIL, (unsigned)(HASH_SIZE-1)*sizeof(*head));
/* Set the default configuration parameters:
*/
max_lazy_match = configuration_table[pack_level].max_lazy;
good_match = configuration_table[pack_level].good_length;
#ifndef FULL_SEARCH
nice_match = configuration_table[pack_level].nice_length;
#endif
max_chain_length = configuration_table[pack_level].max_chain;
if (pack_level <= 2) {
*flags |= FAST;
} else if (pack_level >= 8) {
*flags |= SLOW;
}
/* ??? reduce max_chain_length for binary files */
strstart = 0;
block_start = 0L;
#if defined(ASMV) && !defined(RISCOS)
match_init(); /* initialize the asm code */
#endif
j = WSIZE;
#ifndef MAXSEG_64K
if (sizeof(int) > 2) j <<= 1; /* Can read 64K in one step */
#endif
lookahead = (*read_buf)((char*)window, j);
if (lookahead == 0 || lookahead == (unsigned)EOF) {
eofile = 1, lookahead = 0;
return;
}
eofile = 0;
/* Make sure that we always have enough lookahead. This is important
* if input comes from a device such as a tty.
*/
if (lookahead < MIN_LOOKAHEAD) fill_window();
ins_h = 0;
for (j=0; j<MIN_MATCH-1; j++) UPDATE_HASH(ins_h, window[j]);
/* If lookahead < MIN_MATCH, ins_h is garbage, but this is
* not important since only literal bytes will be emitted.
*/
}
/* ===========================================================================
* Free the window and hash table
*/
void lm_free()
{
#ifdef DYN_ALLOC
if (window != NULL) {
zcfree(window);
window = NULL;
}
if (prev != NULL) {
zcfree(prev);
zcfree(head);
prev = head = NULL;
}
#endif /* DYN_ALLOC */
}
/* ===========================================================================
* Set match_start to the longest match starting at the given string and
* return its length. Matches shorter or equal to prev_length are discarded,
* in which case the result is equal to prev_length and match_start is
* garbage.
* IN assertions: cur_match is the head of the hash chain for the current
* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
*/
#ifndef ASMV
/* For 80x86 and 680x0 and ARM, an optimized version is in match.asm or
* match.S. The code is functionally equivalent, so you can use the C version
* if desired.
*/
int longest_match(cur_match)
IPos cur_match; /* current match */
{
unsigned chain_length = max_chain_length; /* max hash chain length */
register uch far *scan = window + strstart; /* current string */
register uch far *match; /* matched string */
register int len; /* length of current match */
int best_len = prev_length; /* best match length so far */
IPos limit = strstart > (IPos)MAX_DIST ? strstart - (IPos)MAX_DIST : NIL;
/* Stop when cur_match becomes <= limit. To simplify the code,
* we prevent matches with the string of window index 0.
*/
/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
* It is easy to get rid of this optimization if necessary.
*/
#if HASH_BITS < 8 || MAX_MATCH != 258
error: Code too clever
#endif
#ifdef UNALIGNED_OK
/* Compare two bytes at a time. Note: this is not always beneficial.
* Try with and without -DUNALIGNED_OK to check.
*/
register uch far *strend = window + strstart + MAX_MATCH - 1;
register ush scan_start = *(ush far *)scan;
register ush scan_end = *(ush far *)(scan+best_len-1);
#else
register uch far *strend = window + strstart + MAX_MATCH;
register uch scan_end1 = scan[best_len-1];
register uch scan_end = scan[best_len];
#endif
/* Do not waste too much time if we already have a good match: */
if (prev_length >= good_match) {
chain_length >>= 2;
}
Assert(strstart <= window_size-MIN_LOOKAHEAD, "insufficient lookahead");
do {
Assert(cur_match < strstart, "no future");
match = window + cur_match;
/* Skip to next match if the match length cannot increase
* or if the match length is less than 2:
*/
#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
/* This code assumes sizeof(unsigned short) == 2. Do not use
* UNALIGNED_OK if your compiler uses a different size.
*/
if (*(ush far *)(match+best_len-1) != scan_end ||
*(ush far *)match != scan_start) continue;
/* It is not necessary to compare scan[2] and match[2] since they are
* always equal when the other bytes match, given that the hash keys
* are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
* strstart+3, +5, ... up to strstart+257. We check for insufficient
* lookahead only every 4th comparison; the 128th check will be made
* at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
* necessary to put more guard bytes at the end of the window, or
* to check more often for insufficient lookahead.
*/
scan++, match++;
do {
} while (*(ush far *)(scan+=2) == *(ush far *)(match+=2) &&
*(ush far *)(scan+=2) == *(ush far *)(match+=2) &&
*(ush far *)(scan+=2) == *(ush far *)(match+=2) &&
*(ush far *)(scan+=2) == *(ush far *)(match+=2) &&
scan < strend);
/* The funny "do {}" generates better code on most compilers */
/* Here, scan <= window+strstart+257 */
Assert(scan <= window+(unsigned)(window_size-1), "wild scan");
if (*scan == *match) scan++;
len = (MAX_MATCH - 1) - (int)(strend-scan);
scan = strend - (MAX_MATCH-1);
#else /* UNALIGNED_OK */
if (match[best_len] != scan_end ||
match[best_len-1] != scan_end1 ||
*match != *scan ||
*++match != scan[1]) continue;
/* The check at best_len-1 can be removed because it will be made
* again later. (This heuristic is not always a win.)
* It is not necessary to compare scan[2] and match[2] since they
* are always equal when the other bytes match, given that
* the hash keys are equal and that HASH_BITS >= 8.
*/
scan += 2, match++;
/* We check for insufficient lookahead only every 8th comparison;
* the 256th check will be made at strstart+258.
*/
do {
} while (*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
*++scan == *++match && *++scan == *++match &&
scan < strend);
Assert(scan <= window+(unsigned)(window_size-1), "wild scan");
len = MAX_MATCH - (int)(strend - scan);
scan = strend - MAX_MATCH;
#endif /* UNALIGNED_OK */
if (len > best_len) {
match_start = cur_match;
best_len = len;
if (len >= nice_match) break;
#ifdef UNALIGNED_OK
scan_end = *(ush far *)(scan+best_len-1);
#else
scan_end1 = scan[best_len-1];
scan_end = scan[best_len];
#endif
}
} while ((cur_match = prev[cur_match & WMASK]) > limit
&& --chain_length != 0);
return best_len;
}
#endif /* ASMV */
#ifdef DEBUG
/* ===========================================================================
* Check that the match at match_start is indeed a match.
*/
local void check_match(start, match, length)
IPos start, match;
int length;
{
/* check that the match is indeed a match */
if (memcmp((char*)window + match,
(char*)window + start, length) != EQUAL) {
fprintf(stderr,
" start %d, match %d, length %d\n",
start, match, length);
error("invalid match");
}
if (verbose > 1) {
fprintf(stderr,"\\[%d,%d]", start-match, length);
#ifndef WINDLL
do { putc(window[start++], stderr); } while (--length != 0);
#else
do { fprintf(stdout,"%c",window[start++]); } while (--length != 0);
#endif
}
}
#else
# define check_match(start, match, length)
#endif
/* ===========================================================================
* Flush the current block, with given end-of-file flag.
* IN assertion: strstart is set to the end of the current match.
*/
#define FLUSH_BLOCK(eof) \
flush_block(block_start >= 0L ? (char*)&window[(unsigned)block_start] : \
(char*)NULL, (ulg)strstart - (ulg)block_start, (eof))
/* ===========================================================================
* Fill the window when the lookahead becomes insufficient.
* Updates strstart and lookahead, and sets eofile if end of input file.
*
* IN assertion: lookahead < MIN_LOOKAHEAD && strstart + lookahead > 0
* OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
* At least one byte has been read, or eofile is set; file reads are
* performed for at least two bytes (required for the translate_eol option).
*/
local void fill_window()
{
register unsigned n, m;
unsigned more; /* Amount of free space at the end of the window. */
do {
more = (unsigned)(window_size - (ulg)lookahead - (ulg)strstart);
/* If the window is almost full and there is insufficient lookahead,
* move the upper half to the lower one to make room in the upper half.
*/
if (more == (unsigned)EOF) {
/* Very unlikely, but possible on 16 bit machine if strstart == 0
* and lookahead == 1 (input done one byte at time)
*/
more--;
/* For MMAP or BIG_MEM, the whole input file is already in memory so
* we must not perform sliding. We must however call (*read_buf)() in
* order to compute the crc, update lookahead and possibly set eofile.
*/
} else if (strstart >= WSIZE+MAX_DIST && sliding) {
#ifdef FORCE_METHOD
/* When methods "stored" or "store_block" are requested, the
* current block must be flushed before sliding the window.
*/
if (level <= 2) FLUSH_BLOCK(0), block_start = strstart;
#endif
/* By the IN assertion, the window is not empty so we can't confuse
* more == 0 with more == 64K on a 16 bit machine.
*/
memcpy((char*)window, (char*)window+WSIZE, (unsigned)WSIZE);
match_start -= WSIZE;
strstart -= WSIZE; /* we now have strstart >= MAX_DIST: */
block_start -= (long) WSIZE;
for (n = 0; n < HASH_SIZE; n++) {
m = head[n];
head[n] = (Pos)(m >= WSIZE ? m-WSIZE : NIL);
}
for (n = 0; n < WSIZE; n++) {
m = prev[n];
prev[n] = (Pos)(m >= WSIZE ? m-WSIZE : NIL);
/* If n is not on any hash chain, prev[n] is garbage but
* its value will never be used.
*/
}
more += WSIZE;
#ifndef WINDLL
if (verbose) putc('.', stderr);
#else
if (verbose) fprintf(stdout,"%c",'.');
#endif
}
if (eofile) return;
/* If there was no sliding:
* strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
* more == window_size - lookahead - strstart
* => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
* => more >= window_size - 2*WSIZE + 2
* In the MMAP or BIG_MEM case (not yet supported in gzip),
* window_size == input_size + MIN_LOOKAHEAD &&
* strstart + lookahead <= input_size => more >= MIN_LOOKAHEAD.
* Otherwise, window_size == 2*WSIZE so more >= 2.
* If there was sliding, more >= WSIZE. So in all cases, more >= 2.
*/
Assert(more >= 2, "more < 2");
n = (*read_buf)((char*)window+strstart+lookahead, more);
if (n == 0 || n == (unsigned)EOF) {
eofile = 1;
} else {
lookahead += n;
}
} while (lookahead < MIN_LOOKAHEAD && !eofile);
}
/* ===========================================================================
* Processes a new input file and return its compressed length. This
* function does not perform lazy evaluation of matches and inserts
* new strings in the dictionary only for unmatched strings or for short
* matches. It is used only for the fast compression options.
*/
local ulg deflate_fast()
{
IPos hash_head = NIL; /* head of the hash chain */
int flush; /* set if current block must be flushed */
unsigned match_length = 0; /* length of best match */
prev_length = MIN_MATCH-1;
while (lookahead != 0) {
/* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain:
*/
#ifndef DEFL_UNDETERM
if (lookahead >= MIN_MATCH)
#endif
INSERT_STRING(strstart, hash_head);
/* Find the longest match, discarding those <= prev_length.
* At this point we have always match_length < MIN_MATCH
*/
if (hash_head != NIL && strstart - hash_head <= MAX_DIST) {
/* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file).
*/
#ifndef HUFFMAN_ONLY
# ifndef DEFL_UNDETERM
/* Do not look for matches beyond the end of the input.
* This is necessary to make deflate deterministic.
*/
if ((unsigned)nice_match > lookahead) nice_match = (int)lookahead;
# endif
match_length = longest_match (hash_head);
/* longest_match() sets match_start */
if (match_length > lookahead) match_length = lookahead;
#endif
}
if (match_length >= MIN_MATCH) {
check_match(strstart, match_start, match_length);
flush = ct_tally(strstart-match_start, match_length - MIN_MATCH);
lookahead -= match_length;
/* Insert new strings in the hash table only if the match length
* is not too large. This saves time but degrades compression.
*/
if (match_length <= max_insert_length
#ifndef DEFL_UNDETERM
&& lookahead >= MIN_MATCH
#endif
) {
match_length--; /* string at strstart already in hash table */
do {
strstart++;
INSERT_STRING(strstart, hash_head);
/* strstart never exceeds WSIZE-MAX_MATCH, so there are
* always MIN_MATCH bytes ahead.
*/
#ifdef DEFL_UNDETERM
/* If lookahead < MIN_MATCH these bytes are garbage,
* but it does not matter since the next lookahead bytes
* will be emitted as literals.
*/
#endif
} while (--match_length != 0);
strstart++;
} else {
strstart += match_length;
match_length = 0;
ins_h = window[strstart];
UPDATE_HASH(ins_h, window[strstart+1]);
#if MIN_MATCH != 3
Call UPDATE_HASH() MIN_MATCH-3 more times
#endif
}
} else {
/* No match, output a literal byte */
Tracevv((stderr,"%c",window[strstart]));
flush = ct_tally (0, window[strstart]);
lookahead--;
strstart++;
}
if (flush) FLUSH_BLOCK(0), block_start = strstart;
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the
* string following the next match.
*/
if (lookahead < MIN_LOOKAHEAD) fill_window();
}
return FLUSH_BLOCK(1); /* eof */
}
/* ===========================================================================
* Same as above, but achieves better compression. We use a lazy
* evaluation for matches: a match is finally adopted only if there is
* no better match at the next window position.
*/
ulg deflate()
{
IPos hash_head = NIL; /* head of hash chain */
IPos prev_match; /* previous match */
int flush; /* set if current block must be flushed */
int match_available = 0; /* set if previous match exists */
register unsigned match_length = MIN_MATCH-1; /* length of best match */
#ifdef DEBUG
extern ulg isize; /* byte length of input file, for debug only */
#endif
if (level <= 3) return deflate_fast(); /* optimized for speed */
/* Process the input block. */
while (lookahead != 0) {
/* Insert the string window[strstart .. strstart+2] in the
* dictionary, and set hash_head to the head of the hash chain:
*/
#ifndef DEFL_UNDETERM
if (lookahead >= MIN_MATCH)
#endif
INSERT_STRING(strstart, hash_head);
/* Find the longest match, discarding those <= prev_length.
*/
prev_length = match_length, prev_match = match_start;
match_length = MIN_MATCH-1;
if (hash_head != NIL && prev_length < max_lazy_match &&
strstart - hash_head <= MAX_DIST) {
/* To simplify the code, we prevent matches with the string
* of window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file).
*/
#ifndef HUFFMAN_ONLY
# ifndef DEFL_UNDETERM
/* Do not look for matches beyond the end of the input.
* This is necessary to make deflate deterministic.
*/
if ((unsigned)nice_match > lookahead) nice_match = (int)lookahead;
# endif
match_length = longest_match (hash_head);
/* longest_match() sets match_start */
if (match_length > lookahead) match_length = lookahead;
#endif
#ifdef FILTERED
/* Ignore matches of length <= 5 */
if (match_length <= 5) {
#else
/* Ignore a length 3 match if it is too distant: */
if (match_length == MIN_MATCH && strstart-match_start > TOO_FAR){
#endif
/* If prev_match is also MIN_MATCH, match_start is garbage
* but we will ignore the current match anyway.
*/
match_length = MIN_MATCH-1;
}
}
/* If there was a match at the previous step and the current
* match is not better, output the previous match:
*/
if (prev_length >= MIN_MATCH && match_length <= prev_length) {
#ifndef DEFL_UNDETERM
unsigned max_insert = strstart + lookahead - MIN_MATCH;
#endif
check_match(strstart-1, prev_match, prev_length);
flush = ct_tally(strstart-1-prev_match, prev_length - MIN_MATCH);
/* Insert in hash table all strings up to the end of the match.
* strstart-1 and strstart are already inserted.
*/
lookahead -= prev_length-1;
prev_length -= 2;
#ifndef DEFL_UNDETERM
do {
if (++strstart <= max_insert) {
INSERT_STRING(strstart, hash_head);
/* strstart never exceeds WSIZE-MAX_MATCH, so there are
* always MIN_MATCH bytes ahead.
*/
}
} while (--prev_length != 0);
strstart++;
#else /* DEFL_UNDETERM */
do {
strstart++;
INSERT_STRING(strstart, hash_head);
/* strstart never exceeds WSIZE-MAX_MATCH, so there are
* always MIN_MATCH bytes ahead. If lookahead < MIN_MATCH
* these bytes are garbage, but it does not matter since the
* next lookahead bytes will always be emitted as literals.
*/
} while (--prev_length != 0);
strstart++;
#endif /* ?DEFL_UNDETERM */
match_available = 0;
match_length = MIN_MATCH-1;
if (flush) FLUSH_BLOCK(0), block_start = strstart;
} else if (match_available) {
/* If there was no match at the previous position, output a
* single literal. If there was a match but the current match
* is longer, truncate the previous match to a single literal.
*/
Tracevv((stderr,"%c",window[strstart-1]));
if (ct_tally (0, window[strstart-1])) {
FLUSH_BLOCK(0), block_start = strstart;
}
strstart++;
lookahead--;
} else {
/* There is no previous match to compare with, wait for
* the next step to decide.
*/
match_available = 1;
strstart++;
lookahead--;
}
Assert(strstart <= isize && lookahead <= isize, "a bit too far");
/* Make sure that we always have enough lookahead, except
* at the end of the input file. We need MAX_MATCH bytes
* for the next match, plus MIN_MATCH bytes to insert the
* string following the next match.
*/
if (lookahead < MIN_LOOKAHEAD) fill_window();
}
if (match_available) ct_tally (0, window[strstart-1]);
return FLUSH_BLOCK(1); /* eof */
}
#endif /* !USE_ZLIB */

View File

@ -1,284 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2004-May-22 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of 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 */

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +0,0 @@
#define UTIL
#include "fileio.c"

View File

@ -1,97 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2004-May-22 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*
* globals.c by Mark Adler
*/
#define __GLOBALS_C
#define GLOBALS /* include definition of errors[] in zip.h */
#ifndef UTIL
#define UTIL /* do not declare the read_buf variable */
#endif
#include "zip.h"
/* Handy place to build error messages */
char errbuf[FNMAX+81];
/* Argument processing globals */
int recurse = 0; /* 1=recurse into directories encountered */
int dispose = 0; /* 1=remove files after put in zip file */
int pathput = 1; /* 1=store path with name */
#ifdef RISCOS
int scanimage = 1; /* 1=scan through image files */
#endif
int method = BEST; /* one of BEST, DEFLATE (only), or STORE (only) */
int dosify = 0; /* 1=make new entries look like MSDOS */
int verbose = 0; /* 1=report oddities in zip file structure */
int fix = 0; /* 1=fix the zip file */
int adjust = 0; /* 1=adjust offsets for sfx'd file (keep preamble) */
int level = 6; /* 0=fastest compression, 9=best compression */
int translate_eol = 0; /* Translate end-of-line LF -> CR LF */
#ifdef VMS
int vmsver = 0; /* 1=append VMS version number to file names */
int vms_native = 0; /* 1=store in VMS format */
#endif /* VMS */
#if defined(OS2) || defined(WIN32)
int use_longname_ea = 0; /* 1=use the .LONGNAME EA as the file's name */
#endif
int hidden_files = 0; /* process hidden and system files */
int volume_label = 0; /* add volume label */
int dirnames = 1; /* include directory entries by default */
int linkput = 0; /* 1=store symbolic links as such */
int noisy = 1; /* 0=quiet operation */
int extra_fields = 1; /* 0=do not create extra fields */
#ifdef NTSD_EAS
int use_privileges = 0; /* 1=use security privilege overrides */
#endif
#ifndef RISCOS
#ifndef QDOS
#ifndef TANDEM
char *special = ".Z:.zip:.zoo:.arc:.lzh:.arj"; /* List of special suffixes */
#else /* TANDEM */
char *special = " Z: zip: zoo: arc: lzh: arj"; /* List of special suffixes */
#endif
#else /* QDOS */
char *special = "_Z:_zip:_zoo:_arc:_lzh:_arj"; /* List of special suffixes */
#endif
#else /* RISCOS */
char *special = "DDC:D96:68E";
#endif /* ?RISCOS */
char *key = NULL; /* Scramble password if scrambling */
char *tempath = NULL; /* Path for temporary files */
FILE *mesg; /* stdout by default, stderr for piping */
/* Zip file globals */
char *zipfile; /* New or existing zip archive (zip file) */
ulg zipbeg; /* Starting offset of zip structures */
ulg cenbeg; /* Starting offset of central directory */
struct zlist far *zfiles = NULL; /* Pointer to list of files in zip file */
extent zcount; /* Number of files in zip file */
extent zcomlen; /* Length of zip file comment */
char *zcomment = NULL; /* Zip file comment (not zero-terminated) */
struct zlist far **zsort; /* List of files sorted by name */
ulg tempzn; /* Count of bytes written to output zip file */
/* Files to operate on that are not in zip file */
struct flist far *found = NULL; /* List of names found */
struct flist far * far *fnxt = &found;
/* Where to put next name in found list */
extent fcount; /* Count of files in list */
/* Patterns to be matched */
struct plist *patterns = NULL; /* List of patterns to be matched */
unsigned pcount = 0; /* number of patterns */
unsigned icount = 0; /* number of include only patterns */
unsigned Rcount = 0; /* number of -R include patterns */
#ifdef IZ_CHECK_TZ
int zp_tz_is_valid; /* signals "timezone info is available" */
#endif

View File

@ -1,407 +0,0 @@
/*
Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
See the accompanying file LICENSE (the contents of which are also
included in unzip.h, zip.h and wiz.h) for terms of use. If, for
some reason, all of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
*/
/*
* match.s by Jean-loup Gailly. Translated to 32 bit code by Kai Uwe Rommel.
* The 68020 version has been written by Francesco Potorti` <pot@cnuce.cnr.it>
* with adaptations by Carsten Steger <stegerc@informatik.tu-muenchen.de>,
* Andreas Schwab <schwab@lamothe.informatik.uni-dortmund.de> and
* Kristoffer Eriksson <ske@pkmab.se>
*/
/* 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 _prev prev
# define _window window
# define _match_start match_start
# define _prev_length prev_length
# define _good_match good_match
# define _nice_match nice_match
# define _strstart strstart
# define _max_chain_length max_chain_length
# define _match_init match_init
# define _longest_match longest_match
#endif
#ifdef DYN_ALLOC
error: DYN_ALLOC not yet supported in match.s
#endif
/* Use 16-bytes alignment if your assembler supports it. Warning: gas
* uses a log(x) parameter (.align 4 means 16-bytes alignment). On SVR4
* the parameter is a number of bytes.
*/
#ifndef ALIGNMENT
# define ALIGNMENT 4
#endif
#ifndef WSIZE
# define WSIZE 32768
#endif
#define MIN_MATCH 3
#define MAX_MATCH 258
#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1)
#define MAX_DIST (WSIZE - MIN_LOOKAHEAD)
#if defined(i386) || defined(_I386) || defined(_i386) || defined(__i386)
/* This version is for 386 Unix or OS/2 in 32 bit mode.
* Warning: it uses the AT&T syntax: mov source,dest
* This file is only optional. If you want to force the C version,
* add -DNO_ASM to CFLAGS in Makefile and set OBJA to an empty string.
* If you have reduced WSIZE in (g)zip.h, then make sure this is
* assembled with an equivalent -DWSIZE=<whatever>.
* This version assumes static allocation of the arrays (-DDYN_ALLOC not used).
*/
.file "match.S"
.globl _match_init
.globl _longest_match
.text
_match_init:
ret
/*-----------------------------------------------------------------------
* Set match_start to the longest match starting at the given string and
* return its length. Matches shorter or equal to prev_length are discarded,
* in which case the result is equal to prev_length and match_start is
* garbage.
* IN assertions: cur_match is the head of the hash chain for the current
* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
*/
.align ALIGNMENT
_longest_match: /* int longest_match(cur_match) */
#define cur_match 20(%esp)
/* return address */ /* esp+16 */
push %ebp /* esp+12 */
push %edi /* esp+8 */
push %esi /* esp+4 */
push %ebx /* esp */
/*
* match equ esi
* scan equ edi
* chain_length equ ebp
* best_len equ ebx
* limit equ edx
*/
mov cur_match,%esi
mov _strstart,%edx
mov _max_chain_length,%ebp /* chain_length = max_chain_length */
mov %edx,%edi
sub $(MAX_DIST),%edx /* limit = strstart-MAX_DIST */
cld /* string ops increment si and di */
jae limit_ok
sub %edx,%edx /* limit = NIL */
limit_ok:
add $2+_window,%edi /* edi = offset(window+strstart+2) */
mov _prev_length,%ebx /* best_len = prev_length */
movw -2(%edi),%cx /* cx = scan[0..1] */
movw -3(%ebx,%edi),%ax /* ax = scan[best_len-1..best_len] */
cmp _good_match,%ebx /* do we have a good match already? */
jb do_scan
shr $2,%ebp /* chain_length >>= 2 */
jmp do_scan
.align ALIGNMENT
long_loop:
/* at this point, edi == scan+2, esi == cur_match */
movw -3(%ebx,%edi),%ax /* ax = scan[best_len-1..best_len] */
movw -2(%edi),%cx /* cx = scan[0..1] */
short_loop:
/*
* at this point, di == scan+2, si == cur_match,
* ax = scan[best_len-1..best_len] and cx = scan[0..1]
*/
and $(WSIZE-1), %esi
dec %ebp /* --chain_length */
movw _prev(,%esi,2),%si /* cur_match = prev[cur_match] */
/* top word of esi is still 0 */
jz the_end
cmp %edx,%esi /* cur_match <= limit ? */
jbe the_end
do_scan:
cmpw _window-1(%ebx,%esi),%ax/* check match at best_len-1 */
jne short_loop
cmpw _window(%esi),%cx /* check min_match_length match */
jne short_loop
add $2+_window,%esi /* si = match */
mov $((MAX_MATCH>>1)-1),%ecx/* scan for at most MAX_MATCH bytes */
mov %edi,%eax /* ax = scan+2 */
repe; cmpsw /* loop until mismatch */
je maxmatch /* match of length MAX_MATCH? */
mismatch:
movb -2(%edi),%cl /* mismatch on first or second byte? */
xchg %edi,%eax /* edi = scan+2, eax = end of scan */
subb -2(%esi),%cl /* cl = 0 if first bytes equal */
sub %edi,%eax /* eax = len */
sub $2+_window,%esi /* esi = cur_match + len */
sub %eax,%esi /* esi = cur_match */
subb $1,%cl /* set carry if cl == 0 (cannot use DEC) */
adc $0,%eax /* eax = carry ? len+1 : len */
cmp %ebx,%eax /* len > best_len ? */
jle long_loop
mov %esi,_match_start /* match_start = cur_match */
mov %eax,%ebx /* ebx = best_len = len */
#ifdef FULL_SEARCH
cmp $(MAX_MATCH),%eax /* len >= MAX_MATCH ? */
#else
cmp _nice_match,%eax /* len >= nice_match ? */
#endif
jl long_loop
the_end:
mov %ebx,%eax /* result = eax = best_len */
pop %ebx
pop %esi
pop %edi
pop %ebp
ret
.align ALIGNMENT
maxmatch:
cmpsb
jmp mismatch
#else /* !(i386 || _I386 || _i386 || __i386) */
/* ======================== 680x0 version ================================= */
#if defined(m68k)||defined(mc68k)||defined(__mc68000__)||defined(__MC68000__)
# ifndef mc68000
# define mc68000
# endif
#endif
#if defined(__mc68020__) || defined(__MC68020__) || defined(sysV68)
# ifndef mc68020
# define mc68020
# endif
#endif
#if defined(mc68020) || defined(mc68000)
#if (defined(mc68020) || defined(NeXT)) && !defined(UNALIGNED_OK)
# define UNALIGNED_OK
#endif
#ifdef sysV68 /* Try Motorola Delta style */
# define GLOBAL(symbol) global symbol
# define TEXT text
# define FILE(filename) file filename
# define invert_maybe(src,dst) dst,src
# define imm(data) &data
# define reg(register) %register
# define addl add.l
# define addql addq.l
# define blos blo.b
# define bhis bhi.b
# define bras bra.b
# define clrl clr.l
# define cmpmb cmpm.b
# define cmpw cmp.w
# define cmpl cmp.l
# define lslw lsl.w
# define lsrl lsr.l
# define movel move.l
# define movew move.w
# define moveb move.b
# define moveml movem.l
# define subl sub.l
# define subw sub.w
# define subql subq.l
# define IndBase(bd,An) (bd,An)
# define IndBaseNdxl(bd,An,Xn) (bd,An,Xn.l)
# define IndBaseNdxw(bd,An,Xn) (bd,An,Xn.w)
# define predec(An) -(An)
# define postinc(An) (An)+
#else /* default style (Sun 3, NeXT, Amiga, Atari) */
# define GLOBAL(symbol) .globl symbol
# define TEXT .text
# define FILE(filename) .even
# define invert_maybe(src,dst) src,dst
# if defined(sun) || defined(mc68k)
# define imm(data) #data
# else
# define imm(data) \#data
# endif
# define reg(register) register
# define blos bcss
# if defined(sun) || defined(mc68k)
# define movel movl
# define movew movw
# define moveb movb
# endif
# define IndBase(bd,An) An@(bd)
# define IndBaseNdxl(bd,An,Xn) An@(bd,Xn:l)
# define IndBaseNdxw(bd,An,Xn) An@(bd,Xn:w)
# define predec(An) An@-
# define postinc(An) An@+
#endif /* styles */
#define Best_Len reg(d0) /* unsigned */
#define Cur_Match reg(d1) /* Ipos */
#define Loop_Counter reg(d2) /* int */
#define Scan_Start reg(d3) /* unsigned short */
#define Scan_End reg(d4) /* unsigned short */
#define Limit reg(d5) /* IPos */
#define Chain_Length reg(d6) /* unsigned */
#define Scan_Test reg(d7)
#define Scan reg(a0) /* *uch */
#define Match reg(a1) /* *uch */
#define Prev_Address reg(a2) /* *Pos */
#define Scan_Ini reg(a3) /* *uch */
#define Match_Ini reg(a4) /* *uch */
#define Stack_Pointer reg(sp)
GLOBAL (_match_init)
GLOBAL (_longest_match)
TEXT
FILE ("match.S")
_match_init:
rts
/*-----------------------------------------------------------------------
* Set match_start to the longest match starting at the given string and
* return its length. Matches shorter or equal to prev_length are discarded,
* in which case the result is equal to prev_length and match_start is
* garbage.
* IN assertions: cur_match is the head of the hash chain for the current
* string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
*/
/* int longest_match (cur_match) */
#ifdef UNALIGNED_OK
# define pushreg 15928 /* d2-d6/a2-a4 */
# define popreg 7292
#else
# define pushreg 16184 /* d2-d7/a2-a4 */
# define popreg 7420
#endif
_longest_match:
movel IndBase(4,Stack_Pointer),Cur_Match
moveml imm(pushreg),predec(Stack_Pointer)
movel _max_chain_length,Chain_Length
movel _prev_length,Best_Len
movel imm(_prev),Prev_Address
movel imm(_window+MIN_MATCH),Match_Ini
movel _strstart,Limit
movel Match_Ini,Scan_Ini
addl Limit,Scan_Ini
subw imm(MAX_DIST),Limit
bhis L__limit_ok
clrl Limit
L__limit_ok:
cmpl invert_maybe(_good_match,Best_Len)
blos L__length_ok
lsrl imm(2),Chain_Length
L__length_ok:
subql imm(1),Chain_Length
#ifdef UNALIGNED_OK
movew IndBase(-MIN_MATCH,Scan_Ini),Scan_Start
movew IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
#else
moveb IndBase(-MIN_MATCH,Scan_Ini),Scan_Start
lslw imm(8),Scan_Start
moveb IndBase(-MIN_MATCH+1,Scan_Ini),Scan_Start
moveb IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
lslw imm(8),Scan_End
moveb IndBaseNdxw(-MIN_MATCH,Scan_Ini,Best_Len),Scan_End
#endif
bras L__do_scan
L__long_loop:
#ifdef UNALIGNED_OK
movew IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
#else
moveb IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
lslw imm(8),Scan_End
moveb IndBaseNdxw(-MIN_MATCH,Scan_Ini,Best_Len),Scan_End
#endif
L__short_loop:
lslw imm(1),Cur_Match
movew IndBaseNdxl(0,Prev_Address,Cur_Match),Cur_Match
cmpw invert_maybe(Limit,Cur_Match)
dbls Chain_Length,L__do_scan
bras L__return
L__do_scan:
movel Match_Ini,Match
addl Cur_Match,Match
#ifdef UNALIGNED_OK
cmpw invert_maybe(IndBaseNdxw(-MIN_MATCH-1,Match,Best_Len),Scan_End)
bne L__short_loop
cmpw invert_maybe(IndBase(-MIN_MATCH,Match),Scan_Start)
bne L__short_loop
#else
moveb IndBaseNdxw(-MIN_MATCH-1,Match,Best_Len),Scan_Test
lslw imm(8),Scan_Test
moveb IndBaseNdxw(-MIN_MATCH,Match,Best_Len),Scan_Test
cmpw invert_maybe(Scan_Test,Scan_End)
bne L__short_loop
moveb IndBase(-MIN_MATCH,Match),Scan_Test
lslw imm(8),Scan_Test
moveb IndBase(-MIN_MATCH+1,Match),Scan_Test
cmpw invert_maybe(Scan_Test,Scan_Start)
bne L__short_loop
#endif
movew imm((MAX_MATCH-MIN_MATCH+1)-1),Loop_Counter
movel Scan_Ini,Scan
L__scan_loop:
cmpmb postinc(Match),postinc(Scan)
dbne Loop_Counter,L__scan_loop
subl Scan_Ini,Scan
addql imm(MIN_MATCH-1),Scan
cmpl invert_maybe(Best_Len,Scan)
bls L__short_loop
movel Scan,Best_Len
movel Cur_Match,_match_start
#ifdef FULL_SEARCH
cmpl invert_maybe(imm(MAX_MATCH),Best_Len)
#else
cmpl invert_maybe(_nice_match,Best_Len)
#endif
blos L__long_loop
L__return:
moveml postinc(Stack_Pointer),imm(popreg)
rts
#else
error: this asm version is for 386 or 680x0 only
#endif /* mc68000 || mc68020 */
#endif /* i386 || _I386 || _i386 || __i386 */
#endif /* !USE_ZLIB */

View File

@ -1,257 +0,0 @@
/* free mktime function
Copyright 1988, 1989 by David MacKenzie <djm@ai.mit.edu>
and Michael Haertel <mike@ai.mit.edu>
Unlimited distribution permitted provided this copyright notice is
retained and any functional modifications are prominently identified. */
/* Revised 1997 by Christian Spieler:
The code was changed to get more conformance with ANSI's (resp. modern
UNIX releases) definition for mktime():
- Added adjustment for out-of-range values in the fields of struct tm.
- Added iterations to get the correct UTC result for input values at
the gaps when daylight saving time is switched on or off.
- Allow forcing of DST "on" or DST "off" by setting `tm_isdst' field in
the tm struct to positive number resp. zero. The `tm_isdst' field must
be negative on entrance of mktime() to enable automatic determination
if DST is in effect for the requested local time.
- Added optional check for overflowing the time_t range. */
/* Note: This version of mktime is ignorant of the tzfile.
When the tm structure passed to mktime represents a local time that
is valid both as DST time and as standard time (= time value in the
gap when switching from DST back to standard time), the behaviour
for `tm_isdst < 0' depends on the current timezone: TZ east of GMT
assumes winter time, TZ west of GMT assumes summer time.
Although mktime() (resp. mkgmtime()) tries to adjust for invalid values
of struct tm members, this may fail for input values that are far away
from the valid ranges. The adjustment process does not check for overflows
or wrap arounds in the struct tm components. */
#ifndef OF
# ifdef __STDC__
# define OF(a) a
# else
# define OF(a) ()
# endif
#endif
#ifndef ZCONST
# define ZCONST const
#endif
#include <time.h>
time_t mkgmtime OF((struct tm *));
time_t mktime OF((struct tm *));
/* 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); \
}
/* 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 1970 to `y' (not including `y' itself). */
#define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)
/* Additional leapday in February of leap years. */
#define leapday(m, y) ((m) == 1 && leap (y))
/* Length of month `m' (0 .. 11) */
#define monthlen(m, y) (ydays[(m)+1] - ydays[m] + leapday (m, y))
/* Accumulated number of days from 01-Jan up to start of current month. */
static ZCONST short ydays[] =
{
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
};
/* 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 + 1900; /* 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 - 1900;
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] + (months > 1 && leap (years));
tm->tm_yday = days;
/* Now calculate `days' to the number of days since Jan 1, 1970. */
days = (unsigned)days + 365 * (unsigned)(years - 1970) +
(unsigned)(nleap (years));
tm->tm_wday = ((unsigned)days + 4) % 7; /* Jan 1, 1970 was Thursday. */
tm->tm_isdst = 0;
if (years < 1970)
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_MDAY_MAX - 1) +
(TM_MON_MAX > 1 && leap (TM_YEAR_MAX)) ||
(tm->tm_yday == ydays[TM_MON_MAX] + (TM_MDAY_MAX - 1) +
(TM_MON_MAX > 1 && leap (TM_YEAR_MAX)) &&
(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)(86400L * (unsigned long)(unsigned)days +
3600L * (unsigned long)hours +
(unsigned long)(60 * minutes + seconds));
}

View File

@ -1,122 +0,0 @@
/*
Copyright (c) 1990-2006 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 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
*/
/*
* revision.h by Mark Adler.
*/
#ifndef __revision_h
#define __revision_h 1
/* For api version checking */
#define Z_MAJORVER 2
#define Z_MINORVER 3
#define Z_PATCHLEVEL 2
#define Z_BETALEVEL ""
#define VERSION "2.32"
#define REVDATE "June 19th 2006"
#define DW_MAJORVER Z_MAJORVER
#define DW_MINORVER Z_MINORVER
#define DW_PATCHLEVEL Z_PATCHLEVEL
#ifndef WINDLL
/* Copyright notice for binary executables--this notice only applies to
* those (zip, zipcloak, zipsplit, and zipnote), not to this file
* (revision.h).
*/
#ifndef DEFCPYRT /* copyright[] gets defined only once ! */
extern ZCONST char *copyright[1]; /* keep array sizes in sync with number */
extern ZCONST char *swlicense[50]; /* of text line in definition below !! */
extern ZCONST char *versinfolines[7];
extern ZCONST char *cryptnote[7];
#else /* DEFCPYRT */
ZCONST char *copyright[] = {
"Copyright (c) 1990-2006 Info-ZIP - Type '%s \"-L\"' for software license."
};
ZCONST char *versinfolines[] = {
"This is %s %s (%s), by Info-ZIP.",
"Currently maintained by Onno van der Linden. Please send bug reports to",
"the authors using http://www.info-zip.org/zip-bug.html; see README for details.",
"",
"Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip,",
"as of above date; see http://www.info-zip.org/ for other sites.",
""
};
/* new notice - 2/2/2005 EG */
ZCONST char *cryptnote[] = {
"Encryption notice:",
"\tThe encryption code of this program is not copyrighted and is",
"\tput in the public domain. It was originally written in Europe",
"\tand, to the best of our knowledge, can be freely distributed",
"\tin both source and object forms from any country, including",
"\tthe USA under License Exception TSU of the U.S. Export",
"\tAdministration Regulations (section 740.13(e)) of 6 June 2002."
};
ZCONST char *swlicense[] = {
"Copyright (c) 1990-2006 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, Ed Gordon, 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, Steven M. Schweda,",
" Christian Spieler, Cosmin Truta, 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 (including SFXWiz) as part of a",
" self-extracting archive; that is permitted without inclusion of this",
" license, as long as the normal SFX 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."
};
#endif /* DEFCPYRT */
#endif /* !WINDLL */
#endif /* !__revision_h */

View File

@ -1,499 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2004-May-22 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/* Some compiler distributions for Win32/i386 systems try to emulate
* a Unix (POSIX-compatible) environment.
*/
#if (defined(WIN32) && defined(UNIX))
/* Zip does not support merging both ports in a single executable. */
# if (defined(FORCE_WIN32_OVER_UNIX) && defined(FORCE_UNIX_OVER_WIN32))
/* conflicting choice requests -> we prefer the Win32 environment */
# undef FORCE_UNIX_OVER_WIN32
# endif
# ifdef FORCE_WIN32_OVER_UNIX
/* native Win32 support was explicitely requested... */
# undef UNIX
# else
/* use the POSIX (Unix) emulation features by default... */
# undef WIN32
# endif
#endif
#ifdef AMIGA
#include "amiga/osdep.h"
#endif
#ifdef AOSVS
#include "aosvs/osdep.h"
#endif
#ifdef ATARI
#include "atari/osdep.h"
#endif
#if (defined(__BEOS__) || defined(__HAIKU__))
#include "beos/osdep.h"
#endif
#ifdef __ATHEOS__
#include "atheos/osdep.h"
#endif
#ifdef DOS
#include "msdos/osdep.h"
#endif
#ifdef __human68k__
#include "human68k/osdep.h"
#endif
#if ((defined(__MWERKS__) && defined(macintosh)) || defined(MACOS))
#include "macos/osdep.h"
#endif
#ifdef OS2
#include "os2/osdep.h"
#endif
#ifdef __riscos
#include "acorn/osdep.h"
#endif
#ifdef QDOS
#include "qdos/osdep.h"
#endif
#ifdef __TANDEM
#include "tandem.h"
#include "tanzip.h"
#endif
#ifdef UNIX
#include "unix/osdep.h"
#endif
#if defined(__COMPILER_KCC__) || defined(TOPS20)
#include "tops20/osdep.h"
#endif
#if defined(VMS) || defined(__VMS)
#include "vms/osdep.h"
#endif
#if defined(__VM__) || defined(VM_CMS) || defined(MVS)
#include "cmsmvs.h"
#endif
#ifdef WIN32
#include "win32/osdep.h"
#endif
#ifdef THEOS
#include "theos/osdep.h"
#endif
#if (defined(USE_ZLIB) && defined(ASM_CRC))
# undef ASM_CRC
#endif
#if (defined(USE_ZLIB) && defined(ASMV))
# undef ASMV
#endif
/* When "void" is an alias for "int", prototypes cannot be used. */
#if (defined(NO_VOID) && !defined(NO_PROTO))
# define NO_PROTO
#endif
/* Used to remove arguments in function prototypes for non-ANSI C */
#ifndef NO_PROTO
# define OF(a) a
#else /* NO_PROTO */
# define OF(a) ()
#endif /* ?NO_PROTO */
/* If the compiler can't handle const define ZCONST in osdep.h */
/* Define const itself in case the system include files are bonkers */
#ifndef ZCONST
# ifdef NO_CONST
# define ZCONST
# define const
# else
# define ZCONST const
# endif
#endif
/*
* case mapping functions. case_map is used to ignore case in comparisons,
* to_up is used to force upper case even on Unix (for dosify option).
*/
#ifdef USE_CASE_MAP
# define case_map(c) upper[(c) & 0xff]
# define to_up(c) upper[(c) & 0xff]
#else
# define case_map(c) (c)
# define to_up(c) ((c) >= 'a' && (c) <= 'z' ? (c)-'a'+'A' : (c))
#endif /* USE_CASE_MAP */
/* Define void, zvoid, and extent (size_t) */
#include <stdio.h>
#ifndef NO_STDDEF_H
# include <stddef.h>
#endif /* !NO_STDDEF_H */
#ifndef NO_STDLIB_H
# include <stdlib.h>
#endif /* !NO_STDLIB_H */
#ifndef NO_UNISTD_H
# include <unistd.h> /* usually defines _POSIX_VERSION */
#endif /* !NO_UNISTD_H */
#ifndef NO_FCNTL_H
# include <fcntl.h>
#endif /* !NO_FNCTL_H */
#ifndef NO_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif /* NO_STRING_H */
#ifdef NO_VOID
# define void int
typedef char zvoid;
#else /* !NO_VOID */
# ifdef NO_TYPEDEF_VOID
# define zvoid void
# else
typedef void zvoid;
# endif
#endif /* ?NO_VOID */
#ifdef NO_STRRCHR
# define strrchr rindex
#endif
#ifdef NO_STRCHR
# define strchr index
#endif
/*
* A couple of forward declarations that are needed on systems that do
* not supply C runtime library prototypes.
*/
#ifdef NO_PROTO
char *strcpy();
char *strcat();
char *strrchr();
/* XXX use !defined(ZMEM) && !defined(__hpux__) ? */
#if !defined(ZMEM) && defined(NO_STRING_H)
char *memset();
char *memcpy();
#endif /* !ZMEM && NO_STRING_H */
/* XXX use !defined(__hpux__) ? */
#ifdef NO_STDLIB_H
char *calloc();
char *malloc();
char *getenv();
long atol();
#endif /* NO_STDLIB_H */
#ifndef NO_MKTEMP
char *mktemp();
#endif /* !NO_MKTEMP */
/* moved to include mktemp - Cosmin 2/18/05 */
#endif /* NO_PROTO */
/*
* SEEK_* macros, should be defined in stdio.h
*/
/* Define fseek() commands */
#ifndef SEEK_SET
# define SEEK_SET 0
#endif /* !SEEK_SET */
#ifndef SEEK_CUR
# define SEEK_CUR 1
#endif /* !SEEK_CUR */
#ifndef FALSE
# define FALSE 0
#endif
#ifndef TRUE
# define TRUE 1
#endif
#ifdef NO_SIZE_T
typedef unsigned int extent;
#else
typedef size_t extent;
#endif
#ifdef NO_TIME_T
typedef long time_t;
#endif
/* DBCS support for Info-ZIP's zip (mainly for japanese (-: )
* by Yoshioka Tsuneo (QWF00133@nifty.ne.jp,tsuneo-y@is.aist-nara.ac.jp)
* This code is public domain! Date: 1998/12/20
*/
#ifdef _MBCS
# include <locale.h>
/* Multi Byte Character Set */
extern char *___tmp_ptr;
unsigned char *zmbschr OF((ZCONST unsigned char *, unsigned int));
unsigned char *zmbsrchr OF((ZCONST unsigned char *, unsigned int));
# define CLEN(ptr) mblen(ptr, MB_CUR_MAX)
# define PREINCSTR(ptr) (ptr += CLEN(ptr))
# define POSTINCSTR(ptr) (___tmp_ptr=(char *)ptr,ptr += CLEN(ptr),___tmp_ptr)
int lastchar OF((ZCONST char *ptr));
# define MBSCHR(str,c) (char *)zmbschr((ZCONST unsigned char *)(str), c)
# define MBSRCHR(str,c) (char *)zmbsrchr((ZCONST unsigned char *)(str), (c))
# define SETLOCALE(category, locale) setlocale(category, locale)
#else /* !_MBCS */
# define CLEN(ptr) 1
# define PREINCSTR(ptr) (++(ptr))
# define POSTINCSTR(ptr) ((ptr)++)
# define lastchar(ptr) ((*(ptr)=='\0') ? '\0' : ptr[strlen(ptr)-1])
# define MBSCHR(str, c) strchr(str, c)
# define MBSRCHR(str, c) strrchr(str, c)
# define SETLOCALE(category, locale)
#endif /* ?_MBCS */
#define INCSTR(ptr) PREINCSTR(ptr)
/* System independent replacement for "struct utimbuf", which is missing
* in many older OS environments.
*/
typedef struct ztimbuf {
time_t actime; /* new access time */
time_t modtime; /* new modification time */
} ztimbuf;
/* This macro round a time_t value to the OS specific resolution */
#ifndef ROUNDED_TIME
# define ROUNDED_TIME(time) (time)
#endif
/* Some systems define S_IFLNK but do not support symbolic links */
#if defined (S_IFLNK) && defined(NO_SYMLINK)
# undef S_IFLNK
#endif
#ifndef FOPR /* fallback default definitions for FOPR, FOPM, FOPW: */
# define FOPR "r"
# define FOPM "r+"
# define FOPW "w"
#endif /* fallback definition */
#ifndef FOPW_TMP /* fallback default for opening writable temp files */
# define FOPW_TMP FOPW
#endif
/* Open the old zip file in exclusive mode if possible (to avoid adding
* zip file to itself).
*/
#ifdef OS2
# define FOPR_EX FOPM
#else
# define FOPR_EX FOPR
#endif
/* MSDOS file or directory attributes */
#define MSDOS_HIDDEN_ATTR 0x02
#define MSDOS_DIR_ATTR 0x10
/* Define this symbol if your target allows access to unaligned data.
* This is not mandatory, just a speed optimization. The compressed
* output is strictly identical.
*/
#if (defined(MSDOS) && !defined(WIN32)) || defined(i386)
# define UNALIGNED_OK
#endif
#if defined(mc68020) || defined(vax)
# define UNALIGNED_OK
#endif
#if (defined(SMALL_MEM) && !defined(CBSZ))
# define CBSZ 2048 /* buffer size for copying files */
# define ZBSZ 2048 /* buffer size for temporary zip file */
#endif
#if (defined(MEDIUM_MEM) && !defined(CBSZ))
# define CBSZ 8192
# define ZBSZ 8192
#endif
#ifndef CBSZ
# define CBSZ 16384
# define ZBSZ 16384
#endif
#ifndef SBSZ
# define SBSZ CBSZ /* copy buf size for STORED entries, see zipup() */
#endif
#ifndef MEMORY16
# ifdef __WATCOMC__
# undef huge
# undef far
# undef near
# endif
# ifdef THEOS
# undef far
# undef near
# endif
# if (!defined(__IBMC__) || !defined(OS2))
# ifndef huge
# define huge
# endif
# ifndef far
# define far
# endif
# ifndef near
# define near
# endif
# endif
# define nearmalloc malloc
# define nearfree free
# define farmalloc malloc
# define farfree free
#endif /* !MEMORY16 */
#ifndef Far
# define Far far
#endif
/* MMAP and BIG_MEM cannot be used together -> let MMAP take precedence */
#if (defined(MMAP) && defined(BIG_MEM))
# undef BIG_MEM
#endif
#if (defined(BIG_MEM) || defined(MMAP)) && !defined(DYN_ALLOC)
# define DYN_ALLOC
#endif
#ifndef SSTAT
# define SSTAT stat
#endif
#ifdef S_IFLNK
# define LSTAT lstat
# define LSSTAT(n, s) (linkput ? lstat((n), (s)) : SSTAT((n), (s)))
#else
# define LSTAT SSTAT
# define LSSTAT SSTAT
#endif
/* The following default definition of the second input for the crypthead()
* random seed computation can be used on most systems (all those that
* supply a UNIX compatible getpid() function).
*/
#ifdef ZCRYPT_INTERNAL
# ifndef ZCR_SEED2
# define ZCR_SEED2 (unsigned) getpid() /* use PID as seed pattern */
# endif
#endif /* ZCRYPT_INTERNAL */
/* The following OS codes are defined in pkzip appnote.txt */
#ifdef AMIGA
# define OS_CODE 0x100
#endif
#ifdef VMS
# define OS_CODE 0x200
#endif
/* unix 3 */
#ifdef VM_CMS
# define OS_CODE 0x400
#endif
#ifdef ATARI
# define OS_CODE 0x500
#endif
#ifdef OS2
# define OS_CODE 0x600
#endif
#ifdef MACOS
# define OS_CODE 0x700
#endif
/* z system 8 */
/* cp/m 9 */
#ifdef TOPS20
# define OS_CODE 0xa00
#endif
#ifdef WIN32
# define OS_CODE 0xb00
#endif
#ifdef QDOS
# define OS_CODE 0xc00
#endif
#ifdef RISCOS
# define OS_CODE 0xd00
#endif
#ifdef VFAT
# define OS_CODE 0xe00
#endif
#ifdef MVS
# define OS_CODE 0xf00
#endif
#if (defined(__BEOS__) || defined(__HAIKU__))
# define OS_CODE 0x1000
#endif
#ifdef TANDEM
# define OS_CODE 0x1100
#endif
#ifdef THEOS
# define OS_CODE 0x1200
#endif
#ifdef __ATHEOS__
# define OS_CODE 0x1E00
#endif
#define NUM_HOSTS 31
/* Number of operating systems. Should be updated when new ports are made */
#if defined(DOS) && !defined(OS_CODE)
# define OS_CODE 0x000
#endif
#ifndef OS_CODE
# define OS_CODE 0x300 /* assume Unix */
#endif
/* can't use "return 0" from main() on VMS */
#ifndef EXIT
# define EXIT exit
#endif
#ifndef RETURN
# define RETURN return
#endif
#ifndef ZIPERR
# define ZIPERR ziperr
#endif
#if (defined(USE_ZLIB) && defined(MY_ZCALLOC))
/* special zcalloc function is not needed when linked against zlib */
# undef MY_ZCALLOC
#endif
#if (!defined(USE_ZLIB) && !defined(MY_ZCALLOC))
/* Any system without a special calloc function */
# define zcalloc(items,size) \
(zvoid far *)calloc((unsigned)(items), (unsigned)(size))
# define zcfree free
#endif /* !USE_ZLIB && !MY_ZCALLOC */
/* end of tailor.h */

File diff suppressed because it is too large Load Diff

View File

@ -1,700 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 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
#if (defined(__ATHEOS__) || (defined(__BEOS__) || defined(__HAIKU__))) /* 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))
#ifdef ATH_BEO_UNX
#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 /* !ATH_BEO_UNX */
#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 /* ?ATH_BEO_UNX */
#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(ATH_BEO_UNX) || defined(__MINT__))
#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 /* ATH_BEO_UNX || __MINT__ */
#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) */

View File

@ -1,227 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 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(__ATHEOS__) || defined(__BEOS__) || defined(__HAIKU__) || defined(UNIX))
# ifndef ATH_BEO_UNX
# define ATH_BEO_UNX
# 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

@ -1,781 +0,0 @@
/*
Copyright (c) 1990-2006 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 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
*/
/*
* util.c by Mark Adler.
*/
#define __UTIL_C
#include "zip.h"
#include "ebcdic.h"
#include <ctype.h>
#ifdef MSDOS16
# include <dos.h>
#endif
uch upper[256], lower[256];
/* Country-dependent case map table */
#ifndef UTIL /* UTIL picks out namecmp code (all utils) */
/* Local functions */
local int recmatch OF((ZCONST char *, ZCONST char *, int));
local int count_args OF((char *s));
#ifdef MSDOS16
local unsigned ident OF((unsigned chr));
#endif
#ifdef NO_MKTIME
# ifndef IZ_MKTIME_ONLY
# define IZ_MKTIME_ONLY /* only mktime() related code is pulled in */
# endif
# include "timezone.c"
#endif
#ifndef HAVE_FSEEKABLE
int fseekable(fp)
FILE *fp;
{
long x;
return (fp == NULL || (fseek(fp, -1L, SEEK_CUR) == 0 &&
(x = ftell(fp)) >= 0 &&
fseek(fp, 1L, SEEK_CUR) == 0 &&
ftell(fp) == x + 1));
}
#endif /* HAVE_FSEEKABLE */
char *isshexp(p)
char *p; /* candidate sh expression */
/* If p is a sh expression, a pointer to the first special character is
returned. Otherwise, NULL is returned. */
{
for (; *p; INCSTR(p))
if (*p == '\\' && *(p+1))
p++;
#ifdef VMS
else if (*p == '%' || *p == '*')
#else /* !VMS */
# ifdef RISCOS
/* RISC OS uses # as its single-character wildcard */
else if (*p == '#' || *p == '*' || *p == '[')
# else /* !RISC OS */
else if (*p == '?' || *p == '*' || *p == '[')
# endif
#endif /* ?VMS */
return p;
return NULL;
}
local int recmatch(p, s, cs)
ZCONST char *p; /* sh pattern to match */
ZCONST char *s; /* string to match it to */
int cs; /* flag: force case-sensitive matching */
/* 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 deeper than the number of
characters in the pattern. */
{
int c; /* pattern char or start of range in [-] loop */
/* Get first character, the pattern for new recmatch calls follows */
c = *POSTINCSTR(p);
/* If that was the end of the pattern, match if string empty too */
if (c == 0)
return *s == 0;
/* '?' (or '%' or '#') matches any character (but not an empty string) */
#ifdef VMS
if (c == '%')
#else /* !VMS */
# ifdef RISCOS
if (c == '#')
# else /* !RISC OS */
if (c == '?')
# endif
#endif /* ?VMS */
#ifdef WILD_STOP_AT_DIR
return (*s && *s != '/') ? recmatch(p, s + CLEN(s), cs) : 0;
#else
return *s ? recmatch(p, s + CLEN(s), cs) : 0;
#endif
/* '*' matches any number of characters, including zero */
#ifdef AMIGA
if (c == '#' && *p == '?') /* "#?" is Amiga-ese for "*" */
c = '*', p++;
#endif /* AMIGA */
if (c == '*')
{
if (*p == 0)
return 1;
#ifdef WILD_STOP_AT_DIR
for (; *s && *s != '/'; INCSTR(s))
if ((c = recmatch(p, s, cs)) != 0)
return c;
return (*p == '/' || (*p == '\\' && p[1] == '/'))
? recmatch(p, s, cs) : 2;
#else /* !WILD_STOP_AT_DIR */
if (!isshexp((char *)p))
{
/* optimization for rest of pattern being a literal string */
/* optimization to handle patterns like *.txt */
/* if the first char in the pattern is '*' and there */
/* are no other shell expression chars, i.e. a literal string */
/* then just compare the literal string at the end */
ZCONST char *srest;
srest = s + (strlen(s) - strlen(p));
if (srest - s < 0)
/* remaining literal string from pattern is longer than rest of
test string, there can't be a match
*/
return 0;
else
/* compare the remaining literal pattern string with the last bytes
of the test string to check for a match */
#ifdef _MBCS
{
ZCONST char *q = s;
/* MBCS-aware code must not scan backwards into a string from
* the end.
* So, we have to move forward by character from our well-known
* character position s in the test string until we have advanced
* to the srest position.
*/
while (q < srest)
INCSTR(q);
/* In case the byte *srest is a trailing byte of a multibyte
* character, we have actually advanced past the position (srest).
* For this case, the match has failed!
*/
if (q != srest)
return 0;
return ((cs ? strcmp(p, q) : namecmp(p, q)) == 0);
}
#else /* !_MBCS */
return ((cs ? strcmp(p, srest) : namecmp(p, srest)) == 0);
#endif /* ?_MBCS */
}
else
{
/* pattern contains more wildcards, continue with recursion... */
for (; *s; INCSTR(s))
if ((c = recmatch(p, s, cs)) != 0)
return (int)c;
return 2; /* 2 means give up--shmatch will return false */
}
#endif /* ?WILD_STOP_AT_DIR */
}
#ifndef VMS /* No bracket matching in VMS */
/* Parse and process the list of characters and ranges in brackets */
if (c == '[')
{
int e; /* flag true if next char to be taken literally */
ZCONST char *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; q++) /* find closing bracket */
if (e)
e = 0;
else
if (*q == '\\')
e = 1;
else if (*q == ']')
break;
if (*q != ']') /* nothing matches if bad syntax */
return 0;
for (c = 0, e = *p == '-'; p < q; p++) /* go through the list */
{
if (e == 0 && *p == '\\') /* set escape flag if \ */
e = 1;
else if (e == 0 && *p == '-') /* set start of range if - */
c = *(p-1);
else
{
uch cc = (cs ? (uch)*s : case_map((uch)*s));
uch uc = (uch) c;
if (*(p+1) != '-')
for (uc = uc ? uc : (uch)*p; uc <= (uch)*p; uc++)
/* compare range */
if ((cs ? uc : case_map(uc)) == cc)
return r ? 0 : recmatch(q + CLEN(q), s + CLEN(s), cs);
c = e = 0; /* clear range, escape flags */
}
}
return r ? recmatch(q + CLEN(q), s + CLEN(s), cs) : 0;
/* bracket match failed */
}
#endif /* !VMS */
/* If escape ('\'), just compare next character */
if (c == '\\')
if ((c = *p++) == '\0') /* if \ at end, then syntax error */
return 0;
#ifdef VMS
/* 2005-11-06 SMS.
Handle "..." wildcard in p with "." or "]" in s.
*/
if ((c == '.') && (*p == '.') && (*(p+ CLEN( p)) == '.') &&
((*s == '.') || (*s == ']')))
{
/* Match "...]" with "]". Continue after "]" in both. */
if ((*(p+ 2* CLEN( p)) == ']') && (*s == ']'))
return recmatch( (p+ 3* CLEN( p)), (s+ CLEN( s)), cs);
/* Else, look for a reduced match in s, until "]" in or end of s. */
for (; *s && (*s != ']'); INCSTR(s))
if (*s == '.')
/* If reduced match, then continue after "..." in p, "." in s. */
if ((c = recmatch( (p+ CLEN( p)), s, cs)) != 0)
return (int)c;
/* Match "...]" with "]". Continue after "]" in both. */
if ((*(p+ 2* CLEN( p)) == ']') && (*s == ']'))
return recmatch( (p+ 3* CLEN( p)), (s+ CLEN( s)), cs);
/* No reduced match. Quit. */
return 2;
}
#endif /* def VMS */
/* Just a character--compare it */
return (cs ? c == *s : case_map((uch)c) == case_map((uch)*s)) ?
recmatch(p, s + CLEN(s), cs) : 0;
}
int shmatch(p, s, cs)
ZCONST char *p; /* sh pattern to match */
ZCONST char *s; /* string to match it to */
int cs; /* force case-sensitive match if TRUE */
/* Compare the sh pattern p with the string s and return true if they match,
false if they don't or if there is a syntax error in the pattern. */
{
return recmatch(p, s, cs) == 1;
}
#if defined(DOS) || defined(WIN32)
/* XXX also suitable for OS2? Atari? Human68K? TOPS-20?? */
int dosmatch(p, s, cs)
ZCONST char *p; /* dos pattern to match */
ZCONST char *s; /* string to match it to */
int cs; /* force case-sensitive match if TRUE */
/* Treat filenames without periods as having an implicit trailing period */
{
char *s1; /* revised string to match */
int r; /* result */
if (strchr(p, '.') && !strchr(s, '.') &&
((s1 = malloc(strlen(s) + 2)) != NULL))
{
strcpy(s1, s);
strcat(s1, ".");
}
else
{
/* will usually be OK */
s1 = (char *)s;
}
r = recmatch(p, s1, cs) == 1;
if (s != s1)
free((zvoid *)s1);
return r == 1;
}
#endif /* DOS || WIN32 */
zvoid far **search(b, a, n, cmp)
ZCONST zvoid *b; /* pointer to value to search for */
ZCONST zvoid far **a; /* table of pointers to values, sorted */
extent n; /* number of pointers in a[] */
int (*cmp) OF((ZCONST zvoid *, ZCONST zvoid far *)); /* comparison function */
/* Search for b in the pointer list a[0..n-1] using the compare function
cmp(b, c) where c is an element of a[i] and cmp() returns negative if
*b < *c, zero if *b == *c, or positive if *b > *c. If *b is found,
search returns a pointer to the entry in a[], else search() returns
NULL. The nature and size of *b and *c (they can be different) are
left up to the cmp() function. A binary search is used, and it is
assumed that the list is sorted in ascending order. */
{
ZCONST zvoid far **i; /* pointer to midpoint of current range */
ZCONST zvoid far **l; /* pointer to lower end of current range */
int r; /* result of (*cmp)() call */
ZCONST zvoid far **u; /* pointer to upper end of current range */
l = (ZCONST zvoid far **)a; u = l + (n-1);
while (u >= l) {
i = l + ((unsigned)(u - l) >> 1);
if ((r = (*cmp)(b, (ZCONST char far *)*(struct zlist far **)i)) < 0)
u = i - 1;
else if (r > 0)
l = i + 1;
else
return (zvoid far **)i;
}
return NULL; /* If b were in list, it would belong at l */
}
#endif /* !UTIL */
#ifdef MSDOS16
local unsigned ident(unsigned chr)
{
return chr; /* in al */
}
void init_upper()
{
static struct country {
uch ignore[18];
int (far *casemap)(int);
uch filler[16];
} country_info;
struct country far *info = &country_info;
union REGS regs;
struct SREGS sregs;
unsigned int c;
regs.x.ax = 0x3800; /* get country info */
regs.x.dx = FP_OFF(info);
sregs.ds = FP_SEG(info);
intdosx(&regs, &regs, &sregs);
for (c = 0; c < 128; c++) {
upper[c] = (uch) toupper(c);
lower[c] = (uch) c;
}
for (; c < sizeof(upper); c++) {
upper[c] = (uch) (*country_info.casemap)(ident(c));
/* ident() required because casemap takes its parameter in al */
lower[c] = (uch) c;
}
for (c = 0; c < sizeof(upper); c++ ) {
int u = upper[c];
if (u != c && lower[u] == (uch) u) {
lower[u] = (uch)c;
}
}
for (c = 'A'; c <= 'Z'; c++) {
lower[c] = (uch) (c - 'A' + 'a');
}
}
#else /* !MSDOS16 */
# ifndef OS2
void init_upper()
{
unsigned int c;
#if defined(ATARI) || defined(CMS_MVS)
#include <ctype.h>
/* this should be valid for all other platforms too. (HD 11/11/95) */
for (c = 0; c< sizeof(upper); c++) {
upper[c] = islower(c) ? toupper(c) : c;
lower[c] = isupper(c) ? tolower(c) : c;
}
#else
for (c = 0; c < sizeof(upper); c++) upper[c] = lower[c] = (uch)c;
for (c = 'a'; c <= 'z'; c++) upper[c] = (uch)(c - 'a' + 'A');
for (c = 'A'; c <= 'Z'; c++) lower[c] = (uch)(c - 'A' + 'a');
#endif
}
# endif /* !OS2 */
#endif /* ?MSDOS16 */
int namecmp(string1, string2)
ZCONST char *string1, *string2;
/* Compare the two strings ignoring case, and correctly taking into
* account national language characters. For operating systems with
* case sensitive file names, this function is equivalent to strcmp.
*/
{
int d;
for (;;)
{
d = (int) (uch) case_map(*string1)
- (int) (uch) case_map(*string2);
if (d || *string1 == 0 || *string2 == 0)
return d;
string1++;
string2++;
}
}
#ifdef EBCDIC
char *strtoasc(char *str1, ZCONST char *str2)
{
char *old;
old = str1;
while (*str1++ = (char)ascii[(uch)(*str2++)]);
return old;
}
char *strtoebc(char *str1, ZCONST char *str2)
{
char *old;
old = str1;
while (*str1++ = (char)ebcdic[(uch)(*str2++)]);
return old;
}
char *memtoasc(char *mem1, ZCONST char *mem2, unsigned len)
{
char *old;
old = mem1;
while (len--)
*mem1++ = (char)ascii[(uch)(*mem2++)];
return old;
}
char *memtoebc(char *mem1, ZCONST char *mem2, unsigned len)
{
char *old;
old = mem1;
while (len--)
*mem1++ = (char)ebcdic[(uch)(*mem2++)];
return old;
}
#endif /* EBCDIC */
#ifdef IZ_ISO2OEM_ARRAY
char *str_iso_to_oem(dst, src)
ZCONST char *src;
char *dst;
{
char *dest_start = dst;
while (*dst++ = (char)iso2oem[(uch)(*src++)]);
return dest_start;
}
#endif
#ifdef IZ_OEM2ISO_ARRAY
char *str_oem_to_iso(dst, src)
ZCONST char *src;
char *dst;
{
char *dest_start = dst;
while (*dst++ = (char)oem2iso[(uch)(*src++)]);
return dest_start;
}
#endif
/* DBCS support for Info-ZIP's zip (mainly for japanese (-: )
* by Yoshioka Tsuneo (QWF00133@nifty.ne.jp,tsuneo-y@is.aist-nara.ac.jp)
* This code is public domain! Date: 1998/12/20
*/
#ifdef _MBCS
char *___tmp_ptr;
int lastchar(ptr)
ZCONST char *ptr;
{
ZCONST char *oldptr = ptr;
while(*ptr != '\0'){
oldptr = ptr;
INCSTR(ptr);
}
return (int)(unsigned)*oldptr;
}
unsigned char *zmbschr(str, c)
ZCONST unsigned char *str;
unsigned int c;
{
while(*str != '\0'){
if (*str == c) {return (char*)str;}
INCSTR(str);
}
return NULL;
}
unsigned char *zmbsrchr(str, c)
ZCONST unsigned char *str;
unsigned int c;
{
unsigned char *match = NULL;
while(*str != '\0'){
if (*str == c) {match = (char*)str;}
INCSTR(str);
}
return match;
}
#endif /* _MBCS */
#ifndef UTIL
/*****************************************************************
| 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. Parenthesis were added where not needed in some cases
| to make the action of the code less obscure.
****************************************************************/
void envargs(Pargc, Pargv, envstr, envstr2)
int *Pargc;
char ***Pargv;
char *envstr;
char *envstr2;
{
char *envptr; /* value returned by getenv */
char *bufptr; /* copy of env info */
int argc; /* 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 */
envptr = getenv(envstr);
if (envptr != NULL) /* usual var */
while (isspace((uch)*envptr)) /* we must discard leading spaces */
envptr++;
if (envptr == NULL || *envptr == '\0')
if ((envptr = getenv(envstr2)) != NULL) /* alternate */
while (isspace((uch)*envptr))
envptr++;
if (envptr == NULL || *envptr == '\0')
return;
/* count the args so we can allocate room for them */
argc = count_args(envptr);
bufptr = malloc(1 + strlen(envptr));
if (bufptr == NULL)
ziperr(ZE_MEM, "Can't get memory for arguments");
strcpy(bufptr, envptr);
/* allocate a vector large enough for all args */
argv = (char **)malloc((argc + *Pargc + 1) * sizeof(char *));
if (argv == NULL) {
free(bufptr);
ziperr(ZE_MEM, "Can't get memory for arguments");
}
argvect = argv;
/* copy the program name first, that's always true */
*(argv++) = *((*Pargv)++);
/* copy the environment args first, 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; /* skip to char after backslash */
if (ch != '\0') /* overwrite trailing '"' */
*(bufptr++) = '\0';
/* remove escape characters */
while ((argstart = MBSCHR(argstart, '\\')) != NULL) {
strcpy(argstart, argstart + 1);
if (*argstart)
++argstart;
}
} else {
*(argv++) = bufptr;
while ((ch = *bufptr) != '\0' && !isspace((uch)ch)) INCSTR(bufptr);
if (ch != '\0') *(bufptr++) = '\0';
}
#else
# ifdef WIN32
/* We do not support backslash-quoting of quotes in quoted */
/* strings under Win32, 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((uch)ch)) INCSTR(bufptr);
if (ch != '\0') *(bufptr++) = '\0';
}
# else
*(argv++) = bufptr;
while ((ch = *bufptr) != '\0' && !isspace((uch)ch)) INCSTR(bufptr);
if (ch != '\0') *(bufptr++) = '\0';
# endif
#endif /* ?(AMIGA || UNIX) */
while ((ch = *bufptr) != '\0' && isspace((uch)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 = NULL;
/* save the values and return */
*Pargv = argvect;
*Pargc = argc;
}
static int count_args(s)
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')
INCSTR(s);
if (*s) INCSTR(s); /* trailing quote */
} else
while ((ch = *s) != '\0' && !isspace((uch)ch)) INCSTR(s);
#else
# ifdef WIN32
if (*s == '\"') {
++s; /* leading quote */
while ((ch = *s) != '\0' && ch != '\"') INCSTR(s);
if (*s) INCSTR(s); /* trailing quote */
} else
while ((ch = *s) != '\0' && !isspace((uch)ch)) INCSTR(s);
# else
while ((ch = *s) != '\0' && !isspace((uch)ch)) INCSTR(s);
# endif
#endif /* ?(AMIGA || UNIX) */
while ((ch = *s) != '\0' && isspace((uch)ch)) INCSTR(s);
} while (ch);
return(count);
}
/* Extended argument processing -- by Rich Wales
* This function currently deals only with the MKS shell, but could be
* extended later to understand other conventions.
*
* void expand_args(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 "expand_args" 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").
*/
void expand_args(argcp, argvp)
int *argcp;
char ***argvp;
{
#ifdef DOS
/* Do NEVER include (re)definiton of `environ' variable with any version
of MSC or BORLAND/Turbo C. These compilers supply an incompatible
definition in <stdlib.h>. */
#if defined(__GO32__) || defined(__EMX__)
extern char **environ; /* environment */
#endif /* __GO32__ || __EMX__ */
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;
#else /* !DOS */
if (argcp || argvp) return;
#endif /* ?DOS */
}
#endif /* UTIL */
#ifdef DEBUGNAMES
#undef free
int Free(x)
void *x;
{
if (x == (void *) 0xdeadbeef)
exit(-1);
free(x);
return 0;
}
int printnames()
{
struct zlist far *z;
for (z = zfiles; z != NULL; z = z->nxt)
fprintf(stderr, "%s %s %s %p %p %p %08x %08x %08x\n",
z->name, z->zname, z->iname,
z->name, z->zname, z->iname,
*((int *) z->name), *((int *) z->zname),
*((int *) z->iname));
return 0;
}
#endif /* DEBUGNAMES */

View File

@ -1,2 +0,0 @@
#define UTIL
#include "util.c"

File diff suppressed because it is too large Load Diff

View File

@ -1,568 +0,0 @@
/*
This is version 2005-Feb-10 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-2005 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, Ed Gordon, 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, Steven M. Schweda,
Christian Spieler, Cosmin Truta, 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 (including SFXWiz) as part of a
self-extracting archive; that is permitted without inclusion of this
license, as long as the normal SFX 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.
*/
/*
* zip.h by Mark Adler
*/
#ifndef __zip_h
#define __zip_h 1
#define ZIP /* for crypt.c: include zip password functions, not unzip */
/* Set up portability */
#include "tailor.h"
#ifdef USE_ZLIB
# include "zlib.h"
#endif
#define MIN_MATCH 3
#define MAX_MATCH 258
/* The minimum and maximum match lengths */
#ifndef WSIZE
# define WSIZE (0x8000)
#endif
/* Maximum window size = 32K. If you are really short of memory, compile
* with a smaller WSIZE but this reduces the compression ratio for files
* of size > WSIZE. WSIZE must be a power of two in the current implementation.
*/
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
/* Minimum amount of lookahead, except at the end of the input file.
* See deflate.c for comments about the MIN_MATCH+1.
*/
#define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
/* In order to simplify the code, particularly on 16 bit machines, match
* distances are limited to MAX_DIST instead of WSIZE.
*/
/* Forget FILENAME_MAX (incorrectly = 14 on some System V) */
#ifdef DOS
# define FNMAX 256
#else
# define FNMAX 1024
#endif
#ifndef MATCH
# define MATCH shmatch /* Default for pattern matching: UNIX style */
#endif
/* Types centralized here for easy modification */
#define local static /* More meaningful outside functions */
typedef unsigned char uch; /* unsigned 8-bit value */
typedef unsigned short ush; /* unsigned 16-bit value */
typedef unsigned long ulg; /* unsigned 32-bit value */
/* Structure carrying extended timestamp information */
typedef struct iztimes {
time_t atime; /* new access time */
time_t mtime; /* new modification time */
time_t ctime; /* new creation time (!= Unix st.ctime) */
} iztimes;
/* Lengths of headers after signatures in bytes */
#define LOCHEAD 26
#define CENHEAD 42
#define ENDHEAD 18
/* Structures for in-memory file information */
struct zlist {
/* See central header in zipfile.c for what vem..off are */
ush vem, ver, flg, how;
ulg tim, crc, siz, len;
extent nam, ext, cext, com; /* offset of ext must be >= LOCHEAD */
ush dsk, att, lflg; /* offset of lflg must be >= LOCHEAD */
ulg atx, off;
char *name; /* File name in zip file */
char *extra; /* Extra field (set only if ext != 0) */
char *cextra; /* Extra in central (set only if cext != 0) */
char *comment; /* Comment (set only if com != 0) */
char *iname; /* Internal file name after cleanup */
char *zname; /* External version of internal name */
int mark; /* Marker for files to operate on */
int trash; /* Marker for files to delete */
int dosflag; /* Set to force MSDOS file attributes */
struct zlist far *nxt; /* Pointer to next header in list */
};
struct flist {
char *name; /* Raw internal file name */
char *iname; /* Internal file name after cleanup */
char *zname; /* External version of internal name */
int dosflag; /* Set to force MSDOS file attributes */
struct flist far *far *lst; /* Pointer to link pointing here */
struct flist far *nxt; /* Link to next name */
};
struct plist {
char *zname; /* External version of internal name */
int select; /* Selection flag ('i' or 'x') */
};
/* internal file attribute */
#define UNKNOWN (-1)
#define BINARY 0
#define ASCII 1
#define __EBCDIC 2
/* extra field definitions */
#define EF_VMCMS 0x4704 /* VM/CMS Extra Field ID ("G")*/
#define EF_MVS 0x470f /* MVS Extra Field ID ("G") */
#define EF_IZUNIX 0x5855 /* UNIX Extra Field ID ("UX") */
#define EF_IZUNIX2 0x7855 /* Info-ZIP's new Unix ("Ux") */
#define EF_TIME 0x5455 /* universal timestamp ("UT") */
#define EF_OS2EA 0x0009 /* OS/2 Extra Field ID (extended attributes) */
#define EF_ACL 0x4C41 /* ACL Extra Field ID (access control list, "AL") */
#define EF_NTSD 0x4453 /* NT Security Descriptor Extra Field ID, ("SD") */
#define EF_BEOS 0x6542 /* BeOS Extra Field ID ("Be") */
#define EF_ATHEOS 0x7441 /* AtheOS Extra Field ID ("At") */
#define EF_QDOS 0xfb4a /* SMS/QDOS ("J\373") */
#define EF_AOSVS 0x5356 /* AOS/VS ("VS") */
#define EF_SPARK 0x4341 /* David Pilling's Acorn/SparkFS ("AC") */
#define EF_THEOS 0x6854 /* THEOS ("Th") */
#define EF_TANDEM 0x4154 /* Tandem NSK ("TA") */
/* Definitions for extra field handling: */
#define EF_SIZE_MAX ((unsigned)0xFFFF) /* hard limit of total e.f. length */
#define EB_HEADSIZE 4 /* length of a extra field block header */
#define EB_ID 0 /* offset of block ID in header */
#define EB_LEN 2 /* offset of data length field in header */
#define EB_MEMCMPR_HSIZ 6 /* header length for memcompressed data */
#define EB_DEFLAT_EXTRA 10 /* overhead for 64kByte "undeflatable" data */
#define EB_UX_MINLEN 8 /* minimal "UX" field contains atime, mtime */
#define EB_UX_ATIME 0 /* offset of atime in "UX" extra field data */
#define EB_UX_MTIME 4 /* offset of mtime in "UX" extra field data */
#define EB_UX_FULLSIZE 12 /* full "UX" field (atime, mtime, uid, gid) */
#define EB_UX_UID 8 /* byte offset of UID in "UX" field data */
#define EB_UX_GID 10 /* byte offset of GID in "UX" field data */
#define EB_UT_MINLEN 1 /* minimal UT field contains Flags byte */
#define EB_UT_FLAGS 0 /* byte offset of Flags field */
#define EB_UT_TIME1 1 /* byte offset of 1st time value */
#define EB_UT_FL_MTIME (1 << 0) /* mtime present */
#define EB_UT_FL_ATIME (1 << 1) /* atime present */
#define EB_UT_FL_CTIME (1 << 2) /* ctime present */
#define EB_UT_LEN(n) (EB_UT_MINLEN + 4 * (n))
#define EB_UX2_MINLEN 4 /* minimal Ux field contains UID/GID */
#define EB_UX2_UID 0 /* byte offset of UID in "Ux" field data */
#define EB_UX2_GID 2 /* byte offset of GID in "Ux" field data */
#define EB_UX2_VALID (1 << 8) /* UID/GID present */
/* ASCII definitions for line terminators in text files: */
#define LF 10 /* '\n' on ASCII machines; must be 10 due to EBCDIC */
#define CR 13 /* '\r' on ASCII machines; must be 13 due to EBCDIC */
#define CTRLZ 26 /* DOS & OS/2 EOF marker (used in fileio.c, vms.c) */
/* return codes of password fetches (negative: user abort; positive: error) */
#define IZ_PW_ENTERED 0 /* got some PWD 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, ...) */
#define IZ_PW_SKIPVERIFY IZ_PW_CANCEL /* skip encrypt. passwd verification */
/* mode flag values of password prompting function */
#define ZP_PW_ENTER 0 /* request for encryption password */
#define ZP_PW_VERIFY 1 /* request for reentering password */
/* Error return codes and PERR macro */
#include "ziperr.h"
#if 0 /* Optimization: use the (const) result of crc32(0L,NULL,0) */
# define CRCVAL_INITIAL crc32(0L, (uch *)NULL, 0)
#else
# define CRCVAL_INITIAL 0L
#endif
#define DOSTIME_MINIMUM ((ulg)0x00210000L)
#define DOSTIME_2038_01_18 ((ulg)0x74320000L)
/* Public globals */
extern uch upper[256]; /* Country dependent case map table */
extern uch lower[256];
#ifdef EBCDIC
extern ZCONST uch ascii[256]; /* EBCDIC <--> ASCII translation tables */
extern ZCONST uch ebcdic[256];
#endif /* EBCDIC */
#ifdef IZ_ISO2OEM_ARRAY /* ISO 8859-1 (Win CP 1252) --> OEM CP 850 */
extern ZCONST uch Far iso2oem[128];
#endif
#ifdef IZ_OEM2ISO_ARRAY /* OEM CP 850 --> ISO 8859-1 (Win CP 1252) */
extern ZCONST uch Far oem2iso[128];
#endif
extern char errbuf[FNMAX+81]; /* Handy place to build error messages */
extern int recurse; /* Recurse into directories encountered */
extern int dispose; /* Remove files after put in zip file */
extern int pathput; /* Store path with name */
#ifdef RISCOS
extern int scanimage; /* Scan through image files */
#endif
#define BEST -1 /* Use best method (deflation or store) */
#define STORE 0 /* Store method */
#define DEFLATE 8 /* Deflation method*/
extern int method; /* Restriction on compression method */
extern int dosify; /* Make new entries look like MSDOS */
extern char *special; /* Don't compress special suffixes */
extern int verbose; /* Report oddities in zip file structure */
extern int fix; /* Fix the zip file */
extern int adjust; /* Adjust the unzipsfx'd zip file */
extern int level; /* Compression level */
extern int translate_eol; /* Translate end-of-line LF -> CR LF */
#ifdef VMS
extern int vmsver; /* Append VMS version number to file names */
extern int vms_native; /* Store in VMS format */
#endif /* VMS */
#if defined(OS2) || defined(WIN32)
extern int use_longname_ea; /* use the .LONGNAME EA as the file's name */
#endif
#if defined (QDOS) || defined(QLZIP)
extern short qlflag;
#endif
extern int hidden_files; /* process hidden and system files */
extern int volume_label; /* add volume label */
extern int dirnames; /* include directory names */
extern int linkput; /* Store symbolic links as such */
extern int noisy; /* False for quiet operation */
extern int extra_fields; /* do not create extra fields */
#ifdef NTSD_EAS
extern int use_privileges; /* use security privilege overrides */
#endif
extern char *key; /* Scramble password or NULL */
extern char *tempath; /* Path for temporary files */
extern FILE *mesg; /* Where informational output goes */
extern char *zipfile; /* New or existing zip archive (zip file) */
extern ulg zipbeg; /* Starting offset of zip structures */
extern ulg cenbeg; /* Starting offset of central directory */
extern struct zlist far *zfiles;/* Pointer to list of files in zip file */
extern extent zcount; /* Number of files in zip file */
extern extent zcomlen; /* Length of zip file comment */
extern char *zcomment; /* Zip file comment (not zero-terminated) */
extern struct zlist far **zsort;/* List of files sorted by name */
extern ulg tempzn; /* Count of bytes written to output zip file */
extern struct flist far *found; /* List of names found */
extern struct flist far *far *fnxt; /* Where to put next in found list */
extern extent fcount; /* Count of names in found list */
extern struct plist *patterns; /* List of patterns to be matched */
extern unsigned pcount; /* number of patterns */
extern unsigned icount; /* number of include only patterns */
extern unsigned Rcount; /* number of -R include patterns */
#ifdef IZ_CHECK_TZ
extern int zp_tz_is_valid; /* signals "timezone info is available" */
#endif
#if (defined(MACOS) || defined(WINDLL))
extern int zipstate; /* flag "zipfile has been stat()'ed */
#endif
/* Diagnostic functions */
#ifdef DEBUG
# ifdef MSDOS
# undef stderr
# define stderr stdout
# endif
# define diag(where) fprintf(stderr, "zip diagnostic: %s\n", where)
# define Assert(cond,msg) {if(!(cond)) error(msg);}
# ifdef THEOS
# define Trace(x) _fprintf x
# define Tracev(x) {if (verbose) _fprintf x ;}
# define Tracevv(x) {if (verbose>1) _fprintf x ;}
# define Tracec(c,x) {if (verbose && (c)) _fprintf x ;}
# define Tracecv(c,x) {if (verbose>1 && (c)) _fprintf x ;}
# else
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x ;}
# define Tracevv(x) {if (verbose>1) fprintf x ;}
# define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
# endif
#else
# define diag(where)
# define Assert(cond,msg)
# define Trace(x)
# define Tracev(x)
# define Tracevv(x)
# define Tracec(c,x)
# define Tracecv(c,x)
#endif
#ifdef DEBUGNAMES
# define free(x) { int *v;Free(x); v=x;*v=0xdeadbeef;x=(void *)0xdeadbeef; }
#endif
/* Public function prototypes */
#ifndef UTIL
#ifdef USE_ZIPMAIN
int zipmain OF((int, char **));
#else
int main OF((int, char **));
#endif /* USE_ZIPMAIN */
#endif
#ifdef EBCDIC
extern int aflag;
#endif /* EBCDIC */
#ifdef CMS_MVS
extern int bflag;
#endif /* CMS_MVS */
void zipwarn OF((ZCONST char *, ZCONST char *));
void ziperr OF((int, ZCONST char *));
#ifdef UTIL
# define error(msg) ziperr(ZE_LOGIC, msg)
#else
void error OF((ZCONST char *));
# ifdef VMSCLI
void help OF((void));
# endif
int encr_passwd OF((int, char *, int, ZCONST char *));
#endif
/* in zipup.c */
#ifndef UTIL
int percent OF((ulg, ulg));
int zipup OF((struct zlist far *, FILE *));
# ifdef USE_ZLIB
void zl_deflate_free OF((void));
# else
void flush_outbuf OF((char *, unsigned *));
int seekable OF((void));
extern unsigned (*read_buf) OF((char *, unsigned int));
# endif /* !USE_ZLIB */
# ifdef ZP_NEED_MEMCOMPR
ulg memcompress OF((char *, ulg, char *, ulg));
# endif
#endif /* !UTIL */
/* in zipfile.c */
#ifndef UTIL
struct zlist far *zsearch OF((ZCONST char *));
# ifdef USE_EF_UT_TIME
int get_ef_ut_ztime OF((struct zlist far *, iztimes *));
# endif /* USE_EF_UT_TIME */
int trash OF((void));
#endif /* !UTIL */
char *ziptyp OF((char *));
int readzipfile OF((void));
int putlocal OF((struct zlist far *, FILE *));
int putextended OF((struct zlist far *, FILE *));
int putcentral OF((struct zlist far *, FILE *));
int putend OF((unsigned, ulg, ulg, extent, char *, FILE *));
int zipcopy OF((struct zlist far *, FILE *, FILE *));
/* in fileio.c */
#ifndef UTIL
char *getnam OF((char *, FILE *));
struct flist far *fexpel OF((struct flist far *));
char *last OF((char *, int));
char *msname OF((char *));
int check_dup OF((void));
int filter OF((char *, int));
int newname OF((char *, int, int));
#endif /* !UTIL */
#if (!defined(UTIL) || defined(W32_STATROOT_FIX))
time_t dos2unixtime OF((ulg));
#endif
#ifndef UTIL
ulg dostime OF((int, int, int, int, int, int));
ulg unix2dostime OF((time_t *));
int issymlnk OF((ulg a));
# ifdef S_IFLNK
# define rdsymlnk(p,b,n) readlink(p,b,n)
/* extern int readlink OF((char *, char *, int)); */
# else /* !S_IFLNK */
# define rdsymlnk(p,b,n) (0)
# endif /* !S_IFLNK */
#endif /* !UTIL */
int destroy OF((char *));
int replace OF((char *, char *));
int getfileattr OF((char *));
int setfileattr OF((char *, int));
char *tempname OF((char *));
int fcopy OF((FILE *, FILE *, ulg));
#ifdef ZMEM
char *memset OF((char *, int, unsigned int));
char *memcpy OF((char *, char *, unsigned int));
int memcmp OF((char *, char *, unsigned int));
#endif /* ZMEM */
/* in system dependent fileio code (<system>.c) */
#ifndef UTIL
# ifdef PROCNAME
int wild OF((char *));
# endif
char *in2ex OF((char *));
char *ex2in OF((char *, int, int *));
int procname OF((char *, int));
void stamp OF((char *, ulg));
ulg filetime OF((char *, ulg *, long *, iztimes *));
#if !(defined(VMS) && defined(VMS_PK_EXTRA))
int set_extra_field OF((struct zlist far *, iztimes *));
#endif /* ?(VMS && VMS_PK_EXTRA) */
int deletedir OF((char *));
#ifdef MY_ZCALLOC
zvoid far *zcalloc OF((unsigned int, unsigned int));
zvoid zcfree OF((zvoid far *));
#endif /* MY_ZCALLOC */
#endif /* !UTIL */
void version_local OF((void));
/* in util.c */
#ifndef UTIL
int fseekable OF((FILE *));
char *isshexp OF((char *));
int shmatch OF((ZCONST char *, ZCONST char *, int));
#if defined(DOS) || defined(WIN32)
int dosmatch OF((ZCONST char *, ZCONST char *, int));
#endif /* DOS || WIN32 */
#endif /* !UTIL */
void init_upper OF((void));
int namecmp OF((ZCONST char *string1, ZCONST char *string2));
#ifdef EBCDIC
char *strtoasc OF((char *str1, ZCONST char *str2));
char *strtoebc OF((char *str1, ZCONST char *str2));
char *memtoasc OF((char *mem1, ZCONST char *mem2, unsigned len));
char *memtoebc OF((char *mem1, ZCONST char *mem2, unsigned len));
#endif /* EBCDIC */
#ifdef IZ_ISO2OEM_ARRAY
char *str_iso_to_oem OF((char *dst, ZCONST char *src));
#endif
#ifdef IZ_OEM2ISO_ARRAY
char *str_oem_to_iso OF((char *dst, ZCONST char *src));
#endif
zvoid far **search OF((ZCONST zvoid *, ZCONST zvoid far **, extent,
int (*)(ZCONST zvoid *, ZCONST zvoid far *)));
void envargs OF((int *, char ***, char *, char *));
void expand_args OF((int *, char ***));
#ifndef USE_ZLIB
#ifndef UTIL
/* in crc32.c */
ulg crc32 OF((ulg, ZCONST uch *, extent));
#endif /* !UTIL */
/* in crctab.c */
ZCONST ulg near *get_crc_table OF((void));
#ifdef DYNALLOC_CRCTAB
void free_crc_table OF((void));
#endif
#endif /* !USE_ZLIB */
#ifndef UTIL
#ifndef USE_ZLIB
/* in deflate.c */
void lm_init OF((int, ush *));
void lm_free OF((void));
ulg deflate OF((void));
/* in trees.c */
void ct_init OF((ush *, int *));
int ct_tally OF((int, int));
ulg flush_block OF((char far *, ulg, int));
void bi_init OF((char *, unsigned int, int));
#endif /* !USE_ZLIB */
#endif /* !UTIL */
/* in system specific assembler code, replacing C code in trees.c */
#if defined(ASMV) && defined(RISCOS)
void send_bits OF((int, int));
unsigned bi_reverse OF((unsigned int, int));
#endif /* ASMV && RISCOS */
/*---------------------------------------------------------------------------
VMS-only functions:
---------------------------------------------------------------------------*/
#ifdef VMS
int vms_stat OF((char *, stat_t *)); /* vms.c */
void vms_exit OF((int)); /* vms.c */
#ifndef UTIL
#ifdef VMSCLI
ulg vms_zip_cmdline OF((int *, char ***)); /* cmdline.c */
void VMSCLI_help OF((void)); /* cmdline.c */
#endif /* VMSCLI */
#endif /* !UTIL */
#endif /* VMS */
/*---------------------------------------------------------------------------
WIN32-only functions:
---------------------------------------------------------------------------*/
#ifdef WIN32
int ZipIsWinNT OF((void)); /* win32.c */
#endif /* WIN32 */
#if (defined(WINDLL) || defined(DLL_ZIPAPI))
/*---------------------------------------------------------------------------
Prototypes for public Zip API (DLL) functions.
---------------------------------------------------------------------------*/
#include "api.h"
#endif /* WINDLL || DLL_ZIPAPI */
#endif /* !__zip_h */
/* end of zip.h */

View File

@ -1,11 +0,0 @@
resource app_version
{
major = 2,
middle = 3,
minor = 0,
variety = 5,
internal = 0,
short_info = "2.3",
long_info = "2.3 ©1999 Info-ZIP"
};

View File

@ -1,430 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
#define __ZIPCLOAK_C
#ifndef UTIL
#define UTIL
#endif
#include "zip.h"
#define DEFCPYRT /* main module: enable copyright string defines! */
#include "revision.h"
#include "crypt.h"
#include "ttyio.h"
#include <signal.h>
#ifndef NO_STDLIB_H
# include <stdlib.h>
#endif
#if CRYPT /* defined (as TRUE or FALSE) in crypt.h */
int main OF((int argc, char **argv));
local void handler OF((int sig));
local void license OF((void));
local void help OF((void));
local void version_info OF((void));
/* Temporary zip file name and file pointer */
local char *tempzip;
local FILE *tempzf;
/* Pointer to CRC-32 table (used for decryption/encryption) */
#if (!defined(USE_ZLIB) || defined(USE_OWN_CRCTAB))
ZCONST ulg near *crc_32_tab;
#else
ZCONST uLongf *crc_32_tab;
#endif
/***********************************************************************
* Issue a message for the error, clean up files and memory, and exit.
*/
void ziperr(code, msg)
int code; /* error code from the ZE_ class */
ZCONST char *msg; /* message about how it happened */
{
if (PERR(code)) perror("zipcloak error");
fprintf(stderr, "zipcloak error: %s (%s)\n", ziperrors[code-1], msg);
if (tempzf != NULL) fclose(tempzf);
if (tempzip != NULL) {
destroy(tempzip);
free((zvoid *)tempzip);
}
if (zipfile != NULL) free((zvoid *)zipfile);
EXIT(code);
}
/***********************************************************************
* Print a warning message to stderr and return.
*/
void zipwarn(msg1, msg2)
ZCONST char *msg1, *msg2; /* message strings juxtaposed in output */
{
fprintf(stderr, "zipcloak warning: %s%s\n", msg1, msg2);
}
/***********************************************************************
* Upon getting a user interrupt, turn echo back on for tty and abort
* cleanly using ziperr().
*/
local void handler(sig)
int sig; /* signal number (ignored) */
{
#if (!defined(MSDOS) && !defined(__human68k__) && !defined(RISCOS))
echon();
putc('\n', stderr);
#endif
ziperr(ZE_ABORT +sig-sig, "aborting");
/* dummy usage of sig to avoid compiler warnings */
}
/***********************************************************************
* Print license information to stdout.
*/
local void license()
{
extent i;
for (i = 0; i < sizeof(swlicense)/sizeof(char *); i++)
puts(swlicense[i]);
putchar('\n');
}
static ZCONST char *help_info[] = {
"",
"ZipCloak %s (%s)",
#ifdef VM_CMS
"Usage: zipcloak [-dq] [-b fm] zipfile",
#else
"Usage: zipcloak [-dq] [-b path] zipfile",
#endif
" the default action is to encrypt all unencrypted entries in the zip file",
" -d decrypt--decrypt encrypted entries (copy if given wrong password)",
#ifdef VM_CMS
" -b use \"fm\" as the filemode for the temporary zip file",
#else
" -b use \"path\" for the temporary zip file",
#endif
" -q quieter operation, suppress some informational messages",
" -h show this help -v show version info -L show software license"
};
/***********************************************************************
* Print help (along with license info) to stdout.
*/
local void help()
{
extent i; /* counter for help array */
for (i = 0; i < sizeof(help_info)/sizeof(char *); i++) {
printf(help_info[i], VERSION, REVDATE);
putchar('\n');
}
}
local void version_info()
/* Print verbose info about program version and compile time options
to stdout. */
{
extent i; /* counter in text arrays */
/* Options info array */
static ZCONST char *comp_opts[] = {
#ifdef DEBUG
"DEBUG",
#endif
#if CRYPT && defined(PASSWD_FROM_STDIN)
"PASSWD_FROM_STDIN",
#endif /* CRYPT && PASSWD_FROM_STDIN */
NULL
};
for (i = 0; i < sizeof(copyright)/sizeof(char *); i++)
{
printf(copyright[i], "zipcloak");
putchar('\n');
}
for (i = 0; i < sizeof(versinfolines)/sizeof(char *); i++)
{
printf(versinfolines[i], "ZipCloak", VERSION, REVDATE);
putchar('\n');
}
version_local();
puts("ZipCloak special compilation options:");
for (i = 0; (int)i < (int)(sizeof(comp_opts)/sizeof(char *) - 1); i++)
{
printf("\t%s\n",comp_opts[i]);
}
printf("\t[encryption, version %d.%d%s of %s]\n",
CR_MAJORVER, CR_MINORVER, CR_BETA_VER, CR_VERSION_DATE);
for (i = 0; i < sizeof(cryptnote)/sizeof(char *); i++)
puts(cryptnote[i]);
}
/***********************************************************************
* Encrypt or decrypt all of the entries in a zip file. See the command
* help in help() above.
*/
int main(argc, argv)
int argc; /* number of tokens in command line */
char **argv; /* command line tokens */
{
int attr; /* attributes of zip file */
ulg start_offset; /* start of central directory */
int decrypt; /* decryption flag */
int temp_path; /* 1 if next argument is path for temp files */
char passwd[IZ_PWLEN+1]; /* password for encryption or decryption */
char verify[IZ_PWLEN+1]; /* password for encryption or decryption */
char *q; /* steps through option arguments */
int r; /* arg counter */
int res; /* result code */
ulg length; /* length of central directory */
FILE *inzip, *outzip; /* input and output zip files */
struct zlist far *z; /* steps through zfiles linked list */
#ifdef THEOS
setlocale(LC_CTYPE, "I");
#endif
/* If no args, show help */
if (argc == 1) {
help();
EXIT(ZE_OK);
}
/* Informational messages are written to stdout. */
mesg = stdout;
init_upper(); /* build case map table */
crc_32_tab = get_crc_table();
/* initialize crc table for crypt */
/* Go through args */
zipfile = tempzip = NULL;
tempzf = NULL;
#ifdef SIGINT
signal(SIGINT, handler);
#endif
#ifdef SIGTERM /* Some don't have SIGTERM */
signal(SIGTERM, handler);
#endif
#ifdef SIGABRT
signal(SIGABRT, handler);
#endif
#ifdef SIGBREAK
signal(SIGBREAK, handler);
#endif
#ifdef SIGBUS
signal(SIGBUS, handler);
#endif
#ifdef SIGILL
signal(SIGILL, handler);
#endif
#ifdef SIGSEGV
signal(SIGSEGV, handler);
#endif
temp_path = decrypt = 0;
for (r = 1; r < argc; r++) {
if (*argv[r] == '-') {
if (!argv[r][1]) ziperr(ZE_PARMS, "zip file cannot be stdin");
for (q = argv[r]+1; *q; q++) {
switch (*q) {
case 'b': /* Specify path for temporary file */
if (temp_path) {
ziperr(ZE_PARMS, "use -b before zip file name");
}
temp_path = 1; /* Next non-option is path */
break;
case 'd':
decrypt = 1; break;
case 'h': /* Show help */
help();
EXIT(ZE_OK);
case 'l': case 'L': /* Show copyright and disclaimer */
license();
EXIT(ZE_OK);
case 'q': /* Quiet operation, suppress info messages */
noisy = 0; break;
case 'v': /* Show version info */
version_info();
EXIT(ZE_OK);
default:
ziperr(ZE_PARMS, "unknown option");
} /* switch */
} /* for */
} else if (temp_path == 0) {
if (zipfile != NULL) {
ziperr(ZE_PARMS, "can only specify one zip file");
} else if ((zipfile = ziptyp(argv[r])) == NULL) {
ziperr(ZE_MEM, "was processing arguments");
}
} else {
tempath = argv[r];
temp_path = 0;
} /* if */
} /* for */
if (zipfile == NULL) ziperr(ZE_PARMS, "need to specify zip file");
/* Read zip file */
if ((res = readzipfile()) != ZE_OK) ziperr(res, zipfile);
if (zfiles == NULL) ziperr(ZE_NAME, zipfile);
/* Check for something to do */
for (z = zfiles; z != NULL; z = z->nxt) {
if (decrypt ? z->flg & 1 : !(z->flg & 1)) break;
}
if (z == NULL) {
ziperr(ZE_NONE, decrypt ? "no encrypted files"
: "all files encrypted already");
}
/* Before we get carried away, make sure zip file is writeable */
if ((inzip = fopen(zipfile, "a")) == NULL) ziperr(ZE_CREAT, zipfile);
fclose(inzip);
attr = getfileattr(zipfile);
/* Open output zip file for writing */
if ((tempzf = outzip = fopen(tempzip = tempname(zipfile), FOPW)) == NULL) {
ziperr(ZE_TEMP, tempzip);
}
/* Get password */
if (getp("Enter password: ", passwd, IZ_PWLEN+1) == NULL)
ziperr(ZE_PARMS,
"stderr is not a tty (you may never see this message!)");
if (decrypt == 0) {
if (getp("Verify password: ", verify, IZ_PWLEN+1) == NULL)
ziperr(ZE_PARMS,
"stderr is not a tty (you may never see this message!)");
if (strcmp(passwd, verify))
ziperr(ZE_PARMS, "password verification failed");
if (*passwd == '\0')
ziperr(ZE_PARMS, "zero length password not allowed");
}
/* Open input zip file again, copy preamble if any */
if ((inzip = fopen(zipfile, FOPR)) == NULL) ziperr(ZE_NAME, zipfile);
if (zipbeg && (res = fcopy(inzip, outzip, zipbeg)) != ZE_OK) {
ziperr(res, res == ZE_TEMP ? tempzip : zipfile);
}
tempzn = zipbeg;
/* Go through local entries, copying, encrypting, or decrypting */
for (z = zfiles; z != NULL; z = z->nxt) {
if (decrypt && (z->flg & 1)) {
printf("decrypting: %s", z->zname);
fflush(stdout);
if ((res = zipbare(z, inzip, outzip, passwd)) != ZE_OK) {
if (res != ZE_MISS) ziperr(res, "was decrypting an entry");
printf(" (wrong password--just copying)");
}
putchar('\n');
} else if ((!decrypt) && !(z->flg & 1)) {
printf("encrypting: %s\n", z->zname);
fflush(stdout);
if ((res = zipcloak(z, inzip, outzip, passwd)) != ZE_OK) {
ziperr(res, "was encrypting an entry");
}
} else {
printf(" copying: %s\n", z->zname);
fflush(stdout);
if ((res = zipcopy(z, inzip, outzip)) != ZE_OK) {
ziperr(res, "was copying an entry");
}
} /* if */
} /* for */
fclose(inzip);
/* Write central directory and end of central directory */
/* get start of central */
if ((start_offset = (ulg)ftell(outzip)) == (ulg)-1L)
ziperr(ZE_TEMP, tempzip);
for (z = zfiles; z != NULL; z = z->nxt) {
if ((res = putcentral(z, outzip)) != ZE_OK) ziperr(res, tempzip);
}
/* get end of central */
if ((length = (ulg)ftell(outzip)) == (ulg)-1L)
ziperr(ZE_TEMP, tempzip);
length -= start_offset; /* compute length of central */
if ((res = putend((int)zcount, length, start_offset, zcomlen,
zcomment, outzip)) != ZE_OK) {
ziperr(res, tempzip);
}
tempzf = NULL;
if (fclose(outzip)) ziperr(ZE_TEMP, tempzip);
if ((res = replace(zipfile, tempzip)) != ZE_OK) {
zipwarn("new zip file left as: ", tempzip);
free((zvoid *)tempzip);
tempzip = NULL;
ziperr(res, "was replacing the original zip file");
}
free((zvoid *)tempzip);
tempzip = NULL;
setfileattr(zipfile, attr);
#ifdef RISCOS
/* Set the filetype of the zipfile to &DDC */
setfiletype(zipfile, 0xDDC);
#endif
free((zvoid *)zipfile);
zipfile = NULL;
/* Done! */
RETURN(0);
}
#else /* !CRYPT */
int main OF((void));
void zipwarn(msg1, msg2)
ZCONST char *msg1, *msg2;
{
/* Tell picky compilers to shut up about unused variables */
msg1 = msg1; msg2 = msg2;
}
void ziperr(c, h)
int c;
ZCONST char *h;
{
/* Tell picky compilers to shut up about unused variables */
c = c; h = h;
}
int main()
{
fprintf(stderr, "\
This version of ZipCloak does not support encryption. Get the current Zip\n\
source distribution and recompile ZipCloak after you have added an option to\n\
define the symbol USE_CRYPT to the C compiler's command arguments.\n");
RETURN(1);
}
#endif /* ?CRYPT */

View File

@ -1,67 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*
* ziperr.h by Mark Adler
*/
/* Error return values. The values 0..4 and 12..18 follow the conventions
of PKZIP. The values 4..10 are all assigned to "insufficient memory"
by PKZIP, so the codes 5..10 are used here for other purposes. */
#define ZE_MISS -1 /* used by procname(), zipbare() */
#define ZE_OK 0 /* success */
#define ZE_EOF 2 /* unexpected end of zip file */
#define ZE_FORM 3 /* zip file structure error */
#define ZE_MEM 4 /* out of memory */
#define ZE_LOGIC 5 /* internal logic error */
#define ZE_BIG 6 /* entry too large to split, read, or write */
#define ZE_NOTE 7 /* invalid comment format */
#define ZE_TEST 8 /* zip test (-T) failed or out of memory */
#define ZE_ABORT 9 /* user interrupt or termination */
#define ZE_TEMP 10 /* error using a temp file */
#define ZE_READ 11 /* read or seek error */
#define ZE_NONE 12 /* nothing to do */
#define ZE_NAME 13 /* missing or empty zip file */
#define ZE_WRITE 14 /* error writing to a file */
#define ZE_CREAT 15 /* couldn't open to write */
#define ZE_PARMS 16 /* bad command line */
#define ZE_OPEN 18 /* could not open a specified file to read */
#define ZE_MAXERR 18 /* the highest error number */
/* Macro to determine whether to call perror() or not */
#define PERR(e) (e==ZE_READ||e==ZE_WRITE||e==ZE_CREAT||e==ZE_TEMP||e==ZE_OPEN)
#ifdef GLOBALS
/* Error messages for the ziperr() function in the zip programs */
char *ziperrors[ZE_MAXERR] = {
/* 1 */ "",
/* 2 */ "Unexpected end of zip file",
/* 3 */ "Zip file structure invalid",
/* 4 */ "Out of memory",
/* 5 */ "Internal logic error",
/* 6 */ "Entry too big to split, read, or write",
/* 7 */ "Invalid comment format",
/* 8 */ "Zip file invalid or could not spawn unzip",
/* 9 */ "Interrupted",
/* 10 */ "Temporary file failure",
/* 11 */ "Input file read failure",
/* 12 */ "Nothing to do!",
/* 13 */ "Missing or empty zip file",
/* 14 */ "Output file write failure",
/* 15 */ "Could not create output file",
/* 16 */ "Invalid command arguments",
/* 17 */ "",
/* 18 */ "File not found or no read permission"
# ifdef AZTEC_C
, /* extremely lame compiler bug workaround */
# endif
};
#else /* !GLOBALS */
extern char *ziperrors[ZE_MAXERR]; /* Error messages for ziperr() */
#endif /* ?GLOBALS */

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +0,0 @@
#define UTIL
#include "zipfile.c"

View File

@ -1,526 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 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
*/
/*
* zipnote.c by Mark Adler.
*/
#define __ZIPNOTE_C
#ifndef UTIL
#define UTIL
#endif
#include "zip.h"
#define DEFCPYRT /* main module: enable copyright string defines! */
#include "revision.h"
#include <signal.h>
/* Calculate size of static line buffer used in write (-w) mode. */
#define WRBUFSIZ 2047
/* The line buffer size should be at least as large as FNMAX. */
#if FNMAX > WRBUFSIZ
# undef WRBUFSIZ
# define WRBUFSIZ FNMAX
#endif
/* Character to mark zip entry names in the comment file */
#define MARK '@'
#define MARKE " (comment above this line)"
#define MARKZ " (zip file comment below this line)"
/* Temporary zip file name and file pointer */
local char *tempzip;
local FILE *tempzf;
/* Local functions */
local void handler OF((int));
local void license OF((void));
local void help OF((void));
local void version_info OF((void));
local void putclean OF((char *, extent));
/* getline name conflicts with GNU getline() function */
local char *zgetline OF((char *, extent));
local int catalloc OF((char * far *, char *));
int main OF((int, char **));
#ifdef MACOS
#define ziperr(c, h) zipnoteerr(c, h)
#define zipwarn(a, b) zipnotewarn(a, b)
void zipnoteerr(int c, ZCONST char *h);
void zipnotewarn(ZCONST char *a, ZCONST char *b);
#endif
#ifdef QDOS
#define exit(p1) QDOSexit()
#endif
void ziperr(c, h)
int c; /* error code from the ZE_ class */
ZCONST char *h; /* message about how it happened */
/* Issue a message for the error, clean up files and memory, and exit. */
{
if (PERR(c))
perror("zipnote error");
fprintf(stderr, "zipnote error: %s (%s)\n", ziperrors[c-1], h);
if (tempzf != NULL)
fclose(tempzf);
if (tempzip != NULL)
{
destroy(tempzip);
free((zvoid *)tempzip);
}
if (zipfile != NULL)
free((zvoid *)zipfile);
EXIT(c);
}
local void handler(s)
int s; /* signal number (ignored) */
/* Upon getting a user interrupt, abort cleanly using ziperr(). */
{
#ifndef MSDOS
putc('\n', stderr);
#endif /* !MSDOS */
ziperr(ZE_ABORT, "aborting");
s++; /* keep some compilers happy */
}
void zipwarn(a, b)
ZCONST char *a, *b; /* message strings juxtaposed in output */
/* Print a warning message to stderr and return. */
{
fprintf(stderr, "zipnote warning: %s%s\n", a, b);
}
local void license()
/* Print license information to stdout. */
{
extent i; /* counter for copyright array */
for (i = 0; i < sizeof(swlicense)/sizeof(char *); i++)
puts(swlicense[i]);
}
local void help()
/* Print help (along with license info) to stdout. */
{
extent i; /* counter for help array */
/* help array */
static ZCONST char *text[] = {
"",
"ZipNote %s (%s)",
#ifdef VM_CMS
"Usage: zipnote [-w] [-q] [-b fm] zipfile",
#else
"Usage: zipnote [-w] [-q] [-b path] zipfile",
#endif
" the default action is to write the comments in zipfile to stdout",
" -w write the zipfile comments from stdin",
#ifdef VM_CMS
" -b use \"fm\" as the filemode for the temporary zip file",
#else
" -b use \"path\" for the temporary zip file",
#endif
" -q quieter operation, suppress some informational messages",
" -h show this help -v show version info -L show software license",
"",
"Example:",
#ifdef VMS
" define/user sys$output foo.tmp",
" zipnote foo.zip",
" edit foo.tmp",
" ... then you edit the comments, save, and exit ...",
" define/user sys$input foo.tmp",
" zipnote -w foo.zip",
#else
#ifdef RISCOS
" zipnote foo/zip > foo/tmp",
" <!Edit> foo/tmp",
" ... then you edit the comments, save, and exit ...",
" zipnote -w foo/zip < foo/tmp",
#else
#ifdef VM_CMS
" zipnote foo.zip > foo.tmp",
" xedit foo tmp",
" ... then you edit the comments, save, and exit ...",
" zipnote -w foo.zip < foo.tmp",
#else
" zipnote foo.zip > foo.tmp",
" ed foo.tmp",
" ... then you edit the comments, save, and exit ...",
" zipnote -w foo.zip < foo.tmp",
#endif /* VM_CMS */
#endif /* RISCOS */
#endif /* VMS */
"",
" \"@ name\" can be followed by an \"@=newname\" line to change the name"
};
for (i = 0; i < sizeof(copyright)/sizeof(char *); i++) {
printf(copyright[i], "zipnote");
putchar('\n');
}
for (i = 0; i < sizeof(text)/sizeof(char *); i++)
{
printf(text[i], VERSION, REVDATE);
putchar('\n');
}
}
/*
* XXX put this in version.c
*/
local void version_info()
/* Print verbose info about program version and compile time options
to stdout. */
{
extent i; /* counter in text arrays */
/* Options info array */
static ZCONST char *comp_opts[] = {
#ifdef DEBUG
"DEBUG",
#endif
NULL
};
for (i = 0; i < sizeof(copyright)/sizeof(char *); i++)
{
printf(copyright[i], "zipnote");
putchar('\n');
}
for (i = 0; i < sizeof(versinfolines)/sizeof(char *); i++)
{
printf(versinfolines[i], "ZipNote", VERSION, REVDATE);
putchar('\n');
}
version_local();
puts("ZipNote special compilation options:");
for (i = 0; (int)i < (int)(sizeof(comp_opts)/sizeof(char *) - 1); i++)
{
printf("\t%s\n",comp_opts[i]);
}
if (i == 0)
puts("\t[none]");
}
local void putclean(s, n)
char *s; /* string to write to stdout */
extent n; /* length of string */
/* Write the string s to stdout, filtering out control characters that are
not tab or newline (mainly to remove carriage returns), and prefix MARK's
and backslashes with a backslash. Also, terminate with a newline if
needed. */
{
int c; /* next character in string */
int e; /* last character written */
e = '\n'; /* if empty, write nothing */
while (n--)
{
c = *(uch *)s++;
if (c == MARK || c == '\\')
putchar('\\');
if (c >= ' ' || c == '\t' || c == '\n')
{ e=c; putchar(e); }
}
if (e != '\n')
putchar('\n');
}
local char *zgetline(buf, size)
char *buf;
extent size;
/* Read a line of text from stdin into string buffer 'buf' of size 'size'.
In case of buffer overflow or EOF, a NULL pointer is returned. */
{
char *line;
unsigned len;
line = fgets(buf, size, stdin);
if (line != NULL && (len = strlen(line)) > 0) {
if (len == size-1 && line[len-1] != '\n') {
/* buffer is full and record delimiter not seen -> overflow */
line = NULL;
} else {
/* delete trailing record delimiter */
if (line[len-1] == '\n') line[len-1] = '\0';
}
}
return line;
}
local int catalloc(a, s)
char * far *a; /* pointer to a pointer to a malloc'ed string */
char *s; /* string to concatenate on a */
/* Concatentate the string s to the malloc'ed string pointed to by a.
Preprocess s by removing backslash escape characters. */
{
char *p; /* temporary pointer */
char *q; /* temporary pointer */
for (p = q = s; *q; *p++ = *q++)
if (*q == '\\' && *(q+1))
q++;
*p = 0;
if ((p = malloc(strlen(*a) + strlen(s) + 3)) == NULL)
return ZE_MEM;
strcat(strcat(strcpy(p, *a), **a ? "\r\n" : ""), s);
free((zvoid *)*a);
*a = p;
return ZE_OK;
}
#ifndef USE_ZIPNOTEMAIN
int main(argc, argv)
#else
int zipnotemain(argc, argv)
#endif
int argc; /* number of tokens in command line */
char **argv; /* command line tokens */
/* Write the comments in the zipfile to stdout, or read them from stdin. */
{
char a[WRBUFSIZ+1]; /* input line buffer */
ulg c; /* start of central directory */
int k; /* next argument type */
char *q; /* steps through option arguments */
int r; /* arg counter, temporary variable */
ulg s; /* length of central directory */
int t; /* attributes of zip file */
int w; /* true if updating zip file from stdin */
FILE *x, *y; /* input and output zip files */
struct zlist far *z; /* steps through zfiles linked list */
#ifdef THEOS
setlocale(LC_CTYPE, "I");
#endif
/* If no args, show help */
if (argc == 1)
{
help();
EXIT(ZE_OK);
}
/* Direct info messages to stderr; stdout is used for data output. */
mesg = stderr;
init_upper(); /* build case map table */
/* Go through args */
zipfile = tempzip = NULL;
tempzf = NULL;
signal(SIGINT, handler);
#ifdef SIGTERM /* AMIGA has no SIGTERM */
signal(SIGTERM, handler);
#endif
#ifdef SIGABRT
signal(SIGABRT, handler);
#endif
#ifdef SIGBREAK
signal(SIGBREAK, handler);
#endif
#ifdef SIGBUS
signal(SIGBUS, handler);
#endif
#ifdef SIGILL
signal(SIGILL, handler);
#endif
#ifdef SIGSEGV
signal(SIGSEGV, handler);
#endif
k = w = 0;
for (r = 1; r < argc; r++)
if (*argv[r] == '-') {
if (argv[r][1])
for (q = argv[r]+1; *q; q++)
switch (*q)
{
case 'b': /* Specify path for temporary file */
if (k)
ziperr(ZE_PARMS, "use -b before zip file name");
else
k = 1; /* Next non-option is path */
break;
case 'h': /* Show help */
help(); EXIT(ZE_OK);
case 'l': case 'L': /* Show copyright and disclaimer */
license(); EXIT(ZE_OK);
case 'q': /* Quiet operation, suppress info messages */
noisy = 0; break;
case 'v': /* Show version info */
version_info(); EXIT(ZE_OK);
case 'w':
w = 1; break;
default:
ziperr(ZE_PARMS, "unknown option");
}
else
ziperr(ZE_PARMS, "zip file cannot be stdin");
} else
if (k == 0)
{
if (zipfile == NULL)
{
if ((zipfile = ziptyp(argv[r])) == NULL)
ziperr(ZE_MEM, "was processing arguments");
}
else
ziperr(ZE_PARMS, "can only specify one zip file");
}
else
{
tempath = argv[r];
k = 0;
}
if (zipfile == NULL)
ziperr(ZE_PARMS, "need to specify zip file");
/* Read zip file */
if ((r = readzipfile()) != ZE_OK)
ziperr(r, zipfile);
if (zfiles == NULL)
ziperr(ZE_NAME, zipfile);
/* Put comments to stdout, if not -w */
if (!w)
{
for (z = zfiles; z != NULL; z = z->nxt)
{
printf("%c %s\n", MARK, z->zname);
putclean(z->comment, z->com);
printf("%c%s\n", MARK, MARKE);
}
printf("%c%s\n", MARK, MARKZ);
putclean(zcomment, zcomlen);
EXIT(ZE_OK);
}
/* If updating comments, make sure zip file is writeable */
if ((x = fopen(zipfile, "a")) == NULL)
ziperr(ZE_CREAT, zipfile);
fclose(x);
t = getfileattr(zipfile);
/* Process stdin, replacing comments */
z = zfiles;
while (zgetline(a, WRBUFSIZ+1) != NULL &&
(a[0] != MARK || strcmp(a + 1, MARKZ)))
{ /* while input and not file comment */
if (a[0] != MARK || a[1] != ' ') /* better be "@ name" */
ziperr(ZE_NOTE, "unexpected input");
while (z != NULL && strcmp(a + 2, z->zname))
z = z->nxt; /* allow missing entries in order */
if (z == NULL)
ziperr(ZE_NOTE, "unknown entry name");
if (zgetline(a, WRBUFSIZ+1) != NULL && a[0] == MARK && a[1] == '=')
{
if (z->name != z->iname)
free((zvoid *)z->iname);
if ((z->iname = malloc(strlen(a+1))) == NULL)
ziperr(ZE_MEM, "was changing name");
#ifdef EBCDIC
strtoasc(z->iname, a+2);
#else
strcpy(z->iname, a+2);
#endif
/*
* Don't update z->nam here, we need the old value a little later.....
* The update is handled in zipcopy().
*/
zgetline(a, WRBUFSIZ+1);
}
if (z->com) /* change zip entry comment */
free((zvoid *)z->comment);
z->comment = malloc(1); *(z->comment) = 0;
while (a != NULL && *a != MARK)
{
if ((r = catalloc(&(z->comment), a)) != ZE_OK)
ziperr(r, "was building new comments");
zgetline(a, WRBUFSIZ+1);
}
z->com = strlen(z->comment);
z = z->nxt; /* point to next entry */
}
if (a != NULL) /* change zip file comment */
{
zcomment = malloc(1); *zcomment = 0;
while (zgetline(a, WRBUFSIZ+1) != NULL)
if ((r = catalloc(&zcomment, a)) != ZE_OK)
ziperr(r, "was building new comments");
zcomlen = strlen(zcomment);
}
/* Open output zip file for writing */
if ((tempzf = y = fopen(tempzip = tempname(zipfile), FOPW)) == NULL)
ziperr(ZE_TEMP, tempzip);
/* Open input zip file again, copy preamble if any */
if ((x = fopen(zipfile, FOPR)) == NULL)
ziperr(ZE_NAME, zipfile);
if (zipbeg && (r = fcopy(x, y, zipbeg)) != ZE_OK)
ziperr(r, r == ZE_TEMP ? tempzip : zipfile);
tempzn = zipbeg;
/* Go through local entries, copying them over as is */
fix = 3; /* needed for zipcopy if name changed */
for (z = zfiles; z != NULL; z = z->nxt) {
if ((r = zipcopy(z, x, y)) != ZE_OK)
ziperr(r, "was copying an entry");
}
fclose(x);
/* Write central directory and end of central directory with new comments */
if ((c = ftell(y)) == (ulg)(-1L)) /* get start of central */
ziperr(ZE_TEMP, tempzip);
for (z = zfiles; z != NULL; z = z->nxt)
if ((r = putcentral(z, y)) != ZE_OK)
ziperr(r, tempzip);
if ((s = ftell(y)) == (ulg)-1L) /* get end of central */
ziperr(ZE_TEMP, tempzip);
s -= c; /* compute length of central */
if ((r = putend((int)zcount, s, c, zcomlen, zcomment, y)) != ZE_OK)
ziperr(r, tempzip);
tempzf = NULL;
if (fclose(y))
ziperr(ZE_TEMP, tempzip);
if ((r = replace(zipfile, tempzip)) != ZE_OK)
{
zipwarn("new zip file left as: ", tempzip);
free((zvoid *)tempzip);
tempzip = NULL;
ziperr(r, "was replacing the original zip file");
}
free((zvoid *)tempzip);
tempzip = NULL;
setfileattr(zipfile, t);
#ifdef RISCOS
/* Set the filetype of the zipfile to &DDC */
setfiletype(zipfile,0xDDC);
#endif
free((zvoid *)zipfile);
zipfile = NULL;
/* Done! */
RETURN(0);
}

View File

@ -1,828 +0,0 @@
/*
Copyright (c) 1990-2005 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2005-Feb-10 or later
(the contents of which are also included in zip.h) for terms of use.
If, for some reason, both of these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*
* zipsplit.c by Mark Adler.
*/
#define __ZIPSPLIT_C
#ifndef UTIL
#define UTIL
#endif
#include "zip.h"
#define DEFCPYRT /* main module: enable copyright string defines! */
#include "revision.h"
#include <signal.h>
#define DEFSIZ 36000L /* Default split size (change in help() too) */
#ifdef MSDOS
# define NL 2 /* Number of bytes written for a \n */
#else /* !MSDOS */
# define NL 1 /* Number of bytes written for a \n */
#endif /* ?MSDOS */
#ifdef RISCOS
# define INDEX "zipspl/idx" /* Name of index file */
# define TEMPL_FMT "%%0%dld"
# define TEMPL_SIZ 13
# define ZPATH_SEP '.'
#else
#ifdef QDOS
# define ZPATH_SEP '_'
# define INDEX "zipsplit_idx" /* Name of index file */
# define TEMPL_FMT "%%0%dld_zip"
# define TEMPL_SIZ 17
# define exit(p1) QDOSexit()
#else
#ifdef VM_CMS
# define INDEX "zipsplit.idx" /* Name of index file */
# define TEMPL_FMT "%%0%dld.zip"
# define TEMPL_SIZ 21
# define ZPATH_SEP '.'
#else
# define INDEX "zipsplit.idx" /* Name of index file */
# define TEMPL_FMT "%%0%dld.zip"
# define TEMPL_SIZ 17
# define ZPATH_SEP '.'
#endif /* VM_CMS */
#endif /* QDOS */
#endif /* RISCOS */
#ifdef MACOS
#define ziperr(c, h) zipspliterr(c, h)
#define zipwarn(a, b) zipsplitwarn(a, b)
void zipsplitwarn(ZCONST char *a, ZCONST char *b);
void zipspliterr(int c, ZCONST char *h);
#endif /* MACOS */
/* Local functions */
local zvoid *talloc OF((extent));
local void tfree OF((zvoid *));
local void tfreeall OF((void));
local void handler OF((int));
local void license OF((void));
local void help OF((void));
local void version_info OF((void));
local extent simple OF((ulg *, extent, ulg, ulg));
local int descmp OF((ZCONST zvoid *, ZCONST zvoid *));
local extent greedy OF((ulg *, extent, ulg, ulg));
local int retry OF((void));
int main OF((int, char **));
/* Output zip files */
local char template[TEMPL_SIZ]; /* name template for output files */
local int zipsmade = 0; /* number of zip files made */
local int indexmade = 0; /* true if index file made */
local char *path = NULL; /* space for full name */
local char *name; /* where name goes in path[] */
/* The talloc() and tree() routines extend malloc() and free() to keep
track of all allocated memory. Then the tfreeall() routine uses this
information to free all allocated memory before exiting. */
#define TMAX 6 /* set intelligently by examining the code */
zvoid *talls[TMAX]; /* malloc'ed pointers to track */
int talln = 0; /* number of entries in talls[] */
local zvoid *talloc(s)
extent s;
/* does a malloc() and saves the pointer to free later (does not check
for an overflow of the talls[] list) */
{
zvoid *p;
if ((p = (zvoid *)malloc(s)) != NULL)
talls[talln++] = p;
return p;
}
local void tfree(p)
zvoid *p;
/* does a free() and also removes the pointer from the talloc() list */
{
int i;
free(p);
i = talln;
while (i--)
if (talls[i] == p)
break;
if (i >= 0)
{
while (++i < talln)
talls[i - 1] = talls[i];
talln--;
}
}
local void tfreeall()
/* free everything talloc'ed and not tfree'd */
{
while (talln)
free(talls[--talln]);
}
void ziperr(c, h)
int c; /* error code from the ZE_ class */
ZCONST char *h; /* message about how it happened */
/* Issue a message for the error, clean up files and memory, and exit. */
{
if (PERR(c))
perror("zipsplit error");
fprintf(stderr, "zipsplit error: %s (%s)\n", ziperrors[c-1], h);
if (indexmade)
{
strcpy(name, INDEX);
destroy(path);
}
for (; zipsmade; zipsmade--)
{
sprintf(name, template, zipsmade);
destroy(path);
}
tfreeall();
if (zipfile != NULL)
free((zvoid *)zipfile);
EXIT(c);
}
local void handler(s)
int s; /* signal number (ignored) */
/* Upon getting a user interrupt, abort cleanly using ziperr(). */
{
#ifndef MSDOS
putc('\n', stderr);
#endif /* !MSDOS */
ziperr(ZE_ABORT, "aborting");
s++; /* keep some compilers happy */
}
void zipwarn(a, b)
ZCONST char *a, *b; /* message strings juxtaposed in output */
/* Print a warning message to stderr and return. */
{
fprintf(stderr, "zipsplit warning: %s%s\n", a, b);
}
local void license()
/* Print license information to stdout. */
{
extent i; /* counter for copyright array */
for (i = 0; i < sizeof(swlicense)/sizeof(char *); i++)
puts(swlicense[i]);
}
local void help()
/* Print help (along with license info) to stdout. */
{
extent i; /* counter for help array */
/* help array */
static ZCONST char *text[] = {
"",
"ZipSplit %s (%s)",
#ifdef VM_CMS
"Usage: zipsplit [-tipqs] [-n size] [-r room] [-b fm] zipfile",
#else
"Usage: zipsplit [-tipqs] [-n size] [-r room] [-b path] zipfile",
#endif
" -t report how many files it will take, but don't make them",
#ifdef RISCOS
" -i make index (" INDEX ") and count its size against first zip file",
#else
" -i make index (zipsplit.idx) and count its size against first zip file",
#endif
" -n make zip files no larger than \"size\" (default = 36000)",
" -r leave room for \"room\" bytes on the first disk (default = 0)",
#ifdef VM_CMS
" -b use \"fm\" as the filemode for the output zip files",
#else
" -b use \"path\" for the output zip files",
#endif
" -p pause between output zip files",
" -q quieter operation, suppress some informational messages",
" -s do a sequential split even if it takes more zip files",
" -h show this help -v show version info -L show software license"
};
for (i = 0; i < sizeof(copyright)/sizeof(char *); i++) {
printf(copyright[i], "zipsplit");
putchar('\n');
}
for (i = 0; i < sizeof(text)/sizeof(char *); i++)
{
printf(text[i], VERSION, REVDATE);
putchar('\n');
}
}
local void version_info()
/* Print verbose info about program version and compile time options
to stdout. */
{
extent i; /* counter in text arrays */
/* Options info array */
static ZCONST char *comp_opts[] = {
#ifdef DEBUG
"DEBUG",
#endif
NULL
};
for (i = 0; i < sizeof(copyright)/sizeof(char *); i++)
{
printf(copyright[i], "zipsplit");
putchar('\n');
}
for (i = 0; i < sizeof(versinfolines)/sizeof(char *); i++)
{
printf(versinfolines[i], "ZipSplit", VERSION, REVDATE);
putchar('\n');
}
version_local();
puts("ZipSplit special compilation options:");
for (i = 0; (int)i < (int)(sizeof(comp_opts)/sizeof(char *) - 1); i++)
{
printf("\t%s\n",comp_opts[i]);
}
if (i == 0)
puts("\t[none]");
}
local extent simple(a, n, c, d)
ulg *a; /* items to put in bins, return value: destination bins */
extent n; /* number of items */
ulg c; /* capacity of each bin */
ulg d; /* amount to deduct from first bin */
/* Return the number of bins of capacity c that are needed to contain the
integers in a[0..n-1] placed sequentially into the bins. The value d
is deducted initially from the first bin (space for index). The entries
in a[] are replaced by the destination bins. */
{
extent k; /* current bin number */
ulg t; /* space used in current bin */
t = k = 0;
while (n--)
{
if (*a + t > c - (k == 0 ? d : 0))
{
k++;
t = 0;
}
t += *a;
*(ulg huge *)a++ = k;
}
return k + 1;
}
local int descmp(a, b)
ZCONST zvoid *a, *b; /* pointers to pointers to ulg's to compare */
/* Used by qsort() in greedy() to do a descending sort. */
{
return **(ulg **)a < **(ulg **)b ? 1 : (**(ulg **)a > **(ulg **)b ? -1 : 0);
}
local extent greedy(a, n, c, d)
ulg *a; /* items to put in bins, return value: destination bins */
extent n; /* number of items */
ulg c; /* capacity of each bin */
ulg d; /* amount to deduct from first bin */
/* Return the number of bins of capacity c that are needed to contain the
items with sizes a[0..n-1] placed non-sequentially into the bins. The
value d is deducted initially from the first bin (space for index).
The entries in a[] are replaced by the destination bins. */
{
ulg *b; /* space left in each bin (malloc'ed for each m) */
ulg *e; /* copy of argument a[] (malloc'ed) */
extent i; /* steps through items */
extent j; /* steps through bins */
extent k; /* best bin to put current item in */
extent m; /* current number of bins */
ulg **s; /* pointers to e[], sorted descending (malloc'ed) */
ulg t; /* space left in best bin (index k) */
/* Algorithm:
1. Copy a[] to e[] and sort pointers to e[0..n-1] (in s[]), in
descending order.
2. Compute total of s[] and set m to the smallest number of bins of
capacity c that can hold the total.
3. Allocate m bins.
4. For each item in s[], starting with the largest, put it in the
bin with the smallest current capacity greater than or equal to the
item's size. If no bin has enough room, increment m and go to step 4.
5. Else, all items ended up in a bin--return m.
*/
/* Copy a[] to e[], put pointers to e[] in s[], and sort s[]. Also compute
the initial number of bins (minus 1). */
if ((e = (ulg *)malloc(n * sizeof(ulg))) == NULL ||
(s = (ulg **)malloc(n * sizeof(ulg *))) == NULL)
{
if (e != NULL)
free((zvoid *)e);
ziperr(ZE_MEM, "was trying a smart split");
return 0; /* only to make compiler happy */
}
memcpy((char *)e, (char *)a, n * sizeof(ulg));
for (t = i = 0; i < n; i++)
t += *(s[i] = e + i);
m = (extent)((t + c - 1) / c) - 1; /* pre-decrement for loop */
qsort((char *)s, n, sizeof(ulg *), descmp);
/* Stuff bins until successful */
do {
/* Increment the number of bins, allocate and initialize bins */
if ((b = (ulg *)malloc(++m * sizeof(ulg))) == NULL)
{
free((zvoid *)s);
free((zvoid *)e);
ziperr(ZE_MEM, "was trying a smart split");
}
b[0] = c - d; /* leave space in first bin */
for (j = 1; j < m; j++)
b[j] = c;
/* Fill the bins greedily */
for (i = 0; i < n; i++)
{
/* Find smallest bin that will hold item i (size s[i]) */
t = c + 1;
for (k = j = 0; j < m; j++)
if (*s[i] <= b[j] && b[j] < t)
t = b[k = j];
/* If no bins big enough for *s[i], try next m */
if (t == c + 1)
break;
/* Diminish that bin and save where it goes */
b[k] -= *s[i];
a[(int)((ulg huge *)(s[i]) - (ulg huge *)e)] = k;
}
/* Clean up */
free((zvoid *)b);
/* Do until all items put in a bin */
} while (i < n);
/* Done--clean up and return the number of bins needed */
free((zvoid *)s);
free((zvoid *)e);
return m;
}
local int retry()
{
char m[10];
fputs("Error writing to disk--redo entire disk? ", stderr);
fgets(m, 10, stdin);
return *m == 'y' || *m == 'Y';
}
#ifndef USE_ZIPSPLITMAIN
int main(argc, argv)
#else
int zipsplitmain(argc, argv)
#endif
int argc; /* number of tokens in command line */
char **argv; /* command line tokens */
/* Split a zip file into several zip files less than a specified size. See
the command help in help() above. */
{
ulg *a; /* malloc'ed list of sizes, dest bins */
extent *b; /* heads of bin linked lists (malloc'ed) */
ulg c; /* bin capacity, start of central directory */
int d; /* if true, just report the number of disks */
FILE *e; /* input zip file */
FILE *f; /* output index and zip files */
extent g; /* number of bins from greedy(), entry to write */
int h; /* how to split--true means simple split, counter */
ulg i = 0; /* size of index file plus room to leave */
extent j; /* steps through zip entries, bins */
int k; /* next argument type */
extent *n = NULL; /* next item in bin list (heads in b) */
ulg *p; /* malloc'ed list of sizes, dest bins for greedy() */
char *q; /* steps through option characters */
int r; /* temporary variable, counter */
extent s; /* number of bins needed */
ulg t; /* total of sizes, end of central directory */
int u; /* flag to wait for user on output files */
struct zlist far **w; /* malloc'ed table for zfiles linked list */
int x; /* if true, make an index file */
struct zlist far *z; /* steps through zfiles linked list */
#ifdef AMIGA
char tailchar; /* temporary variable used in name generation below */
#endif
#ifdef THEOS
setlocale(LC_CTYPE, "I");
#endif
/* If no args, show help */
if (argc == 1)
{
help();
EXIT(ZE_OK);
}
/* Informational messages are written to stdout. */
mesg = stdout;
init_upper(); /* build case map table */
/* Go through args */
signal(SIGINT, handler);
#ifdef SIGTERM /* Amiga has no SIGTERM */
signal(SIGTERM, handler);
#endif
#ifdef SIGABRT
signal(SIGABRT, handler);
#endif
#ifdef SIGBREAK
signal(SIGBREAK, handler);
#endif
#ifdef SIGBUS
signal(SIGBUS, handler);
#endif
#ifdef SIGILL
signal(SIGILL, handler);
#endif
#ifdef SIGSEGV
signal(SIGSEGV, handler);
#endif
k = h = x = d = u = 0;
c = DEFSIZ;
for (r = 1; r < argc; r++)
if (*argv[r] == '-')
{
if (argv[r][1])
for (q = argv[r]+1; *q; q++)
switch (*q)
{
case 'b': /* Specify path for output files */
if (k)
ziperr(ZE_PARMS, "options are separate and precede zip file");
else
k = 1; /* Next non-option is path */
break;
case 'h': /* Show help */
help(); EXIT(ZE_OK);
case 'i': /* Make an index file */
x = 1;
break;
case 'l': case 'L': /* Show copyright and disclaimer */
license(); EXIT(ZE_OK);
case 'n': /* Specify maximum size of resulting zip files */
if (k)
ziperr(ZE_PARMS, "options are separate and precede zip file");
else
k = 2; /* Next non-option is size */
break;
case 'p':
u = 1;
break;
case 'q': /* Quiet operation, suppress info messages */
noisy = 0;
break;
case 'r':
if (k)
ziperr(ZE_PARMS, "options are separate and precede zip file");
else
k = 3; /* Next non-option is room to leave */
break;
case 's':
h = 1; /* Only try simple */
break;
case 't': /* Just report number of disks */
d = 1;
break;
case 'v': /* Show version info */
version_info(); EXIT(ZE_OK);
default:
ziperr(ZE_PARMS, "Use option -h for help.");
}
else
ziperr(ZE_PARMS, "zip file cannot be stdin");
}
else
switch (k)
{
case 0:
if (zipfile == NULL)
{
if ((zipfile = ziptyp(argv[r])) == NULL)
ziperr(ZE_MEM, "was processing arguments");
}
else
ziperr(ZE_PARMS, "can only specify one zip file");
break;
case 1:
tempath = argv[r];
k = 0;
break;
case 2:
if ((c = (ulg)atol(argv[r])) < 100) /* 100 is smallest zip file */
ziperr(ZE_PARMS, "invalid size given. Use option -h for help.");
k = 0;
break;
default: /* k must be 3 */
i = (ulg)atol(argv[r]);
k = 0;
break;
}
if (zipfile == NULL)
ziperr(ZE_PARMS, "need to specify zip file");
/* Read zip file */
if ((r = readzipfile()) != ZE_OK)
ziperr(r, zipfile);
if (zfiles == NULL)
ziperr(ZE_NAME, zipfile);
/* Make a list of sizes and check against capacity. Also compute the
size of the index file. */
c -= ENDHEAD + 4; /* subtract overhead/zipfile */
if ((a = (ulg *)talloc(zcount * sizeof(ulg))) == NULL ||
(w = (struct zlist far **)talloc(zcount * sizeof(struct zlist far *))) ==
NULL)
{
ziperr(ZE_MEM, "was computing split");
return 1;
}
t = 0;
for (j = 0, z = zfiles; j < zcount; j++, z = z->nxt)
{
w[j] = z;
if (x)
i += z->nam + 6 + NL;
t += a[j] = 8 + LOCHEAD + CENHEAD +
2 * (ulg)z->nam + 2 * (ulg)z->ext + z->com + z->siz;
if (a[j] > c)
ziperr(ZE_BIG, z->zname);
}
/* Decide on split to use, report number of files */
if (h)
s = simple(a, zcount, c, i);
else
{
if ((p = (ulg *)talloc(zcount * sizeof(ulg))) == NULL)
ziperr(ZE_MEM, "was computing split");
memcpy((char *)p, (char *)a, zcount * sizeof(ulg));
s = simple(a, zcount, c, i);
g = greedy(p, zcount, c, i);
if (s <= g)
tfree((zvoid *)p);
else
{
tfree((zvoid *)a);
a = p;
s = g;
}
}
printf("%ld zip files w%s be made (%ld%% efficiency)\n",
(ulg)s, d ? "ould" : "ill", ((200 * ((t + c - 1)/c)) / s + 1) >> 1);
if (d)
{
tfreeall();
free((zvoid *)zipfile);
zipfile = NULL;
EXIT(ZE_OK);
}
/* Set up path for output files */
/* Point "name" past the path, where the filename should go */
if ((path = (char *)talloc(tempath == NULL ? 13 : strlen(tempath) + 14)) ==
NULL)
ziperr(ZE_MEM, "was making output file names");
if (tempath == NULL)
name = path;
else
{
#ifndef VM_CMS
/* Copy the output path to the target */
strcpy(path, tempath);
#endif
#ifdef AMIGA
tailchar = path[strlen(path) - 1]; /* last character */
if (path[0] && (tailchar != '/') && (tailchar != ':'))
strcat(path, "/");
#else
#ifdef RISCOS
if (path[0] && path[strlen(path) - 1] != '.')
strcat(path, ".");
#else
#ifdef QDOS
if (path[0] && path[strlen(path) - 1] != '_')
strcat(path, "_");
#else
#ifndef VMS
if (path[0] && path[strlen(path) - 1] != '/')
strcat(path, "/");
#endif /* !VMS */
#endif /* ?QDOS */
#endif /* ?RISCOS */
#endif /* ?AMIGA */
name = path + strlen(path);
}
/* Make linked lists of results */
if ((b = (extent *)talloc(s * sizeof(extent))) == NULL ||
(n = (extent *)talloc(zcount * sizeof(extent))) == NULL)
ziperr(ZE_MEM, "was computing split");
for (j = 0; j < s; j++)
b[j] = (extent)-1;
j = zcount;
while (j--)
{
g = (extent)a[j];
n[j] = b[g];
b[g] = j;
}
/* Make a name template for the zip files that is eight or less characters
before the .zip, and that will not overwrite the original zip file. */
for (k = 1, j = s; j >= 10; j /= 10)
k++;
if (k > 7)
ziperr(ZE_PARMS, "way too many zip files must be made");
/*
* XXX, ugly ....
*/
/* Find the final "path" separator character */
#ifdef QDOS
q = LastDir(zipfile);
#else
#ifdef VMS
if ((q = strrchr(zipfile, ']')) != NULL)
#else
#ifdef AMIGA
if (((q = strrchr(zipfile, '/')) != NULL)
|| ((q = strrchr(zipfile, ':'))) != NULL)
#else
#ifdef RISCOS
if ((q = strrchr(zipfile, '.')) != NULL)
#else
#ifdef MVS
if ((q = strrchr(zipfile, '.')) != NULL)
#else
if ((q = strrchr(zipfile, '/')) != NULL)
#endif /* MVS */
#endif /* RISCOS */
#endif /* AMIGA */
#endif /* VMS */
q++;
else
q = zipfile;
#endif /* QDOS */
r = 0;
while ((g = *q++) != '\0' && g != ZPATH_SEP && r < 8 - k)
template[r++] = (char)g;
if (r == 0)
template[r++] = '_';
else if (g >= '0' && g <= '9')
template[r - 1] = (char)(template[r - 1] == '_' ? '-' : '_');
sprintf(template + r, TEMPL_FMT, k);
#ifdef VM_CMS
/* For CMS, add the "path" as the filemode at the end */
if (tempath)
{
strcat(template,".");
strcat(template,tempath);
}
#endif
/* Make the zip files from the linked lists of entry numbers */
if ((e = fopen(zipfile, FOPR)) == NULL)
ziperr(ZE_NAME, zipfile);
free((zvoid *)zipfile);
zipfile = NULL;
for (j = 0; j < s; j++)
{
/* jump here on a disk retry */
redobin:
/* prompt if requested */
if (u)
{
char m[10];
fprintf(stderr, "Insert disk #%ld of %ld and hit return: ",
(ulg)j + 1, (ulg)s);
fgets(m, 10, stdin);
}
/* write index file on first disk if requested */
if (j == 0 && x)
{
strcpy(name, INDEX);
printf("creating: %s\n", path);
indexmade = 1;
if ((f = fopen(path, "w")) == NULL)
{
if (u && retry()) goto redobin;
ziperr(ZE_CREAT, path);
}
for (j = 0; j < zcount; j++)
fprintf(f, "%5ld %s\n", a[j] + 1, w[j]->zname);
if ((j = ferror(f)) != 0 || fclose(f))
{
if (j)
fclose(f);
if (u && retry()) goto redobin;
ziperr(ZE_WRITE, path);
}
}
/* create output zip file j */
sprintf(name, template, j + 1L);
printf("creating: %s\n", path);
zipsmade = j + 1;
if ((f = fopen(path, FOPW)) == NULL)
{
if (u && retry()) goto redobin;
ziperr(ZE_CREAT, path);
}
tempzn = 0;
/* write local headers and copy compressed data */
for (g = b[j]; g != (extent)-1; g = (extent)n[g])
{
if (fseek(e, w[g]->off, SEEK_SET))
ziperr(ferror(e) ? ZE_READ : ZE_EOF, zipfile);
if ((r = zipcopy(w[g], e, f)) != ZE_OK)
{
if (r == ZE_TEMP)
{
if (u && retry()) goto redobin;
ziperr(ZE_WRITE, path);
}
else
ziperr(r, zipfile);
}
}
/* write central headers */
if ((c = ftell(f)) == (ulg)(-1L))
{
if (u && retry()) goto redobin;
ziperr(ZE_WRITE, path);
}
for (g = b[j], k = 0; g != (extent)-1; g = n[g], k++)
if ((r = putcentral(w[g], f)) != ZE_OK)
{
if (u && retry()) goto redobin;
ziperr(ZE_WRITE, path);
}
/* write end-of-central header */
if ((t = ftell(f)) == (ulg)(-1L) ||
(r = putend(k, t - c, c, (extent)0, (char *)NULL, f)) != ZE_OK ||
ferror(f) || fclose(f))
{
if (u && retry()) goto redobin;
ziperr(ZE_WRITE, path);
}
#ifdef RISCOS
/* Set the filetype to &DDC */
setfiletype(path,0xDDC);
#endif
}
fclose(e);
/* Done! */
if (u)
fputs("Done.\n", stderr);
tfreeall();
RETURN(0);
}

File diff suppressed because it is too large Load Diff

View File

@ -63,10 +63,6 @@ provides {
cmd:zdiff
cmd:zforce
cmd:zgrep
cmd:zip = 2.32
cmd:zipcloak
cmd:zipnote
cmd:zipsplit
cmd:zmore
cmd:znew
}

View File

@ -63,10 +63,6 @@ provides {
cmd:zdiff
cmd:zforce
cmd:zgrep
cmd:zip = 2.32
cmd:zipcloak
cmd:zipnote
cmd:zipsplit
cmd:zmore
cmd:znew
}

View File

@ -63,10 +63,6 @@ provides {
cmd:zdiff
cmd:zforce
cmd:zgrep
cmd:zip = 2.32
cmd:zipcloak
cmd:zipnote
cmd:zipsplit
cmd:zmore
cmd:znew
}

View File

@ -63,10 +63,6 @@ provides {
cmd:zdiff
cmd:zforce
cmd:zgrep
cmd:zip = 2.32
cmd:zipcloak
cmd:zipnote
cmd:zipsplit
cmd:zmore
cmd:znew
}

View File

@ -62,10 +62,6 @@ provides {
cmd:zdiff
cmd:zforce
cmd:zgrep
cmd:zip = 2.32
cmd:zipcloak
cmd:zipnote
cmd:zipsplit
cmd:zmore
cmd:znew
}

View File

@ -63,10 +63,6 @@ provides {
cmd:zdiff
cmd:zforce
cmd:zgrep
cmd:zip = 2.32
cmd:zipcloak
cmd:zipnote
cmd:zipsplit
cmd:zmore
cmd:znew
lib:libstdc++