home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / vmsnet / sources / 318 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  47.4 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!ames!network.ucsd.edu!mvb.saic.com!vmsnet-sources
  2. From: goathunter@wkuvx1.bitnet
  3. Newsgroups: vmsnet.sources
  4. Subject: Zip v1.9 & UnZip v5.0, part 01/22
  5. Message-ID: <8009574@MVB.SAIC.COM>
  6. Date: Tue, 01 Sep 1992 22:48:14 GMT
  7. Organization: Western Kentucky University, Bowling Green, KY
  8. Lines: 1237
  9. Approved: Mark.Berryman@Mvb.Saic.Com
  10.  
  11. Submitted-by: goathunter@wkuvx1.bitnet
  12. Posting-number: Volume 3, Issue 123
  13. Archive-name: zip_unzip/part01
  14.  
  15. $! ------------------ CUT HERE -----------------------
  16. $ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
  17. $!
  18. $! This archive created by VMS_SHARE Version 7.2-010  25-Jun-1992
  19. $!   On  1-SEP-1992 14:55:11.00   By user BERRYMAN 
  20. $!
  21. $! This VMS_SHARE Written by:
  22. $!    Andy Harper, Kings College London UK
  23. $!
  24. $! Acknowledgements to:
  25. $!    James Gray       - Original VMS_SHARE
  26. $!    Michael Bednarek - Original Concept and implementation
  27. $!
  28. $!+ THIS PACKAGE DISTRIBUTED IN 22 PARTS, TO KEEP EACH PART
  29. $!  BELOW 100 BLOCKS
  30. $!
  31. $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
  32. $! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
  33. $!
  34. $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
  35. $!       1. AAAREADME.TXT;1
  36. $!       2. UNMFTU.COM;1
  37. $!       3. [.UNZIP50]BUGS.;1
  38. $!       4. [.UNZIP50]CONTENTS.;1
  39. $!       5. [.UNZIP50]CONTRIBS.;1
  40. $!       6. [.UNZIP50]COPYING.;1
  41. $!       7. [.UNZIP50]DESCRIP.MMS;1
  42. $!       8. [.UNZIP50]ENVARGS.C;1
  43. $!       9. [.UNZIP50]EXPLODE.C;1
  44. $!      10. [.UNZIP50]EXTRACT.C;1
  45. $!      11. [.UNZIP50]FILE_IO.C;1
  46. $!      12. [.UNZIP50]FUNZIP.1;1
  47. $!      13. [.UNZIP50]FUNZIP.C;1
  48. $!      14. [.UNZIP50]FUNZIP.DOC;1
  49. $!      15. [.UNZIP50]HISTORY.500;1
  50. $!      16. [.UNZIP50]INFLATE.C;1
  51. $!      17. [.UNZIP50]MAKEFILE.;1
  52. $!      18. [.UNZIP50]MAKE_GCC_UNZIP.COM;1
  53. $!      19. [.UNZIP50]MAKE_VAXC_UNZIP.COM;1
  54. $!      20. [.UNZIP50]MAPNAME.C;1
  55. $!      21. [.UNZIP50]MATCH.C;1
  56. $!      22. [.UNZIP50]MISC.C;1
  57. $!      23. [.UNZIP50]OTHER_SYSTEMS.MFTU;1
  58. $!      24. [.UNZIP50]README.;1
  59. $!      25. [.UNZIP50]UNREDUCE.C;1
  60. $!      26. [.UNZIP50]UNSHRINK.C;1
  61. $!      27. [.UNZIP50]UNZIP.1;1
  62. $!      28. [.UNZIP50]UNZIP.C;1
  63. $!      29. [.UNZIP50]UNZIP.DOC;1
  64. $!      30. [.UNZIP50]UNZIP.H;1
  65. $!      31. [.UNZIP50]UNZIP.RNH;1
  66. $!      32. [.UNZIP50]VMS.C;1
  67. $!      33. [.UNZIP50]VMS.NOTES;1
  68. $!      34. [.UNZIP50]VMSSHARE.OPT;1
  69. $!      35. [.UNZIP50]WHERE.;1
  70. $!      36. [.UNZIP50]ZIP.H;1
  71. $!      37. [.UNZIP50]ZIPINFO.1;1
  72. $!      38. [.UNZIP50]ZIPINFO.C;1
  73. $!      39. [.UNZIP50]ZIPINFO.DOC;1
  74. $!      40. [.UNZIP50]ZIPRULES.;1
  75. $!      41. [.ZIP19]ZIP19_ZIP.MFTU;1
  76. $!
  77. $set="set"
  78. $set symbol/scope=(nolocal,noglobal)
  79. $f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
  80. $e="write sys$error  ""%UNPACK"", "
  81. $w="write sys$output ""%UNPACK"", "
  82. $ if f$trnlnm("SHARE_LOG") then $ w = "!"
  83. $ ve=f$getsyi("version")
  84. $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
  85. $ e "-E-OLDVER, Must run at least VMS 4.4"
  86. $ v=f$verify(v)
  87. $ exit 44
  88. $UNPACK: SUBROUTINE ! P1=filename, P2=checksum
  89. $ x = P1 - f$parse(P1,,,"version")
  90. $ y = f$search(x)
  91. $ if y .eqs. "" then $ goto file_absent
  92. $ x = f$integer(f$parse(P1,,,"version")-";")
  93. $ y = f$integer(f$parse(y,,,"version")-";")
  94. $ if x .gt. y then $ goto file_absent
  95. $ if f$mode() .eqs. "INTERACTIVE" then $ goto file_interactive
  96. $ if x .eq. y then e "-W-EXISTS, File ''P1' exists. Skipped."
  97. $ if x .ne. y then e "-W-NEWERVERSION, of File ''P1' exists. Skipped."
  98. $file_delete:
  99. $ delete 'f'*
  100. $ exit
  101. $file_interactive:
  102. $ if x .eq. y then e "-W-EXISTS, File ''P1' exists."
  103. $ if x .ne. y then e "-W-NEWERVERSION, of File ''P1' exists."
  104. $ read/error=file_delete/end=file_delete-
  105.   /prompt="Create new version [y/n]: " -
  106.   sys$command x
  107. $ if .not. x then $ e "-W-SKIPPED, File ''P1' skipped."
  108. $ if .not. x then $ goto file_delete
  109. $ P1 = P1 - f$parse(P1,,,"version")
  110. $file_absent:
  111. $ if f$parse(P1) .nes. "" then $ goto dirok
  112. $ dn=f$parse(P1,,,"DIRECTORY")
  113. $ w "-I-CREDIR, Creating directory ''dn'."
  114. $ create/dir 'dn'
  115. $ if $status then $ goto dirok
  116. $ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
  117. $ delete 'f'*
  118. $ exit
  119. $dirok:
  120. $ w "-I-PROCESS, Processing file ''P1'."
  121. $ if .not. f$verify() then $ define/user sys$output nl:
  122. $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
  123. PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
  124. SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
  125. CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
  126. LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
  127. BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
  128. IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
  129. MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
  130. ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
  131. 1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
  132. POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
  133. ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
  134. COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
  135. "output_file"));ENDPROCEDURE;Unpacker;QUIT;
  136. $ delete/nolog 'f'*
  137. $ CHECKSUM 'P1'
  138. $ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
  139. $ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
  140. $ ENDSUBROUTINE
  141. $START:
  142. $ create 'f'
  143. X         `5B Moderators Note:  The executables (.EXE files) mentioned
  144. X           in this text have been removed from this submission.  The
  145. X           executable images can be built locally with the files
  146. X           provided. `5D
  147. X
  148. XThis directory contains the sources and VMS .OBJs and .EXEs for the
  149. XInfo-ZIP programs Zip v1.9 and UnZip v5.0.  These are compatible with
  150. XPKware's PKZIP v1.93a, as well as previous versions of Zip and UnZip.
  151. X
  152. XZip v1.9 and UnZip v5.0 now support the saving and automatic restoring
  153. Xof VMS file attributes.
  154. X
  155. X`5B.UNZIP50`5D contains the UnZip sources, a VMS BACKUP saveset containing
  156. XVMS .OBJ files, the UnZip .EXEs linked under VMS v5.5-1, and a .ZIP
  157. Xfile containing all the operating system-specific files needed to build
  158. XUnZip for the Amiga, Atari, MS-DOS, OS/2, NT, UNIX, and VMS operating
  159. Xsystems.  The .OBJs, .EXEs, and .ZIP files are encoded using MFTU; you'll
  160. Xneed MFTU to convert back to their binary forms.
  161. X
  162. X`5B.ZIP19`5D contains ZIP19_ZIP.MFTU, an MFTU-encoded .ZIP file containing
  163. Xall the sources for Zip v1.9, along with the VMS .OBJ and .EXE files.
  164. XThis .ZIP file was created using the "-V" option, which stores the
  165. XVMS file attributes; UnZip will automatically restore those attributes.
  166. X
  167. XZip and UnZip can be compiled using either VAX C or GNU C.  There
  168. Xare .COM files in each directory to compile the programs.
  169. X
  170. XYou'll need MFTU.EXE to decode the .OBJ, .EXE, and .ZIP files.
  171. XInstructions for getting MFTU are included below.  Once MFTU.EXE
  172. Xexists, define a foreign symbol that points to it:
  173. X
  174. X`09$ MFTU :== $dev:`5Bdir`5DMFTU.EXE
  175. X
  176. XYou can now execute the command procedure UNMFTU.COM in this directory
  177. Xto decode the .MFTU files:
  178. X
  179. X`09$ MFTU DECODE `5B.UNZIP50`5DUNZIP_EXES.MFTU
  180. X`09$ MFTU DECODE `5B.UNZIP50`5DUNZIP_OBJS.MFTU
  181. X`09$ MFTU DECODE `5B.UNZIP50`5DOTHER_SYSTEMS.MFTU
  182. X`09$ MFTU DECODE `5B.ZIP19`5DZIP19_ZIP.MFTU
  183. X
  184. XIf you don't have a C compiler (either VAX C or GNU C), you can relink
  185. Xthe .OBJs by using the following command to unpack them from the
  186. Xsaveset:
  187. X
  188. X`09$ BACKUP `5B.UNZIP50`5DUNZIP_OBJS.BCK `5B.UNZIP50`5D*.*
  189. X
  190. XOnce you have UNZIP.EXE, define a foreign symbol to point to it, then
  191. Xuse it to UnZip the ZIP19.ZIP file:
  192. X
  193. X`09$ unzip :== $dev:`5Bdir`5Dunzip.exe
  194. X`09$ set default `5B.zip19`5D
  195. X`09$ unzip zip19
  196. X
  197. XOn-line VMS HELP files can be created by using RUNOFF to process the
  198. Xtwo .RNH files in the Zip and UnZip directories and inserting the
  199. Xresulting .HLP files in a VMS help library:
  200. X
  201. X`09$ SET DEFAULT `5B.UNZIP50`5D
  202. X`09$ RUNOFF UNZIP.RNH
  203. X`09$ LIBRARY/INSER/HELP library.HLB UNZIP.HLP
  204. X
  205. X`09$ SET DEFAULT `5B.ZIP19`5D
  206. X`09$ RUNOFF VMS_ZIP.RNH
  207. X`09$ LIBRARY/INSER/HELP library.HLB VMS_ZIP.HLP
  208. X
  209. XYou can get the sources to MFTU using one of these methods:
  210. X
  211. X`09o  Via anonymous ftp from ftp.spc.edu---you'll need the files:
  212. X
  213. X`09`09`5B.MACRO32`5DLZDCMP.EXE
  214. X`09`09`5B.MACRO32.SAVESETS`5DMFTU.BCK_Z
  215. X
  216. X`09o  By sending the command SEND MFTU in the body of a mail message
  217. X`09   to FILESERV@WKUVX1.BITNET.  MFTU is written in MACRO-32, so it
  218. X`09   can be assembled by all VMS sites.
  219. X
  220. XAssembled for VMS e-mail distribution by Hunter Goatley, Western Kentucky
  221. XUniversity, goathunter@WKUVX1.BITNET
  222. $ CALL UNPACK AAAREADME.TXT;1 286679110
  223. $ create 'f'
  224. X$ save_verify = 'f$verify(0)'
  225. X$ if f$type(MFTU).eqs.""
  226. X$ then write sys$output "MFTU foreign symbol does not exist"
  227. X$`09goto common_exit
  228. X$ endif
  229. X$!
  230. X$! The UNZIP_OBJS.MFTU was submitted as a separate part of this package and
  231. V may
  232. X$! not be present if you obtained your copy via FTP or a MAILSERV.  The
  233. X$! UNZIP_EXES.MFTU file is not present in this submission.
  234. X$!
  235. X$ call do_decode "`5B.UNZIP50`5DUNZIP_OBJS.MFTU"
  236. X$! call do_decode "`5B.UNZIP50`5DUNZIP_EXES.MFTU"
  237. X$ call do_decode "`5B.UNZIP50`5DOTHER_SYSTEMS.MFTU"
  238. X$ call do_decode "`5B.ZIP19`5DZIP19_ZIP.MFTU"
  239. X$ common_exit:
  240. X$   exit 1.or.f$verify(save_verify)
  241. X$!
  242. X$ do_decode: subroutine
  243. X$ filename = f$parse("''p1'","","","NAME")
  244. X$ filedir  = f$parse("''p1'","","","DEVICE")+f$parse("''p1'","","","DIRECTOR
  245. VY")
  246. X$ save_default = f$environment("DEFAULT")
  247. X$ if f$search("''p1'").nes.""
  248. X$ then`09set default 'filedir'
  249. X$`09mftu decode 'filename'.MFTU
  250. X$`09set default 'save_default'
  251. X$ else`09write sys$output "''p1' file not found"
  252. X$ endif
  253. X$ exit
  254. X$ endsubroutine
  255. $ CALL UNPACK UNMFTU.COM;1 1667514741
  256. $ create 'f'
  257. XBugs (real and/or imagined):
  258. X---------------------------
  259. X
  260. X - Watcom C getch() broken; password echos (reported to Watcom by K.U.Rommel
  261. V)
  262. X - VMS docs out of date
  263. X - Amiga port broken?
  264. X - VMS unzip no longer sets permissions correctly
  265. X - Macintosh file attributes not interpreted correctly (both unzip, zipinfo)
  266. X - errno declaration conflicts with several compilers' definitions:  change
  267. X    logic so undeclared by default?  How many systems affected?
  268. X - (?) add ifndef MODERN around srand, rand prototypes in crypt.c? `5BJames
  269. X    Birdsall, 4/23`5D
  270. X - pkbug error:  zipfile with incorrect csize and/or ucsize--check for end o
  271. Vf
  272. X    compressed (csize) data in uncompression routines:
  273. X      unimplod.c:    while ((!zipeof) && ((outpos + outcnt) < ucsize)) `7B
  274. X      unreduce.c:    while (((outpos + outcnt) < ucsize) && (!zipeof)) `7B
  275. X    (James Birdsall, Mark, bottom of BUGS.long)
  276. X - if PK signature not found, append .zip and try again without error`20
  277. X    messages (Jean-loup, others, bottom of BUGS.long)
  278. X - disk full:  a few files clear some pointer; continuing beyond "Continue?"
  279. X    prompt, regardless of answer, kills unzip--stack too small? (doesn't see
  280. Vm
  281. X    to matter)  Bug in MSC write() function?  Subsequent write code isn't an
  282. Vy`20
  283. X    different from -t option, so unlikely to be bug in uncompress routines..
  284. V.
  285. X    File descriptor bad/close() failure?  (workaround:  `5EC at prompt)
  286. X - textfile conversions on a PC system add extra CR to lines which already h
  287. Vave
  288. X    CR/LF combo; other directions probably don't work, either (Mac/Unix/...)
  289. V:
  290. X    rewrite "dos2unix" and make general
  291. X - compressed symlinks are allowed:  revise symlink code
  292. X - fix "no errors detected" message for errors occurring *before* extract_or
  293. V_
  294. X    test_files(); count errors?  differentiate between errors and warnings?
  295. X
  296. X
  297. XFeatures (possible and/or definite):
  298. X-----------------------------------
  299. X
  300. X - add -x "exclude following files" option to unzip and zipinfo
  301. X - make use of FILE_IO_C and similar defines to avoid including unnecessary
  302. X    header files in various modules (unzip.h)
  303. X - add "near" to global vars `5BSteve Salisbury, 4/21`5D
  304. X - construct CRC table dynamically? `5BJean-loup, 5/12`5D
  305. X - when listing filenames, use '?' for non-printables? `5BThomas Wolff, 6/1`
  306. V5D
  307. X - modify to decompress input stream if part of a pipe, but continue using
  308. X    central directory if not (BIG job!)--extended local header capability
  309. X - need zipinfo target(s) in makefile.dos
  310. X - build in capability to check text/binary type and warn if -a (if version
  311. X    < 1.1 and not made on DOS--i.e., not early Info-ZIP versions)
  312. X - allow wildcards in zipfile name (loop through each one)
  313. X - test/incorporate Martin Schulz optimization patch (still useful?)
  314. X - add -oo option (overwrite and override):  no user queries (if bad passwor
  315. Vd,
  316. X    skip file; if disk full, take default action; if VMS special on non-VMS,
  317. X    unpack anyway; etc.)
  318. X - add -Q`5BQ`5BQ`5D`5D option (quiet mode on comments, cautions, warnings a
  319. Vnd errors):
  320. X    forget -oo, or make synonym?  Default level -Q?
  321. X - incorporate Atari patches
  322. X - rewrite mapname()
  323. X - modify set_file_time routines to share common code (macro?)
  324. X - add zipinfo "in-depth" option? (check local vs. central filenames, etc.)
  325. X - create zipcat program to concatenate zipfiles
  326. X - create zipfix program to rebuild/salvage damaged zipfiles
  327. X - assembly-language routines?
  328. X - add -i (ignore case for internal filename match) option?  (maybe not)
  329. X - CP/M version (Jeffery Foy)
  330. X - VM/CMS version (Chua Kong Sian, others)
  331. X - put man pages in more "proper" nroff format
  332. X - add OS/2 .INF format helpfiles for UnZip and ZipInfo
  333. X
  334. $ CALL UNPACK [.UNZIP50]BUGS.;1 326700365
  335. $ create 'f'
  336. XContents of the UnZip 5.0 archive (the OS-specific subdirectories at the
  337. Xend contain their own Contents listings):
  338. X
  339. X  Contents`09this file
  340. X  Readme`09what UnZip is; general information
  341. X  Where`09`09where Zip/UnZip and encryption/decryption support can be found
  342. X  History.500`09new features and fixes in this release
  343. X  ZipRules`09Info-ZIP guidelines on contributions to the cause
  344. X  BUGS`09`09known bugs, problems, and (possible) features to be added
  345. X  unzip.1`09UnZip manual page, nroff format
  346. X  unzip.doc`09UnZip manual page, human-readable format
  347. X  zipinfo.1`09ZipInfo manual page, nroff format
  348. X  zipinfo.doc`09ZipInfo manual page, human-readable format
  349. X  funzip.1 `09FUnZip manual page, nroff format
  350. X  funzip.doc `09FUnZip manual page, human-readable format
  351. X  CONTRIBS`09list of contributors to UnZip
  352. X  COPYING`09copyrights and distribution policy
  353. X  crypt.c       NOT INCLUDED:  see "Where" file for sites
  354. X  envargs.c`09code to read options from UNZIP environment var. (required*)
  355. X  explode.c`09code for exploding (required)
  356. X  extract.c`09high-level extraction and decryption code (required)
  357. X  file_io.c`09file manipulation and password code (required)
  358. X  funzip.c `09filter unzip:  extracts in a Unix pipe (not fully supported)
  359. X  inflate.c`09code for inflating (required)
  360. X  mapname.c`09code to map filenames between different OS's (required)
  361. X  match.c`09pattern-matching code for filename wildcards (required*)
  362. X  misc.c`09various support routines (required*)
  363. X  unreduce.c`09code for unReducing (required)
  364. X  unshrink.c`09code for unShrinking (required)
  365. X  unzip.c`09main UnZip driver code (required)
  366. X  unzip.h`09main UnZip header file (required*)
  367. X  zip.h`09`09header for using crypt.c with UnZip (required for decryption)
  368. X  zipinfo.c`09zipfile information utility (useful, but optional)
  369. X  Makefile`09main Unix and OS/2 makefile (required)
  370. X  AMIGA/`09support files for compiling on Amiga (not recently tested)
  371. X  ATARI/`09support files for compiling v4.1 on Atari ST
  372. X  MAC/`09`09support files for compiling on Macintosh
  373. X  MSDOS/`09support files for compiling under MS-DOS
  374. X  NT/`09`09support files for compiling under Windows NT
  375. X  OS2/`09`09support files for compiling under OS/2
  376. X  VMS/`09`09support files for compiling under VMS
  377. X
  378. XFiles marked "required*" are also needed to compile ZipInfo.  There are Unix
  379. Xand MS-DOS targets to make ZipInfo in Makefile (zipinfo, zi_indigo, zi_gcc,`
  380. V20
  381. Xzi_dos).  FUnZip is a new, last-minute program of limited capabilities; for
  382. Xnow, it can only extract the first member in a zipfile from stdin and send
  383. Xit to stdout, and only if the member is either deflated or stored.  It will`
  384. V20
  385. Xprobably have evolved by the time you read this, and it may even be absorbed
  386. V`20
  387. Xinto UnZip itself.
  388. X
  389. XThe Atari ST support is in the form of patches against UnZip 4.1; there
  390. Xare more details in the ATARI sub-archive Contents file.  Amiga support
  391. Xhas not been tested since version 4.1 or earlier (the makefiles, however,
  392. Xhave been updated to reflect the new code structure, and any changes
  393. Xrequired shouldn't be TOO extensive).
  394. $ CALL UNPACK [.UNZIP50]CONTENTS.;1 1510366775
  395. $ create 'f'
  396. XThis is a partial list of contributors to Info-ZIP UnZip and the code upon
  397. Xwhich it is based.  Many, many others have also contributed, and if you are
  398. Xamong them, please let us know.  Aside from the Info-ZIP digest archives,
  399. Xwe have not kept very good track of who contributed what.  Also, contributor
  400. Vs
  401. Xto the makefile are listed at the bottom of Makefile.
  402. X
  403. X  Mark Adler             decryption, inflate, explode, funzip code; misc. ca
  404. Vsts
  405. X  Glenn Andrews          MSDOS makefiles; prototyping bugfix
  406. X  Joel Aycock            descrip.mms bugfix
  407. X  Allan Bjorklund        in misc.c
  408. X  James Birdsall         extract.c bugfix; etc.
  409. X  Wim Bonner             OS/2 stuff
  410. X  John Cowan             mods to original match.c; other stuff?
  411. X  Frank da Cruz          xxu.c, on which mapname.c is based
  412. X  Bill Davidsen          -q(q); mapname stuff; memset/memcpy(?); etc.
  413. X  Arjan de Vet           various things, but I don't remember exactly what..
  414. V.
  415. X  James Dugal            ZMEM stuff; unshrink bugfix; file perms stuff; etc.
  416. X  Jim Dumser             -z stuff; umask bugfixes; etc.
  417. X  Mark Edwards           in mapname.c, misc.c
  418. X  David Feinleib         Windows NT port
  419. X  Mike Freeman           VMS GCC makefiles; etc.
  420. X  Jean-loup Gailly       decryption code; much prodding to fix bugs :-)
  421. X  Hunter Goatley         VMS RUNOFF source (documentation)
  422. X  Robert Heath           original Windows port
  423. X  Dave Heiland           new usage screen `5B, new documentation...?`5D
  424. X  Larry Jones            ZMEM stuff; unimplod bugfix; etc.
  425. X  Kjetil J`7B\o`7Drgenson    ln/copy misc_.c bugfix
  426. X  Bob Kemp               NOTINT16 rewrite (byte arrays instead of structs)
  427. X  J. Kercheval           filmatch.c, on which match.c is based
  428. X  David Kirschbaum       mapname port; general-purpose meddling; Python joke
  429. Vs
  430. X  Alvin Koh              Borland C++ bugfixes
  431. X  Bo Kullmar             -z code; bugfixes: umask, do_string, BSD time; etc.
  432. X  Johnny Lee             Macintosh port; Mac resource fork stuff; Win3.1 por
  433. Vt
  434. X  Warner Losh            in misc.c
  435. X  Igor Mandrichenko      vms.c; many improvements and VMS modifications
  436. X  Fulvio Marino          revised UnZip and ZipInfo man pages
  437. X  Carl Mascott           original Unix port
  438. X  Gene McManus           -o code
  439. X  Joe Meadows            file.c, on which VMSmunch.c is based
  440. X  Mike O'Carroll         OS/2 stuff
  441. X  Humberto Ortiz-Zuazaga Linux port; permissions bugfix; missing declaration
  442. Vs
  443. X  Keith Petersen         former Info-ZIP list maintainer
  444. X  Piet W. Plomp          nice fix for msc_dos Makefile target
  445. X  Antonio Querubin, Jr   descrip.mms (VMS makefile)
  446. X  Greg Roelofs           central directory code; ZipInfo; original VMS port;
  447. V...
  448. X  Kai Uwe Rommel         much OS/2 code; bugfixes; etc.
  449. X  Steve Salisbury        CountryInfo bugfix; variable INBUFSIZ
  450. X  Georg Sassen           Amiga DICE compiler port
  451. X  Jon Saxton             date formats
  452. X  Hugh Schmidt           VMS stuff
  453. X  Martin Schulz          Atari patches
  454. X  Charles Scripter       various bug reports and bugfixes
  455. X  Chris Seaman           Unix time stuff
  456. X  Richard Seay           MS-DOS Quick C makefile
  457. X  Alex Sergejew          file_io.c bugfix; stat() bugfix; Down Under jokes
  458. X  Samuel H. Smith        original unzip code (Pascal and C) for PC
  459. X  Cliff Stanford         file_io.c umask bug
  460. X  Onno van der Linden    SCO optimization bugfix; etc.
  461. X  Jim Van Zandt          one of original man pages
  462. X  Antoine Verheijen      MTS/EBCDIC stuff; FILENAME_MAX stuff; Mac fixes; et
  463. Vc.
  464. X  Rich Wales             current Info-ZIP moderator and zip guy
  465. X  Paul Wells             original Amiga port for SAS/C and Lattice C (?)
  466. $ CALL UNPACK [.UNZIP50]CONTRIBS.;1 254357436
  467. $ create 'f'
  468. X============================================================================
  469. V===
  470. X   The following copyrights are claimed on portions of the UnZip source code
  471. V.
  472. X   Further comments are at the bottom.
  473. X============================================================================
  474. V===
  475. X
  476. X  Copyright in unzip.c, originally from unzip version 1.2 (?):
  477. X
  478. X     * Copyright 1989 Samuel H. Smith;  All rights reserved
  479. X     *
  480. X     * Do not distribute modified versions without my permission.
  481. X     * Do not remove or alter this notice or any other copyright notice.
  482. X     * If you use this in your own program you must distribute source code.
  483. X     * Do not use any of this in a commercial product.
  484. X
  485. X----------------------------------------------------------------------------
  486. V---
  487. X
  488. X  Copyright in misc.c, applying to UpdateCRC() and crc_32_tab`5B`5D:
  489. X
  490. X     COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or code
  491. X     or tables extracted from it, as desired without restriction.
  492. X
  493. X----------------------------------------------------------------------------
  494. V---
  495. X
  496. X  Copyright in vms.c, distributed with UnZip versions 4.2 and later:
  497. X
  498. X     * Copyright (C) 1992 Igor Mandrichenko.
  499. X     * Permission is granted to any individual or institution to use, copy,
  500. X     * or redistribute this software so long as all of the original files
  501. X     * are included unmodified, that it is not sold for profit, and that
  502. X     * this copyright notice is retained.
  503. X
  504. X----------------------------------------------------------------------------
  505. V---
  506. X
  507. X  Additional copyright information:
  508. X
  509. X     BILF (distributed with the VMS stuff) is copyrighted by Rahul Dhesi,
  510. X     but it is freely distributable.
  511. X
  512. X     The functions extract_or_test_files() and store_info() in extract.c,
  513. X     do_string() and return_VMS() in misc.c, VMS version of echo() in
  514. X     file_io.c, and find_end_central_dir() in unzip.c, were written by
  515. X     Greg Roelofs and subsequently modified by many others via Info-ZIP.
  516. X     I do not claim a copyright on these routines, but I do ask that no
  517. X     one else do so either, :-) and that anyone using them in other pro-
  518. X     grams note their source.
  519. X
  520. X     The function decrypt_member() in extract.c and the password functions
  521. X     in file_io.c were written by Mark Adler, as were the inflate.c and
  522. X     explode.c modules.
  523. X
  524. X     The function mapped_name() in mapname.c was written by David Kirschbaum
  525. V,
  526. X     based on the XXU program by Frank Da Cruz.
  527. X
  528. X     The module match.c was written by J. Kercheval and modified by David
  529. X     Kirschbaum for use in UnZip.
  530. X
  531. X     Original notes from unzip 2.0a by Carl Mascott, cmascott@world.std.com
  532. X     (these are only the modifications which seem still to exist):
  533. X        * 12/14/89  C. Mascott  2.0a   adapt for UNIX
  534. X        *              don't pre-allocate output file space
  535. X        *              implement -t, -v, member file specs
  536. X        *              buffer all input
  537. X        *              fix "Bad CRC" msg: good/bad CRCs were swapped
  538. X        *              check for write error on output file
  539. X
  540. X     Most of the remaining routines have contributions from all of us, and
  541. X     show it. :-)
  542. X
  543. X============================================================================
  544. V===
  545. X
  546. X   Info-ZIP comments:
  547. X
  548. X   Info-ZIP has very little interest in legal matters, aside from the usual
  549. X   "CYA" sense (that's an acronym, and you can figure it out yourself :-) ).
  550. X
  551. X   As far as we are aware--and please note that the numerous contributors`20
  552. X   and copyright holders make this a little uncertain--the UnZip code is now
  553. V`20
  554. X   "clean" in the sense that an UnZip executable may be distributed with a
  555. X   commercial product SO LONG AS IT IS CLEAR THAT UNZIP IS NOT BEING SOLD,
  556. X   THAT THE SOURCE CODE IS FREELY AVAILABLE, AND THAT THERE ARE NO EXTRA OR
  557. X   HIDDEN CHARGES RESULTING FROM ITS USE BY OR INCLUSION WITH THE COMMERCIAL
  558. X   PRODUCT.  In particular, the retroactive copyright on unimplode.c which
  559. X   Carl Mascott requested we include in UnZip 4.2 is no longer in force, sin
  560. Vce
  561. X   Mark Adler has rewritten the module in question from scratch (it's about
  562. X   twice as fast, too! :-) ).
  563. X
  564. X   Regarding the original copyright by Mr. Smith:  Info-ZIP has finally foun
  565. Vd
  566. X   him again (he's moved to southern California), and he's apparently happy
  567. X   with the current code and restrictions.  More specifically, since the`20
  568. X   current incarnation of UnZip can be considered "our own"--it bears very`2
  569. V0
  570. X   little resemblance to his original program, in either content or size :-)
  571. X   --and since we freely distribute the source code, we believe that we are`
  572. V20
  573. X   within the bounds of his third stipulation.
  574. X
  575. X   Info-ZIP continues to rewrite portions of the code as time permits, in an
  576. X   effort to eliminate as many of the restrictions (and bugs) as possible.
  577. X   The bugs are our primary concern, however, so don't hold your breath. :-)
  578. X
  579. X============================================================================
  580. V===
  581. $ CALL UNPACK [.UNZIP50]COPYING.;1 23492127
  582. $ create 'f'
  583. X!==========================================================================
  584. X! MMS description file for UnZip 5.0+                          26 June 1992
  585. X!==========================================================================
  586. X!
  587. X!   Original by Antonio Querubin, Jr., <querubin@uhccvx.uhcc.hawaii.edu>
  588. X!     (23 Dec 90)
  589. X!   Enhancements by Igor Mandrichenko, <mandrichenko@mx.decnet.ihep.su>
  590. X!     (9 Feb 92)
  591. X
  592. X! To build UnZip that uses shared libraries,
  593. X!`09mms
  594. X! (One-time users will find it easier to use the MAKE_UNZIP_VAXC.COM command
  595. X! file, which generates both UnZip and ZipInfo.  Just type "@MAKE_UNZIP_VAXC
  596. V";
  597. X! or "@MAKE_UNZIP_GCC" if you have GNU C.)
  598. X
  599. X! To build UnZip without shared libraries,
  600. X!`09mms noshare
  601. X
  602. X! To delete unnecessary .OBJ files,
  603. X!`09mms clean
  604. X
  605. XCRYPTF =
  606. XCRYPTO =
  607. X! To build decryption version, uncomment next two lines:
  608. X!CRYPTF = /def=(CRYPT)
  609. X!CRYPTO = crypt.obj,
  610. X
  611. XCC = cc
  612. XCFLAGS = $(CRYPTF)
  613. XLD = link
  614. XLDFLAGS =
  615. XEXE =
  616. XO = .obj;
  617. XOBJS = unzip$(O), $(CRYPTO) envargs$(O), explode$(O), extract$(O),\
  618. X       file_io$(O), inflate$(O), mapname$(O), match$(O), misc$(O),\
  619. X       unreduce$(O), unshrink$(O), vms$(O)
  620. XOBJI = zipinfo$(O), envargs$(O), match$(O), misc.obj_, vms.obj_
  621. X
  622. XLDFLAGS2 =
  623. X
  624. Xdefault`09:`09unzip.exe, zipinfo.exe
  625. X`09@`09!`09Do nothing.
  626. X
  627. Xunzip.exe :`09$(OBJS), vmsshare.opt
  628. X`09$(LD) $(LDFLAGS) $(OBJS), \
  629. X`09`09vmsshare.opt/options
  630. X
  631. Xzipinfo.exe :`09$(OBJI), vmsshare.opt
  632. X`09$(LD) $(LDFLAGS) $(OBJI), \
  633. X`09`09vmsshare.opt/options
  634. X
  635. X
  636. Xnoshare :`09$(OBJS)
  637. X`09$(LD) $(LDFLAGS) $(OBJS), \
  638. X`09`09sys$library:vaxcrtl.olb/library $(LDFLAGS2)
  639. X
  640. Xclean :
  641. X`09delete $(OBJS)`09! you may want to change this to 'delete *.obj;*'
  642. X
  643. Xcrypt$(O) :`09crypt.c unzip.h zip.h`09! may or may not be included in distri
  644. Vb
  645. Xenvargs$(O) :`09envargs.c unzip.h
  646. Xexplode$(O) :`09explode.c unzip.h
  647. Xextract$(O) :`09extract.c unzip.h
  648. Xfile_io$(O) :`09file_io.c unzip.h
  649. Xinflate$(O) :`09inflate.c unzip.h
  650. Xmapname$(O) :`09mapname.c unzip.h
  651. Xmatch$(O) :`09match.c unzip.h
  652. Xmisc$(O) :`09misc.c unzip.h
  653. Xunreduce$(O) :`09unreduce.c unzip.h
  654. Xunshrink$(O) :`09unshrink.c unzip.h
  655. Xunzip$(O) :`09unzip.c unzip.h
  656. Xvms$(O)`09  :`09vms.c unzip.h
  657. XVMSmunch$(O) :`09VMSmunch.c VMSmunch.h
  658. Xmisc.obj_ :`09misc.c unzip.h
  659. X`09$(CC)/object=misc.obj_/define="ZIPINFO" misc.c
  660. X
  661. Xvms.obj_ :`09vms.c unzip.h
  662. X`09$(CC)/object=vms.obj_/define="ZIPINFO" vms.c
  663. $ CALL UNPACK [.UNZIP50]DESCRIP.MMS;1 2081498107
  664. $ create 'f'
  665. X/*****************************************************************
  666. X `7C envargs - add default options from environment to command line
  667. X `7C----------------------------------------------------------------
  668. X `7C Author: Bill Davidsen, original 10/13/91, revised 23 Oct 1991.
  669. X `7C This program is in the public domain.
  670. X `7C----------------------------------------------------------------
  671. X `7C Minor program notes:
  672. X `7C  1. Yes, the indirection is a tad complex
  673. X `7C  2. Parenthesis were added where not needed in some cases
  674. X `7C     to make the action of the code less obscure.
  675. X `7C  3. Set tabsize to four to make this pretty
  676. X `7C----------------------------------------------------------------
  677. X `7C UnZip notes 24 May 92 ("v1.4"):
  678. X `7C  1. #include "unzip.h" for prototypes
  679. X `7C  2. changed ch to type char
  680. X `7C  3. added an ifdef to avoid Borland warnings
  681. X *****************************************************************/
  682. X
  683. X#include "unzip.h"
  684. Xstatic int count_args __((char *));
  685. Xstatic void mem_err __((void));
  686. X
  687. X#if (defined(SCCS) && !defined(lint))  /* causes warnings:  annoying */
  688. Xstatic char *SCCSid = "@(#)envargs.c`091.3 23 Oct 1991";
  689. X#endif
  690. X
  691. Xvoid
  692. Xenvargs(Pargc, Pargv, envstr)
  693. Xint *Pargc;
  694. Xchar ***Pargv;
  695. Xchar *envstr;
  696. X`7B
  697. X`09char *getenv();
  698. X`09char *envptr;`09`09`09`09/* value returned by getenv */
  699. X`09char *bufptr;`09`09`09`09/* copy of env info */
  700. X`09int argc = 0;`09`09`09`09/* internal arg count */
  701. X`09char ch;`09`09`09`09`09/* spare temp value */
  702. X`09char **argv;`09`09`09`09/* internal arg vector */
  703. X`09char **argvect;`09`09`09`09/* copy of vector address */
  704. X
  705. X`09/* see if anything in the environment */
  706. X`09envptr = getenv(envstr);
  707. X`09if (envptr == (char *)NULL `7C`7C *envptr == 0) return;
  708. X
  709. X`09/* count the args so we can allocate room for them */
  710. X`09argc = count_args(envptr);
  711. X`09bufptr = (char *)malloc(1+strlen(envptr));
  712. X`09if (bufptr == (char *)NULL) mem_err();
  713. X`09strcpy(bufptr, envptr);
  714. X
  715. X`09/* allocate a vector large enough for all args */
  716. X`09argv = (char **)malloc((argc+*Pargc+1)*sizeof(char *));
  717. X`09if (argv == (char **)NULL) mem_err();
  718. X`09argvect = argv;
  719. X
  720. X`09/* copy the program name first, that's always true */
  721. X`09*(argv++) = *((*Pargv)++);
  722. X
  723. X`09/* copy the environment args next, may be changed */
  724. X`09do `7B
  725. X`09`09*(argv++) = bufptr;
  726. X`09`09/* skip the arg and any trailing blanks */
  727. X`09`09while (((ch = *bufptr) != '\0') && ch != ' ') ++bufptr;
  728. X`09`09if (ch == ' ') *(bufptr++) = '\0';
  729. X`09`09while (((ch = *bufptr) != '\0') && ch == ' ') ++bufptr;
  730. X`09`7D while (ch);
  731. X
  732. X`09/* now save old argc and copy in the old args */
  733. X`09argc += *Pargc;
  734. X`09while (--(*Pargc)) *(argv++) = *((*Pargv)++);
  735. X
  736. X`09/* finally, add a NULL after the last arg, like UNIX */
  737. X`09*argv = (char *)NULL;
  738. X
  739. X`09/* save the values and return */
  740. X`09*Pargv = argvect;
  741. X`09*Pargc = argc;
  742. X`7D
  743. X
  744. Xstatic int
  745. Xcount_args(s)
  746. Xchar *s;
  747. X`7B
  748. X`09int count = 0;
  749. X`09char ch;
  750. X
  751. X`09do `7B
  752. X`09`09/* count and skip args */
  753. X`09`09++count;
  754. X`09`09while (((ch = *s) != '\0') && ch != ' ') ++s;
  755. X`09`09while (((ch = *s) != '\0') && ch == ' ') ++s;
  756. X`09`7D while (ch);
  757. X
  758. X`09return count;
  759. X`7D
  760. X
  761. Xstatic void
  762. Xmem_err()
  763. X`7B
  764. X`09perror("Can't get memory for arguments");
  765. X`09exit(2);
  766. X`7D
  767. X`0C
  768. X#ifdef TEST
  769. Xmain(argc, argv)
  770. Xint argc;
  771. Xchar **argv;
  772. X`7B
  773. X`09int i;
  774. X
  775. X`09printf("Orig argv: %p\n", argv);
  776. X`09dump_args(argc, argv);
  777. X`09envargs(&argc, &argv, "ENVTEST");
  778. X`09printf(" New argv: %p\n", argv);
  779. X`09dump_args(argc, argv);
  780. X`7D
  781. X
  782. Xdump_args(argc, argv)
  783. Xint argc;
  784. Xchar *argv`5B`5D;
  785. X`7B
  786. X`09int i;
  787. X
  788. X`09printf("\nDump %d args:\n", argc);
  789. X`09for (i=0; i<argc; ++i) `7B
  790. X`09`09printf("%3d %s\n", i, argv`5Bi`5D);
  791. X`09`7D
  792. X`7D
  793. X#endif
  794. $ CALL UNPACK [.UNZIP50]ENVARGS.C;1 1581522662
  795. $ create 'f'
  796. X/* explode.c -- Not copyrighted 1992 by Mark Adler
  797. X   version c7, 27 June 1992 */
  798. X
  799. X
  800. X/* You can do whatever you like with this source file, though I would
  801. X   prefer that if you modify it and redistribute it that you include
  802. X   comments to that effect with your name and the date.  Thank you.
  803. X
  804. X   History:
  805. X   vers    date          who           what
  806. X   ----  ---------  --------------  ------------------------------------
  807. X    c1   30 Mar 92  M. Adler        explode that uses huft_build from inflat
  808. Ve
  809. X                                    (this gives over a 70% speed improvement
  810. X                                    over the original unimplode.c, which
  811. X                                    decoded a bit at a time)
  812. X    c2    4 Apr 92  M. Adler        fixed bug for file sizes a multiple of 3
  813. V2k.
  814. X    c3   10 Apr 92  M. Adler        added a little memory tracking if DEBUG
  815. X    c4   11 Apr 92  M. Adler        added NOMEMCPY do kill use of memcpy()
  816. X    c5   21 Apr 92  M. Adler        added the WSIZE #define to allow reducin
  817. Vg
  818. X                                    the 32K window size for specialized
  819. X                                    applications.
  820. X    c6   31 May 92  M. Adler        added typecasts to eliminate some warnin
  821. Vgs
  822. X    c7   27 Jun 92  G. Roelofs      added more typecasts
  823. X */
  824. X
  825. X
  826. X/*
  827. X   Explode imploded (PKZIP method 6 compressed) data.  This compression
  828. X   method searches for as much of the current string of bytes (up to a lengt
  829. Vh
  830. X   of `7E320) in the previous 4K or 8K bytes.  If it doesn't find any matche
  831. Vs
  832. X   (of at least length 2 or 3), it codes the next byte.  Otherwise, it codes
  833. X   the length of the matched string and its distance backwards from the
  834. X   current position.  Single bytes ("literals") are preceded by a one (a
  835. X   single bit) and are either uncoded (the eight bits go directly into the
  836. X   compressed stream for a total of nine bits) or Huffman coded with a
  837. X   supplied literal code tree.  If literals are coded, then the minimum matc
  838. Vh
  839. X   length is three, otherwise it is two.
  840. X  `20
  841. X   There are therefore four kinds of imploded streams: 8K search with coded
  842. X   literals (min match = 3), 4K search with coded literals (min match = 3),
  843. X   8K with uncoded literals (min match = 2), and 4K with uncoded literals
  844. X   (min match = 2).  The kind of stream is identified in two bits of a
  845. X   general purpose bit flag that is outside of the compressed stream.
  846. X  `20
  847. X   Distance-length pairs are always coded.  Distance-length pairs for matche
  848. Vd
  849. X   strings are preceded by a zero bit (to distinguish them from literals) an
  850. Vd
  851. X   are always coded.  The distance comes first and is either the low six (4K
  852. V)
  853. X   or low seven (8K) bits of the distance (uncoded), followed by the high si
  854. Vx
  855. X   bits of the distance coded.  Then the length is six bits coded (0..63 +
  856. X   min match length), and if the maximum such length is coded, then it's
  857. X   followed by another eight bits (uncoded) to be added to the coded length.
  858. X   This gives a match length range of 2..320 or 3..321 bytes.
  859. X
  860. X   The literal, length, and distance codes are all represented in a slightly
  861. X   compressed form themselves.  What is sent are the lengths of the codes fo
  862. Vr
  863. X   each value, which is sufficient to construct the codes.  Each byte of the
  864. X   code representation is the code length (the low four bits representing
  865. X   1..16), and the number of values sequentially with that length (the high
  866. X   four bits also representing 1..16).  There are 256 literal code values (i
  867. Vf
  868. X   literals are coded), 64 length code values, and 64 distance code values,
  869. X   in that order at the beginning of the compressed stream.  Each set of cod
  870. Ve
  871. X   values is preceded (redundantly) with a byte indicating how many bytes ar
  872. Ve
  873. X   in the code description that follows, in the range 1..256.
  874. X
  875. X   The codes themselves are decoded using tables made by huft_build() from
  876. X   the bit lengths.  That routine and its comments are in the inflate.c
  877. X   module.
  878. X */
  879. X
  880. X#include "unzip.h"      /* this must supply the slide`5B`5D (byte) array */
  881. X
  882. X#ifndef WSIZE
  883. X#  define WSIZE 0x8000  /* window size--must be a power of two, and at least
  884. X                           8K for zip's implode method */
  885. X#endif /* !WSIZE */
  886. X
  887. X
  888. Xstruct huft `7B
  889. X  byte e;               /* number of extra bits or operation */
  890. X  byte b;               /* number of bits in this code or subcode */
  891. X  union `7B
  892. X    UWORD n;            /* literal, length base, or distance base */
  893. X    struct huft *t;     /* pointer to next level of table */
  894. X  `7D v;
  895. X`7D;
  896. X
  897. X/* Function prototypes */
  898. X/* routines from inflate.c */
  899. Xextern unsigned hufts;
  900. Xint huft_build OF((unsigned *, unsigned, unsigned, UWORD *, UWORD *,
  901. X                   struct huft **, int *));
  902. Xint huft_free OF((struct huft *));
  903. Xvoid flush OF((unsigned));
  904. X
  905. X/* routines here */
  906. Xint get_tree OF((unsigned *, unsigned));
  907. Xint explode_lit8 OF((struct huft *, struct huft *, struct huft *,
  908. X                     int, int, int));
  909. Xint explode_lit4 OF((struct huft *, struct huft *, struct huft *,
  910. X                     int, int, int));
  911. Xint explode_nolit8 OF((struct huft *, struct huft *, int, int));
  912. Xint explode_nolit4 OF((struct huft *, struct huft *, int, int));
  913. Xint explode OF((void));
  914. X
  915. X
  916. X/* The implode algorithm uses a sliding 4K or 8K byte window on the
  917. X   uncompressed stream to find repeated byte strings.  This is implemented
  918. X   here as a circular buffer.  The index is updated simply by incrementing
  919. X   and then and'ing with 0x0fff (4K-1) or 0x1fff (8K-1).  Here, the 32K
  920. X   buffer of inflate is used, and it works just as well to always have
  921. X   a 32K circular buffer, so the index is anded with 0x7fff.  This is
  922. X   done to allow the window to also be used as the output buffer. */
  923. X/* This must be supplied in an external module useable like "byte slide`5B81
  924. V92`5D;"
  925. X   or "byte *slide;", where the latter would be malloc'ed.  In unzip, slide`
  926. V5B`5D
  927. X   is actually a 32K area for use by inflate, which uses a 32K sliding windo
  928. Vw.
  929. X */
  930. X
  931. X
  932. X/* Tables for length and distance */
  933. XUWORD cplen2`5B`5D = `7B2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
  934. V 17,
  935. X        18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
  936. X        35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
  937. X        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65`7D;
  938. XUWORD cplen3`5B`5D = `7B3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
  939. V 18,
  940. X        19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
  941. X        36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
  942. X        53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66`7D;
  943. XUWORD extra`5B`5D = `7B0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  944. V 0,
  945. X        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  946. X        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  947. X        8`7D;
  948. XUWORD cpdist4`5B`5D = `7B1, 65, 129, 193, 257, 321, 385, 449, 513, 577, 641,
  949. V 705,
  950. X        769, 833, 897, 961, 1025, 1089, 1153, 1217, 1281, 1345, 1409, 1473,
  951. X        1537, 1601, 1665, 1729, 1793, 1857, 1921, 1985, 2049, 2113, 2177,
  952. X        2241, 2305, 2369, 2433, 2497, 2561, 2625, 2689, 2753, 2817, 2881,
  953. X        2945, 3009, 3073, 3137, 3201, 3265, 3329, 3393, 3457, 3521, 3585,
  954. X        3649, 3713, 3777, 3841, 3905, 3969, 4033`7D;
  955. XUWORD cpdist8`5B`5D = `7B1, 129, 257, 385, 513, 641, 769, 897, 1025, 1153, 1
  956. V281,
  957. X        1409, 1537, 1665, 1793, 1921, 2049, 2177, 2305, 2433, 2561, 2689,
  958. X        2817, 2945, 3073, 3201, 3329, 3457, 3585, 3713, 3841, 3969, 4097,
  959. X        4225, 4353, 4481, 4609, 4737, 4865, 4993, 5121, 5249, 5377, 5505,
  960. X        5633, 5761, 5889, 6017, 6145, 6273, 6401, 6529, 6657, 6785, 6913,
  961. X        7041, 7169, 7297, 7425, 7553, 7681, 7809, 7937, 8065`7D;
  962. X
  963. X
  964. X/* Macros for inflate() bit peeking and grabbing.
  965. X   The usage is:
  966. X  `20
  967. X        NEEDBITS(j)
  968. X        x = b & mask_bits`5Bj`5D;
  969. X        DUMPBITS(j)
  970. X
  971. X   where NEEDBITS makes sure that b has at least j bits in it, and
  972. X   DUMPBITS removes the bits from b.  The macros use the variable k
  973. X   for the number of bits in b.  Normally, b and k are register
  974. X   variables for speed.
  975. X */
  976. X
  977. Xextern UWORD bytebuf;           /* (use the one in inflate.c) */
  978. X#define NEXTBYTE    (ReadByte(&bytebuf), bytebuf)
  979. X#define NEEDBITS(n) `7Bwhile(k<(n))`7Bb`7C=((ULONG)NEXTBYTE)<<k;k+=8;`7D`7D
  980. X#define DUMPBITS(n) `7Bb>>=(n);k-=(n);`7D
  981. X
  982. X
  983. X
  984. Xint get_tree(l, n)
  985. Xunsigned *l;            /* bit lengths */
  986. Xunsigned n;             /* number expected */
  987. X/* Get the bit lengths for a code representation from the compressed
  988. X   stream.  If get_tree() returns 4, then there is an error in the data.
  989. X   Otherwise zero is returned. */
  990. X`7B
  991. X  unsigned i;           /* bytes remaining in list */
  992. X  unsigned k;           /* lengths entered */
  993. X  unsigned j;           /* number of codes */
  994. X  unsigned b;           /* bit length for those codes */`20
  995. X
  996. X
  997. X  /* get bit lengths */
  998. X  ReadByte(&bytebuf);
  999. X  i = bytebuf + 1;                      /* length/count pairs to read */
  1000. X  k = 0;                                /* next code */
  1001. X  do `7B
  1002. X    ReadByte(&bytebuf);
  1003. X    b = ((j = bytebuf) & 0xf) + 1;      /* bits in code (1..16) */
  1004. X    j = ((j & 0xf0) >> 4) + 1;          /* codes with those bits (1..16) */
  1005. X    if (k + j > n)
  1006. X      return 4;                         /* don't overflow l`5B`5D */
  1007. X    do `7B
  1008. X      l`5Bk++`5D = b;
  1009. X    `7D while (--j);
  1010. X  `7D while (--i);
  1011. X  return k != n ? 4 : 0;                /* should have read n of them */
  1012. X`7D
  1013. X
  1014. X
  1015. X
  1016. Xint explode_lit8(tb, tl, td, bb, bl, bd)
  1017. Xstruct huft *tb, *tl, *td;      /* literal, length, and distance tables */
  1018. Xint bb, bl, bd;                 /* number of bits decoded by those */
  1019. X/* Decompress the imploded data using coded literals and an 8K sliding
  1020. X   window. */
  1021. X`7B
  1022. X  longint s;            /* bytes to decompress */
  1023. X  register unsigned e;  /* table entry flag/number of extra bits */
  1024. X  unsigned n, d;        /* length and index for copy */
  1025. X  unsigned w;           /* current window position */
  1026. X  struct huft *t;       /* pointer to table entry */
  1027. X  unsigned mb, ml, md;  /* masks for bb, bl, and bd bits */
  1028. X  register ULONG b;     /* bit buffer */
  1029. X  register unsigned k;  /* number of bits in bit buffer */
  1030. X  unsigned u;           /* true if unflushed */
  1031. X
  1032. X
  1033. X  /* explode the coded data */
  1034. X  b = k = w = 0;                /* initialize bit buffer, window */
  1035. X  u = 1;                        /* buffer unflushed */
  1036. X  mb = mask_bits`5Bbb`5D;           /* precompute masks for speed */
  1037. X  ml = mask_bits`5Bbl`5D;
  1038. X  md = mask_bits`5Bbd`5D;
  1039. X  s = ucsize;
  1040. X  while (s > 0)                 /* do until ucsize bytes uncompressed */
  1041. X  `7B
  1042. X    NEEDBITS(1)
  1043. X    if (b & 1)                  /* then literal--decode it */
  1044. X    `7B
  1045. X      DUMPBITS(1)
  1046. X      s--;
  1047. X      NEEDBITS((unsigned)bb)    /* get coded literal */
  1048. X      if ((e = (t = tb + ((`7E(unsigned)b) & mb))->e) > 16)
  1049. X        do `7B
  1050. X          if (e == 99)
  1051. X            return 1;
  1052. X          DUMPBITS(t->b)
  1053. X          e -= 16;
  1054. X          NEEDBITS(e)
  1055. X        `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
  1056. V->e) > 16);
  1057. X      DUMPBITS(t->b)
  1058. X      slide`5Bw++`5D = (byte)t->v.n;
  1059. X      if (w == WSIZE)
  1060. X      `7B
  1061. X        flush(w);
  1062. X        w = u = 0;
  1063. X      `7D
  1064. X    `7D
  1065. X    else                        /* else distance/length */
  1066. X    `7B
  1067. X      DUMPBITS(1)
  1068. X      NEEDBITS(7)               /* get distance low bits */
  1069. X      d = (unsigned)b & 0x7f;
  1070. X      DUMPBITS(7)
  1071. X      NEEDBITS((unsigned)bd)    /* get coded distance high bits */
  1072. X      if ((e = (t = td + ((`7E(unsigned)b) & md))->e) > 16)
  1073. X        do `7B
  1074. X          if (e == 99)
  1075. X            return 1;
  1076. X          DUMPBITS(t->b)
  1077. X          e -= 16;
  1078. X          NEEDBITS(e)
  1079. X        `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
  1080. V->e) > 16);
  1081. X      DUMPBITS(t->b)
  1082. X      d = w - d - t->v.n;       /* construct offset */
  1083. X      NEEDBITS((unsigned)bl)    /* get coded length */
  1084. X      if ((e = (t = tl + ((`7E(unsigned)b) & ml))->e) > 16)
  1085. X        do `7B
  1086. X          if (e == 99)
  1087. X            return 1;
  1088. X          DUMPBITS(t->b)
  1089. X          e -= 16;
  1090. X          NEEDBITS(e)
  1091. X        `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
  1092. V->e) > 16);
  1093. X      DUMPBITS(t->b)
  1094. X      n = t->v.n;
  1095. X      if (e)                    /* get length extra bits */
  1096. X      `7B
  1097. X        NEEDBITS(8)
  1098. X        n += (unsigned)b & 0xff;
  1099. X        DUMPBITS(8)
  1100. X      `7D
  1101. X
  1102. X      /* do the copy */
  1103. X      s -= n;
  1104. X      do `7B
  1105. X        n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
  1106. X        if (u && w <= d)
  1107. X        `7B
  1108. X          memset(slide + w, 0, e);
  1109. X          w += e;
  1110. X          d += e;
  1111. X        `7D
  1112. X        else
  1113. X#ifndef NOMEMCPY
  1114. X          if (w - d >= e)       /* (this test assumes unsigned comparison) *
  1115. V/
  1116. X          `7B
  1117. X            memcpy(slide + w, slide + d, e);
  1118. X            w += e;
  1119. X            d += e;
  1120. X          `7D
  1121. X          else                  /* do it slow to avoid memcpy() overlap */
  1122. X#endif /* !NOMEMCPY */
  1123. X            do `7B
  1124. X              slide`5Bw++`5D = slide`5Bd++`5D;
  1125. X            `7D while (--e);
  1126. X        if (w == WSIZE)
  1127. X        `7B
  1128. X          flush(w);
  1129. X          w = u = 0;
  1130. X        `7D
  1131. X      `7D while (n);
  1132. X    `7D
  1133. X  `7D
  1134. X
  1135. X  /* flush out slide */
  1136. X  flush(w);
  1137. X  return csize ? 5 : 0;         /* should have read csize bytes */
  1138. X`7D
  1139. X
  1140. X
  1141. X
  1142. Xint explode_lit4(tb, tl, td, bb, bl, bd)
  1143. Xstruct huft *tb, *tl, *td;      /* literal, length, and distance tables */
  1144. Xint bb, bl, bd;                 /* number of bits decoded by those */
  1145. X/* Decompress the imploded data using coded literals and a 4K sliding
  1146. X   window. */
  1147. X`7B
  1148. X  longint s;            /* bytes to decompress */
  1149. X  register unsigned e;  /* table entry flag/number of extra bits */
  1150. X  unsigned n, d;        /* length and index for copy */
  1151. X  unsigned w;           /* current window position */
  1152. X  struct huft *t;       /* pointer to table entry */
  1153. X  unsigned mb, ml, md;  /* masks for bb, bl, and bd bits */
  1154. X  register ULONG b;     /* bit buffer */
  1155. X  register unsigned k;  /* number of bits in bit buffer */
  1156. X  unsigned u;           /* true if unflushed */
  1157. X
  1158. X
  1159. X  /* explode the coded data */
  1160. X  b = k = w = 0;                /* initialize bit buffer, window */
  1161. X  u = 1;                        /* buffer unflushed */
  1162. X  mb = mask_bits`5Bbb`5D;           /* precompute masks for speed */
  1163. X  ml = mask_bits`5Bbl`5D;
  1164. X  md = mask_bits`5Bbd`5D;
  1165. X  s = ucsize;
  1166. X  while (s > 0)                 /* do until ucsize bytes uncompressed */
  1167. X  `7B
  1168. X    NEEDBITS(1)
  1169. X    if (b & 1)                  /* then literal--decode it */
  1170. X    `7B
  1171. X      DUMPBITS(1)
  1172. X      s--;
  1173. X      NEEDBITS((unsigned)bb)    /* get coded literal */
  1174. X      if ((e = (t = tb + ((`7E(unsigned)b) & mb))->e) > 16)
  1175. X        do `7B
  1176. X          if (e == 99)
  1177. X            return 1;
  1178. X          DUMPBITS(t->b)
  1179. X          e -= 16;
  1180. X          NEEDBITS(e)
  1181. X        `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
  1182. V->e) > 16);
  1183. X      DUMPBITS(t->b)
  1184. X      slide`5Bw++`5D = (byte)t->v.n;
  1185. X      if (w == WSIZE)
  1186. X      `7B
  1187. X        flush(w);
  1188. X        w = u = 0;
  1189. X      `7D
  1190. X    `7D
  1191. X    else                        /* else distance/length */
  1192. X    `7B
  1193. X      DUMPBITS(1)
  1194. X      NEEDBITS(6)               /* get distance low bits */
  1195. X      d = (unsigned)b & 0x3f;
  1196. X      DUMPBITS(6)
  1197. X      NEEDBITS((unsigned)bd)    /* get coded distance high bits */
  1198. X      if ((e = (t = td + ((`7E(unsigned)b) & md))->e) > 16)
  1199. X        do `7B
  1200. X          if (e == 99)
  1201. X            return 1;
  1202. X          DUMPBITS(t->b)
  1203. X          e -= 16;
  1204. X          NEEDBITS(e)
  1205. X        `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
  1206. V->e) > 16);
  1207. X      DUMPBITS(t->b)
  1208. X      d = w - d - t->v.n;       /* construct offset */
  1209. X      NEEDBITS((unsigned)bl)    /* get coded length */
  1210. X      if ((e = (t = tl + ((`7E(unsigned)b) & ml))->e) > 16)
  1211. X        do `7B
  1212. X          if (e == 99)
  1213. X            return 1;
  1214. X          DUMPBITS(t->b)
  1215. X          e -= 16;
  1216. X          NEEDBITS(e)
  1217. X        `7D while ((e = (t = t->v.t + ((`7E(unsigned)b) & mask_bits`5Be`5D))
  1218. V->e) > 16);
  1219. X      DUMPBITS(t->b)
  1220. X      n = t->v.n;
  1221. X      if (e)                    /* get length extra bits */
  1222. X      `7B
  1223. X        NEEDBITS(8)
  1224. X        n += (unsigned)b & 0xff;
  1225. X        DUMPBITS(8)
  1226. X      `7D
  1227. X
  1228. X      /* do the copy */
  1229. X      s -= n;
  1230. X      do `7B
  1231. X        n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);
  1232. X        if (u && w <= d)
  1233. X        `7B
  1234. X          memset(slide + w, 0, e);
  1235. X          w += e;
  1236. X          d += e;
  1237. X        `7D
  1238. X        else
  1239. X#ifndef NOMEMCPY
  1240. X          if (w - d >= e)       /* (this test assumes unsigned comparison) *
  1241. V/
  1242. X          `7B
  1243. X            memcpy(slide + w, slide + d, e);
  1244. X            w += e;
  1245. X            d += e;
  1246. X          `7D
  1247. +-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-
  1248.