home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
SOFTWARE
/
SOURCES
/
UNZIP52.ZIP
/
process.c
(
.txt
)
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-29
|
42KB
|
1,105 lines
/*---------------------------------------------------------------------------
process.c
This file contains the top-level routines for processing multiple zipfiles.
Contains: process_zipfiles()
do_seekable()
find_ecrec()
uz_end_central()
process_cdir_file_hdr()
get_cdir_ent()
process_local_file_hdr()
ef_scan_for_izux()
---------------------------------------------------------------------------*/
#define UNZIP_INTERNAL
#include "unzip.h"
#ifdef MSWIN
# include <windows.h>
# include "wingui\wizunzip.h"
#endif
static int do_seekable OF((__GPRO__ int lastchance));
static int find_ecrec OF((__GPRO__ long searchlen));
static char Far CantAllocateBuffers[] =
"error: can't allocate unzip buffers\n";
#ifdef SFX
static char Far CantFindMyself[] =
"unzipsfx: can't find myself! [%s]\n";
#else /* !SFX */
/* process_zipfiles() strings */
static char Far FilesProcessOK[] = "%d archive%s successfully processed.\n";
static char Far ArchiveWarning[] =
"%d archive%s had warnings but no fatal errors.\n";
static char Far ArchiveFatalError[] = "%d archive%s had fatal errors.\n";
static char Far FileHadNoZipfileDir[] =
"%d file%s had no zipfile directory.\n";
static char Far ZipfileWasDir[] = "1 \"zipfile\" was a directory.\n";
static char Far ManyZipfilesWereDir[] =
"%d \"zipfiles\" were directories.\n";
static char Far NoZipfileFound[] = "No zipfiles found.\n";
/* do_seekable() strings */
# ifdef UNIX
static char Far CantFindZipfileDirMsg[] =
"%s: can't find zipfile directory in one of %s or\n\
%s%s.zip, and can't find %s, period.\n";
static char Far CantFindEitherZipfile[] =
"%s: can't find %s, %s.zip or %s, so there.\n";
# else /* !UNIX */
static char Far CantFindWildcardMatch[] =
"%s: can't find any matches for wildcard specification \"%s\".\n";
static char Far CantFindZipfileDirMsg[] =
"%s: can't find zipfile directory in %s,\n\
%sand can't find %s, period.\n";
static char Far CantFindEitherZipfile[] =
"%s: can't find either %s or %s, so there.\n";
# endif /* ?UNIX */
extern char Far Zipnfo[]; /* in unzip.c */
#ifndef MSWIN
static char Far Unzip[] = "unzip";
#else
static char Far Unzip[] = "WizUnZip";
#endif
static char Far MaybeExe[] =
"note: %s may be a plain executable, not an archive\n";
static char Far CentDirNotInZipMsg[] = "\n\
[%s]:\n\
Zipfile is disk %u of a multi-disk archive, and this is not the disk on\n\
which the central zipfile directory begins (disk %u).\n";
static char Far EndCentDirBogus[] =
"\nwarning [%s]: end-of-central-directory record claims this\n\
is disk %u but that the central directory starts on disk %u; this is a\n\
contradiction. Attempting to process anyway.\n";
# ifdef NO_MULTIPART
static char Far NoMultiDiskArcSupport[] =
"\nerror [%s]: zipfile is part of multi-disk archive\n\
(sorry, not yet supported).\n";
static char Far MaybePakBug[] = "warning [%s]:\
zipfile claims to be 2nd disk of a 2-part archive;\n\
attempting to process anyway. If no further errors occur, this archive\n\
was probably created by PAK v2.51 or earlier. This bug was reported to\n\
NoGate in March 1991 and was supposed to have been fixed by mid-1991; as\n\
of mid-1992 it still hadn't been. (If further errors do occur, archive\n\
was probably created by PKZIP 2.04c or later; UnZip does not yet support\n\
multi-part archives.)\n";
# else
static char Far MaybePakBug[] = "warning [%s]:\
zipfile claims to be last disk of a multi-part archive;\n\
attempting to process anyway, assuming all parts have been concatenated\n\
together in order. Expect \"errors\" and warnings...true multi-part support\
\n doesn't exist yet (coming soon).\n";
# endif
static char Far ExtraBytesAtStart[] =
"warning [%s]: %ld extra byte%s at beginning or within zipfile\n\
(attempting to process anyway)\n";
#endif /* ?SFX */
static char Far MissingBytes[] =
"error [%s]: missing %ld bytes in zipfile\n\
(attempting to process anyway)\n";
static char Far NullCentDirOffset[] =
"error [%s]: NULL central directory offset\n\
(attempting to process anyway)\n";
static char Far ZipfileEmpty[] = "warning [%s]: zipfile is empty\n";
static char Far CentDirStartNotFound[] =
"error [%s]: start of central directory not found;\n\
zipfile corrupt.\n%s";
static char Far CentDirTooLong[] =
"error [%s]: reported length of central directory is\n\
%ld bytes too long (Atari STZip zipfile? J.H.Holm ZIPSPLIT 1.1\n\
zipfile?). Compensating...\n";
static char Far CentDirEndSigNotFound[] = "\
End-of-central-directory signature not found. Either this file is not\n\
a zipfile, or it constitutes one disk of a multi-part archive. In the\n\
latter case the central directory and zipfile comment will be found on\n\
the last disk(s) of this archive.\n";
static char Far ZipfileCommTrunc1[] = "\ncaution: zipfile comment truncated\n";
/*******************************/
/* Function process_zipfiles() */
/*******************************/
int process_zipfiles(__G) /* return PK-type error code */
__GDEF
{
#ifndef SFX
char *lastzipfn = (char *)NULL;
int NumWinFiles, NumLoseFiles, NumWarnFiles;
int NumMissDirs, NumMissFiles;
#endif
int error=0, error_in_archive=0;
/*---------------------------------------------------------------------------
Start by allocating buffers and (re)constructing the various PK signature
strings.
---------------------------------------------------------------------------*/
G.inbuf = (uch *)malloc(INBUFSIZ + 4); /* 4 extra for hold[] (below) */
/* Normally realbuf and outbuf will be the same. However, if the data
* are redirected to a large memory buffer, realbuf will point to the
* new location while outbuf will remain pointing to the malloc'd
* memory buffer. (The extra "1" is for string termination.) */
G.realbuf = G.outbuf = (uch *)malloc(OUTBUFSIZ + 1);
if ((G.inbuf == (uch *)NULL) || (G.outbuf == (uch *)NULL)) {
Info(slide, 0x401, ((char *)slide, LoadFarString(CantAllocateBuffers)));
RETURN(PK_MEM);
}
G.hold = G.inbuf + INBUFSIZ; /* to check for boundary-spanning sigs */
#ifndef VMS /* VMS uses its own buffer scheme for textmode flush(). */
#ifdef SMALL_MEM
G.outbuf2 = G.outbuf+RAWBUFSIZ; /* never changes */
#endif
#endif /* !VMS */
#if 0 /* CRC_32_TAB has been NULLified by CONSTRUCTGLOBALS !!!! */
/* allocate the CRC table only later when we know we have a zipfile */
CRC_32_TAB = (ulg *)NULL;
#endif /* 0 */
G.local_hdr_sig[0] /* = extd_local_sig[0] */ = 0x50; /* ASCII 'P', */
G.central_hdr_sig[0] = G.end_central_sig[0] = 0x50; /* not EBCDIC */
G.local_hdr_sig[1] /* = extd_local_sig[1] */ = 0x4B; /* ASCII 'K', */
G.central_hdr_sig[1] = G.end_central_sig[1] = 0x4B; /* not EBCDIC */
/* GRR FIX: no need for these to be in global struct; OK to "overwrite" */
strcpy(G.local_hdr_sig+2, LOCAL_HDR_SIG);
strcpy(G.central_hdr_sig+2, CENTRAL_HDR_SIG);
strcpy(G.end_central_sig+2, END_CENTRAL_SIG);
/* strcpy(extd_local_sig+2, EXTD_LOCAL_SIG); still to be used in multi? */
#if (defined(OS2) && defined(__IBMC__))
_tzset(); /* initialize timezone info (from TZ) since no other chance */
#endif /* (underscore name is accepted by all versions of C Set) */
/*---------------------------------------------------------------------------
Match (possible) wildcard zipfile specification with existing files and
attempt to process each. If no hits, try again after appending ".zip"
suffix. If still no luck, give up.
---------------------------------------------------------------------------*/
#ifdef SFX
if ((error = do_seekable(__G__ 0)) == PK_NOZIP) {
#ifdef EXE_EXTENSION
int len=strlen(G.argv0);
/* append .exe if appropriate; also .sfx? */
if ( (G.zipfn = (char *)malloc(len+sizeof(EXE_EXTENSION)