Article View: vmsnet.sources
Article #61Zip v1.9 & UnZip v5.0, part 01/22
From: goathunter
Date: Tue, 01 Sep 1992 22:48
Date: Tue, 01 Sep 1992 22:48
1237 lines
49829 bytes
49829 bytes
Submitted-by: goathunter@wkuvx1.bitnet
Posting-number: Volume 3, Issue 123
Archive-name: zip_unzip/part01
$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-010 25-Jun-1992
$! On 1-SEP-1992 14:55:11.00 By user BERRYMAN
$!
$! This VMS_SHARE Written by:
$! Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$! James Gray - Original VMS_SHARE
$! Michael Bednarek - Original Concept and implementation
$!
$!+ THIS PACKAGE DISTRIBUTED IN 22 PARTS, TO KEEP EACH PART
$! BELOW 100 BLOCKS
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE ( @name )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$! 1. AAAREADME.TXT;1
$! 2. UNMFTU.COM;1
$! 3. [.UNZIP50]BUGS.;1
$! 4. [.UNZIP50]CONTENTS.;1
$! 5. [.UNZIP50]CONTRIBS.;1
$! 6. [.UNZIP50]COPYING.;1
$! 7. [.UNZIP50]DESCRIP.MMS;1
$! 8. [.UNZIP50]ENVARGS.C;1
$! 9. [.UNZIP50]EXPLODE.C;1
$! 10. [.UNZIP50]EXTRACT.C;1
$! 11. [.UNZIP50]FILE_IO.C;1
$! 12. [.UNZIP50]FUNZIP.1;1
$! 13. [.UNZIP50]FUNZIP.C;1
$! 14. [.UNZIP50]FUNZIP.DOC;1
$! 15. [.UNZIP50]HISTORY.500;1
$! 16. [.UNZIP50]INFLATE.C;1
$! 17. [.UNZIP50]MAKEFILE.;1
$! 18. [.UNZIP50]MAKE_GCC_UNZIP.COM;1
$! 19. [.UNZIP50]MAKE_VAXC_UNZIP.COM;1
$! 20. [.UNZIP50]MAPNAME.C;1
$! 21. [.UNZIP50]MATCH.C;1
$! 22. [.UNZIP50]MISC.C;1
$! 23. [.UNZIP50]OTHER_SYSTEMS.MFTU;1
$! 24. [.UNZIP50]README.;1
$! 25. [.UNZIP50]UNREDUCE.C;1
$! 26. [.UNZIP50]UNSHRINK.C;1
$! 27. [.UNZIP50]UNZIP.1;1
$! 28. [.UNZIP50]UNZIP.C;1
$! 29. [.UNZIP50]UNZIP.DOC;1
$! 30. [.UNZIP50]UNZIP.H;1
$! 31. [.UNZIP50]UNZIP.RNH;1
$! 32. [.UNZIP50]VMS.C;1
$! 33. [.UNZIP50]VMS.NOTES;1
$! 34. [.UNZIP50]VMSSHARE.OPT;1
$! 35. [.UNZIP50]WHERE.;1
$! 36. [.UNZIP50]ZIP.H;1
$! 37. [.UNZIP50]ZIPINFO.1;1
$! 38. [.UNZIP50]ZIPINFO.C;1
$! 39. [.UNZIP50]ZIPINFO.DOC;1
$! 40. [.UNZIP50]ZIPRULES.;1
$! 41. [.ZIP19]ZIP19_ZIP.MFTU;1
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ x = P1 - f$parse(P1,,,"version")
$ y = f$search(x)
$ if y .eqs. "" then $ goto file_absent
$ x = f$integer(f$parse(P1,,,"version")-";")
$ y = f$integer(f$parse(y,,,"version")-";")
$ if x .gt. y then $ goto file_absent
$ if f$mode() .eqs. "INTERACTIVE" then $ goto file_interactive
$ if x .eq. y then e "-W-EXISTS, File ''P1' exists. Skipped."
$ if x .ne. y then e "-W-NEWERVERSION, of File ''P1' exists. Skipped."
$file_delete:
$ delete 'f'*
$ exit
$file_interactive:
$ if x .eq. y then e "-W-EXISTS, File ''P1' exists."
$ if x .ne. y then e "-W-NEWERVERSION, of File ''P1' exists."
$ read/error=file_delete/end=file_delete-
/prompt="Create new version [y/n]: " -
sys$command x
$ if .not. x then $ e "-W-SKIPPED, File ''P1' skipped."
$ if .not. x then $ goto file_delete
$ P1 = P1 - f$parse(P1,,,"version")
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
"output_file"));ENDPROCEDURE;Unpacker;QUIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create 'f'
X `5B Moderators Note: The executables (.EXE files) mentioned
X in this text have been removed from this submission. The
X executable images can be built locally with the files
X provided. `5D
X
XThis directory contains the sources and VMS .OBJs and .EXEs for the
XInfo-ZIP programs Zip v1.9 and UnZip v5.0. These are compatible with
XPKware's PKZIP v1.93a, as well as previous versions of Zip and UnZip.
X
XZip v1.9 and UnZip v5.0 now support the saving and automatic restoring
Xof VMS file attributes.
X
X`5B.UNZIP50`5D contains the UnZip sources, a VMS BACKUP saveset containing
XVMS .OBJ files, the UnZip .EXEs linked under VMS v5.5-1, and a .ZIP
Xfile containing all the operating system-specific files needed to build
XUnZip for the Amiga, Atari, MS-DOS, OS/2, NT, UNIX, and VMS operating
Xsystems. The .OBJs, .EXEs, and .ZIP files are encoded using MFTU; you'll
Xneed MFTU to convert back to their binary forms.
X
X`5B.ZIP19`5D contains ZIP19_ZIP.MFTU, an MFTU-encoded .ZIP file containing
Xall the sources for Zip v1.9, along with the VMS .OBJ and .EXE files.
XThis .ZIP file was created using the "-V" option, which stores the
XVMS file attributes; UnZip will automatically restore those attributes.
X
XZip and UnZip can be compiled using either VAX C or GNU C. There
Xare .COM files in each directory to compile the programs.
X
XYou'll need MFTU.EXE to decode the .OBJ, .EXE, and .ZIP files.
XInstructions for getting MFTU are included below. Once MFTU.EXE
Xexists, define a foreign symbol that points to it:
X
X`09$ MFTU :== $dev:`5Bdir`5DMFTU.EXE
X
XYou can now execute the command procedure UNMFTU.COM in this directory
Xto decode the .MFTU files:
X
X`09$ MFTU DECODE `5B.UNZIP50`5DUNZIP_EXES.MFTU
X`09$ MFTU DECODE `5B.UNZIP50`5DUNZIP_OBJS.MFTU
X`09$ MFTU DECODE `5B.UNZIP50`5DOTHER_SYSTEMS.MFTU
X`09$ MFTU DECODE `5B.ZIP19`5DZIP19_ZIP.MFTU
X
XIf you don't have a C compiler (either VAX C or GNU C), you can relink
Xthe .OBJs by using the following command to unpack them from the
Xsaveset:
X
X`09$ BACKUP `5B.UNZIP50`5DUNZIP_OBJS.BCK `5B.UNZIP50`5D*.*
X
XOnce you have UNZIP.EXE, define a foreign symbol to point to it, then
Xuse it to UnZip the ZIP19.ZIP file:
X
X`09$ unzip :== $dev:`5Bdir`5Dunzip.exe
X`09$ set default `5B.zip19`5D
X`09$ unzip zip19
X
XOn-line VMS HELP files can be created by using RUNOFF to process the
Xtwo .RNH files in the Zip and UnZip directories and inserting the
Xresulting .HLP files in a VMS help library:
X
X`09$ SET DEFAULT `5B.UNZIP50`5D
X`09$ RUNOFF UNZIP.RNH
X`09$ LIBRARY/INSER/HELP library.HLB UNZIP.HLP
X
X`09$ SET DEFAULT `5B.ZIP19`5D
X`09$ RUNOFF VMS_ZIP.RNH
X`09$ LIBRARY/INSER/HELP library.HLB VMS_ZIP.HLP
X
XYou can get the sources to MFTU using one of these methods:
X
X`09o Via anonymous ftp from ftp.spc.edu---you'll need the files:
X
X`09`09`5B.MACRO32`5DLZDCMP.EXE
X`09`09`5B.MACRO32.SAVESETS`5DMFTU.BCK_Z
X
X`09o By sending the command SEND MFTU in the body of a mail message
X`09 to FILESERV@WKUVX1.BITNET. MFTU is written in MACRO-32, so it
X`09 can be assembled by all VMS sites.
X
XAssembled for VMS e-mail distribution by Hunter Goatley, Western Kentucky
XUniversity, goathunter@WKUVX1.BITNET
$ CALL UNPACK AAAREADME.TXT;1 286679110
$ create 'f'
X$ save_verify = 'f$verify(0)'
X$ if f$type(MFTU).eqs.""
X$ then write sys$output "MFTU foreign symbol does not exist"
X$`09goto common_exit
X$ endif
X$!
X$! The UNZIP_OBJS.MFTU was submitted as a separate part of this package and
V may
X$! not be present if you obtained your copy via FTP or a MAILSERV. The
X$! UNZIP_EXES.MFTU file is not present in this submission.
X$!
X$ call do_decode "`5B.UNZIP50`5DUNZIP_OBJS.MFTU"
X$! call do_decode "`5B.UNZIP50`5DUNZIP_EXES.MFTU"
X$ call do_decode "`5B.UNZIP50`5DOTHER_SYSTEMS.MFTU"
X$ call do_decode "`5B.ZIP19`5DZIP19_ZIP.MFTU"
X$ common_exit:
X$ exit 1.or.f$verify(save_verify)
X$!
X$ do_decode: subroutine
X$ filename = f$parse("''p1'","","","NAME")
X$ filedir = f$parse("''p1'","","","DEVICE")+f$parse("''p1'","","","DIRECTOR
VY")
X$ save_default = f$environment("DEFAULT")
X$ if f$search("''p1'").nes.""
X$ then`09set default 'filedir'
X$`09mftu decode 'filename'.MFTU
X$`09set default 'save_default'
X$ else`09write sys$output "''p1' file not found"
X$ endif
X$ exit
X$ endsubroutine
$ CALL UNPACK UNMFTU.COM;1 1667514741
$ create 'f'
XBugs (real and/or imagined):
X---------------------------
X
X - Watcom C getch() broken; password echos (reported to Watcom by K.U.Rommel
V)
X - VMS docs out of date
X - Amiga port broken?
X - VMS unzip no longer sets permissions correctly
X - Macintosh file attributes not interpreted correctly (both unzip, zipinfo)
X - errno declaration conflicts with several compilers' definitions: change
X logic so undeclared by default? How many systems affected?
X - (?) add ifndef MODERN around srand, rand prototypes in crypt.c? `5BJames
X Birdsall, 4/23`5D
X - pkbug error: zipfile with incorrect csize and/or ucsize--check for end o
Vf
X compressed (csize) data in uncompression routines:
X unimplod.c: while ((!zipeof) && ((outpos + outcnt) < ucsize)) `7B
X unreduce.c: while (((outpos + outcnt) < ucsize) && (!zipeof)) `7B
X (James Birdsall, Mark, bottom of BUGS.long)
X - if PK signature not found, append .zip and try again without error`20
X messages (Jean-loup, others, bottom of BUGS.long)
X - disk full: a few files clear some pointer; continuing beyond "Continue?"
X prompt, regardless of answer, kills unzip--stack too small? (doesn't see
Vm
X to matter) Bug in MSC write() function? Subsequent write code isn't an
Vy`20
X different from -t option, so unlikely to be bug in uncompress routines..
V.
X File descriptor bad/close() failure? (workaround: `5EC at prompt)
X - textfile conversions on a PC system add extra CR to lines which already h
Vave
X CR/LF combo; other directions probably don't work, either (Mac/Unix/...)
V:
X rewrite "dos2unix" and make general
X - compressed symlinks are allowed: revise symlink code
X - fix "no errors detected" message for errors occurring *before* extract_or
V_
X test_files(); count errors? differentiate between errors and warnings?
X
X
XFeatures (possible and/or definite):
X-----------------------------------
X
X - add -x "exclude following files" option to unzip and zipinfo
X - make use of FILE_IO_C and similar defines to avoid including unnecessary
X header files in various modules (unzip.h)
X - add "near" to global vars `5BSteve Salisbury, 4/21`5D
X - construct CRC table dynamically? `5BJean-loup, 5/12`5D
X - when listing filenames, use '?' for non-printables? `5BThomas Wolff, 6/1`
V5D
X - modify to decompress input stream if part of a pipe, but continue using
X central directory if not (BIG job!)--extended local header capability
X - need zipinfo target(s) in makefile.dos
X - build in capability to check text/binary type and warn if -a (if version
X < 1.1 and not made on DOS--i.e., not early Info-ZIP versions)
X - allow wildcards in zipfile name (loop through each one)
X - test/incorporate Martin Schulz optimization patch (still useful?)
X - add -oo option (overwrite and override): no user queries (if bad passwor
Vd,
X skip file; if disk full, take default action; if VMS special on non-VMS,
X unpack anyway; etc.)
X - add -Q`5BQ`5BQ`5D`5D option (quiet mode on comments, cautions, warnings a
Vnd errors):
X forget -oo, or make synonym? Default level -Q?
X - incorporate Atari patches
X - rewrite mapname()
X - modify set_file_time routines to share common code (macro?)
X - add zipinfo "in-depth" option? (check local vs. central filenames, etc.)
X - create zipcat program to concatenate zipfiles
X - create zipfix program to rebuild/salvage damaged zipfiles
X - assembly-language routines?
X - add -i (ignore case for internal filename match) option? (maybe not)
X - CP/M version (Jeffery Foy)
X - VM/CMS version (Chua Kong Sian, others)
X - put man pages in more "proper" nroff format
X - add OS/2 .INF format helpfiles for UnZip and ZipInfo
X
$ CALL UNPACK [.UNZIP50]BUGS.;1 326700365
$ create 'f'
XContents of the UnZip 5.0 archive (the OS-specific subdirectories at the
Xend contain their own Contents listings):
X
X Contents`09this file
X Readme`09what UnZip is; general information
X Where`09`09where Zip/UnZip and encryption/decryption support can be found
X History.500`09new features and fixes in this release
X ZipRules`09Info-ZIP guidelines on contributions to the cause
X BUGS`09`09known bugs, problems, and (possible) features to be added
X unzip.1`09UnZip manual page, nroff format
X unzip.doc`09UnZip manual page, human-readable format
X zipinfo.1`09ZipInfo manual page, nroff format
X zipinfo.doc`09ZipInfo manual page, human-readable format
X funzip.1 `09FUnZip manual page, nroff format
X funzip.doc `09FUnZip manual page, human-readable format
X CONTRIBS`09list of contributors to UnZip
X COPYING`09copyrights and distribution policy
X crypt.c NOT INCLUDED: see "Where" file for sites
X envargs.c`09code to read options from UNZIP environment var. (required*)
X explode.c`09code for exploding (required)
X extract.c`09high-level extraction and decryption code (required)
X file_io.c`09file manipulation and password code (required)
X funzip.c `09filter unzip: extracts in a Unix pipe (not fully supported)
X inflate.c`09code for inflating (required)
X mapname.c`09code to map filenames between different OS's (required)
X match.c`09pattern-matching code for filename wildcards (required*)
X misc.c`09various support routines (required*)
X unreduce.c`09code for unReducing (required)
X unshrink.c`09code for unShrinking (required)
X unzip.c`09main UnZip driver code (required)
X unzip.h`09main UnZip header file (required*)
X zip.h`09`09header for using crypt.c with UnZip (required for decryption)
X zipinfo.c`09zipfile information utility (useful, but optional)
X Makefile`09main Unix and OS/2 makefile (required)
X AMIGA/`09support files for compiling on Amiga (not recently tested)
X ATARI/`09support files for compiling v4.1 on Atari ST
X MAC/`09`09support files for compiling on Macintosh
X MSDOS/`09support files for compiling under MS-DOS
X NT/`09`09support files for compiling under Windows NT
X OS2/`09`09support files for compiling under OS/2
X VMS/`09`09support files for compiling under VMS
X
XFiles marked "required*" are also needed to compile ZipInfo. There are Unix
Xand MS-DOS targets to make ZipInfo in Makefile (zipinfo, zi_indigo, zi_gcc,`
V20
Xzi_dos). FUnZip is a new, last-minute program of limited capabilities; for
Xnow, it can only extract the first member in a zipfile from stdin and send
Xit to stdout, and only if the member is either deflated or stored. It will`
V20
Xprobably have evolved by the time you read this, and it may even be absorbed
V`20
Xinto UnZip itself.
X
XThe Atari ST support is in the form of patches against UnZip 4.1; there
Xare more details in the ATARI sub-archive Contents file. Amiga support
Xhas not been tested since version 4.1 or earlier (the makefiles, however,
Xhave been updated to reflect the new code structure, and any changes
Xrequired shouldn't be TOO extensive).
$ CALL UNPACK [.UNZIP50]CONTENTS.;1 1510366775
$ create 'f'
XThis is a partial list of contributors to Info-ZIP UnZip and the code upon
Xwhich it is based. Many, many others have also contributed, and if you are
Xamong them, please let us know. Aside from the Info-ZIP digest archives,
Xwe have not kept very good track of who contributed what. Also, contributor
Vs
Xto the makefile are listed at the bottom of Makefile.
X
X Mark Adler decryption, inflate, explode, funzip code; misc. ca
Vsts
X Glenn Andrews MSDOS makefiles; prototyping bugfix
X Joel Aycock descrip.mms bugfix
X Allan Bjorklund in misc.c
X James Birdsall extract.c bugfix; etc.
X Wim Bonner OS/2 stuff
X John Cowan mods to original match.c; other stuff?
X Frank da Cruz xxu.c, on which mapname.c is based
X Bill Davidsen -q(q); mapname stuff; memset/memcpy(?); etc.
X Arjan de Vet various things, but I don't remember exactly what..
V.
X James Dugal ZMEM stuff; unshrink bugfix; file perms stuff; etc.
X Jim Dumser -z stuff; umask bugfixes; etc.
X Mark Edwards in mapname.c, misc.c
X David Feinleib Windows NT port
X Mike Freeman VMS GCC makefiles; etc.
X Jean-loup Gailly decryption code; much prodding to fix bugs :-)
X Hunter Goatley VMS RUNOFF source (documentation)
X Robert Heath original Windows port
X Dave Heiland new usage screen `5B, new documentation...?`5D
X Larry Jones ZMEM stuff; unimplod bugfix; etc.
X Kjetil J`7B\o`7Drgenson ln/copy misc_.c bugfix
X Bob Kemp NOTINT16 rewrite (byte arrays instead of structs)
X J. Kercheval filmatch.c, on which match.c is based
X David Kirschbaum mapname port; general-purpose meddling; Python joke
Vs
X Alvin Koh Borland C++ bugfixes
X Bo Kullmar -z code; bugfixes: umask, do_string, BSD time; etc.
X Johnny Lee Macintosh port; Mac resource fork stuff; Win3.1 por
Vt
X Warner Losh in misc.c
X Igor Mandrichenko vms.c; many improvements and VMS modifications
X Fulvio Marino revised UnZip and ZipInfo man pages
X Carl Mascott original Unix port
X Gene McManus -o code
X Joe Meadows file.c, on which VMSmunch.c is based
X Mike O'Carroll OS/2 stuff
X Humberto Ortiz-Zuazaga Linux port; permissions bugfix; missing declaration
Vs
X Keith Petersen former Info-ZIP list maintainer
X Piet W. Plomp nice fix for msc_dos Makefile target
X Antonio Querubin, Jr descrip.mms (VMS makefile)
X Greg Roelofs central directory code; ZipInfo; original VMS port;
V...
X Kai Uwe Rommel much OS/2 code; bugfixes; etc.
X Steve Salisbury CountryInfo bugfix; variable INBUFSIZ
X Georg Sassen Amiga DICE compiler port
X Jon Saxton date formats
X Hugh Schmidt VMS stuff
X Martin Schulz Atari patches
X Charles Scripter various bug reports and bugfixes
X Chris Seaman Unix time stuff
X Richard Seay MS-DOS Quick C makefile
X Alex Sergejew file_io.c bugfix; stat() bugfix; Down Under jokes
X Samuel H. Smith original unzip code (Pascal and C) for PC
X Cliff Stanford file_io.c umask bug
X Onno van der Linden SCO optimization bugfix; etc.
X Jim Van Zandt one of original man pages
X Antoine Verheijen MTS/EBCDIC stuff; FILENAME_MAX stuff; Mac fixes; et
Vc.
X Rich Wales current Info-ZIP moderator and zip guy
X Paul Wells original Amiga port for SAS/C and Lattice C (?)
$ CALL UNPACK [.UNZIP50]CONTRIBS.;1 254357436
$ create 'f'
X============================================================================
V===
X The following copyrights are claimed on portions of the UnZip source code
V.
X Further comments are at the bottom.
X============================================================================
V===
X
X Copyright in unzip.c, originally from unzip version 1.2 (?):
X
X * Copyright 1989 Samuel H. Smith; All rights reserved
X *
X * Do not distribute modified versions without my permission.
X * Do not remove or alter this notice or any other copyright notice.
X * If you use this in your own program you must distribute source code.
X * Do not use any of this in a commercial product.
X
X----------------------------------------------------------------------------
V---
X
X Copyright in misc.c, applying to UpdateCRC() and crc_32_tab`5B`5D:
X
X COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or code
X or tables extracted from it, as desired without restriction.
X
X----------------------------------------------------------------------------
V---
X
X Copyright in vms.c, distributed with UnZip versions 4.2 and later:
X
X * Copyright (C) 1992 Igor Mandrichenko.
X * Permission is granted to any individual or institution to use, copy,
X * or redistribute this software so long as all of the original files
X * are included unmodified, that it is not sold for profit, and that
X * this copyright notice is retained.
X
X----------------------------------------------------------------------------
V---
X
X Additional copyright information:
X
X BILF (distributed with the VMS stuff) is copyrighted by Rahul Dhesi,
X but it is freely distributable.
X
X The functions extract_or_test_files() and store_info() in extract.c,
X do_string() and return_VMS() in misc.c, VMS version of echo() in
X file_io.c, and find_end_central_dir() in unzip.c, were written by
X Greg Roelofs and subsequently modified by many others via Info-ZIP.
X I do not claim a copyright on these routines, but I do ask that no
X one else do so either, :-) and that anyone using them in other pro-
X grams note their source.
X
X The function decrypt_member() in extract.c and the password functions
X in file_io.c were written by Mark Adler, as were the inflate.c and
X explode.c modules.
X
X The function mapped_name() in mapname.c was written by David Kirschbaum
V,
X based on the XXU program by Frank Da Cruz.
X
X The module match.c was written by J. Kercheval and modified by David
X Kirschbaum for use in UnZip.
X
X Original notes from unzip 2.0a by Carl Mascott, cmascott@world.std.com
X (these are only the modifications which seem still to exist):
X * 12/14/89 C. Mascott 2.0a adapt for UNIX
X * don't pre-allocate output file space
X * implement -t, -v, member file specs
X * buffer all input
X * fix "Bad CRC" msg: good/bad CRCs were swapped
X * check for write error on output file
X
X Most of the remaining routines have contributions from all of us, and
X show it. :-)
X
X============================================================================
V===
X
X Info-ZIP comments:
X
X Info-ZIP has very little interest in legal matters, aside from the usual
X "CYA" sense (that's an acronym, and you can figure it out yourself :-) ).
X
X As far as we are aware--and please note that the numerous contributors`20
X and copyright holders make this a little uncertain--the UnZip code is now
V`20
X "clean" in the sense that an UnZip executable may be distributed with a
X commercial product SO LONG AS IT IS CLEAR THAT UNZIP IS NOT BEING SOLD,
X THAT THE SOURCE CODE IS FREELY AVAILABLE, AND THAT THERE ARE NO EXTRA OR
X HIDDEN CHARGES RESULTING FROM ITS USE BY OR INCLUSION WITH THE COMMERCIAL
X PRODUCT. In particular, the retroactive copyright on unimplode.c which
X Carl Mascott requested we include in UnZip 4.2 is no longer in force, sin
Vce
X Mark Adler has rewritten the module in question from scratch (it's about
X twice as fast, too! :-) ).
X
X Regarding the original copyright by Mr. Smith: Info-ZIP has finally foun
Vd
X him again (he's moved to southern California), and he's apparently happy
X with the current code and restrictions. More specifically, since the`20
X current incarnation of UnZip can be considered "our own"--it bears very`2
V0
X little resemblance to his original program, in either content or size :-)
X --and since we freely distribute the source code, we believe that we are`
V20
X within the bounds of his third stipulation.
X
X Info-ZIP continues to rewrite portions of the code as time permits, in an
X effort to eliminate as many of the restrictions (and bugs) as possible.
X The bugs are our primary concern, however, so don't hold your breath. :-)
X
X============================================================================
V===
$ CALL UNPACK [.UNZIP50]COPYING.;1 23492127
$ create 'f'
X!==========================================================================
X! MMS description file for UnZip 5.0+ 26 June 1992
X!==========================================================================
X!
X! Original by Antonio Querubin, Jr., <querubin@uhccvx.uhcc.hawaii.edu>
X! (23 Dec 90)
X! Enhancements by Igor Mandrichenko, <mandrichenko@mx.decnet.ihep.su>
X! (9 Feb 92)
X
X! To build UnZip that uses shared libraries,
X!`09mms
X! (One-time users will find it easier to use the MAKE_UNZIP_VAXC.COM command
X! file, which generates both UnZip and ZipInfo. Just type "@MAKE_UNZIP_VAXC
V";
X! or "@MAKE_UNZIP_GCC" if you have GNU C.)
X
X! To build UnZip without shared libraries,
X!`09mms noshare
X
X! To delete unnecessary .OBJ files,
X!`09mms clean
X
XCRYPTF =
XCRYPTO =
X! To build decryption version, uncomment next two lines:
X!CRYPTF = /def=(CRYPT)
X!CRYPTO = crypt.obj,
X
XCC = cc
XCFLAGS = $(CRYPTF)
XLD = link
XLDFLAGS =
XEXE =
XO = .obj;
XOBJS = unzip$(O), $(CRYPTO) envargs$(O), explode$(O), extract$(O),\
X file_io$(O), inflate$(O), mapname$(O), match$(O), misc$(O),\
X unreduce$(O), unshrink$(O), vms$(O)
XOBJI = zipinfo$(O), envargs$(O), match$(O), misc.obj_, vms.obj_
X
XLDFLAGS2 =
X
Xdefault`09:`09unzip.exe, zipinfo.exe
X`09@`09!`09Do nothing.
X
Xunzip.exe :`09$(OBJS), vmsshare.opt
X`09$(LD) $(LDFLAGS) $(OBJS), \
X`09`09vmsshare.opt/options
X
Xzipinfo.exe :`09$(OBJI), vmsshare.opt
X`09$(LD) $(LDFLAGS) $(OBJI), \
X`09`09vmsshare.opt/options
X
X
Xnoshare :`09$(OBJS)
X`09$(LD) $(LDFLAGS) $(OBJS), \
X`09`09sys$library:vaxcrtl.olb/library $(LDFLAGS2)
X
Xclean :
X`09delete $(OBJS)`09! you may want to change this to 'delete *.obj;*'
X
Xcrypt$(O) :`09crypt.c unzip.h zip.h`09! may or may not be included in distri
Vb
Xenvargs$(O) :`09envargs.c unzip.h
Xexplode$(O) :`09explode.c unzip.h
Xextract$(O) :`09extract.c unzip.h
Xfile_io$(O) :`09file_io.c unzip.h
Xinflate$(O) :`09inflate.c unzip.h
Xmapname$(O) :`09mapname.c unzip.h
Xmatch$(O) :`09match.c unzip.h
Xmisc$(O) :`09misc.c unzip.h
Xunreduce$(O) :`09unreduce.c unzip.h
Xunshrink$(O) :`09unshrink.c unzip.h
Xunzip$(O) :`09unzip.c unzip.h
Xvms$(O)`09 :`09vms.c unzip.h
XVMSmunch$(O) :`09VMSmunch.c VMSmunch.h
Xmisc.obj_ :`09misc.c unzip.h
X`09$(CC)/object=misc.obj_/define="ZIPINFO" misc.c
X
Xvms.obj_ :`09vms.c unzip.h
X`09$(CC)/object=vms.obj_/define="ZIPINFO" vms.c
$ CALL UNPACK [.UNZIP50]DESCRIP.MMS;1 2081498107
$ create 'f'
X/*****************************************************************
X `7C envargs - add default options from environment to command line
X `7C----------------------------------------------------------------
X `7C Author: Bill Davidsen, original 10/13/91, revised 23 Oct 1991.
X `7C This program is in the public domain.
X `7C----------------------------------------------------------------
X `7C Minor program notes:
X `7C 1. Yes, the indirection is a tad complex
X `7C 2. Parenthesis were added where not needed in some cases
X `7C to make the action of the code less obscure.
X `7C 3. Set tabsize to four to make this pretty
X `7C----------------------------------------------------------------
X `7C UnZip notes 24 May 92 ("v1.4"):
X `7C 1. #include "unzip.h" for prototypes
X `7C 2. changed ch to type char
X `7C 3. added an ifdef to avoid Borland warnings
X *****************************************************************/
X
X#include "unzip.h"
Xstatic int count_args __((char *));
Xstatic void mem_err __((void));
X
X#if (defined(SCCS) && !defined(lint)) /* causes warnings: annoying */
Xstatic char *SCCSid = "@(#)envargs.c`091.3 23 Oct 1991";
X#endif
X
Xvoid
Xenvargs(Pargc, Pargv, envstr)
Xint *Pargc;
Xchar ***Pargv;
Xchar *envstr;
X`7B
X`09char *getenv();
X`09char *envptr;`09`09`09`09/* value returned by getenv */
X`09char *bufptr;`09`09`09`09/* copy of env info */
X`09int argc = 0;`09`09`09`09/* internal arg count */
X`09char ch;`09`09`09`09`09/* spare temp value */
X`09char **argv;`09`09`09`09/* internal arg vector */
X`09char **argvect;`09`09`09`09/* copy of vector address */
X
X`09/* see if anything in the environment */
X`09envptr = getenv(envstr);
X`09if (envptr == (char *)NULL `7C`7C *envptr == 0) return;
X
X`09/* count the args so we can allocate room for them */
X`09argc = count_args(envptr);
X`09bufptr = (char *)malloc(1+strlen(envptr));
X`09if (bufptr == (char *)NULL) mem_err();
X`09strcpy(bufptr, envptr);
X
X`09/* allocate a vector large enough for all args */
X`09argv = (char **)malloc((argc+*Pargc+1)*sizeof(char *));
X`09if (argv == (char **)NULL) mem_err();
X`09argvect = argv;
X
X`09/* copy the program name first, that's always true */
X`09*(argv++) = *((*Pargv)++);
X
X`09/* copy the environment args next, may be changed */
X`09do `7B
X`09`09*(argv++) = bufptr;
X`09`09/* skip the arg and any trailing blanks */
X`09`09while (((ch = *bufptr) != '\0') && ch != ' ') ++bufptr;
X`09`09if (ch == ' ') *(bufptr++) = '\0';
X`09`09while (((ch = *bufptr) != '\0') && ch == ' ') ++bufptr;
X`09`7D while (ch);
X
X`09/* now save old argc and copy in the old args */
X`09argc += *Pargc;
X`09while (--(*Pargc)) *(argv++) = *((*Pargv)++);
X
X`09/* finally, add a NULL after the last arg, like UNIX */
X`09*argv = (char *)NULL;
X
X`09/* save the values and return */
X`09*Pargv = argvect;
X`09*Pargc = argc;
X`7D
X
Xstatic int
Xcount_args(s)
Xchar *s;
X`7B
X`09int count = 0;
X`09char ch;
X
X`09do `7B
X`09`09/* count and skip args */
X`09`09++count;
X`09`09while (((ch = *s) != '\0') && ch != ' ') ++s;
X`09`09while (((ch = *s) != '\0') && ch == ' ') ++s;
X`09`7D while (ch);
X
X`09return count;
X`7D
X
Xstatic void
Xmem_err()
X`7B
X`09perror("Can't get memory for arguments");
X`09exit(2);
X`7D
X`0C
X#ifdef TEST
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X`7B
X`09int i;
X
X`09printf("Orig argv: %p\n", argv);
X`09dump_args(argc, argv);
X`09envargs(&argc, &argv, "ENVTEST");
X`09printf(" New argv: %p\n", argv);
X`09dump_args(argc, argv);
X`7D
X
Xdump_args(argc, argv)
Xint argc;
Xchar *argv`5B`5D;
X`7B
X`09int i;
X
X`09printf("\nDump %d args:\n", argc);
X`09for (i=0; i<argc; ++i) `7B
X`09`09printf("%3d %s\n", i, argv`5Bi`5D);
X`09`7D
X`7D
X#endif
$ CALL UNPACK [.UNZIP50]ENVARGS.C;1 1581522662
$ create 'f'
X/* explode.c -- Not copyrighted 1992 by Mark Adler
X version c7, 27 June 1992 */
X
X
X/* You can do whatever you like with this source file, though I would
X prefer that if you modify it and redistribute it that you include
X comments to that effect with your name and the date. Thank you.
X
X History:
X vers date who what
X ---- --------- -------------- ------------------------------------
X c1 30 Mar 92 M. Adler explode that uses huft_build from inflat
Ve
X (this gives over a 70% speed improvement
X over the original unimplode.c, which
X decoded a bit at a time)
X c2 4 Apr 92 M. Adler fixed bug for file sizes a multiple of 3
V2k.
X c3 10 Apr 92 M. Adler added a little memory tracking if DEBUG
X c4 11 Apr 92 M. Adler added NOMEMCPY do kill use of memcpy()
X c5 21 Apr 92 M. Adler added the WSIZE #define to allow reducin
Vg
X the 32K window size for specialized
X applications.
X c6 31 May 92 M. Adler added typecasts to eliminate some warnin
Vgs
X c7 27 Jun 92 G. Roelofs added more typecasts
X */
X
X
X/*
X Explode imploded (PKZIP method 6 compressed) data. This compression
X method searches for as much of the current string of bytes (up to a lengt
Vh
X of `7E320) in the previous 4K or 8K bytes. If it doesn't find any matche
Vs
X (of at least length 2 or 3), it codes the next byte. Otherwise, it codes
X the length of the matched string and its distance backwards from the
X current position. Single bytes ("literals") are preceded by a one (a
X single bit) and are either uncoded (the eight bits go directly into the
X compressed stream for a total of nine bits) or Huffman coded with a
X supplied literal code tree. If literals are coded, then the minimum matc
Vh
X length is three, otherwise it is two.
X `20
X There are therefore four kinds of imploded streams: 8K search with coded
X literals (min match = 3), 4K search with coded literals (min match = 3),
X 8K with uncoded literals (min match = 2), and 4K with uncoded literals
X (min match = 2). The kind of stream is identified in two bits of a
X general purpose bit flag that is outside of the compressed stream.
X `20
X Distance-length pairs are always coded. Distance-length pairs for matche
Vd
X strings are preceded by a zero bit (to distinguish them from literals) an
Vd
X are always coded. The distance comes first and is either the low six (4K
V)
X or low seven (8K) bits of the distance (uncoded), followed by the high si
Vx
X bits of the distance coded. Then the length is six bits coded (0..63 +
X min match length), and if the maximum such length is coded, then it's
X followed by another eight bits (uncoded) to be added to the coded length.
X This gives a match length range of 2..320 or 3..321 bytes.
X
X The literal, length, and distance codes are all represented in a slightly
X compressed form themselves. What is sent are the lengths of the codes fo
Vr
X each value, which is sufficient to construct the codes. Each byte of the
X code representation is the code length (the low four bits representing
X 1..16), and the number of values sequentially with that length (the high
X four bits also representing 1..16). There are 256 literal code values (i
Vf
X literals are coded), 64 length code values, and 64 distance code values,
X in that order at the beginning of the compressed stream. Each set of cod
Ve
X values is preceded (redundantly) with a byte indicating how many bytes ar
Ve
X in the code description that follows, in the range 1..256.
X
X The codes themselves are decoded using tables made by huft_build() from
X the bit lengths. That routine and its comments are in the inflate.c
X module.
X */
X
X#include "unzip.h" /* this must supply the slide`5B`5D (byte) array */
X
X#ifndef WSIZE
X# define WSIZE 0x8000 /* window size--must be a power of two, and at least
X 8K for zip's implode method */
X#endif /* !WSIZE */
X
X
Xstruct huft `7B
X byte e; /* number of extra bits or operation */
X byte b; /* number of bits in this code or subcode */
X union `7B
X UWORD n; /* literal, length base, or distance base */
X struct huft *t; /* pointer to next level of table */
X `7D v;
X`7D;
X
X/* Function prototypes */
X/* routines from inflate.c */
Xextern unsigned hufts;
Xint huft_build OF((unsigned *, unsigned, unsigned, UWORD *, UWORD *,
X struct huft **, int *));
Xint huft_free OF((struct huft *));
Xvoid flush OF((unsigned));
X
X/* routines here */
Xint get_tree OF((unsigned *, unsigned));
Xint explode_lit8 OF((struct huft *, struct huft *, struct huft *,
X int, int, int));
Xint explode_lit4 OF((struct huft *, struct huft *, struct huft *,
X int, int, int));
Xint explode_nolit8 OF((struct huft *, struct huft *, int, int));
Xint explode_nolit4 OF((struct huft *, struct huft *, int, int));
Xint explode OF((void));
X
X
X/* The implode algorithm uses a sliding 4K or 8K byte window on the
X uncompressed stream to find repeated byte strings. This is implemented
X here as a circular buffer. The index is updated simply by incrementing
X and then and'ing with 0x0fff (4K-1) or 0x1fff (8K-1). Here, the 32K
X buffer of inflate is used, and it works just as well to always have
X a 32K circular buffer, so the index is anded with 0x7fff. This is
X done to allow the window to also be used as the output buffer. */
X/* This must be supplied in an external module useable like "byte slide`5B81
V92`5D;"
X or "byte *slide;", where the latter would be malloc'ed. In unzip, slide`
V5B`5D
X is actually a 32K area for use by inflate, which uses a 32K sliding windo
Vw.
X */
X
X
X/* Tables for length and distance */
XUWORD cplen2`5B`5D = `7B2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
V 17,
X 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
X 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
X 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65`7D;
XUWORD cplen3`5B`5D = `7B3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
V 18,
X 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
X 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
X 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66`7D;
XUWORD extra`5B`5D = `7B0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
V 0,
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
X 8`7D;
XUWORD cpdist4`5B`5D = `7B1, 65, 129, 193, 257, 321, 385, 449, 513, 577, 641,
V 705,
X 769, 833, 897, 961, 1025, 1089, 1153, 1217, 1281, 1345, 1409, 1473,
X 1537, 1601, 1665, 1729, 1793, 1857, 1921, 1985, 2049, 2113, 2177,
X 2241, 2305, 2369, 2433, 2497, 2561, 2625, 2689, 2753, 2817, 2881,
X 2945, 3009, 3073, 3137, 3201, 3265, 3329, 3393, 3457, 3521, 3585,
X 3649, 3713, 3777, 3841, 3905, 3969, 4033`7D;
XUWORD cpdist8`5B`5D = `7B1, 129, 257, 385, 513, 641, 769, 897, 1025, 1153, 1
V281,
X 1409, 1537, 1665, 1793, 1921, 2049, 2177, 2305, 2433, 2561, 2689,
X 2817, 2945, 3073, 3201, 3329, 3457, 3585, 3713, 3841, 3969, 4097,
X 4225, 4353, 4481, 4609, 4737, 4865, 4993, 5121, 5249, 5377, 5505,
X 5633, 5761, 5889, 6017, 6145, 6273, 6401, 6529, 6657, 6785, 6913,
X 7041, 7169, 7297, 7425, 7553, 7681, 7809, 7937, 8065`7D;
X
X
X/* Macros for inflate() bit peeking and grabbing.
X The usage is:
X `20
X NEEDBITS(j)
X x = b & mask_bits`5Bj`5D;
X DUMPBITS(j)
X
X where NEEDBITS makes sure that b has at least j bits in it, and
X DUMPBITS removes the bits from b. The macros use the variable k
X for the number of bits in b. Normally, b and k are register
X variables for speed.
X */
X
Xextern UWORD bytebuf; /* (use the one in inflate.c) */
X#define NEXTBYTE (ReadByte(&bytebuf), bytebuf)
X#define NEEDBITS(n) `7Bwhile(k<(n))`7Bb`7C=((ULONG)NEXTBYTE)<<k;k+=8;`7D`7D
X#define DUMPBITS(n) `7Bb>>=(n);k-=(n);`7D
X
X
X
Xint get_tree(l, n)
Xunsigned *l; /* bit lengths */
Xunsigned n; /* number expected */
X/* Get the bit lengths for a code representation from the compressed
X stream. If get_tree() returns 4, then there is an error in the data.
X Otherwise zero is returned. */
X`7B
X unsigned i; /* bytes remaining in list */
X unsigned k; /* lengths entered */
X unsigned j; /* number of codes */
X unsigned b; /* bit length for those codes */`20
X
X
X /* get bit lengths */
X ReadByte(&bytebuf);
X i = bytebuf + 1; /* length/count pairs to read */
X k = 0; /* next code */
X do `7B
X ReadByte(&bytebuf);
X b = ((j = bytebuf) & 0xf) + 1; /* bits in code (1..16) */
X j = ((j & 0xf0) >> 4) + 1; /* codes with those bits (1..16) */
X if (k + j > n)
X return 4; /* don't overflow l`5B`5D */
X do `7B
X l`5Bk++`5D = b;
X `7D while (--j);
X `7D while (--i);
X return k != n ? 4 : 0; /* should have read n of them */
X`7D
X
X
X
Xint explode_lit8(tb, tl, td, bb, bl, bd)
Xstruct huft *tb, *tl, *td; /* literal, length, and distance tables */
Xint bb, bl, bd; /* number of bits decoded by those */
X/* Decompress the imploded data using coded literals and an 8K sliding
X window. */
X`7B
X longint s; /* bytes to decompress */
X register unsigned e; /* table entry flag/number of extra bits */
X unsigned n, d; /* length and index for copy */
X unsigned w; /* current window position */
X struct huft *t; /* pointer to table entry */
X unsigned mb, ml, md; /* masks for bb, bl, and bd bits */
X register ULONG b; /* bit buffer */
X register unsigned k; /* number of bits in bit buffer */
X unsigned u; /* true if unflushed */
X
X
X /* explode the coded data */
X b = k = w = 0; /* initialize bit buffer, window */
X u = 1; /* buffer unflushed */
X mb = mask_bits`5Bbb`5D; /* precompute masks for speed */
X ml = mask_bits`5Bbl`5D;
X md = mask_bits`5Bbd`5D;
X s = ucsize;
X while (s > 0) /* do until ucsize bytes uncompressed */
X `7B
X NEEDBITS(1)
X if (b & 1) /* then literal--decode it */
X `7B
X DUMPBITS(1)
X s--;
X NEEDBITS((unsigned)bb) /* get coded literal */
X if ((e = (t = tb + ((`7E(unsigned)b) & mb))->e) > 16)
X do `7B
X if (e == 99)
X return 1;
X DUMPBITS(t->b)
X e -= 16;
X NEEDBITS(e)
X `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
V->e) > 16);
X DUMPBITS(t->b)
X slide`5Bw++`5D = (byte)t->v.n;
X if (w == WSIZE)
X `7B
X flush(w);
X w = u = 0;
X `7D
X `7D
X else /* else distance/length */
X `7B
X DUMPBITS(1)
X NEEDBITS(7) /* get distance low bits */
X d = (unsigned)b & 0x7f;
X DUMPBITS(7)
X NEEDBITS((unsigned)bd) /* get coded distance high bits */
X if ((e = (t = td + ((`7E(unsigned)b) & md))->e) > 16)
X do `7B
X if (e == 99)
X return 1;
X DUMPBITS(t->b)
X e -= 16;
X NEEDBITS(e)
X `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
V->e) > 16);
X DUMPBITS(t->b)
X d = w - d - t->v.n; /* construct offset */
X NEEDBITS((unsigned)bl) /* get coded length */
X if ((e = (t = tl + ((`7E(unsigned)b) & ml))->e) > 16)
X do `7B
X if (e == 99)
X return 1;
X DUMPBITS(t->b)
X e -= 16;
X NEEDBITS(e)
X `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
V->e) > 16);
X DUMPBITS(t->b)
X n = t->v.n;
X if (e) /* get length extra bits */
X `7B
X NEEDBITS(8)
X n += (unsigned)b & 0xff;
X DUMPBITS(8)
X `7D
X
X /* do the copy */
X s -= n;
X do `7B
X n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
X if (u && w <= d)
X `7B
X memset(slide + w, 0, e);
X w += e;
X d += e;
X `7D
X else
X#ifndef NOMEMCPY
X if (w - d >= e) /* (this test assumes unsigned comparison) *
V/
X `7B
X memcpy(slide + w, slide + d, e);
X w += e;
X d += e;
X `7D
X else /* do it slow to avoid memcpy() overlap */
X#endif /* !NOMEMCPY */
X do `7B
X slide`5Bw++`5D = slide`5Bd++`5D;
X `7D while (--e);
X if (w == WSIZE)
X `7B
X flush(w);
X w = u = 0;
X `7D
X `7D while (n);
X `7D
X `7D
X
X /* flush out slide */
X flush(w);
X return csize ? 5 : 0; /* should have read csize bytes */
X`7D
X
X
X
Xint explode_lit4(tb, tl, td, bb, bl, bd)
Xstruct huft *tb, *tl, *td; /* literal, length, and distance tables */
Xint bb, bl, bd; /* number of bits decoded by those */
X/* Decompress the imploded data using coded literals and a 4K sliding
X window. */
X`7B
X longint s; /* bytes to decompress */
X register unsigned e; /* table entry flag/number of extra bits */
X unsigned n, d; /* length and index for copy */
X unsigned w; /* current window position */
X struct huft *t; /* pointer to table entry */
X unsigned mb, ml, md; /* masks for bb, bl, and bd bits */
X register ULONG b; /* bit buffer */
X register unsigned k; /* number of bits in bit buffer */
X unsigned u; /* true if unflushed */
X
X
X /* explode the coded data */
X b = k = w = 0; /* initialize bit buffer, window */
X u = 1; /* buffer unflushed */
X mb = mask_bits`5Bbb`5D; /* precompute masks for speed */
X ml = mask_bits`5Bbl`5D;
X md = mask_bits`5Bbd`5D;
X s = ucsize;
X while (s > 0) /* do until ucsize bytes uncompressed */
X `7B
X NEEDBITS(1)
X if (b & 1) /* then literal--decode it */
X `7B
X DUMPBITS(1)
X s--;
X NEEDBITS((unsigned)bb) /* get coded literal */
X if ((e = (t = tb + ((`7E(unsigned)b) & mb))->e) > 16)
X do `7B
X if (e == 99)
X return 1;
X DUMPBITS(t->b)
X e -= 16;
X NEEDBITS(e)
X `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
V->e) > 16);
X DUMPBITS(t->b)
X slide`5Bw++`5D = (byte)t->v.n;
X if (w == WSIZE)
X `7B
X flush(w);
X w = u = 0;
X `7D
X `7D
X else /* else distance/length */
X `7B
X DUMPBITS(1)
X NEEDBITS(6) /* get distance low bits */
X d = (unsigned)b & 0x3f;
X DUMPBITS(6)
X NEEDBITS((unsigned)bd) /* get coded distance high bits */
X if ((e = (t = td + ((`7E(unsigned)b) & md))->e) > 16)
X do `7B
X if (e == 99)
X return 1;
X DUMPBITS(t->b)
X e -= 16;
X NEEDBITS(e)
X `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
V->e) > 16);
X DUMPBITS(t->b)
X d = w - d - t->v.n; /* construct offset */
X NEEDBITS((unsigned)bl) /* get coded length */
X if ((e = (t = tl + ((`7E(unsigned)b) & ml))->e) > 16)
X do `7B
X if (e == 99)
X return 1;
X DUMPBITS(t->b)
X e -= 16;
X NEEDBITS(e)
X `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
V->e) > 16);
X DUMPBITS(t->b)
X n = t->v.n;
X if (e) /* get length extra bits */
X `7B
X NEEDBITS(8)
X n += (unsigned)b & 0xff;
X DUMPBITS(8)
X `7D
X
X /* do the copy */
X s -= n;
X do `7B
X n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
X if (u && w <= d)
X `7B
X memset(slide + w, 0, e);
X w += e;
X d += e;
X `7D
X else
X#ifndef NOMEMCPY
X if (w - d >= e) /* (this test assumes unsigned comparison) *
V/
X `7B
X memcpy(slide + w, slide + d, e);
X w += e;
X d += e;
X `7D
+-+-+-+-+-+-+-+- END OF PART 1 +-+-+-+-+-+-+-+-
Technical Details
Message-ID:
<8009574@MVB.SAIC.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!ames!network.ucsd.edu!mvb.saic.com!vmsnet-sourcesShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!elroy.jpl.nasa.gov!ames!network.ucsd.edu!mvb.saic.com!vmsnet-sources From: goathunter@wkuvx1.bitnet Newsgroups: vmsnet.sources Subject: Zip v1.9 & UnZip v5.0, part 01/22 Message-ID: <8009574@MVB.SAIC.COM> Date: Tue, 01 Sep 1992 22:48:14 GMT Organization: Western Kentucky University, Bowling Green, KY Lines: 1237 Approved: Mark.Berryman@Mvb.Saic.Com