home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!elroy.jpl.nasa.gov!ames!agate!dog.ee.lbl.gov!network.ucsd.edu!mvb.saic.com!vmsnet-sources
- From: goathunter@wkuvx1.bitnet
- Newsgroups: vmsnet.sources
- Subject: Zip v1.9 & UnZip v5.0, part 10/22
- Message-ID: <8009640@MVB.SAIC.COM>
- Date: Tue, 01 Sep 1992 22:51:20 GMT
- Organization: Western Kentucky University, Bowling Green, KY
- Lines: 1369
- Approved: Mark.Berryman@Mvb.Saic.Com
-
- Submitted-by: goathunter@wkuvx1.bitnet
- Posting-number: Volume 3, Issue 132
- Archive-name: zip_unzip/part10
-
- -+-+-+-+-+-+-+-+ START OF PART 10 -+-+-+-+-+-+-+-+
- X while ((cd < maxcodemax) && (prefix_of`5Bcd`5D != -1))
- X cd++;
- X free_ent = cd;
- X`7D
- $ CALL UNPACK [.UNZIP50]UNSHRINK.C;1 1162406257
- $ create 'f'
- X.TH UNZIP 1 "21 Aug 92 (v5.0)"
- X.SH NAME
- Xunzip \- list/test/extract from a ZIP archive file
- X.SH SYNOPSIS
- X\fBunzip\fP `5B \-\fBcflptuvxz\fP`5B\fBajnoqUV\fP`5D `5D \fIfile\fP`5B\fI.zi
- Vp\fP`5D `5B\fIfilespec\fP\ ...`5D
- X.SH ARGUMENTS
- X.IP \fIfile\fP`5B\fI.zip\fP`5D \w'`5B\fIfilespec\fP`5D'u+2m
- XPath of the ZIP archive. The suffix
- X`60`60\fI.zip\fP'' is applied if the \fIfile\fP specified does not exist.
- XNote that self-extracting ZIP files are supported; just specify the
- X`60`60\fI.exe\fP'' suffix yourself.
- X.IP `5B\fIfilespec\fP`5D
- XAn optional list of archive members to be processed.
- XExpressions may be used to match multiple members; be sure to quote
- Xexpressions that contain characters interpreted by the operating
- Xsystem. See DESCRIPTION (below) for more details.
- X.SH OPTIONS
- X.PD 0
- X.IP \-c \w'\-c'u+2m
- Xextract files to stdout/screen (`60`60CRT'')
- X.IP \-f
- Xfreshen existing files (replace if newer); create none
- X.IP \-l
- Xlist archive files (short format)
- X.IP \-p
- Xextract files to pipe; no informational messages
- X.IP \-t
- Xtest archive files
- X.IP \-u
- Xupdate existing files; create new ones if needed
- X.IP \-v
- Xlist archive files (verbose format)
- X.IP \-x
- Xextract files in archive (default)
- X.IP \-z
- Xdisplay only the archive comment
- X.PD
- X.SH MODIFIERS
- X.PD 0
- X.IP \-a \w'\-a'u+2m
- Xconvert to MS-DOS textfile format (CR LF), Mac format (CR), Unix/VMS
- Xformat (LF), OR from ASCII to EBCDIC, depending on your system (only
- Xuse for TEXT files!)
- X.IP \-j
- Xjunk paths (don't recreate archive's directory structure)
- X.IP \-n
- Xnever overwrite existing files; don't prompt
- X.IP \-o
- XOK to overwrite files without prompting
- X.IP \-q
- Xperform operations quietly (\-qq \(rh even quieter)
- X.IP \-s
- X`5BOS/2, MS-DOS`5D allow spaces in filenames (e.g., `60`60EA\ DATA.\ SF'')
- X.IP \-U
- Xleave filenames uppercase if created under MS-DOS, VMS, etc.
- X.IP \-V
- Xretain (VMS) file version numbers
- X.IP \-X
- X`5BVMS`5D restore owner/protection info (may require privileges)
- X.PD
- X.SH DESCRIPTION
- X.I UnZip
- Xwill list, test, or extract from a ZIP archive, commonly found on MSDOS
- Xsystems.
- XArchive member extraction is implied by the absence of the \-c, \-p,
- X\-t, \-l, \-v or \-z options. All archive members are processed unless a
- X.I filespec
- Xis provided to specify a subset of the archive members. The
- X.I filespec
- Xis similar to an egrep expression, and may contain:
- X.sp 1
- X.ta \w'`5B...`5D'u+2m
- X*`09matches a sequence of 0 or more characters
- X.br
- X?`09matches exactly 1 character
- X.br
- X\\nnn`09matches the character having octal code nnn
- X.PD 0
- X.IP `5B...`5D \w'`5B...`5D'u+2m
- Xmatches any single character found inside the brackets; ranges
- Xare specified by a beginning character, a hyphen, and an ending
- Xcharacter. If an exclamation point or a carat (`60!' or `60`5E') follows
- Xthe left bracket, then the range of characters matched is complemented
- Xwith respect to the ASCII character set (that is, anything except the
- Xcharacters inside the brackets is considered a match).
- X.PD
- X.SH ENVIRONMENT OPTIONS
- X\fIUnZip\fP's default behavior may be modified via options placed in
- Xan environment variable. This can be done with any option, but it
- Xis probably most useful with the
- X\-q, \-o, or \-n modifiers: in order to make \fIUnZip\fP quieter by`20
- Xdefault, or to make it always overwrite or never overwrite files as it
- Xextracts them. For example, to
- Xmake \fIUnZip\fP act as quietly as possible, only reporting errors, one woul
- Vd
- Xuse one of the following commands:
- X.ta \w'tabset'u +\w'UNZIP=-qq; export UNZIP'u+4m
- X.PP
- X.IP "\tsetenv UNZIP -qq\tUnix C shell"
- X.br
- X.IP "\tUNZIP=-qq; export UNZIP\tUnix Bourne shell"
- X.PP
- X.IP "\tset UNZIP=-qq\tOS/2 or MS-DOS"
- X.PP
- X.IP "\tdefine UNZIP_OPTS ""-qq""\tVMS (quotes for LOWERCASE)"
- X.PP
- XEnvironment options are, in effect, considered to be just like any other
- Xcommand-line options, except that they are effectively the first options
- Xon the command line. To override
- Xan environment option, one may use the `60`60minus operator'' to remove it.
- V For
- Xinstance, to override one of the quiet-flags in the example above, use the
- Xcommand
- X.PP
- X.IP "\t\fIunzip\fP \-\-q`5Bother options`5D zipfile"
- X.PP
- XThe first hyphen is the normal
- Xswitch character, and the second is a minus sign, acting on the q option.
- XThus the effect here is to cancel a single quantum of quietness. To cancel
- Xboth quiet flags, two (or more) minuses may be used:
- X.PP
- X.IP "\t\fIunzip\fP \-x\-\-q zipfile"
- X.PP
- Xor
- X.PP
- X.IP "\t\fIunzip\fP \-\-\-qx zipfile"
- X.PP
- X(the two are equivalent). This may seem awkward
- Xor confusing, but it is reasonably intuitive: just ignore the first
- Xhyphen and go from there. It is also consistent with the behavior of Unix
- Xnice(1).
- X.PD
- X.SH EXAMPLES
- XTo use \fIUnZip\fP to extract all members of the archive letters.zip,
- Xcreating any directories as necessary:
- X.PP
- X.IP "\t\fIunzip\fP letters"
- X.PP
- XTo extract all members of letters.zip to the current directory:
- X.PP
- X.IP "\t\fIunzip\fP -j letters"
- X.PP
- XTo test letters.zip, printing only a summary message indicating
- Xwhether the archive is OK or not:
- X.PP
- X.IP "\t\fIunzip\fP -tq letters"
- X.PP
- XTo extract to standard output all members of letters.zip whose names end
- Xin `60`60.tex'', converting to the local end-of-line convention and piping t
- Vhe
- Xoutput into more(1):
- X.PP
- X.IP "\t\fIunzip\fP \-ca letters \e*.tex `7C more"
- X.PP
- X(The backslash before the asterisk is only required if the shell expands
- Xwildcards, as in Unix; double quotes could have been used instead, as in
- Xthe source example below.)\ \ To extract the binary file paper1.dvi to`20
- Xstandard output and pipe it to a printing program:
- X.PP
- X.IP "\t\fIunzip\fP \-p articles paper1.dvi `7C dvips"
- X.PP
- XTo extract all FORTRAN and C source files--*.f, *.c, *.h, Makefile (the
- Xdouble quotes are necessary only in Unix and only if globbing is turned on):
- X.PP
- X.IP "\t\fIunzip\fP source.zip ""*.`5Bfch`5D"" Makefile"
- X.PP
- XTo extract only newer versions of the files already in the current directory
- V,
- Xwithout querying (NOTE: be careful of unzipping in one timezone a zipfile`2
- V0
- Xcreated in another--ZIP archives contain no timezone information, and a`20
- X`60`60newer'' file from an eastern timezone may, in fact, be older):
- X.PP
- X.IP "\t\fIunzip\fP \-fo sources"
- X.PP
- XTo extract newer versions of the files already in the current directory and
- Xto create any files not already there (same caveat as previous example):
- X.PP
- X.IP "\t\fIunzip\fP \-uo sources"
- X.PP
- X.PP
- XIn the last five examples, assume that UNZIP or UNZIP_OPTS is set to -q.
- XTo do a singly quiet listing:
- X.PP
- X.IP "\t\fIunzip\fP \-\fIl\fP \fIfile\fP"
- X.PP
- XTo do a doubly quiet listing:
- X.PP
- X.IP "\t\fIunzip\fP \-\fIql\fP \fIfile\fP"
- X.PP
- XTo do a standard listing:
- X.PP
- X.IP "\t\fIunzip\fP \-\-\fIql\fP \fIfile\fP"
- X.PP
- Xor
- X.PP
- X.IP "\t\fIunzip\fP \-\fIl\fP\-\fIq\fP \fIfile\fP"
- X.PP
- Xor
- X.PP
- X.IP "\t\fIunzip\fP \-\fIl\fP\-\-\fIq\fP \fIfile\fP"
- X.PP
- X(extra minuses don't hurt).
- X.PD
- X.SH TIPS
- XThe current maintainer, being a lazy sort, finds it very useful to define
- Xan alias `60`60tt'' for `60`60unzip -tq''. One may then simply type `60`60t
- Vt zipfile''
- Xto test the archive, something which one ought make a habit of doing.
- XWith luck \fIUnZip\fP will report `60`60No errors detected in zipfile.zip,''
- Xafter which one may breathe a sigh of relief.
- X.PD
- X.SH SEE ALSO
- Xfunzip(1), zip(1), zipcloak(1), zipinfo(1), zipnote(1), zipsplit(1)
- X.PD
- X.SH AUTHORS
- XSamuel H. Smith, Carl Mascott, David P. Kirschbaum, Greg R. Roelofs, Mark
- XAdler, Kai Uwe Rommel, Igor Mandrichenko, Johnny Lee, Jean-loup Gailly; Glen
- Vn
- XAndrews, Joel Aycock, Allan Bjorklund, James Birdsall, Wim Bonner, John Cowa
- Vn,
- XFrank da Cruz, Bill Davidsen, Arjan de Vet, James Dugal, Jim Dumser, Mark
- XEdwards, David Feinleib, Mike Freeman, Hunter Goatley, Robert Heath, Dave
- XHeiland, Larry Jones, Kjetil J`7B\o`7Drgenson, Bob Kemp, J. Kercheval, Alvin
- V Koh,
- XBo Kullmar, Johnny Lee, Warner Losh, Fulvio Marino, Gene McManus, Joe Meadow
- Vs,
- XMike O'Carroll, Humberto Ortiz-Zuazaga, Piet W. Plomp, Antonio Querubin Jr.,
- XSteve Salisbury, Georg Sassen, Jon Saxton, Hugh Schmidt, Martin Schulz, Char
- Vles
- XScripter, Chris Seaman, Richard Seay, Alex Sergejew, Cliff Stanford, Onno va
- Vn
- Xder Linden, Jim Van Zandt, Antoine Verheijen, Paul Wells.
- X.PD
- X.SH VERSIONS
- X.ta \w'vx.x\ \ 'u +\w'fall 1989\ \ 'u
- X.PD 0
- X.IP "v1.2\t15 Mar 89" \w'\t\t'u
- XSamuel H. Smith
- X.IP "v2.0\t\ 9 Sep 89"
- XSamuel H. Smith
- X.IP "v2.x\tfall 1989"
- Xmany Usenet contributors
- X.IP "v3.0\t\ 1 May 90"
- XInfo-ZIP (DPK, consolidator)
- X.IP "v3.1\t15 Aug 90"
- XInfo-ZIP (DPK, consolidator)
- X.IP "v4.0\t\ 1 Dec 90"
- XInfo-ZIP (GRR, maintainer)
- X.IP "v4.1\t12 May 91"
- XInfo-ZIP
- X.IP "v4.2\t20 Mar 92"
- XInfo-ZIP (zip-bugs subgroup; GRR, maint.)
- X.IP "v5.0\t21 Aug 92"
- XInfo-ZIP (zip-bugs subgroup; GRR, maint.)
- X.PD
- $ CALL UNPACK [.UNZIP50]UNZIP.1;1 1882148306
- $ create 'f'
- X/*--------------------------------------------------------------------------
- V-
- X
- X unzip.c
- X
- X UnZip - a zipfile extraction utility. See below for make instructions, or
- X read the comments in Makefile and the various Contents files for more de-
- X tailed explanations. To report a bug, send a *complete* description to
- X zip-bugs@cs.ucla.edu; include machine type, operating system and version,
- X compiler and version, and reasonably detailed error messages or problem
- X report. To join Info-ZIP, send a message to info-zip-request@cs.ucla.edu.
- X
- X UnZip 5.x is a greatly expanded and partially rewritten successor to 4.x,
- X which in turn was almost a complete rewrite of version 3.x. For a detaile
- Vd
- X revision history, see UnzpHist.zip at Info-ZIP headquarters (below). For
- V a`20
- X (partial) list of the many (near infinite) contributors, see "CONTRIBS" in
- X the UnZip source distribution.
- X
- X --------------------------------------------------------------------------
- V-
- X
- X To compile (partial instructions):
- X
- X under Unix (cc): make <system name>
- X (type "make list" for a list of valid names, or read Makefile for`20
- X details. "make unzip" works for most systems. If you have a NEW
- X system, not covered by any of the existing targets, send FULL infor-
- X mation--hardware, OS, versions, etc.--to zip-bugs@cs.ucla.edu)
- X
- X under MS-DOS (MSC, Turbo C, or Borland C++): use the makefiles or
- X project files in the MSDOS sub-archive; edit or otherwise modify
- X as appropriate. For MSC, use NMAKE.
- X
- X under MS Windows 3.x: get wunz12sr.`7Bzip `7C zoo `7C whatever`7D and
- V use
- X the included makefile
- X
- X under OS/2 (MSC, gcc, IBM C Set/2, Watcom C): make -f makefile.os2
- X (from OS2 sub-archive; for MSC, use NMAKE)
- X
- X under VMS (VAX C or GNU C): @make_unzip_vaxc or @make_unzip_gcc
- X (from VMS sub-archive; can also use MMS or MAKE/VMS; see VMS.notes)
- X
- X under Macintosh OS: Double click on unzip.make. Press <Command>-M.
- X (from MAC sub-archive)
- X
- X under Windows NT: use makefile.nt (from NT sub-archive)
- X
- X under AmigaDOS: try one of the makefiles in the AMIGA sub-archive;
- X may need some work yet...
- X
- X under Atari TOS: needs considerable work yet...
- X
- X --------------------------------------------------------------------------
- V-
- X
- X Version: unzip50.`7Btar.Z `7C zip `7C zoo`7D for Unix, VMS, OS/2, MS-DOS,
- V Windows,
- X Windows NT, Macintosh and Amiga. Decryption requires sources
- X in zcrypt19.zip, and Windows (not NT) support requires sources
- X in wunz12sr.zip. See accompanying file "Where" in the main
- X source distribution for ftp, uucp and mail-server sites.
- X Copyrights: see accompanying file "COPYING" in UnZip source distribution.
- X
- X --------------------------------------------------------------------------
- V-*/
- X
- X
- X
- X
- X
- X#include "unzip.h" /* includes, defines, and macros */
- X#ifdef MSWIN
- X# include "wizunzip.h" /* see History.500 for version history */
- X#endif
- X
- X#define VERSION "v5.0 of 21 August 1992"
- X/* #define VERSION "v5.0p BETA of 8-21-92" */ /* internal beta level */
- X#define PAKFIX /* temporary(?) solution to PAK-created zipfiles */
- X
- X
- X
- X
- X
- X/**********************/
- X/* Global Variables */
- X/**********************/
- X
- Xint aflag=0; /* -a: do ASCII to EBCDIC translation, or CR-LF */
- X /* to CR or LF conversion of extracted files */
- X/* int bflag=0; RESERVED for -b: extract as binary */
- Xint cflag=0; /* -c: output to stdout */
- Xint fflag=0; /* -f: "freshen" (extract only newer files) */
- Xint jflag=0; /* -j: junk pathnames */
- Xint overwrite_none=0; /* -n: never overwrite files (no prompting) */
- Xint overwrite_all=0; /* -o: OK to overwrite files without prompting */
- Xint force_flag=0; /* (shares -o for now): force to override errors, etc.
- V */
- Xint quietflg=0; /* -q: produce a lot less output */
- X#ifdef DOS_OS2
- X int sflag=1; /* -s: allow spaces (blanks) in filenames */
- X#endif /* DOS_OS2 */
- Xint tflag=0; /* -t: test */
- Xint uflag=0; /* -u: "update" (extract only newer & brand-new files)
- V */
- Xstatic int U_flag=0; /* -U: leave filenames in upper or mixed case */
- Xstatic int vflag=0; /* -v: view directory (only used in unzip.c) */
- Xint V_flag=0; /* -V: don't strip VMS version numbers */
- X#ifdef VMS
- X int secinf=0; /* -X: keep owner/protection */
- X#endif /* VMS */
- Xint zflag=0; /* -z: display only the archive comment */
- Xint process_all_files=0;
- X
- Xlongint csize; /* used by list_files(), ReadByte(): must be signed */
- Xlongint ucsize; /* used by list_files(), unReduce(), explode() */
- X
- Xchar *fnames`5B2`5D = `7B"*", NULL`7D; /* default filenames vector */
- Xchar **fnv = fnames;
- Xchar sig`5B5`5D;
- Xchar answerbuf`5B10`5D;
- X
- Xmin_info info`5BDIR_BLKSIZ`5D, *pInfo=info;
- X
- X#ifdef OS2
- X int longname; /* used in extract.c, mapname.c and file_io.c
- V */
- X char longfilename`5BFILNAMSIZ`5D;
- X#endif /* OS2 */
- X
- X#ifdef CRYPT
- X char *key = (char *)NULL; /* password with which to decrypt data, or NUL
- VL */
- X#endif /* CRYPT */
- X
- X/*--------------------------------------------------------------------------
- V-
- X unShrink/unReduce/explode/inflate working storage and globals:
- X --------------------------------------------------------------------------
- V-*/
- X
- Xunion work area; /* see unzip.h for the definition of work */
- XULONG crc32val;
- X
- XUWORD mask_bits`5B`5D = `7B
- X 0x0000,
- X 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
- X 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
- X`7D;
- X
- X/*--------------------------------------------------------------------------
- V-
- X Input file variables:
- X --------------------------------------------------------------------------
- V-*/
- X
- Xbyte *inbuf, *inptr; /* input buffer (any size is legal) and pointer */
- Xint incnt;
- X
- XULONG bitbuf;
- Xint bits_left;
- Xboolean zipeof;
- X
- Xint zipfd; /* zipfile file handle */
- X#ifdef MSWIN
- X char *zipfn;
- X#else
- X char zipfn`5BFILNAMSIZ`5D;
- X#endif
- X
- Xchar local_hdr_sig`5B5`5D = "\120"; /* remaining signature bytes come lat
- Ver */
- Xchar central_hdr_sig`5B5`5D = "\120"; /* (must initialize at runtime so un
- Vzip */
- Xchar end_central_sig`5B5`5D = "\120"; /* executable won't look like a zipf
- Vile) */
- X/* char extd_local_sig`5B5`5D = "\120"; NOT USED YET */
- X
- Xcdir_file_hdr crec; /* used in unzip.c, extract.c, misc.c */
- Xlocal_file_hdr lrec; /* used in unzip.c, extract.c */
- Xecdir_rec ecrec; /* used in unzip.c, extract.c */
- Xstruct stat statbuf; /* used by main(), mapped_name(), check_for_newer()
- V */
- X
- Xlongint extra_bytes = 0; /* used in unzip.c, misc.c */
- Xlongint cur_zipfile_bufstart; /* extract_or_test_files, readbuf, ReadByte
- V */
- X `20
- X#ifdef MACOS
- X short gnVRefNum;
- X long glDirID;
- X OSType gostCreator;
- X OSType gostType;
- X boolean fMacZipped;
- X boolean macflag;
- X CursHandle rghCursor`5B4`5D; /* status cursors */
- X short giCursor = 0;
- X#endif
- X
- X/*--------------------------------------------------------------------------
- V-
- X Output stream variables:
- X --------------------------------------------------------------------------
- V-*/
- X
- Xbyte *outbuf; /* buffer for rle look-back */
- Xbyte *outptr;
- X#ifdef MSWIN
- X byte __far *outout;
- X char *filename;
- X#else /* !MSWIN */
- X byte *outout; /* scratch pad for ASCII-native trans */
- X char filename`5BFILNAMSIZ`5D;
- X#endif /* ?MSWIN */
- Xbyte *extra_field = (byte *)NULL; /* used by VMS, Mac and OS/2 versions */
- Xlongint outpos; /* absolute position in outfile */
- Xint outcnt; /* current position in outbuf */
- Xint outfd;
- Xint mem_mode = 0;
- Xint disk_full;
- X
- X/*--------------------------------------------------------------------------
- V-
- X unzip.c static global variables (visible only within this file):
- X --------------------------------------------------------------------------
- V-*/
- X
- Xstatic byte *hold;
- Xstatic char unkn`5B10`5D;
- Xstatic longint ziplen;
- Xstatic UWORD methnum;
- X
- X/*--------------------------------------------------------------------------
- V-
- X unzip.c repeated error messages (we use all of these at least twice)
- X --------------------------------------------------------------------------
- V-*/
- X
- Xchar *EndSigMsg = "\nwarning:\
- X didn't find end-of-central-dir signature at end of central dir.\n";
- Xchar *CentSigMsg =
- X "error: expected central file header signature not found (file #%u).\n";
- Xchar *SeekMsg =
- X "error: attempt to seek before beginning of zipfile\n%s";
- X
- X#ifdef VMS
- Xchar *ReportMsg = "\
- X (please check that you have transferred or created the zipfile in the\n\
- X appropriate BINARY mode--this includes ftp, Kermit, AND unzip'd zipfiles)\
- Vn";
- X#else /* !VMS */
- Xchar *ReportMsg = "\
- X (please check that you have transferred or created the zipfile in the\n\
- X appropriate BINARY mode and that you have compiled unzip properly)\n";
- X#endif /* ?VMS */
- X
- X
- X#ifdef MSWIN
- X/* MS Windows Setup and Take-Down functions bracket calls to`20
- X * process_zipfile().
- X * These functions allocate and free the necessary buffers, set and clear
- X * any global variables so that process_zipfile() can be called multiple
- X * times in the same session of WizUnzip. You'll recognize some of the`20
- X * code from main() in SetUpToProcessZipFile().
- X */
- XHANDLE hOutBuf;
- XHANDLE hOutOut; /* added 04/03/92 for version 1.1 */
- XHANDLE hInBuf;
- XHANDLE hZipFN;
- XHANDLE hFileName;
- X
- XBOOL FSetUpToProcessZipFile(int ncflag, int ntflag, int nvflag, int nUflag,`
- V20
- X int nzflag, int ndflag, int noflag, int naflag, int argc,
- X LPSTR lpszZipFN, PSTR *FNV)
- X`7B
- X /* clear all global flags -- need to or not. */
- X
- X tflag = vflag=cflag=aflag=U_flag=quietflg=zflag = 0;
- X overwrite_all=overwrite_none=0;
- X fnv = &fnames`5B0`5D; /* assign default file name vector */
- X
- X cflag = ncflag ; overwrite_all = noflag;
- X tflag = ntflag ; vflag = nvflag; zflag = nzflag; U_flag = nUflag;
- X aflag = naflag;
- X sflag = 1;
- X
- X local_hdr_sig`5B0`5D = central_hdr_sig`5B0`5D = end_central_sig`5B0`5D =
- V '\120';
- X local_hdr_sig`5B1`5D = central_hdr_sig`5B1`5D = end_central_sig`5B1`5D =
- V '\0';
- X
- X if (!(hZipFN = LocalAlloc(LMEM_MOVEABLE, FILNAMSIZ)))
- X return FALSE;
- X
- X zipfn = (char *)LocalLock(hZipFN);
- X lstrcpy(zipfn, lpszZipFN);
- X if (stat(zipfn, &statbuf) `7C`7C (statbuf.st_mode & S_IFMT) == S_IFDIR)
- X strcat(zipfn, ZSUFX);
- X
- X if (stat(zipfn, &statbuf)) `7B /* try again */
- X fprintf(stderr, "error: can't find zipfile `5B %s `5D\n", zipfn);
- X return TRUE; /* 9: file not found */
- X `7D else
- X ziplen = statbuf.st_size;
- X
- X if (argc != 0) `7B
- X fnv = FNV;
- X process_all_files = FALSE;
- X `7D else
- X process_all_files = TRUE; /* for speed */
- X
- X/*--------------------------------------------------------------------------
- V-
- X Okey dokey, we have everything we need to get started. Let's roll.
- X --------------------------------------------------------------------------
- V-*/
- X
- X if (hInBuf = LocalAlloc(LMEM_MOVEABLE, INBUFSIZ+4)) `7B /* 4 extra: hol
- Vd`5B`5D */
- X inbuf = (byte *) LocalLock(hInBuf);
- X WinAssert(inbuf);
- X `7D
- X if (hOutBuf = LocalAlloc(LMEM_MOVEABLE, OUTBUFSIZ+1)) `7B /* extra: ASC
- VIIZ */
- X outbuf = (byte *)LocalLock(hOutBuf);
- X WinAssert(outbuf);
- X if (aflag) `7B /* if LF => CR,LF translation */
- X if (hOutOut = GlobalAlloc(GMEM_MOVEABLE,OUTBUFSIZ)) `7B
- X outout = (byte _far *)GlobalLock(hOutOut);
- X WinAssert(outout);
- X `7D
- X `7D else /* no translation; just re-use output buffer */
- X outout = (byte _far *)outbuf; /* point to outbuf */
- X `7D
- X if ( hFileName = LocalAlloc(LMEM_MOVEABLE, FILNAMSIZ)) `7B
- X filename = (char *)LocalLock(hFileName);
- X WinAssert(filename);
- X `7D
- X
- X if ((inbuf == NULL) `7C`7C (outbuf == NULL) `7C`7C (outout == NULL) `7C`
- V7C
- X (zipfn == NULL) `7C`7C (filename == NULL))
- X return FALSE;
- X
- X hold = &inbuf`5BINBUFSIZ`5D; /* to check for boundary-spanning signatu
- Vres */
- X
- X return TRUE; /* set up was OK */
- X`7D
- X
- Xvoid TakeDownFromProcessZipFile(void)
- X`7B
- X if (inbuf) `7B
- X LocalUnlock(hInBuf);
- X inbuf = NULL;
- X `7D
- X if (hInBuf)
- X hInBuf = LocalFree(hInBuf);
- X
- X if (outbuf) `7B
- X LocalUnlock(hOutBuf);
- X outbuf = NULL;
- X `7D
- X if (hOutBuf)
- X hOutBuf = LocalFree(hOutBuf);
- X
- X if (aflag && outout) /* if doing LF => CR,LF translation */
- X GlobalUnlock(hOutOut);
- X outout = NULL; /* free now, translation or not */
- X if (hOutOut)
- X hOutOut = GlobalFree(hOutOut); /* mark buffer as freed */
- X
- X if (zipfn) `7B
- X LocalUnlock(hZipFN);
- X zipfn = NULL;
- X `7D
- X if (hZipFN)
- X hZipFN = LocalFree(hZipFN);
- X
- X if (filename) `7B
- X LocalUnlock(hFileName);
- X filename = NULL;
- X `7D
- X if (hFileName)
- X hFileName = LocalFree(hFileName);
- X`7D
- X
- X#else /* !MSWIN */
- X
- X/******************/
- X/* Main program */
- X/******************/
- X
- Xint main(argc, argv) /* return PK-type error code (except under VMS) */
- X int argc;
- X char *argv`5B`5D;
- X`7B
- X char *s;
- X int c, error=FALSE, negative=0;
- X
- X
- X/*--------------------------------------------------------------------------
- V-
- X Macintosh initialization code.
- X --------------------------------------------------------------------------
- V-*/
- X
- X#ifdef MACOS
- X#ifdef THINK_C
- X# include <console.h>
- X static char *argstr`5B30`5D, args`5B30*64`5D;
- X Point p;
- X SFTypeList sfT;
- X EventRecord theEvent;
- X short eMask;
- X SFReply fileRep;
- X#endif /* THINK_C */
- X int a;
- X
- X for (a = 0; a < 4; ++a)
- X rghCursor`5Ba`5D = GetCursor(a+128);
- X giCursor = 0;
- X
- X area.Slide = (byte *)calloc(8193, sizeof(short)+sizeof(char)+sizeof(char
- V));
- X area.shrink.Prefix_of = (short *)area.Slide;
- X area.shrink.Suffix_of = area.Slide + (sizeof(short)*(HSIZE+1));
- X area.shrink.Stack = area.Slide + (sizeof(short) + sizeof(char))*(HSIZE+1
- V);
- X
- X#ifdef THINK_C `20
- X for (a = 0; a < 30; ++a)
- X argstr`5Ba`5D = &args`5Ba*64`5D;
- Xstart:
- X tflag=vflag=cflag=aflag=jflag=U_flag=quietflg=fflag=uflag=zflag = 0;
- X local_hdr_sig`5B1`5D = central_hdr_sig`5B1`5D = end_central_sig`5B1`5D =
- V '\0';
- X/* extd_local_sig`5B1`5D = '\0'; */
- X error = FALSE;
- X
- X argc = ccommand(&argv);
- X SetPt(&p, 40, 40);
- X
- X SFGetFile(p, "\pSpecify ZIP file:", 0L, -1, sfT, 0L, &fileRep);
- X if (fileRep.good) `7B
- X macfstest(fileRep.vRefNum);
- X ResolveMacVol(fileRep.vRefNum, &gnVRefNum, &glDirID, NULL);
- X for (a = 1; a < argc; ++a)
- X if (argv`5Ba`5D`5B0`5D == '-')
- X BlockMove(argv`5Ba`5D, argstr`5Ba`5D, (strlen(argv`5Ba`5D) >
- V 63) ? 64 :
- X strlen(argv`5Ba`5D)+1);
- X else
- X break;
- X PtoCstr((char *)fileRep.fName);
- X strcpy(argstr`5Ba`5D, (char *)fileRep.fName);
- X for (; a < argc; ++a)
- X BlockMove(argv`5Ba`5D, argstr`5Ba+1`5D, (strlen(argv`5Ba`5D) > 6
- V3) ? 64 :
- X strlen(argv`5Ba`5D)+1);
- X ++argc;
- X argv = argstr;
- X
- X if (hfsflag == FALSE) /* can't support directories: junk pathnames
- V */
- X jflag = 1;
- X `7D
- X#endif /* THINK_C */
- X#endif /* MACOS */
- X
- X/*--------------------------------------------------------------------------
- V-
- X Set signal handler for restoring echo, warn of zipfile corruption, etc.
- X --------------------------------------------------------------------------
- V-*/
- X
- X signal(SIGINT, handler);
- X signal(SIGTERM, handler);
- X#ifdef SIGBUS
- X signal(SIGBUS, handler);
- X#endif
- X#ifdef SIGSEGV
- X signal(SIGSEGV, handler);
- X#endif
- X
- X/*--------------------------------------------------------------------------
- V-
- X Debugging info for checking on structure padding:
- X --------------------------------------------------------------------------
- V-*/
- X
- X#ifdef DEBUG_STRUC
- X printf("local_file_hdr size: %X\n",
- X sizeof(local_file_hdr));
- X printf("local_byte_hdr size: %X\n",
- X sizeof(local_byte_hdr));
- X printf("actual size of local headers: %X\n", LREC_SIZE);
- X
- X printf("central directory header size: %X\n",
- X sizeof(cdir_file_hdr));
- X printf("central directory byte header size: %X\n",
- X sizeof(cdir_byte_hdr));
- X printf("actual size of central dir headers: %X\n", CREC_SIZE);
- X
- X printf("end central dir record size: %X\n",
- X sizeof(ecdir_rec));
- X printf("end central dir byte record size: %X\n",
- X sizeof(ec_byte_rec));
- X printf("actual size of end-central-dir record: %X\n", ECREC_SIZE);
- X#endif /* DEBUG_STRUC */
- X
- X/*--------------------------------------------------------------------------
- V-
- X Put environment-variable options into the queue, then rip through any
- X command-line options lurking about...
- X --------------------------------------------------------------------------
- V-*/
- X
- X envargs(&argc, &argv, ENV_UNZIP);
- X
- X while (--argc > 0 && (*++argv)`5B0`5D == '-') `7B
- X s = argv`5B0`5D + 1;
- X while ((c = *s++) != 0) `7B /* "!= 0": prevent Turbo C warning *
- V/
- X switch (c) `7B
- X case ('-'):
- X ++negative;
- X break;
- X case ('a'):
- X if (negative)
- X aflag = FALSE, negative = 0;
- X else
- X aflag = TRUE;
- X break;
- X#if 0
- X case ('b'): /* force binary mode */
- X if (negative)
- X bflag = FALSE, negative = 0;
- X else
- X bflag = TRUE;
- X break;
- X#endif
- X case ('c'):
- X if (negative) `7B
- X cflag = FALSE, negative = 0;
- X#ifdef NATIVE
- X aflag = FALSE;
- X#endif
- X `7D else `7B
- X cflag = TRUE;
- X#ifdef NATIVE
- X aflag = TRUE; /* so you can read it on the screen *
- V/
- X#endif
- X `7D
- X break;
- X case ('d'): /* re-create directory structure (default) */
- X if (negative)
- X jflag = TRUE, negative = 0;
- X break;
- X case ('e'): /* just ignore -e, -x options (extract) */
- X break;
- X case ('f'): /* "freshen" (extract only newer files) */
- X if (negative)
- X fflag = uflag = FALSE, negative = 0;
- X else
- X fflag = uflag = TRUE;
- X break;
- X case ('j'): /* junk pathnames/directory structure */
- X if (negative)
- X jflag = FALSE, negative = 0;
- X else
- X jflag = TRUE;
- X break;
- X case ('l'):
- X if (negative) `7B
- X vflag = MAX(vflag-negative,0);
- X negative = 0;
- X `7D else
- X ++vflag;
- X break;
- X case ('n'): /* don't overwrite any files */
- X if (negative)
- X overwrite_none = FALSE, negative = 0;
- X else
- X overwrite_none = TRUE;
- X break;
- X case ('o'): /* OK to overwrite files without prompting */
- X if (negative) `7B
- X overwrite_all = MAX(overwrite_all-negative,0);
- X force_flag = MAX(force_flag-negative,0);
- X negative = 0;
- X `7D else `7B
- X ++overwrite_all;
- X ++force_flag; /* (share -o for now) force to cont.
- V */
- X `7D
- X break;
- X case ('p'): /* pipes: stdout, no tranlation, no messages
- V */
- X if (negative) `7B
- X cflag = FALSE;
- X quietflg = MAX(quietflg-999,0);
- X negative = 0;
- X `7D else `7B
- X cflag = TRUE;
- X quietflg += 999;
- X `7D
- X break;
- X case ('q'): /* quiet: fewer comments/messages */
- X if (negative) `7B
- X quietflg = MAX(quietflg-negative,0);
- X negative = 0;
- X `7D else
- X ++quietflg;
- X break;
- X#ifdef DOS_OS2
- X case ('s'): /* spaces in filenames: allow by default */
- X if (negative)
- X sflag = TRUE, negative = 0;
- X else
- X sflag = FALSE;
- X break;
- X#endif
- X case ('t'):
- X if (negative)
- X tflag = FALSE, negative = 0;
- X else
- X tflag = TRUE;
- X break;
- X case ('U'): /* Uppercase (don't convert to all-lower) */
- X if (negative)
- X U_flag = FALSE, negative = 0;
- X else
- X U_flag = TRUE;
- X break;
- X case ('u'): /* update (extract only new and newer files)
- V */
- X if (negative)
- X uflag = FALSE, negative = 0;
- X else
- X uflag = TRUE;
- X break;
- X case ('V'): /* Version (retain VMS/DEC-20 file versions)
- V */
- X if (negative)
- X V_flag = FALSE, negative = 0;
- X else
- X V_flag = TRUE;
- X break;
- X case ('v'): /* verbose */
- X if (negative) `7B
- X vflag = MAX(vflag-negative,0);
- X negative = 0;
- X `7D else if (vflag)
- X ++vflag;
- X else
- X vflag = 2;
- X break;
- X#ifdef VMS
- X case ('X'): /* restore owner/protection info (need privs?)
- V */
- X if (negative)
- X secinf = FALSE, negative = 0;
- X else
- X secinf = TRUE;
- X break;
- X#endif /* VMS */
- X case ('x'): /* extract: default */
- X break;
- X case ('z'): /* display only the archive comment */
- X if (negative) `7B
- X zflag = MAX(zflag-negative,0);
- X negative = 0;
- X `7D else
- X ++zflag;
- X break;
- X default:
- X error = TRUE;
- X break;
- X
- X `7D /* end switch */
- X `7D /* end while (not end of argument string) */
- X `7D /* end while (not done with switches) */
- X
- X/*--------------------------------------------------------------------------
- V-
- X Make sure we aren't trying to do too many things here. `5BThis seems li
- Vke
- X kind of a brute-force way to do things; but aside from that, isn't the
- X -a option useful when listing the directory (i.e., for reading zipfile
- X comments)? It's a modifier, not an action in and of itself, so perhaps
- X it should not be included in the test--certainly, in the case of zipfile
- X testing, it can just be ignored.`5D
- X --------------------------------------------------------------------------
- V-*/
- X
- X if ((aflag && tflag) `7C`7C (aflag && vflag) `7C`7C (cflag && tflag) `7C
- V`7C
- X (cflag && uflag) `7C`7C (cflag && vflag) `7C`7C (tflag && uflag) `7C
- V`7C
- X (tflag && vflag) `7C`7C (uflag && vflag) `7C`7C (fflag && overwrite_
- Vnone)) `7B
- X fprintf(stderr, "error:\
- X -at, -av, -ct, -cu, -cv, -fn, -tu, -tv, -uv combinations not allowed\n");
- X error = TRUE;
- X `7D
- X if (quietflg && zflag)
- X quietflg = 0;
- X if (overwrite_all && overwrite_none) `7B
- X fprintf(stderr, "caution: both -n and -o specified; ignoring -o\n")
- V;
- X overwrite_all = FALSE;
- X `7D
- X if ((argc-- == 0) `7C`7C error)
- X RETURN(usage(error));
- X
- X/*--------------------------------------------------------------------------
- V-
- X Now get the zipfile name from the command line and see if it exists as a
- X regular (non-directory) file. If not, append the ".zip" suffix. We don
- V't
- X immediately check to see if this results in a good name, but we will do
- V so
- X later. In the meantime, see if there are any member filespecs on the co
- Vm-
- X mand line, and if so, set the filename pointer to point at them.
- X --------------------------------------------------------------------------
- V-*/
- X
- X strcpy(zipfn, *argv++);
- X if (stat(zipfn, &statbuf) `7C`7C (statbuf.st_mode & S_IFMT) == S_IFDIR)
- X strcat(zipfn, ZSUFX);
- X#if (defined(UNIX) && !defined(VMS)) /* Unix executables have no extension--
- V */
- X else if (statbuf.st_mode & S_IXUSR) /* might find zip, not zip.zip; etc
- V */
- X fprintf(stderr, "\nnote: file `5B %s `5D may be an executable\n\n",
- V zipfn);
- X#endif /* UNIX && !VMS */
- X
- X if (stat(zipfn, &statbuf)) `7B/* try again */
- X fprintf(stderr, "error: can't find zipfile `5B %s `5D\n", zipfn);
- X RETURN(9); /* 9: file not found */
- X `7D else
- X ziplen = statbuf.st_size;
- X
- X if (argc != 0) `7B
- X fnv = argv;
- X process_all_files = FALSE;
- X `7D else
- X process_all_files = TRUE; /* for speed */
- X
- X/*--------------------------------------------------------------------------
- V-
- X Okey dokey, we have everything we need to get started. Let's roll.
- X --------------------------------------------------------------------------
- V-*/
- X
- X inbuf = (byte *) malloc(INBUFSIZ + 4); /* 4 extra for hold`5B`5D (be
- Vlow) */
- X outbuf = (byte *) malloc(OUTBUFSIZ + 1); /* 1 extra for string termin.
- V */
- X#ifndef DOS_OS2
- X if (aflag) /* if need an ascebc scratch, */
- X outout = (byte *) malloc(OUTBUFSIZ);
- X else /* allocate it... */
- X#endif /* !DOS_OS2 */
- X outout = outbuf; /* else just point to outbuf */
- X
- X if ((inbuf == (byte *)NULL) `7C`7C (outbuf == (byte *)NULL) `7C`7C
- X (outout == (byte *)NULL)) `7B
- X fprintf(stderr, "error: can't allocate unzip buffers\n");
- X RETURN(4); /* 4-8: insufficient memory */
- X `7D
- X hold = &inbuf`5BINBUFSIZ`5D; /* to check for boundary-spanning signat
- Vures */
- X
- X RETURN(process_zipfile()); /* keep passing errors back... */
- X
- X`7D /* end main() */
- X
- X
- X
- X
- X
- X/**********************/
- X/* Function usage() */
- X/**********************/
- X
- Xint usage(error) /* return PK-type error code */
- X int error;
- X`7B
- X#ifdef NATIVE
- X#ifdef EBCDIC
- X char *astring = "-a convert ASCII to EBCDIC";
- X#else /* !EBCDIC */
- X char *astring = "-a convert ASCII to native chars";
- X#endif /* ?EBCDIC */
- X/* char *astring = "-a convert ASCII to " NATIVE; (ANSI C concatenation)
- V */
- X char *loc_str = "";
- X#else /* !NATIVE */
- X#ifdef DOS_OS2
- X char *astring = "-a convert text (LF => CR LF)";
- X char *loc_str = "-s spaces in filenames => _";
- X#else /* !DOS_OS2 */
- X#ifdef MACOS
- X char *astring = "-a convert text (CR LF => CR)";
- X char *loc_str = "";
- X#else /* !MACOS: UNIX, VMS */
- X char *astring = "-a convert text (CR LF => LF)";
- X#ifdef VMS
- X char *loc_str = "-X restore owner/protection info";
- X#else /* !VMS */
- X char *loc_str = "";
- X#endif /* ?VMS */
- X#endif /* ?MACOS */
- X#endif /* ?DOS_OS2 */
- X#endif /* ?NATIVE */
- X FILE *usagefp;
- X
- X
- X/*--------------------------------------------------------------------------
- V-
- X If user requested usage, send it to stdout; else send to stderr.
- X --------------------------------------------------------------------------
- V-*/
- X
- X if (error)
- X usagefp = (FILE *) stderr;
- X else
- X usagefp = (FILE *) stdout;
- X
- X fprintf(usagefp, "\
- XUnZip: Zipfile Extract %s; (c) 1989 S.H.Smith and others\n\
- XVersions 3.0 and later by Info-ZIP. Bug reports ONLY to zip-bugs@cs.ucla.ed
- Vu\
- X\n\n", VERSION);
- X
- X fprintf(usagefp, "\
- XUsage: unzip `5B -options`5Bmodifiers`5D `5D file`5B.zip`5D `5Bfilespec...`5
- VD\n\
- X -x extract files (default) -l list files (short format)\n
- V\
- X -c extract files to stdout/screen (CRT) -v list files (verbose format)
- V\n\
- X -f freshen existing files, create none -p extract to pipe, no message
- Vs\n\
- X -u update files, create if necessary -t test archive integrity\n\
- X -z display archive comment\n\
- Xmodifiers:\n\
- X -n never overwrite existing files %s\n", loc_str);
- X fprintf(usagefp, "\
- X -o overwrite files WITHOUT prompting %s\n\
- X -j junk paths (don't make directories) -U don't make names lowercase\
- Vn\
- X -q quiet mode (-qq => quieter) -V retain VMS version numbers\
- X\n\n\
- XExamples: (See manual for more information)\n\
- X unzip data1 Readme => extracts file Readme from zipfile data1.zip\n\
- X unzip -p foo `7C more => send contents of foo.zip via pipe into program m
- Vore\n\
- X unzip -fo foo => quietly replace existing files if archive files ne
- Vwer\
- X\n", astring);
- X
- X#ifdef VMS
- X fprintf(usagefp, "\
- X unzip \"-V\" foo \"Bar\" => must quote uppercase options and filenames in
- V VMS\
- X\n");
- X#endif
- X
- X if (error)
- X return 10; /* 10: bad or illegal parameters specified */
- X else
- X return 0; /* just wanted usage screen: no error */
- X
- X`7D /* end function usage() */
- X
- X#endif /* ?MSWIN */
- X
- X
- X
- X
- X/********************************/
- X/* Function process_zipfile() */
- X/********************************/
- X
- Xint process_zipfile() /* return PK-type error code */
- X`7B
- X int error=0, error_in_archive;
- X longint real_ecrec_offset, expect_ecrec_offset;
- X
- X
- X/*--------------------------------------------------------------------------
- V-
- X Open the zipfile for reading and in BINARY mode to prevent CR/LF trans-
- X lation, which would corrupt the bitstreams.
- X --------------------------------------------------------------------------
- V-*/
- X
- X#ifdef VMS
- X if (check_format()) /* check for variable-length format */
- X return 2; /* 2: error in zipfile */
- X#endif /* VMS */
- X
- X if (open_input_file()) /* this should never happen, given the */
- X return 9; /* stat() test in main(), but... */
- X
- X/*--------------------------------------------------------------------------
- V-
- X Reconstruct the various PK signature strings, and find and process the
- X end-of-central-directory header.
- X --------------------------------------------------------------------------
- V-*/
- X
- X strcat(local_hdr_sig, LOCAL_HDR_SIG);
- X strcat(central_hdr_sig, CENTRAL_HDR_SIG);
- X strcat(end_central_sig, END_CENTRAL_SIG);
- X/* strcat(extd_local_sig, EXTD_LOCAL_SIG); */
- X
- X if (find_end_central_dir()) `7B /* not found; nothing to do */
- X close(zipfd);
- X return 2; /* 2: error in zipfile */
- X `7D
- X
- X real_ecrec_offset = cur_zipfile_bufstart+(inptr-inbuf);
- X#ifdef TEST
- X printf("\n found end-of-central-dir signature at offset %ld (%.8lXh)\n"
- V,
- X real_ecrec_offset, real_ecrec_offset);
- X printf(" from beginning of file; offset %d (%.4Xh) within block\n",
- X inptr-inbuf, inptr-inbuf);
- X#endif
- X
- X if ((error_in_archive = process_end_central_dir()) > 1) `7B
- X close(zipfd);
- X return error_in_archive;
- X `7D
- X
- X if (zflag) `7B
- X close(zipfd);
- X return 0;
- X `7D
- X
- X/*--------------------------------------------------------------------------
- V-
- X Test the end-of-central-directory info for incompatibilities and incon-
- X sistencies.
- X --------------------------------------------------------------------------
- V-*/
- X
- X#ifndef PAKFIX
- X if (ecrec.number_this_disk == 0) `7B
- X#else /* PAKFIX */
- X error = ((ecrec.number_this_disk == 1) &&
- X (ecrec.num_disk_with_start_central_dir == 1));
- X if ((ecrec.number_this_disk == 0) `7C`7C error) `7B
- X if (error) `7B
- X fprintf(stderr,
- X "\n Warning: zipfile claims to be disk 2 of a two-part archive;\n\
- X attempting to process anyway. If no further errors occur, this\n\
- X archive was probably created by PAK v2.51 or earlier. This bug\n\
- X was reported to NoGate in March 1991 and was supposed to have been\n\
- X fixed by mid-1991; as of mid-1992 it still hadn't been.\n\n");
- X error_in_archive = 1; /* 1: warning */
- X `7D
- X#endif /* ?PAKFIX */
- X expect_ecrec_offset = ecrec.offset_start_central_directory +
- X ecrec.size_central_directory;
- X if ((extra_bytes = real_ecrec_offset - expect_ecrec_offset) < 0) `7B
- X fprintf(stderr, "\nerror: missing %ld bytes in zipfile (\
- Xattempting to process anyway)\n\n", -extra_bytes);
- X error_in_archive = 2; /* 2: (weak) error in zipfile */
- X `7D else if (extra_bytes > 0) `7B
- X if ((ecrec.offset_start_central_directory == 0) &&
- X (ecrec.size_central_directory != 0)) /* zip 1.5 -go bug */
- X `7B
- X fprintf(stderr, "\nerror: NULL central directory offset (\
- Xattempting to process anyway)\n\n");
- X ecrec.offset_start_central_directory = extra_bytes;
- X extra_bytes = 0;
- X error_in_archive = 2; /* 2: (weak) error in zipfile */
- X `7D else `7B
- X fprintf(stderr, "\nwarning: extra %ld bytes at beginning or
- V\
- X within zipfile\n (attempting to process anyway)\n\n", extra_bytes)
- V;
- X error_in_archive = 1; /* 1: warning error */
- X `7D
- X `7D
- X
- X /*----------------------------------------------------------------------
- V-
- X Check for empty zipfile and exit now if so.
- X ----------------------------------------------------------------------
- V-*/
- X
- X if (expect_ecrec_offset == 0L && ecrec.size_central_directory == 0
- V) `7B
- X fprintf(stderr, "warning: zipfile is empty\n");
- X close(zipfd);
- X return (error_in_archive > 1)? error_in_archive : 1;
- X `7D
- X
- X /*----------------------------------------------------------------------
- V-
- X Compensate for missing or extra bytes, and seek to where the start
- X of central directory should be. If header not found, uncompensate
- X and try again (necessary for at least some Atari archives created
- X with STZIP, as well as archives created by J.H. Holm's ZIPSPLIT).
- X ----------------------------------------------------------------------
- V-*/
- X
- X LSEEK( ecrec.offset_start_central_directory )
- X if ((readbuf(sig, 4) <= 0) `7C`7C strncmp(sig, central_hdr_sig, 4))
- V `7B
- X longint tmp = extra_bytes;
- X
- X extra_bytes = 0;
- X LSEEK( ecrec.offset_start_central_directory )
- X if ((readbuf(sig, 4) <= 0) `7C`7C strncmp(sig, central_hdr_sig,
- V 4)) `7B
- X fprintf(stderr,
- X "error: start of central directory not found; zipfile corrupt.\
- Vn");
- X fprintf(stderr, ReportMsg);
- X close(zipfd);
- X return 3; /* 3: severe error in zipfile */
- X `7D
- X fprintf(stderr, "error: reported length of central directory is
- V \
- X%d bytes too\n long (Atari STZIP zipfile? J.H. Holm ZIPSPLIT zipfile
- V?)\
- X.\n Compensating...\n\n", -tmp);
- X error_in_archive = 2; /* 2: (weak) error in zipfile */
- X `7D
- X
- X /*----------------------------------------------------------------------
- V-
- X Seek to the start of the central directory one last time, since we
- X have just read the first entry's signature bytes; then list, extract
- X or test member files as instructed, and close the zipfile.
- X ----------------------------------------------------------------------
- V-*/
- X
- X LSEEK( ecrec.offset_start_central_directory )
- X if (vflag)
- X error = list_files(); /* LIST 'EM */
- X else
- X error = extract_or_test_files(); /* EXTRACT OR TEST 'EM */
- X if (error > error_in_archive) /* don't overwrite stronger error */
- X error_in_archive = error; /* with (for example) a warning */
- X `7D else `7B
- X fprintf(stderr, "\nerror: zipfile is part of multi-disk archive \
- X(sorry, not supported).\n");
- X /* fprintf(stderr, "Please report to zip-bugs@cs.ucla.edu\n"); */
- X error_in_archive = 11; /* 11: no files found */
- X `7D
- X
- X close(zipfd);
- X return error_in_archive;
- X
- X`7D /* end function process_zipfile() */
- X
- X
- X
- X
- X
- X/************************************/
- X/* Function find_end_central_dir() */
- X/************************************/
- X
- Xint find_end_central_dir() /* return 0 if found, 1 otherwise */
- X`7B
- X int i, numblks;
- X longint tail_len;
- X
- X
- X
- X/*--------------------------------------------------------------------------
- V-
- X Treat case of short zipfile separately.
- X --------------------------------------------------------------------------
- V-*/
- X
- X if (ziplen <= INBUFSIZ) `7B
- X lseek(zipfd, 0L, SEEK_SET);
- X if ((incnt = read(zipfd,(char *)inbuf,(unsigned int)ziplen)) ==
- X (int)ziplen)
- X
- X /* 'P' must be at least 22 bytes from end of zipfile */
- X for (inptr = inbuf+(int)ziplen-22; inptr >= inbuf; --inptr)
- +-+-+-+-+-+-+-+- END OF PART 10 +-+-+-+-+-+-+-+-
-