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

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!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 05/22
  5. Message-ID: <8009604@MVB.SAIC.COM>
  6. Date: Tue, 01 Sep 1992 22:49:47 GMT
  7. Organization: Western Kentucky University, Bowling Green, KY
  8. Lines: 1413
  9. Approved: Mark.Berryman@Mvb.Saic.Com
  10.  
  11. Submitted-by: goathunter@wkuvx1.bitnet
  12. Posting-number: Volume 3, Issue 127
  13. Archive-name: zip_unzip/part05
  14.  
  15. -+-+-+-+-+-+-+-+ START OF PART 5 -+-+-+-+-+-+-+-+
  16. X  if (n != (unsigned)((`7Eb) & 0xffff))
  17. X    return 1;                   /* error in compressed data */
  18. X  DUMPBITS(16)
  19. X
  20. X
  21. X  /* read and output the compressed data */
  22. X  while (n--)
  23. X  `7B
  24. X    NEEDBITS(8)
  25. X    slide`5Bw++`5D = (byte)b;
  26. X    if (w == WSIZE)
  27. X    `7B
  28. X      flush(w);
  29. X      w = 0;
  30. X    `7D
  31. X    DUMPBITS(8)
  32. X  `7D
  33. X
  34. X
  35. X  /* restore the globals from the locals */
  36. X  wp = w;                       /* restore global window pointer */
  37. X  bb = b;                       /* restore global bit buffer */
  38. X  bk = k;
  39. X  return 0;
  40. X`7D
  41. X
  42. X
  43. X
  44. Xint inflate_fixed()
  45. X/* decompress an inflated type 1 (fixed Huffman codes) block.  We should
  46. X   either replace this with a custom decoder, or at least precompute the
  47. X   Huffman tables. */
  48. X`7B
  49. X  int i;                /* temporary variable */
  50. X  struct huft *tl;      /* literal/length code table */
  51. X  struct huft *td;      /* distance code table */
  52. X  int bl;               /* lookup bits for tl */
  53. X  int bd;               /* lookup bits for td */
  54. X  unsigned l`5B288`5D;      /* length list for huft_build */
  55. X
  56. X
  57. X  /* set up literal table */
  58. X  for (i = 0; i < 144; i++)
  59. X    l`5Bi`5D = 8;
  60. X  for (; i < 256; i++)
  61. X    l`5Bi`5D = 9;
  62. X  for (; i < 280; i++)
  63. X    l`5Bi`5D = 7;
  64. X  for (; i < 288; i++)          /* make a complete, but wrong code set */
  65. X    l`5Bi`5D = 8;
  66. X  bl = 7;
  67. X  if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0)
  68. X    return i;
  69. X
  70. X
  71. X  /* set up distance table */
  72. X  for (i = 0; i < 30; i++)      /* make an incomplete code set */
  73. X    l`5Bi`5D = 5;
  74. X  bd = 5;
  75. X  if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1)
  76. X  `7B
  77. X    huft_free(tl);
  78. X    return i;
  79. X  `7D
  80. X
  81. X
  82. X  /* decompress until an end-of-block code */
  83. X  if (inflate_codes(tl, td, bl, bd))
  84. X    return 1;
  85. X
  86. X
  87. X  /* free the decoding tables, return */
  88. X  huft_free(tl);
  89. X  huft_free(td);
  90. X  return 0;
  91. X`7D
  92. X
  93. X
  94. X
  95. Xint inflate_dynamic()
  96. X/* decompress an inflated type 2 (dynamic Huffman codes) block. */
  97. X`7B
  98. X  int i;                /* temporary variables */
  99. X  unsigned j;
  100. X  unsigned l;           /* last length */
  101. X  unsigned m;           /* mask for bit lengths table */
  102. X  unsigned n;           /* number of lengths to get */
  103. X  struct huft *tl;      /* literal/length code table */
  104. X  struct huft *td;      /* distance code table */
  105. X  int bl;               /* lookup bits for tl */
  106. X  int bd;               /* lookup bits for td */
  107. X  unsigned nb;          /* number of bit length codes */
  108. X  unsigned nl;          /* number of literal/length codes */
  109. X  unsigned nd;          /* number of distance codes */
  110. X  unsigned ll`5B286+30`5D;  /* literal/length and distance code lengths */
  111. X  register ULONG b;     /* bit buffer */
  112. X  register unsigned k;  /* number of bits in bit buffer */
  113. X
  114. X
  115. X  /* make local bit buffer */
  116. X  b = bb;
  117. X  k = bk;
  118. X
  119. X
  120. X  /* read in table lengths */
  121. X  NEEDBITS(5)
  122. X  nl = 257 + ((unsigned)b & 0x1f);      /* number of literal/length codes */
  123. X  DUMPBITS(5)
  124. X  NEEDBITS(5)
  125. X  nd = 1 + ((unsigned)b & 0x1f);        /* number of distance codes */
  126. X  DUMPBITS(5)
  127. X  NEEDBITS(4)
  128. X  nb = 4 + ((unsigned)b & 0xf);         /* number of bit length codes */
  129. X  DUMPBITS(4)
  130. X  if (nl > 286 `7C`7C nd > 30)
  131. X    return 1;                   /* bad lengths */
  132. X
  133. X
  134. X  /* read in bit-length-code lengths */
  135. X  for (j = 0; j < nb; j++)
  136. X  `7B
  137. X    NEEDBITS(3)
  138. X    ll`5Bborder`5Bj`5D`5D = (unsigned)b & 7;
  139. X    DUMPBITS(3)
  140. X  `7D
  141. X  for (; j < 19; j++)
  142. X    ll`5Bborder`5Bj`5D`5D = 0;
  143. X
  144. X
  145. X  /* build decoding table for trees--single level, 7 bit lookup */
  146. X  bl = 7;
  147. X  if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0)
  148. X  `7B
  149. X    if (i == 1)
  150. X      huft_free(tl);
  151. X    return i;                   /* incomplete code set */
  152. X  `7D
  153. X
  154. X
  155. X  /* read in literal and distance code lengths */
  156. X  n = nl + nd;
  157. X  m = mask_bits`5Bbl`5D;
  158. X  i = l = 0;
  159. X  while ((unsigned)i < n)
  160. X  `7B
  161. X    NEEDBITS((unsigned)bl)
  162. X    j = (td = tl + ((unsigned)b & m))->b;
  163. X    DUMPBITS(j)
  164. X    j = td->v.n;
  165. X    if (j < 16)                 /* length of code in bits (0..15) */
  166. X      ll`5Bi++`5D = l = j;          /* save last length in l */
  167. X    else if (j == 16)           /* repeat last length 3 to 6 times */
  168. X    `7B
  169. X      NEEDBITS(2)
  170. X      j = 3 + ((unsigned)b & 3);
  171. X      DUMPBITS(2)
  172. X      if ((unsigned)i + j > n)
  173. X        return 1;
  174. X      while (j--)
  175. X        ll`5Bi++`5D = l;
  176. X    `7D
  177. X    else if (j == 17)           /* 3 to 10 zero length codes */
  178. X    `7B
  179. X      NEEDBITS(3)
  180. X      j = 3 + ((unsigned)b & 7);
  181. X      DUMPBITS(3)
  182. X      if ((unsigned)i + j > n)
  183. X        return 1;
  184. X      while (j--)
  185. X        ll`5Bi++`5D = 0;
  186. X      l = 0;
  187. X    `7D
  188. X    else                        /* j == 18: 11 to 138 zero length codes */
  189. X    `7B
  190. X      NEEDBITS(7)
  191. X      j = 11 + ((unsigned)b & 0x7f);
  192. X      DUMPBITS(7)
  193. X      if ((unsigned)i + j > n)
  194. X        return 1;
  195. X      while (j--)
  196. X        ll`5Bi++`5D = 0;
  197. X      l = 0;
  198. X    `7D
  199. X  `7D
  200. X
  201. X
  202. X  /* free decoding table for trees */
  203. X  huft_free(tl);
  204. X
  205. X
  206. X  /* restore the global bit buffer */
  207. X  bb = b;
  208. X  bk = k;
  209. X
  210. X
  211. X  /* build the decoding tables for literal/length and distance codes */
  212. X  bl = lbits;
  213. X  if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0)
  214. X  `7B
  215. X    if (i == 1)
  216. X      huft_free(tl);
  217. X    return i;                   /* incomplete code set */
  218. X  `7D
  219. X  bd = dbits;
  220. X  if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
  221. X  `7B
  222. X    if (i == 1)
  223. X      huft_free(td);
  224. X    huft_free(tl);
  225. X    return i;                   /* incomplete code set */
  226. X  `7D
  227. X
  228. X
  229. X  /* decompress until an end-of-block code */
  230. X  if (inflate_codes(tl, td, bl, bd))
  231. X    return 1;
  232. X
  233. X
  234. X  /* free the decoding tables, return */
  235. X  huft_free(tl);
  236. X  huft_free(td);
  237. X  return 0;
  238. X`7D
  239. X
  240. X
  241. X
  242. Xint inflate_block(e)
  243. Xint *e;                 /* last block flag */
  244. X/* decompress an inflated block */
  245. X`7B
  246. X  unsigned t;           /* block type */
  247. X  register ULONG b;     /* bit buffer */
  248. X  register unsigned k;  /* number of bits in bit buffer */
  249. X
  250. X
  251. X  /* make local bit buffer */
  252. X  b = bb;
  253. X  k = bk;
  254. X
  255. X
  256. X  /* read in last block bit */
  257. X  NEEDBITS(1)
  258. X  *e = (int)b & 1;
  259. X  DUMPBITS(1)
  260. X
  261. X
  262. X  /* read in block type */
  263. X  NEEDBITS(2)
  264. X  t = (unsigned)b & 3;
  265. X  DUMPBITS(2)
  266. X
  267. X
  268. X  /* restore the global bit buffer */
  269. X  bb = b;
  270. X  bk = k;
  271. X
  272. X
  273. X  /* inflate that block type */
  274. X  if (t == 2)
  275. X    return inflate_dynamic();
  276. X  if (t == 0)
  277. X    return inflate_stored();
  278. X  if (t == 1)
  279. X    return inflate_fixed();
  280. X
  281. X
  282. X  /* bad block type */
  283. X  return 2;
  284. X`7D
  285. X
  286. X
  287. X
  288. Xint inflate_entry()
  289. X/* decompress an inflated entry */
  290. X`7B
  291. X  int e;                /* last block flag */
  292. X  int r;                /* result code */
  293. X  unsigned h;           /* maximum struct huft's malloc'ed */
  294. X
  295. X
  296. X  /* initialize window, bit buffer */
  297. X  wp = 0;
  298. X  bk = 0;
  299. X  bb = 0;
  300. X
  301. X
  302. X  /* decompress until the last block */
  303. X  h = 0;
  304. X  do `7B
  305. X    hufts = 0;
  306. X    if ((r = inflate_block(&e)) != 0)
  307. X      return r;
  308. X    if (hufts > h)
  309. X      h = hufts;
  310. X  `7D while (!e);
  311. X
  312. X
  313. X  /* flush out slide */
  314. X  flush(wp);
  315. X
  316. X
  317. X  /* return success */
  318. X#ifdef DEBUG
  319. X  fprintf(stderr, "<%u> ", h);
  320. X#endif /* DEBUG */
  321. X  return 0;
  322. X`7D
  323. X
  324. X
  325. Xvoid inflate()
  326. X/* ignore the return code for now ... */
  327. X`7B
  328. X  inflate_entry();
  329. X`7D
  330. $ CALL UNPACK [.UNZIP50]INFLATE.C;1 394025229
  331. $ create 'f'
  332. X#===========================================================================
  333. V===
  334. X# Makefile for UnZip, ZipInfo & FUnZip:  Unix, OS/2, MS-DOS ("real" makes on
  335. Vly)
  336. X# Version:  5.0 (inflate,explode)                                20 August 1
  337. V992
  338. X#===========================================================================
  339. V===
  340. X#
  341. X#
  342. X# INSTRUCTIONS (such as they are):
  343. X#
  344. X# "make vax"`09-- makes UnZip on a VAX 11-780 BSD 4.3 in current directory
  345. X#`09`09   (or a SysV VAX, or an 8600 running Ultrix, or...)
  346. X# "make"`09-- uses environment variable SYSTEM to set the type
  347. X#`09`09   system to compile for.  This doesn't work for some
  348. X#`09`09   particularly brain-damaged versions of make (VAX BSD,
  349. X#`09`09   Gould, and SCO Unix are in this group).  If SYSTEM not
  350. X#`09`09   set, gives instructions on what to try instead.
  351. X# "make list"`09-- lists all supported systems (targets), including related
  352. X#`09`09   utilities' targets
  353. X# "make wombat" -- Chokes and dies if you haven't added the specifics
  354. X#`09`09   for your Wombat 68000 (or whatever) to the systems list.
  355. X#
  356. X# CF are flags for the C compiler.  LF are flags for the loader.  LF2 are
  357. X# more flags for the loader, if they need to be at the end of the line
  358. X# instead of at the beginning (for example, some libraries).  LOCAL_UNZIP
  359. X# is an environment variable that can be used to add default C flags to
  360. X# your compile without editing the Makefile (e.g., -DDEBUG_STRUC, or -FPi87
  361. X# on PCs).
  362. X#
  363. X# My host (a VAX 11-780 running BSD 4.3) is hereafter referred to as "my hos
  364. Vt."
  365. X#
  366. X# My host's /usr/include/sys/param.h defines BSD for me.  You may have to ad
  367. Vd
  368. X# "-DBSD" to the list of CF for your system.
  369. X#
  370. X# Some versions of make do not define the macro "$(MAKE)" (my host did not).
  371. X# The makefile should now handle such systems correctly, more or less; the
  372. X# possible exception to this is if you've used a make command-line option
  373. X# (for example, the one which displays the commands which WOULD be executed,
  374. X# but doesn't actually execute them).  It probably needs some more tinkering
  375. V.
  376. X# If things still don't work, use "make" instead of "$(MAKE)" in your system
  377. V's
  378. X# makerule.  Or try adding the following line to your .login file:
  379. X#   setenv MAKE "make"
  380. X# (It didn't help on my host.)
  381. X#
  382. X# Memcpy and memset are provided for those systems that don't have them;
  383. X# they're found in misc.c and will be used if -DZMEM is included in the list
  384. X# of CF.  These days *almost* all systems have them (they're mandated by
  385. X# ANSI), but older systems might be lacking.  And at least one machine's
  386. X# version results in some serious performance degradation...
  387. X#
  388. X# Be sure to test your nice new UnZip; successful compilation does not alway
  389. Vs
  390. X# imply a working program.
  391. X
  392. X
  393. X#####################
  394. X# MACRO DEFINITIONS #
  395. X#####################
  396. X
  397. X# Defaults most systems use (use LOCAL_UNZIP in environment to add flags,`20
  398. X# such as -DNOMEMCPY).
  399. X
  400. XCRYPTF =
  401. XCRYPTO =
  402. X# Uncomment next two lines for decryption version:
  403. X#CRYPTF = -DCRYPT
  404. X#CRYPTO = crypt$O
  405. X
  406. X# UnZip flags
  407. XCC = cc#`09try using "gcc" target rather than changing this (if you do,
  408. XLD = cc#`09you MUST change LD, too--else "unresolved symbol:  ___main")
  409. XLOC = $(LOCAL_UNZIP) $(CRYPTF)
  410. XCF = -O $(LOC)
  411. XLF = -o unzip
  412. XLF2 = -s
  413. X
  414. X# ZipInfo flags
  415. XZC = -DZIPINFO
  416. XZL = -o zipinfo
  417. XZL2 = -s
  418. X
  419. X# FUnZip flags
  420. XFC = # not used
  421. XFL = -o funzip
  422. XFL2 = -s
  423. X
  424. X# general-purpose stuff
  425. XLN = rm -f misc_.c; ln
  426. XRM = rm -f
  427. XE =
  428. XO = .o
  429. XSHELL = /bin/sh
  430. XINSTALL = cp#`09 `09   probably can change this to 'install' if you have it
  431. XBINDIR = /usr/local/bin#   target directory - where to install executables
  432. X
  433. X# object files
  434. XOBJS1 = unzip$O $(CRYPTO) envargs$O explode$O extract$O file_io$O inflate$O
  435. XOBJS2 = mapname$O match$O misc$O unreduce$O unshrink$O
  436. XOBJS = $(OBJS1) $(OBJS2)
  437. XLOBJS = $(OBJS)
  438. XOS2_OBJS = $(OBJS:.o=.obj) os2unzip.obj
  439. XOBJZ = zipinfo$O envargs$O match$O misc_$O
  440. XOS2_OBJZ = $(OBJZ:.o=.obj) os2zinfo.obj
  441. XOBJF = funzip$O $(CRYPTO) inflate$O
  442. XOS2_OBJF = # not yet supported
  443. XUNZIPS = unzip$E # zipinfo$E funzip$E`09# zipinfo, funzip not fully supporte
  444. Vd
  445. X#`09`09`09`09`09#  yet (next release)
  446. X
  447. X# list of supported systems/targets in this version
  448. XSYSTEMS1 = 386i 3Bx 7300 amdahl apollo aviion bsd bull c120 c210 coherent
  449. XSYSTEMS2 = convex cray cray_cc cray_v3 cyber_sgi dec dnix encore eta
  450. XSYSTEMS3 = gcc gcc_dos generic generic2 gould hk68 hp indigo linux
  451. XSYSTEMS4 = minix mips msc_dos next osf1 p_iris pyramid rs6000 rtaix
  452. XSYSTEMS5 = sco sco_dos sco_x286 sequent sgi stellar sun sysv sysv6300
  453. XSYSTEMS6 = tahoe ultrix vax wombat xos
  454. X
  455. XSYS_UTIL1 = zi_dos zi_gcc zi_indigo zipinfo fu_gcc funzip
  456. X# SYS_UTIL2 = ship ship_dos ship_sysv
  457. X
  458. X
  459. X####################
  460. X# DEFAULT HANDLING #
  461. X####################
  462. X
  463. X# The below will try to use your shell variable "SYSTEM" as the type system
  464. X# to use (e.g., if you type "make" with no parameters at the command line).
  465. X# The test for $(MAKE) is necessary for VAX BSD make (and Gould, apparently)
  466. V,
  467. X# as is the "goober" (else stupid makes see an "else ;" statement, which the
  468. Vy
  469. X# don't like).  "goober" must then be made into a valid target for machines
  470. X# which DO define MAKE properly (and have SYSTEM set).  Quel kludge, non?
  471. X# And to top it all off, it appears that the VAX, at least, can't pick SYSTE
  472. VM
  473. X# out of the environment either (which, I suppose, should not be surprising)
  474. V.
  475. X# `5BBtw, if the empty "goober" target causes someone else's make to barf, j
  476. Vust
  477. X# add an "@echo > /dev/null" command (or whatever).  Works OK on the Amdahl
  478. X# and Crays, though.`5D
  479. X
  480. Xdefault:
  481. X`09@if test -z "$(MAKE)"; then\
  482. X`09`09if test -z "$(SYSTEM)";\
  483. X`09`09then make help;\
  484. X`09`09else make $(SYSTEM) MAKE="make";\
  485. X`09`09fi;\
  486. X`09else\
  487. X`09`09if test -z "$(SYSTEM)";\
  488. X`09`09then $(MAKE) help;\
  489. X`09`09else $(MAKE) $(SYSTEM) goober;\
  490. X`09`09fi;\
  491. X`09fi
  492. X
  493. Xgoober:
  494. X
  495. Xhelp:
  496. X`09@echo
  497. X`09@echo\
  498. X "  If you're not sure about the characteristics of your system, try typing"
  499. X`09@echo\
  500. X '  "make generic".  If the compiler barfs and says something unpleasant abo
  501. Vut'
  502. X`09@echo\
  503. X '  "timezone redefined," try typing "make clean" followed by "make generic2
  504. V".'
  505. X`09@echo\
  506. X '  One of these actions should produce a working copy of unzip on most Unix
  507. V'
  508. X`09@echo\
  509. X '  systems.  If you know a bit more about the machine on which you work, yo
  510. Vu'
  511. X`09@echo\
  512. X '  might try "make list" for a list of the specific systems supported herei
  513. Vn.'
  514. X`09@echo\
  515. X '  And as a last resort, feel free to read the numerous comments within the
  516. V'
  517. X`09@echo\
  518. X '  Makefile itself.  Note that to compile the decryption version of UnZip,'
  519. X`09@echo\
  520. X '  you must obtain crypt.c separately, in addition to uncommenting two line
  521. Vs'
  522. X`09@echo\
  523. X '  in Makefile (see the main Contents file for ftp and mail-server sites).'
  524. X`09@echo\
  525. X '  Have an excruciatingly pleasant day.'
  526. X`09@echo
  527. X
  528. Xlist:
  529. X`09@echo
  530. X`09@echo\
  531. X 'Type "make <system>", where <system> is one of the following:'
  532. X`09@echo
  533. X`09@echo  "`09$(SYSTEMS1)"
  534. X`09@echo  "`09$(SYSTEMS2)"
  535. X`09@echo  "`09$(SYSTEMS3)"
  536. X`09@echo  "`09$(SYSTEMS4)"
  537. X`09@echo  "`09$(SYSTEMS5)"
  538. X`09@echo  "`09$(SYSTEMS6)"
  539. X`09@echo
  540. X`09@echo\
  541. X 'Otherwise set the shell variable SYSTEM to one of these and just type "mak
  542. Ve".'
  543. X`09@echo\
  544. X 'Targets for related utilities (ZipInfo) include:'
  545. X`09@echo
  546. X`09@echo  "`09$(SYS_UTIL1)"
  547. X#`09@echo  "`09$(SYS_UTIL2)"
  548. X`09@echo
  549. X`09@echo\
  550. X 'For further (very useful) information, please read the comments in Makefil
  551. Ve.'
  552. X`09@echo
  553. X
  554. X
  555. X###############################################
  556. X# BASIC COMPILE INSTRUCTIONS AND DEPENDENCIES #
  557. X###############################################
  558. X
  559. X.c$O :
  560. X`09$(CC) -c $(CF) $*.c
  561. X
  562. Xunzips:`09`09$(UNZIPS)
  563. X
  564. Xunzip$E:`09$(OBJS)
  565. X`09$(LD) $(LF) $(LOBJS) $(LF2)
  566. X
  567. Xcrypt$O:        crypt.c unzip.h zip.h`09# may or may not be in distribution
  568. Xenvargs$O:      envargs.c unzip.h
  569. Xexplode$O:      explode.c unzip.h
  570. Xextract$O:      extract.c unzip.h
  571. Xfile_io$O:      file_io.c unzip.h
  572. Xfunzip$O:       funzip.c unzip.h
  573. Xinflate$O:      inflate.c unzip.h
  574. Xmapname$O:      mapname.c unzip.h
  575. Xmatch$O:        match.c unzip.h
  576. Xmisc$O:         misc.c unzip.h
  577. Xos2unzip$O:     os2unzip.c unzip.h`09# for OS/2 only
  578. Xos2zinfo$O:     os2unzip.c unzip.h`09# for OS/2 only
  579. Xunreduce$O:     unreduce.c unzip.h
  580. Xunshrink$O:     unshrink.c unzip.h
  581. Xunzip$O:        unzip.c unzip.h
  582. X
  583. Xall:`09generic_msg generic zipinfo
  584. X
  585. Xgeneric_msg:
  586. X`09@echo
  587. X`09@echo\
  588. X '  Attempting "make generic" and "make zipinfo" now.  If this fails for som
  589. Ve'
  590. X`09@echo\
  591. X '  reason, type "make help" and/or "make list" for suggestions.'
  592. X`09@echo
  593. X
  594. Xinstall:`09$(UNZIPS)
  595. X`09$(INSTALL) $(UNZIPS) $(BINDIR)
  596. X
  597. Xclean:
  598. X`09rm -f $(OBJS) unzip$E $(OBJZ) zipinfo$E
  599. X
  600. X
  601. X################################
  602. X# INDIVIDUAL MACHINE MAKERULES #
  603. X################################
  604. X
  605. X# these are the makerules for various systems
  606. X# TABS ARE REQUIRED FOR MANY VERSIONS OF "MAKE"!
  607. X
  608. X
  609. X# --------------------------------------------------------------------------
  610. V-
  611. X#   Generic targets (can't assume make utility groks "$(MAKE)")
  612. X# --------------------------------------------------------------------------
  613. V-
  614. X
  615. Xgeneric:`09unzip`09# first try if unknown
  616. X
  617. Xgeneric2:`09`09# second try if unknown:  hope make is called "make"...
  618. X`09make unzip CF="$(CF) -DBSD"
  619. X
  620. X# --------------------------------------------------------------------------
  621. V-
  622. X#   "Normal" group (both big- and little-endian, structure-padding or not):
  623. X# --------------------------------------------------------------------------
  624. V-
  625. X
  626. X386i:`09`09unzip`09# sun386i, SunOS 4.0.2
  627. X3Bx:`09`09unzip`09# AT&T 3B2/1000-80; should work on any WE32XXX machine
  628. X7300:`09`09unzip`09# AT&T 7300 (M68000/SysV)
  629. Xapollo:`09`09unzip`09# Apollo Domain/OS machines
  630. Xbull:`09`09unzip`09# Bull DPX/2, BOS 2.00.45 (doesn't require -Xk switch)
  631. Xcoherent:`09unzip`09# Coherent 3.10, Mark Williams C
  632. Xcray_cc:`09unzip`09# Cray-2 and Y-MP, using default (possibly old) compiler
  633. Xdec:`09`09unzip`09# DEC 5820 (MIPS RISC), test version of Ultrix v4.0
  634. Xencore:`09`09unzip`09# Multimax
  635. Xeta:`09`09unzip`09# ETA-10P*, hybrid SysV with BSD 4.3 enhancements
  636. Xgould:`09`09unzip`09# Gould PN9000 running UTX/32 2.1Bu01
  637. Xhp:`09`09unzip`09# HP 9000 series (68020), 4.3BSD or HP-UX A.B3.10 Ver D
  638. Xhp_ux:`09`09unzip`09# (to match zip's makefile entry)
  639. Xmips:`09`09unzip`09# MIPS M120-5(?), SysV.3 `5Berror in sys/param.h file?`5D
  640. Xpyramid:`09unzip`09# Pyramid 90X, prob. all, under >= OSx4.1, BSD universe
  641. Xrtaix:`09`09unzip`09# IBM RT 6150 under AIX 2.2.1
  642. Xsco:`09`09unzip`09# Xenix/386 (tested on 2.3.1); SCO Unix 3.2.0.
  643. Xstellar:`09unzip`09# gs-2000
  644. Xsun:`09`09unzip`09# Sun 3, 4; SunOS 4.x (SOME SYSTEMS ARE SYSTEM V!)
  645. Xtahoe:`09`09unzip`09# tahoe (CCI Power6/32), 4.3BSD
  646. Xultrix:`09`09unzip`09# VAXen, DEC 58x0 (MIPS guts), DECstation 2100; v4.x
  647. Xvax:`09`09unzip`09# general-purpose VAX target (not counting VMS)
  648. X
  649. X# --------------------------------------------------------------------------
  650. V-
  651. X#   BSD group (for timezone structs `5Bstruct timeb`5D):
  652. X# --------------------------------------------------------------------------
  653. V-
  654. X
  655. Xbsd:`09`09_bsd`09# generic BSD (BSD 4.2 & Ultrix handled in unzip.h)
  656. X
  657. X_bsd:
  658. X`09$(MAKE) unzip CF="$(CF) -DBSD"
  659. X
  660. X# --------------------------------------------------------------------------
  661. V-
  662. X#   SysV group (for extern long timezone and ioctl.h instead of sgtty.h):
  663. X# --------------------------------------------------------------------------
  664. V-
  665. X
  666. Xamdahl:`09`09_sysv`09# Amdahl (IBM) mainframe, UTS (SysV) 1.2.4 and 2.0.1
  667. Xaviion:         _sysv`09# Data General AViiONs, DG/UX 4.3x
  668. Xsgi:`09`09_sysv`09# Silicon Graphics Iris 4D, Irix SysV rel. 3.3.2
  669. Xsysv:`09`09_sysv`09# generic System V Unix
  670. Xxos:`09`09_sysv`09# Olivetti LSX-3005..3045, X/OS 2.3 and 2.4
  671. X
  672. X_sysv:
  673. X`09$(MAKE) unzip CF="$(CF) -DSYSV -DTERMIO"
  674. X
  675. X# --------------------------------------------------------------------------
  676. V-
  677. X#   "Unique" group (require non-standard options):
  678. X# --------------------------------------------------------------------------
  679. V-
  680. X
  681. X# Apparently the C-120 has an optimization bug, and possibly another
  682. X# bug in the (SysV?) time routines which adds 11 years to the date.
  683. X# -DCONVEX not needed?  `5BRZM:  The remark above the C-120 entry`20
  684. X# about a bug may not be true.  I think it is rather time procedures
  685. X# uncompatibility between unixes.`5D `5BGRR:  So is -O2 ok for c120?`5D
  686. X#
  687. Xc120:`09`09`09# Convex C-120, OS 9.0, with non-vectorizing cc 4.0
  688. X`09$(MAKE) unzip CF="-O1 $(LOC) -Dunix -DBSD"
  689. X
  690. Xc210:`09`09`09# Convex C-210, OS 9.0, cc 4.0
  691. X`09$(MAKE) unzip CF="-O2 $(LOC) -Dunix -DBSD"
  692. X
  693. X# Enclosed you'll find a context diff for the unzip41 makefile
  694. X# which enhances compilation on a convex.  The previous version
  695. X# probably worked great a couple of years ago, and would still do
  696. X# so if one compiles in our "backward compatible" pcc mode.   The
  697. X# following allows it to work better in a modern convexian environment.
  698. X# `5BThis target results in the following error on various Convex's,`20
  699. X# however:  "cc: Error on line 79 of file_io.c: 'ioctl' redeclared:
  700. X# incompatible types."`5D
  701. X#
  702. Xconvex:`09`09`09# previous target was tested on C200/C400
  703. X`09$(MAKE) unzip CF="$(CF) -Dunix -DCONVEX -ext" LF="$(LF) -ext"
  704. X
  705. X# Cray-2 and Y-MP, running Unicos 5.1 to 6.1 (SysV + BSD enhancements)
  706. X# and Standard (ANSI) C compiler 1.5, 2.0 or 3.0.
  707. Xcray:
  708. X`09$(MAKE) unzip CC="scc" LD="scc"
  709. X
  710. X# Ditto, for Cray Standard C 3.0 or later.
  711. Xcray_v3:
  712. X`09$(MAKE) unzip CC="scc" LD="scc" CF="$(CF) -h scalar3 -h vector3"
  713. X
  714. X# The unzip41 build on a Cyber 910/SGI running Irix v3.3.3 was successful
  715. X# with the following change to Makefile:
  716. Xcyber_sgi:
  717. X`09$(MAKE) unzip CF="$(CF) -I/usr/include/bsd"\
  718. X`09 LF="-lbsd $(LF)"
  719. X
  720. X# The DIAB dnix 5.3 compiler does not define __STDC__ but understands
  721. X# prototypes, void, etc., anyway.  It also does not provide any predefined
  722. X# macros to detect this (aside from "unix" and the four file, line, time
  723. X# and date macros).  Thus we must define MODERN and PROTO by hand.
  724. X#
  725. Xdnix:`09`09# 680X0, DIAB dnix 5.2/5.3 (a Swedish System V clone)
  726. X`09$(MAKE) unzip CF="$(CF) -DPROTO -DMODERN"
  727. X
  728. X# Generic BSDish Unix gcc.  `60`60The -O2 only works with the latest version
  729. V of
  730. X# gcc; you may have to use -O only for earlier versions.  I have no idea why
  731. X# -s causes this bug in gcc.''  `5BBug:  "nm: unzip: no name list", "collect
  732. V:
  733. X# /usr/bin/nm returned 1 exit status".`5D  If you don't have strip, don't
  734. X# worry about it (it just makes the executable smaller).
  735. X#
  736. Xgcc:
  737. X`09$(MAKE) unzip CC=gcc LD=gcc CF="-O2 $(LOC)" LF2=""
  738. X`09strip unzip
  739. X
  740. X# MS-DOS with D.J. Delorie's djgcc 1.06.  Note that go32 doesn't support
  741. X# dos function 0x38 (yet); to fix, append to line 400 of exphdlr.c (go32)
  742. X# the following:  "case 0x38:".
  743. X#
  744. Xgcc_dos:`09# may need to add -Uunix to CF
  745. X`09$(MAKE) unzip CC=gcc LD=gcc CF="-O2 -Wall $(LOC)"\
  746. X`09 LF="-s" LF2="-o unzip"
  747. X`09aout2exe unzip
  748. X
  749. X# Heurikon HK68 (68010), UniPlus+ System V 5.0, Green Hills C-68000
  750. Xhk68:
  751. X`09$(MAKE) unzip CC="gcc" LD="gcc" LF="-n $(LF)" \
  752. X`09CF="-ga -X138 $(LOC) -Dlocaltime=localti -Dtimezone=timezon"
  753. X
  754. X# Rules needed to build the unzip program for an Iris Indigo running
  755. X# Irix Version 4.0.1
  756. Xindigo:
  757. X`09$(MAKE) unzip CF="-cckr $(CF) -DTERMIO"
  758. X
  759. X# Linux is almost sysv but not quite
  760. Xlinux:                # Linux pre-0.96 with gcc 2.1
  761. X`09$(MAKE) unzip CF="$(CF) -DTERMIO -DLINUX" CC=gcc LD=gcc
  762. X
  763. X# Minix 1.5 PC for the 386 with gcc or bcc
  764. Xminix:
  765. X`09$(MAKE) unzip CC=gcc CF="$(CF) -DMINIX"
  766. X
  767. X# PCs (IBM-type), running MS-DOS, Microsoft C 6.0 and NMAKE.  Can't use
  768. X# SYSTEM environment variable:  "default" target is > 200 characters.
  769. X# "nmake msc_dos" works fine, aside from (possibly) an irrelevant message
  770. X# about the creation of a temporary file.  Environment variable LOCAL_UNZIP
  771. X# should be set via "SET LOCAL_UNZIP=-FPi87" if you use the 80x87 library;
  772. X# also add -G2 or -G3 if using a 286/386/486 system.
  773. X#
  774. X#msc_dos:
  775. X#`09$(MAKE) unzip.exe\
  776. X#`09 CF="-Ox $(LOC) -nologo -G2" CC=cl LD=link E=.exe O=.obj\
  777. X#`09 LF="/noi/nol" LF2=",unzip;"
  778. X
  779. Xmsc_dos:`09rsp
  780. X`09$(MAKE) unzip.exe CF="-Ox $(LOC) -nologo" CC=cl LD=link E=.exe\
  781. X`09 O=.obj LOBJS="" LF="@rsp" LF2=""
  782. X`09del rsp
  783. X
  784. Xrsp:
  785. X`09echo $(OBJS1:.o=.obj)+ > rsp
  786. X`09echo $(OBJS2:.o=.obj)/noi/e/st:0x1000; >> rsp
  787. X
  788. X# $(LOCAL_UNZIP):  math libraries and/or any other personal or debugging
  789. X#                  definitions:  e.g., SET LOCAL_UNZIP=-FPi87 -DDEBUG_STRUC
  790. X# $(NOD):  intended to be used as   SET NOD=-link /nod:slibcep   to allow th
  791. Ve
  792. X#          use of default library names (slibce.lib) instead of protected-mo
  793. Vde
  794. X#          names (slibcep.lib), but it fails:  MSC adds its own /nod qualifi
  795. Ver,
  796. X#          and there seems to be no way to override this.  Typical...
  797. X#
  798. Xmsc_os2:`09`09# 16-bit OS/2 (1.x) with MSC 6.00 (use makefile.os2)
  799. X`09$(MAKE) -nologo unzip.exe zipinfo.exe CC=cl LD=cl E=.exe O=.obj\
  800. X`09 OBJS="$(OS2_OBJS)" OBJZ="$(OS2_OBJZ)"\
  801. X`09 CF="-nologo -AC -Ocegit -G2s -DOS2 -DMSC $(LOC)"\
  802. X`09 LF="-nologo -AC $(LOC) -Lp -F 2000"\
  803. X`09 LF2="unzip.def -o unzip.exe $(NOD)" LN="copy" RM="del"\
  804. X`09 ZL="-nologo -AC $(LOC) -Lp -Fb" ZL2="zipinfo.def -o zipinfo.exe"
  805. X
  806. X# NeXT 2.x: make the executable smaller.
  807. Xnext:`09`09`09# 68030 BSD 4.3+Mach
  808. X`09$(MAKE) unzip LF2="-object -s"
  809. X
  810. X# Rules to build the unzip program on a DecStation running DEC OSF/1 V1.0.
  811. X# This machine hasn't got ftime(3) in the standard C library.
  812. Xosf1:
  813. X`09$(MAKE) unzip LF2="-lbsd"
  814. X
  815. X# I successfully compiled and tested the unzip program (v30) for the
  816. X# Silicon Graphics environment (Personal Iris 4D20/G with IRIX v3.2.2)
  817. Xp_iris:
  818. X`09$(MAKE) unzip CF="$(CF) -I/usr/include/bsd -DBSD"\
  819. X`09 LF="-lbsd $(LF)"
  820. X
  821. X# I have finished porting unzip 3.0 to the Pyramid 90X under OSX4.1.
  822. X# The biggest problem was the default structure alignment yielding two
  823. X# extra bytes.  The compiler has the -q option to pack structures, and
  824. X# this was all that was needed.  To avoid needing ZMEMS we could compile
  825. X# in the AT&T universe, but it runs more slowly!
  826. X#
  827. X#UnZip 5.0f:  moved to regular targets as test
  828. X#pyramid:`09# Pyramid 90X, probably all, under >= OSx4.1, BSD universe
  829. X#`09make unzip CF="$(CF) -q"
  830. X
  831. X# IBM RS/6000 under AIX 3.2
  832. Xrs6000:
  833. X`09$(MAKE) unzip CF="$(CF) -DBSD -D_BSD -DUNIX" LF="-lbsd $(LF)"
  834. X
  835. X# SCO cross compile from unix to DOS. Tested with Xenix/386 and OpenDeskTop.
  836. X# Should work with xenix/286 as well. (davidsen)  Note that you *must* remov
  837. Ve
  838. X# the unix objects and executable before doing this!  (Piet Plomp:  gcc won'
  839. Vt
  840. X# recognize the -M0 flag which forces 8086 code.)
  841. X#
  842. Xsco_dos:`09# uncomment zipinfo in UNZIPS if desired
  843. X`09$(MAKE) unzips CF="-O $(LOC) -DNO_ERRNO -dos -M0" LF="-dos -F 2000"\
  844. X`09 LF2="-o unzip.exe" ZL="-dos" ZL2="-o zipinfo.exe"
  845. X
  846. X# SCO Xenix/286 2.2.1
  847. Xsco_x286:
  848. X`09$(MAKE) unzip CF="$(CF) -Ml2" LF="$(LF) -Ml2"
  849. X
  850. X# Sequent Symmetry is a 386 but needs -DZMEM
  851. X# This should also work on Balance but I can't test it just yet.
  852. Xsequent:`09# Sequent w/Dynix
  853. X`09$(MAKE) unzip CF="$(CF) -DBSD -DZMEM"
  854. X
  855. X# AT&T 6300+, running System V.? Unix:  out-of-memory error if don't use -Ml
  856. Xsysv6300:
  857. X`09$(MAKE) unzip CF="$(CF) -Ml -DTERMIO" LF="$(LF) -Ml"
  858. X
  859. X# I didn't do this.  I swear.  No, really.
  860. Xwombat:`09`09# Wombat 68000 (or whatever)
  861. X`09@echo
  862. X`09@echo  '`09Ha ha!  Just kidding.'
  863. X`09@echo
  864. X
  865. X
  866. X#####################
  867. X# ZIPINFO MAKERULES #
  868. X#####################
  869. X
  870. X# ZipInfo section:  less hand-holding here, but it should be pretty
  871. X# straightforward by now.
  872. X
  873. Xzipinfo$O:`09zipinfo.c unzip.h
  874. X`09$(CC) -c $(CF) zipinfo.c
  875. X
  876. Xmisc_$O:`09misc.c unzip.h
  877. X`09$(LN) misc.c misc_.c
  878. X`09$(CC) -c $(CF) $(ZC) misc_.c
  879. X`09$(RM) misc_.c
  880. X
  881. Xos2zinfo$O:`09os2unzip.c unzip.h
  882. X`09$(LN) os2unzip.c os2zinfo.c
  883. X`09$(CC) -c $(CF) $(ZC) os2zinfo.c
  884. X`09$(RM) os2zinfo.c
  885. X
  886. Xzipinfo$E:`09$(OBJZ)
  887. X`09$(LD) $(ZL) $(OBJZ) $(ZL2)
  888. X
  889. Xzi_gcc:`09`09`09# GNU gcc under Unix (if no strip, don't worry)
  890. X`09$(MAKE) zipinfo CC=gcc LD=gcc ZL2=""
  891. X`09strip zipinfo
  892. X
  893. Xzi_indigo:`09`09# SGI Iris Indigo
  894. X`09$(MAKE) zipinfo CF="-cckr -O -DUNIX $(LOC)"
  895. X
  896. Xzi_dos:`09`09`09# MSC 6.0 + nmake, MS-DOS
  897. X`09$(MAKE) zipinfo.exe CF="-Ox -nologo $(LOC) -G2" CC=cl\
  898. X`09 LD=link E=.exe O=.obj ZL="/noi /nol" ZL2=",zipinfo;"\
  899. X`09 LN="copy" RM="DEL"
  900. X
  901. X
  902. X####################
  903. X# FUNZIP MAKERULES #
  904. X####################
  905. X
  906. X# FUnZip section:  FUnZip (Filter UnZip) is a last-minute addition to the
  907. X# UnZip suite and is still VERY raw.  Its purpose is to take a zipfile from`
  908. V20
  909. X# stdin and decompress the first entry to stdout.  Only non-encrypted, store
  910. Vd
  911. X# or deflated files are allowed at present.  FUnZip may be absorbed into
  912. X# regular UnZip in a subsequent release.  This target should work for some
  913. X# Unix systems but is not guaranteed to work for all (or even most).
  914. X
  915. Xfunzip$E:`09$(OBJF)
  916. X`09$(LD) $(FL) $(OBJF) $(FL2)
  917. X
  918. Xfu_gcc:`09`09`09# GNU gcc under Unix (if no strip, don't worry)
  919. X`09$(MAKE) funzip CC=gcc LD=gcc FL2=""
  920. X`09strip funzip
  921. X
  922. X
  923. X################
  924. X# ATTRIBUTIONS #
  925. X################
  926. X
  927. X# Thanks to the following people for their help in testing and/or porting
  928. X# to various machines (and thanks to the many others who aren't listed
  929. X# here but should be):
  930. X#
  931. X#  (original Unix port:  Carl Mascott <cmascott@world.std.com>)
  932. X#  386i:`09Richard Stephen <stephen@corp.telecom.co.nz>
  933. X#  3Bx:`09`09Bob Kemp <hrrca!bobc@cbnewse.att.com>
  934. X#  7300:`09Richard H. Gumpertz <rhg@cpsolv.CPS.COM>
  935. X#`09`09Greg Roelofs <roelofs@amelia.nas.nasa.gov>
  936. X#  amdahl:`09Kim DeVaughn <ked01@juts.ccc.amdahl.com>, Greg Roelofs
  937. X#  apollo:`09Tim Geibelhaus
  938. X#  aviion:`09Bruce Kahn <bkahn@archive.webo.dg.com>
  939. X#  bull:`09Matt D'Errico <doc@magna.com>
  940. X#  c120:`09Rafal Maszkowski <sgumk%pltumk11.bitnet>
  941. X#  coherent:`09David Fenyes <dfenyes@thesis1.med.uth.tmc.edu>
  942. X#  convex:`09Randy Wright <rwright@convex.com>
  943. X#  cray:`09Greg Roelofs, Paul Borman <prb@cray.com>
  944. X#  cray_cc:`09Greg Roelofs
  945. X#  cray_v3:`09Greg Roelofs
  946. X#  cyber_sgi:`09Clint Pulley <u001@cs910.cciw.ca>
  947. X#  dec:`09`09"Moby" Dick O'Connor <djo7613@u.washington.edu>
  948. X#  dnix:`09Bo Kullmar <bk@kullmar.se>
  949. X#  eta:`09`09Greg Flint <afc@klaatu.cc.purdue.edu>
  950. X#  gcc:`09`09Jean-loup Gailly <jloup@chorus.fr>
  951. X#  gcc_dos:`09Onno van der Linden <linden@fwi.uva.nl>
  952. X#  gcc_os2:`09Kai Uwe Rommel <rommel@informatik.tu-muenchen.de>
  953. X#  gould:`09Onno van der Linden
  954. X#  hk68:`09John Limpert <gronk!johnl@uunet.UU.NET>
  955. X#  hp:`09`09Randy McCaskile <rmccask@seas.gwu.edu> (HP-UX)
  956. X#`09`09Gershon Elber <gershon@cs.utah.edu> (HP BSD 4.3)
  957. X#  icc_os2:`09Kai Uwe Rommel
  958. X#  indigo:`09Kjetil Wiekhorst J`7Crgensen <jorgens@lise.unit.no>
  959. X#  linux:`09Humberto Ortiz-Zuazaga <zuazaga@ucunix.san.uc.edu>
  960. X#  minix:`09Kai Uwe Rommel (Minix 1.5)
  961. X#  mips:`09Peter Jones <jones@mips1.uqam.ca>
  962. X#  msc_dos:`09Greg Roelofs <roe2@ellis.uchicago.edu>
  963. X#`09`09Piet W. Plomp <piet@icce.rug.nl>
  964. X#  msc_os2:`09Wim Bonner <wbonner@yoda.eecs.wsu.edu>
  965. X#`09`09Kai Uwe Rommel, Greg Roelofs
  966. X#  next:`09Mark Adler <madler@piglet.caltech.edu>
  967. X#  osf1:`09Kjetil Wiekhorst J`7B\o`7Drgensen
  968. X#  p_iris:`09Valter V. Cavecchia <root@itnsg1.cineca.it>
  969. X#  pyramid:`09James Dugal <jpd@usl.edu>
  970. X#  rs6000:`09Filip Gieszczykiewicz <fmg@smi.med.pitt.edu>
  971. X#`09`09Trevor Paquette <tpaquett@ita.lgc.com>
  972. X#  rtaix:`09Erik-Jan Vens
  973. X#  sco:`09`09Onno van der Linden (SCO Unix 3.2.0)
  974. X#   `09`09Bill Davidsen <davidsen@crdos1.crd.ge.com> (Xenix/386)
  975. X#  sco_dos:`09Bill Davidsen, Piet W. Plomp
  976. X#  sco_x286:`09Ricky Mobley <ddi1!lrark!rick@uunet.UU.NET>
  977. X#  sequent:`09Phil Howard <phil@ux1.cso.uiuc.edu>
  978. X#  sgi:`09`09Greg Roelofs (Iris 4D/380?)
  979. X#  sun:`09`09Onno van der Linden (Sun 4), Greg Roelofs (Sun 3, 4)
  980. X#  sysv:`09Greg Roelofs
  981. X#  sysv6300:`09Peter Mauzey <ptm@mtdcc.att.com>
  982. X#  tahoe:`09Mark Edwards <mce%sdcc10@ucsd.edu>
  983. X#  ultrix:`09Greg Flint (VAX)
  984. X#`09`09Michael Graff <explorer@iastate.edu> (DECstation 2100?)
  985. X#`09`09Greg Roelofs (DEC 5810)
  986. X#`09`09Alex A Sergejew <aas@brain.wph.uq.oz.au>
  987. X#  vax:`09`09Forrest Gehrke <feg@dodger.att.com> (SysV)
  988. X#`09`09David Kirschbaum <kirsch@usasoc.soc.mil> (BSD 4.3)
  989. X#`09`09Jim Steiner <steiner@pica.army.mil> (8600+Ultrix)
  990. X#  wombat:`09Joe Isuzu <joe@trustme.isuzu.com>
  991. X#  xos:`09`09Fulvio Marino <fulvio@iconet.ico.olivetti.com>
  992. X#  zi_dos:`09Greg Roelofs
  993. X#  zi_icc:`09Kai Uwe Rommel
  994. X#  zi_os2:`09Greg Roelofs, Kai Uwe Rommel
  995. X#  zipinfo:`09Greg Roelofs
  996. $ CALL UNPACK [.UNZIP50]MAKEFILE.;1 1597202701
  997. $ create 'f'
  998. X$ !
  999. X$ !`09`09"Makefile" for VMS versions of UnZip and ZipInfo
  1000. X$ !`09`09`09`09(version:  GNU C)
  1001. X$ !
  1002. X$ ! Find out current disk and directory
  1003. X$ !
  1004. X$ my_name = f$env("procedure")
  1005. X$ here = f$parse(my_name,,,"device") + f$parse(my_name,,,"directory")
  1006. X$ set verify`09! like "echo on", eh?
  1007. X$ !
  1008. X$ ! Do UnZip:
  1009. X$ !   (for decryption version, add /def=CRYPT to each of following lines,
  1010. X$ !   uncomment crypt compile line, and add crypt to link line)
  1011. X$ !
  1012. X$ gcc unzip
  1013. X$ gcc envargs
  1014. X$ gcc explode
  1015. X$ gcc extract
  1016. X$ gcc file_io
  1017. X$ gcc inflate
  1018. X$ gcc mapname
  1019. X$ gcc match
  1020. X$ gcc misc
  1021. X$ gcc unreduce
  1022. X$ gcc unshrink
  1023. X$ gcc vms
  1024. X$! gcc crypt
  1025. X$ link unzip, envargs, explode, extract, file_io, inflate, mapname,-
  1026. X`09match, misc, unreduce, unshrink, vms, gnu_cc:`5B000000`5Dgcclib.olb/lib,-
  1027. X`09sys$input:/opt
  1028. X sys$share:vaxcrtl.exe/shareable
  1029. X$ !
  1030. X$ ! Do ZipInfo:
  1031. X$ !
  1032. X$ gcc zipinfo
  1033. X$ gcc /def=(ZIPINFO) /object=misc_.obj misc
  1034. X$ gcc /def=(ZIPINFO) /object=vms_.obj  vms
  1035. X$ link zipinfo, envargs, match, misc_, vms_, gnu_cc:`5B000000`5Dgcclib.olb/l
  1036. Vib,-
  1037. X`09sys$input:/opt
  1038. X sys$share:vaxcrtl.exe/shareable
  1039. X$ !
  1040. X$ ! Next line:  put a similar line (full pathname for unzip.exe and zipinfo.
  1041. Vexe)
  1042. X$ ! in login.com.  Remember to include the leading "$" before disk name.
  1043. X$ !
  1044. X$ unzip == "$''here'unzip.exe"`09`09! set up symbol to use unzip
  1045. X$ zipinfo == "$''here'zipinfo.exe"`09! set up symbol to use zipinfo
  1046. X$ !
  1047. X$ set noverify
  1048. $ CALL UNPACK [.UNZIP50]MAKE_GCC_UNZIP.COM;1 1193557854
  1049. $ create 'f'
  1050. X$ !
  1051. X$ !`09`09"Makefile" for VMS versions of UnZip and ZipInfo
  1052. X$ !`09`09`09`09(version:  VAX C)
  1053. X$ !
  1054. X$ ! Find out current disk and directory
  1055. X$ !
  1056. X$ my_name = f$env("procedure")
  1057. X$ here = f$parse(my_name,,,"device") + f$parse(my_name,,,"directory")
  1058. X$ set verify`09! like "echo on", eh?
  1059. X$ !
  1060. X$ ! Do UnZip:
  1061. X$ !   (for decryption version, add /def=CRYPT to compile line, and add
  1062. X$ !   crypt to both compile and link lines)
  1063. X$ !
  1064. X$ cc unzip, envargs, explode, extract, file_io, inflate, mapname,-
  1065. X`09match, misc, unreduce, unshrink, vms
  1066. X$ link unzip, envargs, explode, extract, file_io, inflate, mapname,-
  1067. X`09match, misc, unreduce, unshrink, vms, sys$input:/opt
  1068. X sys$share:vaxcrtl.exe/shareable
  1069. X$ !
  1070. X$ ! Do ZipInfo:
  1071. X$ !
  1072. X$ cc zipinfo
  1073. X$ cc /def=(ZIPINFO) /obj=misc_.obj  misc.c
  1074. X$ cc /def=(ZIPINFO) /obj=vms_.obj   vms.c
  1075. X$ link zipinfo, envargs, match, misc_, vms_, sys$input:/opt
  1076. X sys$share:vaxcrtl.exe/shareable
  1077. X$ !
  1078. X$ ! Next line:  put a similar line (full pathname for unzip.exe and zipinfo.
  1079. Vexe)
  1080. X$ ! in login.com.  Remember to include the leading "$" before disk name.
  1081. X$ !
  1082. X$ unzip == "$''here'unzip.exe"`09`09! set up symbol to use unzip
  1083. X$ zipinfo == "$''here'zipinfo.exe"`09! set up symbol to use zipinfo
  1084. X$ !
  1085. X$ set noverify
  1086. $ CALL UNPACK [.UNZIP50]MAKE_VAXC_UNZIP.COM;1 1869379771
  1087. $ create 'f'
  1088. X/*--------------------------------------------------------------------------
  1089. V-
  1090. X
  1091. X  mapname.c
  1092. X
  1093. X  This routine changes DEC-20, VAX/VMS, and DOS-style filenames into normal
  1094. X  Unix names (and vice versa, in some cases); it also creates any necessary`
  1095. V20
  1096. X  directories, if the -d switch was specified.
  1097. X
  1098. X  --------------------------------------------------------------------------
  1099. V-
  1100. X
  1101. X  Notes:
  1102. X
  1103. X     - This routine REALLY needs to be rewritten (different routines for
  1104. X       each output OS, with different rules for different parts of the path
  1105. X       name).  If each zip program stores local-format names (like the VMS
  1106. X       one did at one time), it would probably be best to convert to an in-
  1107. X       termediate format first (assuming we're not extracting under the same
  1108. X       OS as that under which the zipfile was created), then from that to
  1109. X       the current operating system's format.
  1110. X     - The strcpy and strcat operations on both cdp and filename may over-
  1111. X       write memory, since they don't check lengths.  With a kilobyte in
  1112. X       which to work, this is probably not that big a deal, but it could
  1113. X       cause problems eventually.
  1114. X
  1115. X  --------------------------------------------------------------------------
  1116. V-*/
  1117. X
  1118. X
  1119. X#include "unzip.h"
  1120. X
  1121. X
  1122. X/*******************/
  1123. X/* Mapname Defines */
  1124. X/*******************/
  1125. X
  1126. X#ifdef VMS
  1127. X#  define PERMS   0
  1128. X#else
  1129. X#  define PERMS   0777
  1130. X#endif
  1131. X
  1132. X#ifndef NO_MKDIR
  1133. X#  if (defined(DOS_OS2) && !defined(__GO32__))
  1134. X#    if (_MSC_VER >= 600)       /* have special MSC mkdir prototype */
  1135. X#      include <direct.h>
  1136. X#    else                       /* own prototype because dir.h conflicts? */
  1137. X       int mkdir(const char *path);
  1138. X#    endif /* ?(MSC 6.0 or later) */
  1139. X#    define MKDIR(path,mode)   mkdir(path)
  1140. X#  else /* !DOS_OS2 `7C`7C __GO32__ */
  1141. X#    ifdef MACOS
  1142. X#      define MKDIR(path,mode)   macmkdir(path,gnVRefNum,glDirID)
  1143. X#    else /* !MACOS */
  1144. X#      define MKDIR(path,mode)   mkdir(path,mode)
  1145. X#    endif /* ?MACOS */
  1146. X#  endif /* ?(DOS_OS2 && !__GO32__)  */
  1147. X#endif /* !NO_MKDIR */
  1148. X
  1149. X
  1150. X
  1151. X
  1152. X/************************/
  1153. X/*  Function mapname()  */
  1154. X/************************/
  1155. X
  1156. Xint mapname(create_dirs)   /* return 0 if no error, 1 if caution (filename *
  1157. V/
  1158. X    int create_dirs;       /*  truncated), 2 if warning (skip file because *
  1159. V/
  1160. X`7B                          /*  dir doesn't exist), 3 if error (skip file)
  1161. V */
  1162. X#ifdef NO_MKDIR
  1163. X    char command`5BFILNAMSIZ+40`5D; /* buffer for system() call */
  1164. X#endif
  1165. X#ifdef VMS
  1166. X    int stat_val;               /* temp. holder for stat() return value */
  1167. X    char *dp, *xp;              /* pointers to directory name */
  1168. X    char *np;                   /* pointer into filename */
  1169. X#endif /* VMS */
  1170. X#ifdef DOS_VMS
  1171. X    char *last_dot=NULL;        /* last dot not converted to underscore */
  1172. X#endif /* DOS_VMS */
  1173. X#ifdef OS2
  1174. X    char *last;
  1175. X    extern char longfilename`5B`5D; /*  AFTER file created and closed */
  1176. X    extern int longname;        /* used also in file_io.c:  set EAs */
  1177. X    int longdir;
  1178. X#endif /* OS2 */
  1179. X    char name`5BFILNAMSIZ`5D;       /* file name buffer */
  1180. X    char *pp, *cp, *cdp;        /* character pointers */
  1181. X    char delim = '\0';          /* directory delimiter */
  1182. X    int quote = FALSE;          /* flags */
  1183. X    int indir = FALSE;
  1184. X    int done = FALSE;
  1185. X    int created = FALSE;
  1186. X    register unsigned workch;   /* hold the character being tested */
  1187. X
  1188. X
  1189. X/*--------------------------------------------------------------------------
  1190. V-
  1191. X    Initialize various pointers and counters and stuff.
  1192. X  --------------------------------------------------------------------------
  1193. V-*/
  1194. X
  1195. X#ifdef MAP_DEBUG
  1196. X    fprintf(stderr, "%s ", filename);   /* echo name of this file */
  1197. X#endif
  1198. X    cdp = (char *)NULL;
  1199. X    pp = name;                  /* point to translation buffer */
  1200. X    *name = '\0';               /* initialize buffer */
  1201. X    if (!jflag) `7B               /* -j => junk pathnames */
  1202. X        cdp = (char *)malloc(strlen(filename) + 3);   /* place for holding *
  1203. V/
  1204. X        if (cdp == (char *)NULL) `7B                    /*  directory name *
  1205. V/
  1206. X            fprintf(stderr, "mapname:  out of memory `5B%s`5D\n", filename);
  1207. X            return 3;
  1208. X        `7D
  1209. X#ifdef VMS
  1210. X        *cdp++ = '`5B';
  1211. X        xp = cdp;               /* always points to last non-NULL char */
  1212. X        *cdp++ = '.';
  1213. X#endif /* VMS */
  1214. X#ifdef MACOS
  1215. X        *cdp = ':';             /* the Mac uses ':' as a directory separator
  1216. V */
  1217. X        cdp`5B1`5D = '\0';
  1218. X#else /* !MACOS */
  1219. X        *cdp = '\0';
  1220. X#endif /* ?MACOS */
  1221. X    `7D
  1222. X
  1223. X/*--------------------------------------------------------------------------
  1224. V-
  1225. X    Begin main loop through characters in filename.
  1226. X  --------------------------------------------------------------------------
  1227. V-*/
  1228. X
  1229. X    for (cp = filename; (workch = (unsigned char) *cp++) != 0  &&  !done;) `
  1230. V7B
  1231. X
  1232. X        if (quote) `7B                 /* if char quoted, */
  1233. X            *pp++ = (char) workch;   /*  include it literally */
  1234. X            quote = FALSE;
  1235. X        `7D else if (indir) `7B          /* if in directory name, */
  1236. X            if (workch == (unsigned)delim)  /*  look for end delimiter */
  1237. X                indir = FALSE;
  1238. X        `7D else
  1239. X            switch (workch) `7B
  1240. X            case '<':                /* discard DEC-20 directory name */
  1241. X                indir = TRUE;
  1242. X                delim = '>';
  1243. X                break;
  1244. X            case '`5B':                /* discard VMS directory name */
  1245. X                indir = TRUE;
  1246. X                delim = '`5D';
  1247. X                break;
  1248. X            case '/':                /* discard Unix path name  */
  1249. X            case '\\':               /*  or MS-DOS path name... */
  1250. X                                     /*  iff -j flag was given  */
  1251. X                /*
  1252. X                 * Special processing case:  if -j flag was not specified on
  1253. X                 * command line and create_dirs is TRUE, create any necessar
  1254. Vy
  1255. X                 * directories included in the pathname.  Creation of dirs i
  1256. Vs
  1257. X                 * straightforward on BSD and MS-DOS machines but requires u
  1258. Vse
  1259. X                 * of the system() command on SysV systems (or any others wh
  1260. Vich
  1261. X                 * don't have mkdir()).  The stat() check is necessary with
  1262. X                 * MSC because it doesn't have an EEXIST errno, and it saves
  1263. X                 * the overhead of multiple system() calls on SysV machines.
  1264. X                 */
  1265. X
  1266. X                if (!jflag) `7B
  1267. X                    *pp = '\0';
  1268. X#ifdef VMS
  1269. X                    dp = name;
  1270. X                    while (*++xp = *dp++);  /* copy name to cdp */
  1271. X                    last_dot = NULL;        /* dir name:  no dots allowed */
  1272. X                    strcpy(xp, ".dir");     /* add extension for stat check
  1273. V */
  1274. X                    stat_val = stat(cdp, &statbuf);
  1275. X                    *xp = '\0';             /* remove extension for all else
  1276. V */
  1277. X                    if (stat_val) `7B         /* doesn't exist, so create */
  1278. X#else /* !VMS */
  1279. X#ifdef MSDOS
  1280. X                    if (last_dot != NULL) `7B  /* one dot in dir name is leg
  1281. Val */
  1282. X                        *last_dot = '.';
  1283. X                        last_dot = NULL;
  1284. X                    `7D
  1285. X#endif /* MSDOS */
  1286. X                    strcat(cdp, name);
  1287. X#ifdef OS2
  1288. X                    if ((longdir = !IsFileNameValid(cdp)) != 0) `7B
  1289. X                        last = strrchr(cdp, '/');
  1290. X                        strcpy(longfilename, last ? last + 1 : cdp);
  1291. X                        fprintf(stderr, "renaming directory \"%s\"", cdp);
  1292. X                        ChangeNameForFAT(cdp);
  1293. X                        fprintf(stderr, " to \"%s\"\n", cdp);
  1294. X                    `7D
  1295. X#endif /* OS2 */
  1296. X                    if (stat(cdp, &statbuf)) `7B  /* doesn't exist, so creat
  1297. Ve */
  1298. X#endif /* ?VMS */
  1299. X                        if (!create_dirs) /* told not to create (freshening)
  1300. V */
  1301. X                            return 2;
  1302. X#ifdef NO_MKDIR
  1303. X                        sprintf(command,
  1304. X                          "IFS=\" \t\n\" /bin/mkdir %s 2>/dev/null", cdp);
  1305. X                        if (system(command)) `7B
  1306. X#else /* !NO_MKDIR */
  1307. X                        if (MKDIR(cdp, PERMS) == -1) `7B
  1308. X#endif /* ?NO_MKDIR */
  1309. X                            perror(cdp);
  1310. X                            free(cdp);
  1311. X                            fprintf(stderr, "mapame:  unable to process `5B%
  1312. Vs`5D\n",
  1313. X                              filename);
  1314. X                            return 3;
  1315. X                        `7D
  1316. X                        created = TRUE;
  1317. X#ifdef OS2
  1318. X                        if (longdir)
  1319. X                            SetLongNameEA(cdp, longfilename);
  1320. X#endif /* OS2 */
  1321. X                    `7D else if (!(statbuf.st_mode & S_IFDIR)) `7B
  1322. X                        fprintf(stderr,
  1323. X                          "mapname:  %s exists but is not a directory\n", cd
  1324. Vp);
  1325. X                        free(cdp);
  1326. X                        fprintf(stderr, "mapame:  unable to process `5B%s`5D
  1327. V\n",
  1328. X                          filename);
  1329. X                        return 3;
  1330. X                    `7D
  1331. X#ifdef VMS
  1332. X                    *xp = '/';  /* for now... (mkdir()) */
  1333. X#else /* !VMS */
  1334. X#ifdef MACOS
  1335. X                    strcat(cdp, ":");
  1336. X#else /* !MACOS */
  1337. X                    strcat(cdp, "/");
  1338. X#endif /* ?MACOS */
  1339. X#endif /* ?VMS */
  1340. X                `7D
  1341. X                pp = name;
  1342. X                break;
  1343. X            case ':':
  1344. X#ifdef UNIX                       /* colon is a valid character in Unix */
  1345. X                *pp++ = workch;   /*  filenames, so keep it; anywhere else,
  1346. V */
  1347. X#else /* !UNIX */                 /*  change it to an underscore (should  */
  1348. X                *pp++ = '_';      /*  NOT have stored drive/node names!!) */
  1349. X#endif /* ?UNIX */
  1350. X             /* pp = name;  (OLD) discard DEC dev: or node:: name */
  1351. X                break;
  1352. X            case '.':                   /* DEC-20 generation number or */
  1353. X#ifdef DOS_VMS                          /*  MS-DOS or VMS separator */
  1354. X                last_dot = pp;          /* point at last dot so far... */
  1355. X                *pp++ = '_';            /* convert dot to underscore */
  1356. X#else /* !DOS_VMS */
  1357. X                *pp++ = workch;
  1358. X#endif /* ?DOS_VMS */
  1359. X                break;
  1360. X            case ';':                   /* VMS generation or DEC-20 attrib *
  1361. V/
  1362. X#ifdef MACOS
  1363. X                if (V_flag `7C`7C macflag)
  1364. X#else /* !MACOS */
  1365. X                if (V_flag)                 /* if requested, save VMS ";##"
  1366. V */
  1367. X#endif /* ?MACOS */                         /*  version info or Macintosh */
  1368. X                    *pp++ = (char) workch;  /*  (?) info; otherwise discard
  1369. V */
  1370. X                else                        /*  everything starting with */
  1371. X                    done = TRUE;            /*  semicolon.  (Worry about */
  1372. X                break;                      /*  DEC-20 later.) */
  1373. X            case '\026':                /* control-V quote for special chars
  1374. V */
  1375. X                quote = TRUE;           /* set flag for next character */
  1376. X                break;
  1377. X            case ' ':
  1378. X#if (defined(VMS) `7C`7C defined(MTS))
  1379. X                *pp++ = '_';            /* change spaces to underscore */
  1380. X#else /* !(VMS `7C`7C MTS) */               /*  under VMS and MTS, and under
  1381. V DOS */
  1382. X#ifdef DOS_OS2                          /*  and OS/2 if -s not specified. */
  1383. X                if (!sflag)
  1384. X                    *pp++ = '_';
  1385. X                else
  1386. X#endif /* DOS_OS2 */
  1387. X                *pp++ = (char) workch;  /* otherwise, leave as spaces */
  1388. X#endif /* ?(VMS `7C`7C MTS) */
  1389. X                break;
  1390. X            default:
  1391. X#ifdef MACOS
  1392. X                if ((macflag && ((unsigned)workch > 0x1F)) `7C`7C isprint(wo
  1393. Vrkch))
  1394. X#else /* !MACOS */
  1395. X#if (defined(DOS_OS2) `7C`7C (defined(UNIX) && !defined(VMS)))  /* allow non
  1396. V-US */
  1397. X                if (isprint(workch) `7C`7C (128 <= workch && workch <= 254))
  1398. X#else /* !(DOS_OS2 `7C`7C UNIX) */
  1399. X                if (isprint(workch))    /* other printable, just keep */
  1400. X#endif /* ?(DOS_OS2 `7C`7C UNIX) */
  1401. X#endif /* ?MACOS */
  1402. X                    *pp++ = (char) workch;
  1403. X            `7D /* end switch */
  1404. X    `7D /* end for loop */
  1405. X    *pp = '\0';                         /* done with name:  terminate it */
  1406. X#ifdef DOS_VMS                          /*  and put a dot back in if VMS */
  1407. X    if (last_dot != NULL)               /*  or MS-DOS */
  1408. X        *last_dot = '.';
  1409. X#endif /* DOS_VMS */
  1410. X
  1411. X/*--------------------------------------------------------------------------
  1412. V-
  1413. X    We COULD check for existing names right now, create a "unique" name, etc
  1414. V.
  1415. X    At present, we do this in extract_or_test_files() (immediately after we
  1416. X    return from here).  If conversion went bad, the name'll either be nulled
  1417. X    out (in which case we'll return non-0), or following procedures won't be
  1418. X    able to create the extracted file and other error msgs will result.
  1419. X  --------------------------------------------------------------------------
  1420. V-*/
  1421. X
  1422. X    if (filename`5Bstrlen(filename) - 1`5D == '/') `7B
  1423. +-+-+-+-+-+-+-+-  END  OF PART 5 +-+-+-+-+-+-+-+-
  1424.