home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume29 / unzip / part06 < prev    next >
Encoding:
Text File  |  1992-04-02  |  54.0 KB  |  1,622 lines

  1. Newsgroups: comp.sources.misc
  2. From: info-zip@cs.ucla.edu (Info-Zip)
  3. Subject:  v29i036:  unzip - Info-ZIP's portable UnZip v4.2, Part06/12
  4. Message-ID: <1992Apr3.063218.28897@sparky.imd.sterling.com>
  5. X-Md4-Signature: b0fe195f36d8823912a214b16b8bd0af
  6. Date: Fri, 3 Apr 1992 06:32:18 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: info-zip@cs.ucla.edu (Info-Zip)
  10. Posting-number: Volume 29, Issue 36
  11. Archive-name: unzip/part06
  12. Environment: Unix, VMS, OS/2, MS-DOS, Amiga, Macintosh
  13. Supersedes: unzip, Volume 19, Issues 96-101
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  20. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  21. # Contents:  Makefile.cr file_io.c
  22. # Wrapped by kent@sparky on Mon Mar 30 01:45:53 1992
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 6 (of 12)."'
  26. if test -f 'Makefile.cr' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'Makefile.cr'\"
  28. else
  29.   echo shar: Extracting \"'Makefile.cr'\" \(21865 characters\)
  30.   sed "s/^X//" >'Makefile.cr' <<'END_OF_FILE'
  31. X# ===========================================================================
  32. X# Makefile for UnZip, ZipInfo & Ship:  Unix, OS/2 and MS-DOS (MSC NMAKE only)
  33. X# Version:  decrypt + (conditionally) inflate
  34. X# ===========================================================================
  35. X#
  36. X#
  37. X# INSTRUCTIONS (such as they are):
  38. X#
  39. X# "make vax"    -- makes UnZip on a VAX 11-780 BSD 4.3 in current directory
  40. X#           (or a SysV VAX, or an 8600 running Ultrix, or...)
  41. X# "make"    -- uses environment variable SYSTEM to set the type
  42. X#           system to compile for.  This doesn't work for some
  43. X#           particularly brain-damaged versions of make (VAX BSD,
  44. X#           Gould, and SCO Unix are in this group).  If SYSTEM not
  45. X#           set, gives instructions on what to try instead.
  46. X# "make list"    -- lists all supported systems (targets), including ship
  47. X#           and zipinfo targets
  48. X# "make wombat" -- Chokes and dies if you haven't added the specifics
  49. X#           for your Wombat 68000 (or whatever) to the systems list.
  50. X#
  51. X# CFLAGS are flags for the C compiler.  LDFLAGS are flags for the loader.
  52. X# LDFLAGS2 are more flags for the loader, if they need to be at the end of
  53. X# the line instead of at the beginning.
  54. X#
  55. X# My host (a VAX 11-780 running BSD 4.3) is hereafter referred to as "my host."
  56. X#
  57. X# My host's /usr/include/sys/param.h defines BSD for me.  You may have to add
  58. X# "-DBSD" to the list of CFLAGS for your system.
  59. X#
  60. X# Some versions of make do not define the macro "$(MAKE)" (my host did not).
  61. X# The makefile should now handle such systems correctly, more or less; the
  62. X# possible exception to this is if you've used a make command-line option
  63. X# (for example, the one which displays the commands which WOULD be executed,
  64. X# but doesn't actually execute them).  It probably needs some more tinkering.
  65. X# If things still don't work, use "make" instead of "$(MAKE)" in your system's
  66. X# makerule.  Or try adding the following line to your .login file:
  67. X#   setenv MAKE "make"
  68. X# (It didn't help on my host.)
  69. X#
  70. X# memcpy and memset are provided for those systems that don't have them;
  71. X# they're found in misc.c and will be used if -DZMEM is included in the list
  72. X# of CFLAGS.  These days ALMOST all systems have them (they're mandated by
  73. X# ANSI), but older systems might be lacking.  And at least ONE machine's
  74. X# version results in some serious performance degradation...
  75. X#
  76. X# SCO Unix 3.2.0:  Don't use -Ox with cc (derived from Microsoft 5.1); there
  77. X# is a bug in the loop optimization which causes bad CRC's.  [Onno van der
  78. X# Linden]
  79. X#
  80. X# Be sure to test your nice new UnZip; successful compilation does not always
  81. X# imply a working program.
  82. X
  83. X
  84. X#####################
  85. X# MACRO DEFINITIONS #
  86. X#####################
  87. X
  88. X# Defaults most systems use (use LOCAL_UNZIP in environment to add flags).
  89. X# To add inflation:  uncomment INFL_OBJ below or add it to your environment
  90. X# as appropriate, and add -DINFLATE to CFLAGS or to LOCAL_UNZIP.  (This
  91. X# won't work if you don't have inflate.c, so don't be a goober...)
  92. X
  93. XCC = cc
  94. XCR = -DCRYPT
  95. XCFLAGS = -O -DUNIX $(CR) $(LOCAL_UNZIP)
  96. XZC = -DZMEM
  97. XLD = cc
  98. XLDFLAGS = -o unzip
  99. XLDFLAGS2 = -s
  100. XZL = -o zipinfo
  101. XZL2 = -s
  102. XMV = mv
  103. XEXE =
  104. XO = .o
  105. X#INFL_OBJ = inflate.o  -or-  inflate.obj  (pick one)
  106. XOBJS = unzip$O crypt$O extract$O file_io$O $(INFL_OBJ)\
  107. X   mapname$O match$O misc$O unimplod$O unreduce$O unshrink$O
  108. XOS2_OBJS = unzip.obj crypt.obj dosname.obj extract.obj file_io.obj $(INFL_OBJ)\
  109. X   mapname.obj match.obj misc.obj unimplod.obj unreduce.obj unshrink.obj
  110. XZI_OBJS = zipinfo$O misc_$O match$O
  111. X
  112. XSHELL = /bin/sh
  113. X
  114. X# list of supported systems in this version
  115. XSYSTEMS1 = 386i 3Bx 7300 amdahl apollo aviion bsd bull coherent convex
  116. XSYSTEMS2 = cray cray_cc cyber_sgi dec dnix encore eta gcc_os2 generic
  117. XSYSTEMS3 = generic2 gould hk68 hp icc_os2 minix mips msc_dos msc_os2 next
  118. XSYSTEMS4 = p_iris pyramid rs6000 rtaix sco sco_dos sco_x286 sequent sgi
  119. XSYSTEMS5 = stellar sun sysv tahoe ultrix vax wombat
  120. X
  121. XSYS_UTIL1 = ship ship_dos ship_gcc ship_icc ship_os2 ship_sysv zi_dos
  122. XSYS_UTIL2 = zi_gcc zi_icc zi_os2 zipinfo 
  123. X
  124. X####################
  125. X# DEFAULT HANDLING #
  126. X####################
  127. X
  128. X# The below will try to use your shell variable "SYSTEM" as the type system
  129. X# to use (e.g., if you type "make" with no parameters at the command line).
  130. X# The test for $(MAKE) is necessary for VAX BSD make (and Gould, apparently),
  131. X# as is the "goober" (else stupid makes see an "else ;" statement, which they
  132. X# don't like).  "goober" must then be made into a valid target for machines
  133. X# which DO define MAKE properly (and have SYSTEM set).  Quel kluge, non?
  134. X# And to top it all off, it appears that the VAX, at least, can't pick SYSTEM
  135. X# out of the environment either (which, I suppose, should not be surprising).
  136. X# [Btw, if the empty "goober" target causes someone else's make to barf, just
  137. X# add an "@echo > /dev/null" command (or whatever).  Works OK on the Amdahl
  138. X# and Crays, though.]
  139. X
  140. Xdefault:
  141. X    @if test -z "$(MAKE)"; then\
  142. X        if test -z "$(SYSTEM)";\
  143. X        then make ERROR;\
  144. X        else make $(SYSTEM) MAKE="make";\
  145. X        fi;\
  146. X    else\
  147. X        if test -z "$(SYSTEM)";\
  148. X        then $(MAKE) ERROR;\
  149. X        else $(MAKE) $(SYSTEM) goober;\
  150. X        fi;\
  151. X    fi
  152. X
  153. Xgoober:
  154. X
  155. XERROR:
  156. X    @echo
  157. X    @echo\
  158. X "  If you're not sure about the characteristics of your system, try typing"
  159. X    @echo\
  160. X '  "make generic".  If the compiler barfs and says something unpleasant about'
  161. X    @echo\
  162. X '  "timezone redefined," try typing "make clean" followed by "make generic2".'
  163. X    @echo\
  164. X '  One of these actions should produce a working copy of unzip on most Unix'
  165. X    @echo\
  166. X '  systems.  If you know a bit more about the machine on which you work, you'
  167. X    @echo\
  168. X '  might try "make list" for a list of the specific systems supported herein.'
  169. X    @echo\
  170. X '  And as a last resort, feel free to read the numerous comments within the'
  171. X    @echo\
  172. X '  Makefile itself.  Have an excruciatingly pleasant day.'
  173. X    @echo
  174. X
  175. Xlist:
  176. X    @echo
  177. X    @echo\
  178. X 'Type "make <system>", where <system> is one of the following:'
  179. X    @echo
  180. X    @echo  "    $(SYSTEMS1)"
  181. X    @echo  "    $(SYSTEMS2)"
  182. X    @echo  "    $(SYSTEMS3)"
  183. X    @echo  "    $(SYSTEMS4)"
  184. X    @echo  "    $(SYSTEMS5)"
  185. X    @echo
  186. X    @echo\
  187. X 'Otherwise set the shell variable SYSTEM to one of these and just type "make".'
  188. X    @echo\
  189. X 'Targets for related utilities (ZipInfo and Ship) include:'
  190. X    @echo
  191. X    @echo  "    $(SYS_UTIL1)"
  192. X    @echo  "    $(SYS_UTIL2)"
  193. X    @echo
  194. X    @echo\
  195. X 'For further (very useful) information, please read the comments in Makefile.'
  196. X    @echo
  197. X
  198. X
  199. X###############################################
  200. X# BASIC COMPILE INSTRUCTIONS AND DEPENDENCIES #
  201. X###############################################
  202. X
  203. X.c$O :
  204. X    $(CC) -c $(CFLAGS) $*.c
  205. X
  206. Xunzip$(EXE):    $(OBJS)
  207. X    $(LD) $(LDFLAGS) $(OBJS) $(LDFLAGS2)
  208. X
  209. Xcrypt$O:        crypt.c unzip.h zip.h    # may or may not be in distribution
  210. Xdosname.obj:    dosname.c        # for OS/2 only
  211. Xextract$O:      extract.c unzip.h
  212. Xfile_io$O:      file_io.c unzip.h
  213. Xinflate$O:      inflate.c unzip.h    # may or may not be in distribution
  214. Xmapname$O:      mapname.c unzip.h
  215. Xmatch$O:        match.c unzip.h
  216. Xmisc$O:         misc.c unzip.h
  217. Xunimplod$O:     unimplod.c unzip.h
  218. Xunreduce$O:     unreduce.c unzip.h
  219. Xunshrink$O:     unshrink.c unzip.h
  220. Xunzip$O:        unzip.c unzip.h
  221. X
  222. Xclean:
  223. X    rm -f $(OBJS) unzip$(EXE)
  224. X
  225. X
  226. X################################
  227. X# INDIVIDUAL MACHINE MAKERULES #
  228. X################################
  229. X
  230. X# these are the makerules for various systems
  231. X# TABS ARE REQUIRED FOR MANY VERSIONS OF "MAKE"!
  232. X
  233. X
  234. X# ---------------------------------------------------------------------------
  235. X#   Generic targets (can't assume make utility groks "$(MAKE)")
  236. X# ---------------------------------------------------------------------------
  237. X
  238. Xgeneric:    unzip    # first try if unknown
  239. X
  240. Xgeneric2:        # second try if unknown:  hope make is called "make"...
  241. X    make unzip CFLAGS="$(CFLAGS) -DBSD"
  242. X
  243. X# ---------------------------------------------------------------------------
  244. X#   "Normal" group (both big- and little-endian, structure-padding or not):
  245. X# ---------------------------------------------------------------------------
  246. X
  247. X386i:        unzip    # sun386i, SunOS 4.0.2 ["sun:" works, too, but bigger]
  248. X3Bx:        unzip    # AT&T 3B2/1000-80; should work on any WE32XXX machine
  249. X7300:        unzip    # AT&T 7300 (M68000/SysV)
  250. Xapollo:        unzip    # Apollo Domain/OS machines
  251. Xaviion:         unzip    # Data General AViiONs, DG/UX 4.3x
  252. Xbull:        unzip    # Bull DPX/2, BOS 2.00.45 (doesn't require -Xk switch)
  253. Xcoherent:    unzip    # Coherent 3.10, Mark Williams C
  254. Xcray_cc:    unzip    # Cray-2 and Y-MP, using default (possibly old) compiler
  255. Xdec:        unzip    # DEC 5820 (MIPS RISC), test version of Ultrix v4.0
  256. Xdnix:        unzip    # 680X0, DIAB dnix 5.2/5.3 (a Swedish System V clone)
  257. Xencore:        unzip    # Multimax
  258. Xeta:        unzip    # ETA-10P*, hybrid SysV with BSD 4.3 enhancements
  259. Xgould:        unzip    # Gould PN9000 running UTX/32 2.1Bu01
  260. Xhp:        unzip    # HP 9000 series (68020), 4.3BSD or HP-UX A.B3.10 Ver D
  261. Xhp_ux:        unzip    # (to match zip's makefile entry)
  262. Xmips:        unzip    # MIPS M120-5(?), SysV R3 [error in sys/param.h file?]
  263. Xrs6000:        unzip    # IBM RS/6000 under AIX 3
  264. Xrtaix:        unzip    # IBM RT 6150 under AIX 2.2.1
  265. Xsco:        unzip    # Xenix/386 (tested on 2.3.1); SCO Unix 3.2.0.
  266. Xstellar:    unzip    # gs-2000
  267. Xsun:        unzip    # Sun 4/110, SunOS 4.0.3c; Sun 3 (68020), SunOS 4.0.3
  268. Xtahoe:        unzip    # tahoe (CCI Power6/32), 4.3BSD
  269. Xultrix:        unzip    # VAXen, DEC 58x0 (MIPS guts), DECstation 2100; v4.x
  270. Xvax:        unzip    # general-purpose VAX target (not counting VMS)
  271. X
  272. X# ---------------------------------------------------------------------------
  273. X#   BSD group (for timezone structs [struct timeb]):
  274. X# ---------------------------------------------------------------------------
  275. X
  276. Xbsd:        _bsd    # generic BSD (BSD 4.2, Ultrix handled in unzip.h)
  277. X
  278. X_bsd:
  279. X    $(MAKE) unzip CFLAGS="$(CFLAGS) -DBSD"
  280. X
  281. X# ---------------------------------------------------------------------------
  282. X#   SysV group (for extern long timezone and ioctl.h instead of sgtty.h):
  283. X# ---------------------------------------------------------------------------
  284. X
  285. Xsysv:        _sysv    # generic SysV
  286. Xamdahl:        _sysv    # Amdahl (IBM) mainframe, UTS (SysV) 1.2.4 and 2.0.1
  287. Xsgi:        _sysv    # Silicon Graphics Iris 4D, Irix SysV rel. 3.3.2
  288. X
  289. X_sysv:
  290. X    $(MAKE) unzip CFLAGS="$(CFLAGS) -DTERMIO"
  291. X
  292. X# ---------------------------------------------------------------------------
  293. X#   "Unique" group (require non-standard options):
  294. X# ---------------------------------------------------------------------------
  295. X
  296. X# Enclosed you'll find a context diff for the unzip41 makefile
  297. X# which enhances compilation on a convex.  The previous version
  298. X# probably worked great a couple of years ago, and would still do
  299. X# so if one compiles in our "backward compatible" pcc mode.   The
  300. X# following allows it to work better in a modern convexian environment
  301. X# (define __STDC__ manually because default compilation mode has
  302. X# extensions and thus doesn't do so).  [5 Mar 1992:  -D__STDC__ removed
  303. X# for now because of problems with stat.h]
  304. X#
  305. X#    $(MAKE) unzip CFLAGS="$(CFLAGS) -D__STDC__ -DCONVEX -ext" ...
  306. Xconvex:            # previous version was tested on C200/C400
  307. X    $(MAKE) unzip CFLAGS="$(CFLAGS) -DCONVEX -ext"\
  308. X     LDFLAGS="$(LDFLAGS) -ext"
  309. X
  310. X# Cray-2 and Y-MP, running Unicos 5.1 or 6.0 (SysV + BSD enhancements)
  311. X# and Standard (ANSI) C compiler 1.5, 2.0 or 3.0.
  312. Xcray:
  313. X    $(MAKE) unzip CC="scc" LD="scc"
  314. X
  315. X# The unzip41 build on a Cyber 910/SGI running Irix v3.3.3 was successful
  316. X# with the following change to Makefile:
  317. Xcyber_sgi:
  318. X    $(MAKE) unzip CFLAGS="$(CFLAGS) -I/usr/include/bsd"\
  319. X     LDFLAGS="-lbsd $(LDFLAGS)"
  320. X
  321. X# OS/2 2.0 (32-bit) with GNU C compiler (emx)
  322. Xgcc_os2:
  323. X    $(MAKE) unzip.exe CC=gcc LD=gcc EXE=.exe\
  324. X     OBJS="$(OBJS) dosname.o"\
  325. X     CFLAGS="-O -DOS2 -DEMX32 $(CR) $(LOCAL_UNZIP)"\
  326. X     LDFLAGS="-s" LDFLAGS2="-los2 -o unzip.exe"
  327. X
  328. X# Heurikon HK68 (68010), UniPlus+ System V 5.0, Green Hills C-68000
  329. Xhk68:
  330. X    $(MAKE) unzip CC="gcc" LD="gcc" LDFLAGS="-n $(LDFLAGS)" \
  331. X    CFLAGS="-ga -X138 -DUNIX $(CR) $(LOCAL_UNZIP) -Dlocaltime=localti -Dtimezone=timezon"
  332. X
  333. X# OS/2 2.0 (32-bit) with IBM C Set/2 compiler
  334. X#
  335. Xfile_io2.obj:        # compile this one module without optimization
  336. X    $(CC) -c $(CFLAGS) -O- -Fofile_io2.obj file_io.c
  337. X
  338. Xicc_os2:
  339. X    $(MAKE) -nologo unzip.exe CC=icc LD=icc EXE=.exe O=.obj\
  340. X     OBJS="$(OS2_OBJS:file_io.obj=file_io2.obj)"\
  341. X     CFLAGS="-Q -Sm -O -Gs -DOS2 $(CR) $(LOCAL_UNZIP)"\
  342. X     LDFLAGS="-Q" LDFLAGS2="unzip.def -Fe unzip.exe"
  343. X
  344. X# Minix 1.5 PC for the 386 with gcc or bcc
  345. Xminix:
  346. X    $(MAKE) unzip CC=gcc CFLAGS="$(CFLAGS) -DMINIX"
  347. X
  348. X# PCs (IBM-type), running MS-DOS, Microsoft C 6.00 and NMAKE.  Can't use the
  349. X# SYSTEM environment variable; that requires processing the "default:" target,
  350. X# which expands to some 200+ characters--well over DOS's 128-character limit.
  351. X# "nmake msc_dos" works fine, aside from an annoying message, "temporary file
  352. X# e:\ln023193 has been created."  I have no idea how to suppress this, but it
  353. X# appears to be benign (comes from the link phase; the file is always deleted).
  354. X# The environment variable LOCAL_UNZIP should be set to something appropriate
  355. X# if your library uses other than the default floating-point routines; for 
  356. X# example, SET LOCAL_UNZIP=-FPi87.  This target assumes the small-model library
  357. X# and an 80286 or better.  At present, everything should still fit within the
  358. X# 128-character command-line limit (barely); if not, remove the -nologo.  [GRR]
  359. X#
  360. Xmsc_dos:
  361. X    $(MAKE) unzip.exe\
  362. X     CFLAGS="-Ox $(CR) $(LOCAL_UNZIP) -nologo -G2" CC=cl\
  363. X     LD=link EXE=.exe O=.obj LDFLAGS="/noi /nol" LDFLAGS2=",unzip;"
  364. X
  365. X# The stack size for OS/2 must be increased to 0x1000, i.e. 
  366. X# "-F 1000" has to be added to LDFLAGS for msc_os2. Otherwise
  367. X# stack overflow occurs, which are only detected if compiled
  368. X# with debugging option, i.e. not with -Gs!! Otherwise something
  369. X# minor important seems to be overwritten :-)  [K. U. Rommel]
  370. X#
  371. X# Extra stack causes errors in GRR version ("/st:0x1000"); no problems
  372. X# encountered so far without.  EXEHDR /VERBOSE reports 0a00 bytes of
  373. X# extra stack already, so maybe the two versions are different... [GRR]
  374. X#
  375. X# $(LOCAL_UNZIP):  math libraries and/or any other personal or debugging
  376. X#                  definitions:  e.g., SET LOCAL_UNZIP=-FPi87 -DDEBUG_STRUC
  377. X# $(NOD):  intended to be used as   SET NOD=-link /nod:slibcep   to allow the
  378. X#          use of default library names (slibce.lib) instead of protected-mode
  379. X#          names (slibcep.lib), but it fails:  MSC adds its own /nod qualifier,
  380. X#          and there seems to be no way to override this.  Typical...
  381. X#
  382. X#msc_os2:        # old Newtware version (may not work)
  383. X#    $(MAKE) -nologo unzip.exe CC=cl LD=link EXE=.exe O=.obj\
  384. X#      OBJS="$(OBJS) dosname.obj"\
  385. X#      CFLAGS="-nologo -Ox -G2s -DOS2 $(CR) $(LOCAL_UNZIP) -Lp"\
  386. X#      LDFLAGS="/noi /nol" LDFLAGS2=",unzip,,,unzip.def"
  387. X#    bind -nologo unzip.exe -n DOSSETPATHINFO
  388. Xmsc_os2:        # Kai Uwe Rommel version
  389. X    $(MAKE) -nologo unzip.exe CC=cl LD=cl EXE=.exe O=.obj\
  390. X     OBJS="$(OS2_OBJS)"\
  391. X     CFLAGS="-nologo -Ox -G2s -DOS2 $(CR) $(LOCAL_UNZIP)"\
  392. X     LDFLAGS="-nologo $(LOCAL_UNZIP) -Lp -F 1000"\
  393. X     LDFLAGS2="unzip.def -o unzip.exe $(NOD)"
  394. X    bind -nologo unzip.exe -n DOSSETPATHINFO
  395. X
  396. X# NeXT 2.x: make the executable smaller.
  397. Xnext:            # 68030 BSD 4.3+Mach
  398. X    $(MAKE) unzip LDFLAGS2="-object -s"
  399. X
  400. X# I successfully compiled and tested the unzip program (v30) for the
  401. X# Silicon Graphics environment (Personal Iris 4D20/G with IRIX v3.2.2)
  402. Xp_iris:            # Silicon Graphics Personal Iris 4D20
  403. X    $(MAKE) unzip CFLAGS="$(CFLAGS) -I/usr/include/bsd -DBSD"\
  404. X     LDFLAGS="-lbsd $(LDFLAGS)"
  405. X
  406. X# I have finished porting unzip 3.0 to the Pyramid 90X under OSX4.1.
  407. X# The biggest problem was the default structure alignment yielding two
  408. X# extra bytes.  The compiler has the -q option to pack structures, and
  409. X# this was all that was needed.  To avoid needing ZMEMS we could compile in
  410. X# the att universe, but it runs slower!
  411. X#
  412. Xpyramid:    # Pyramid 90X, probably all, under >= OSx4.1, BSD universe
  413. X    make unzip CFLAGS="$(CFLAGS) -q -DBSD -DZMEM"
  414. X
  415. X# SCO cross compile from unix to DOS. Tested with Xenix/386 and
  416. X# OpenDeskTop. Should work with xenix/286 as well. (davidsen)
  417. X# Note that you *must* remove the unix objects and executable
  418. X# before doing this!
  419. X#
  420. Xsco_dos:
  421. X    $(MAKE) unzip CFLAGS="-O $(CR) $(LOCAL_UNZIP) -dos -M0" LDFLAGS="-dos"\
  422. X     LDFLAGS2="-o unzip.exe"
  423. X
  424. X# SCO Xenix/286 2.2.1
  425. Xsco_x286:
  426. X    $(MAKE) unzip CFLAGS="$(CFLAGS) -Ml2" LDFLAGS="$(LDFLAGS) -Ml2"
  427. X
  428. X# Sequent Symmetry is a 386 but needs -DZMEM
  429. X# This should also work on Balance but I can't test it just yet.
  430. Xsequent:    # Sequent w/Dynix
  431. X    $(MAKE) unzip CFLAGS="$(CFLAGS) -DBSD -DZMEM"
  432. X
  433. X# I didn't do this.  I swear.  No, really.
  434. Xwombat:        # Wombat 68000 (or whatever)
  435. X    @echo
  436. X    @echo  '    Ha ha!  Just kidding.'
  437. X    @echo
  438. X
  439. X
  440. X##################
  441. X# SHIP MAKERULES #
  442. X##################
  443. X
  444. X# Ship section:  ship comes with the Zip distribution and is more properly
  445. X# supported there.  But the following targets should at least get you started
  446. X# if for some reason you're only interested in UnZip.  The comments near the
  447. X# top of ship.c explain how to use it, and a little further poking around
  448. X# should clear up any problems related to things which should be defined but
  449. X# aren't, or which shouldn't be defined but are.  As with ZipInfo below, we
  450. X# assume *some* competence...
  451. X
  452. X_ship:    ship.c $(DEF)
  453. X    $(CC) $(CFLAGS) ship.c $(DEF) $(LDFLAGS2)
  454. X
  455. Xship:            # most BSD-type systems, by default
  456. X    $(MAKE) _ship LDFLAGS2="-s -o ship"
  457. X
  458. Xship_sysv:        # not tested; DIRENT used only to determine mailer
  459. X    $(MAKE) _ship CFLAGS="$(CFLAGS) -DDIRENT" LDFLAGS2="-s -o ship"
  460. X
  461. Xship_dos:        # not tested
  462. X    $(MAKE) -nologo _ship CC=cl EXE=.exe\
  463. X     CFLAGS="-nologo -Ox $(LOCAL_UNZIP) -G2s -F 2000"\
  464. X     LDFLAGS2="-o ship.exe"
  465. X
  466. Xship_os2:        # MSC 6.0, 16-bit OS/2
  467. X    $(MAKE) -nologo _ship CC=cl EXE=.exe DEF=ship.def\
  468. X     CFLAGS="-nologo -Ox $(LOCAL_UNZIP) -G2s -DOS2 -Lp -F 2000"\
  469. X     LDFLAGS2="-o ship.exe"
  470. X    bind -nologo ship.exe
  471. X
  472. Xship_icc:        # IBM C Set/2, 32-bit OS/2
  473. X    $(MAKE) -nologo _ship CC=icc EXE=.exe DEF=ship.def\
  474. X     CFLAGS="-Q -Sm -O $(LOCAL_UNZIP) -Gs -DOS2"\
  475. X     LDFLAGS2="-Fe ship.exe"
  476. X
  477. Xship_gcc:        # GNU gcc / emx, 32-bit OS/2
  478. X    $(MAKE) _ship CC=gcc LD=gcc EXE=.exe\
  479. X     CFLAGS="-O -DOS2" LDFLAGS2="-s -o ship.exe"
  480. X
  481. X
  482. X#####################
  483. X# ZIPINFO MAKERULES #
  484. X#####################
  485. X
  486. X# Zipinfo section:  it is assumed here that anyone competent enough to
  487. X# wonder about the internal guts of a zipfile is probably also competent
  488. X# enough to compile the program without a lot of hand-holding.  If not...
  489. X# oh well. :-)
  490. X
  491. Xzipinfo$O:    zipinfo.c unzip.h
  492. X    $(CC) -c $(CFLAGS) $(ZC) zipinfo.c
  493. X
  494. Xmisc_$O:    misc.c unzip.h
  495. X    $(MV) misc.c misc_.c
  496. X    $(CC) -c $(CFLAGS) $(ZC) -DZIPINFO misc_.c
  497. X    $(MV) misc_.c misc.c
  498. X
  499. Xzipinfo$(EXE):    $(ZI_OBJS)
  500. X    $(LD) $(ZL) $(ZI_OBJS) $(ZL2)
  501. X
  502. Xzi_dos:
  503. X    $(MAKE) zipinfo.exe CFLAGS="-Ox -nologo $(LOCAL_UNZIP) -G2" CC=cl\
  504. X     LD=link EXE=.exe O=.obj ZL="/noi /nol" ZL2=",zipinfo;" ZC="" MV="ren"
  505. X
  506. X#zi_os2:         # GRR (Newtware) version (do not delete!)
  507. X#    $(MAKE) -nologo zipinfo.exe CC=cl LD=link EXE=.exe O=.obj\
  508. X#     CFLAGS="-nologo -Ox $(LOCAL_UNZIP) -G2s -DOS2 -Lp" ZC="" MV="ren"\
  509. X#     ZL="/nol /noi" ZL2=",zipinfo,,,zipinfo.def"
  510. X#    bind -nologo zipinfo.exe
  511. Xzi_os2:         # Kai Uwe Rommel version (do not delete!)
  512. X    $(MAKE) -nologo zipinfo.exe CC=cl LD=cl EXE=.exe O=.obj\
  513. X     CFLAGS="-nologo -Ox $(LOCAL_UNZIP) -G2s -DOS2" ZC="" MV="ren"\
  514. X     ZL="-nologo $(LOCAL_UNZIP) -Lp -Fb" ZL2="zipinfo.def -o zipinfo.exe"
  515. X
  516. Xzi_icc:            # IBM C Set/2, 32-bit OS/2
  517. X    $(MAKE) -nologo zipinfo.exe CC=icc LD=icc EXE=.exe O=.obj\
  518. X     CFLAGS="-Q -Sm -O -Gs -DOS2" ZC="" MV="ren"\
  519. X     ZL="-Q" ZL2="zipinfo.def -Fe zipinfo.exe"
  520. X
  521. Xzi_gcc:            # GNU gcc / emx, 32-bit OS/2
  522. X    $(MAKE) zipinfo.exe CC=gcc LD=gcc EXE=.exe\
  523. X     CFLAGS="-O -DOS2 -DEMX32" ZC="" MV="ren"\
  524. X     ZL="-s" ZL2="-o zipinfo.exe"
  525. X
  526. X
  527. X################
  528. X# ATTRIBUTIONS #
  529. X################
  530. X
  531. X# Thanks to the following people for their help in testing and/or porting
  532. X# to various machines (and thanks to the many others who aren't listed
  533. X# here but should be):
  534. X#
  535. X#  (original Unix port:  Carl Mascott <cmascott@world.std.com>)
  536. X#  386i:    Richard Stephen <stephen@corp.telecom.co.nz>
  537. X#  3Bx:        Bob Kemp <hrrca!bobc@cbnewse.att.com>
  538. X#  7300:    Richard H. Gumpertz <rhg@cpsolv.CPS.COM>
  539. X#        Greg Roelofs <roelofs@amelia.nas.nasa.gov>
  540. X#  amdahl:    Kim DeVaughn <ked01@juts.ccc.amdahl.com>, Greg Roelofs
  541. X#  apollo:    Tim Geibelhaus
  542. X#  aviion:    Bruce Kahn <bkahn@archive.webo.dg.com>
  543. X#  bull:    Matt D'Errico <doc@magna.com>
  544. X#  coherent:    David Fenyes <dfenyes@thesis1.med.uth.tmc.edu>
  545. X#  convex:    Randy Wright <rwright@convex.com>
  546. X#  cray:    Greg Roelofs, Paul Borman <prb@cray.com>
  547. X#  cyber_sgi:    Clint Pulley <u001@cs910.cciw.ca>
  548. X#  dec:        "Moby" Dick O'Connor <djo7613@u.washington.edu>
  549. X#  dnix:    Bo Kullmar <bk@kullmar.se>
  550. X#  eta:        Greg Flint <afc@klaatu.cc.purdue.edu>
  551. X#  gould:    Onno van der Linden <linden@fwi.uva.nl>
  552. X#  hk68:    John Limpert <gronk!johnl@uunet.UU.NET>
  553. X#  hp:        Randy McCaskile <rmccask@seas.gwu.edu> (HP-UX)
  554. X#        Gershon Elber <gershon@cs.utah.edu> (HP BSD 4.3)
  555. X#  icc_os2:    Kai Uwe Rommel <rommel@informatik.tu-muenchen.de>
  556. X#  minix:    Kai Uwe Rommel (Minix 1.5)
  557. X#  mips:    Peter Jones <jones@mips1.uqam.ca>
  558. X#  msc_dos:    Greg Roelofs
  559. X#  msc_os2:    Wim Bonner <wbonner@yoda.eecs.wsu.edu>
  560. X#        Kai Uwe Rommel, Greg Roelofs
  561. X#  next:    Mark Adler <madler@piglet.caltech.edu>
  562. X#  p_iris:    Valter V. Cavecchia <root@itnsg1.cineca.it>
  563. X#  pyramid:    James Dugal <jpd@usl.edu>
  564. X#  rs6000:    Filip Gieszczykiewicz <fmg@smi.med.pitt.edu>
  565. X#  rtaix:    Erik-Jan Vens
  566. X#  sco:        Onno van der Linden (SCO Unix 3.2.0)
  567. X#           Bill Davidsen <davidsen@crdos1.crd.ge.com> (Xenix/386)
  568. X#  sco_dos:    Bill Davidsen
  569. X#  sco_x286:    Ricky Mobley <ddi1!lrark!rick@uunet.UU.NET>
  570. X#  sequent:    Phil Howard <phil@ux1.cso.uiuc.edu>
  571. X#  sgi:        Greg Roelofs (Iris 4D/380?)
  572. X#  sun:        Onno van der Linden (Sun 4), Greg Roelofs (Sun 3, 4)
  573. X#  tahoe:    Mark Edwards <mce%sdcc10@ucsd.edu>
  574. X#  ultrix:    Greg Flint (VAX)
  575. X#        Michael Graff <explorer@iastate.edu> (DECstation 2100?)
  576. X#        Greg Roelofs (DEC 5810)
  577. X#        Alex A Sergejew <aas@brain.wph.uq.oz.au>
  578. X#  vax:        Forrest Gehrke <feg@dodger.att.com> (SysV)
  579. X#        David Kirschbaum <kirsch@usasoc.soc.mil> (BSD 4.3)
  580. X#        Jim Steiner <steiner@pica.army.mil> (8600+Ultrix)
  581. X#  wombat:    Joe Isuzu <joe@trustme.isuzu.com>
  582. X#  zi_dos:    Greg Roelofs
  583. X#  zi_icc:    Kai Uwe Rommel
  584. X#  zi_os2:    Greg Roelofs, Kai Uwe Rommel
  585. X#  zipinfo:    Greg Roelofs
  586. END_OF_FILE
  587.   if test 21865 -ne `wc -c <'Makefile.cr'`; then
  588.     echo shar: \"'Makefile.cr'\" unpacked with wrong size!
  589.   fi
  590.   # end of 'Makefile.cr'
  591. fi
  592. if test -f 'file_io.c' -a "${1}" != "-c" ; then 
  593.   echo shar: Will not clobber existing file \"'file_io.c'\"
  594. else
  595.   echo shar: Extracting \"'file_io.c'\" \(29594 characters\)
  596.   sed "s/^X//" >'file_io.c' <<'END_OF_FILE'
  597. X/*---------------------------------------------------------------------------
  598. X
  599. X  file_io.c
  600. X
  601. X  This file contains routines for doing direct input/output, file-related
  602. X  sorts of things.  Most of the system-specific code for unzip is contained
  603. X  here, including the non-echoing password code for decryption (bottom).
  604. X
  605. X  ---------------------------------------------------------------------------*/
  606. X
  607. X
  608. X#define const
  609. X#include "unzip.h"
  610. X
  611. X
  612. X/************************************/
  613. X/*  File_IO Local Prototypes, etc.  */
  614. X/************************************/
  615. X
  616. X#ifndef DOS_OS2
  617. X   static int dos2unix __((unsigned char *buf, int len));
  618. X   int CR_flag = 0;      /* when last char of buffer == CR (for dos2unix()) */
  619. X#endif
  620. X
  621. X#ifdef OS2
  622. X   extern int   longname;          /* set in mapname.c */
  623. X   extern char  longfilename[];
  624. X#endif
  625. X
  626. X#ifdef CRYPT
  627. X   typedef char  voidp;
  628. X#  if defined(DOS_OS2) || defined(VMS)
  629. X#    define MSVMS
  630. X#    ifdef DOS_OS2
  631. X#      include <conio.h>
  632. X#    else /* !DOS_OS2 */
  633. X#      define getch() getc(stderr)
  634. X#      define OFF 0   /* for echo control */
  635. X#      define ON 1
  636. X#      include <descrip.h>
  637. X#      include <iodef.h>
  638. X#      include <ttdef.h>
  639. X#      ifndef SS$_NORMAL
  640. X#        define SS$_NORMAL 1   /* only thing we need from <ssdef.h> */
  641. X#      endif
  642. X#    endif /* ?DOS_OS2 */
  643. X#  else /* !(DOS_OS2 || VMS) */
  644. X#    ifdef TERMIO    /* Amdahl, Cray, all SysV? */
  645. X#      ifdef CONVEX
  646. X#        include <sys/termios.h>
  647. X#     include <sgtty.h>
  648. X#      else /* !CONVEX */
  649. X#        include <sys/termio.h>
  650. X#        define sgttyb termio
  651. X#        define sg_flags c_lflag
  652. X#      endif /* ?CONVEX */
  653. X       int ioctl OF((int, int, voidp *));
  654. X#      define GTTY(f,s) ioctl(f,TCGETA,(voidp *)s)
  655. X#      define STTY(f,s) ioctl(f,TCSETAW,(voidp *)s)
  656. X#    else /* !TERMIO */
  657. X#      ifndef MINIX
  658. X#     include <sys/ioctl.h>
  659. X#      endif /* !MINIX */
  660. X#      include <sgtty.h>
  661. X       int gtty OF((int, struct sgttyb *));
  662. X       int stty OF((int, struct sgttyb *));
  663. X#      define GTTY gtty
  664. X#      define STTY stty
  665. X#    endif /* ?TERMIO */
  666. X     int isatty OF((int));
  667. X     char *ttyname OF((int));
  668. X     int open OF((char *, int, ...));
  669. X     int close OF((int));
  670. X     int read OF((int, voidp *, int));
  671. X#  endif /* ?(DOS_OS2 || VMS) */
  672. X#endif /* CRYPT */
  673. X
  674. X
  675. X
  676. X
  677. X
  678. X/******************************/
  679. X/* Function open_input_file() */
  680. X/******************************/
  681. X
  682. Xint open_input_file()
  683. X{                               /* return non-0 if open failed */
  684. X    /*
  685. X     *  open the zipfile for reading and in BINARY mode to prevent cr/lf
  686. X     *  translation, which would corrupt the bitstreams
  687. X     */
  688. X
  689. X#ifdef UNIX
  690. X    zipfd = open(zipfn, O_RDONLY);
  691. X#else
  692. X    zipfd = open(zipfn, O_RDONLY | O_BINARY);
  693. X#endif
  694. X    if (zipfd < 1) {
  695. X        fprintf(stderr, "error:  can't open zipfile [ %s ]\n", zipfn);
  696. X        return (1);
  697. X    }
  698. X    return 0;
  699. X}
  700. X
  701. X
  702. X
  703. X
  704. X
  705. X/**********************/
  706. X/* Function readbuf() */
  707. X/**********************/
  708. X
  709. Xint readbuf(buf, size)
  710. Xchar *buf;
  711. Xregister unsigned size;
  712. X{                               /* return number of bytes read into buf */
  713. X    register int count;
  714. X    int n;
  715. X
  716. X    n = size;
  717. X    while (size) {
  718. X        if (incnt == 0) {
  719. X            if ((incnt = read(zipfd, (char *)inbuf, INBUFSIZ)) <= 0)
  720. X                return (n-size);
  721. X            /* buffer ALWAYS starts on a block boundary:  */
  722. X            cur_zipfile_bufstart += INBUFSIZ;
  723. X            inptr = inbuf;
  724. X        }
  725. X        count = min(size, incnt);
  726. X        memcpy(buf, inptr, count);
  727. X        buf += count;
  728. X        inptr += count;
  729. X        incnt -= count;
  730. X        size -= count;
  731. X    }
  732. X    return (n);
  733. X}
  734. X
  735. X
  736. X
  737. X
  738. X
  739. X#ifndef VMS   /* for VMS use code in vms.c (old VMS code below is retained
  740. X               * in case of problems...will be removed in a later release) */
  741. X
  742. X/*********************************/
  743. X/* Function create_output_file() */
  744. X/*********************************/
  745. X
  746. Xint create_output_file()
  747. X{                               /* return non-0 if creat failed */
  748. X
  749. X
  750. X/*---------------------------------------------------------------------------
  751. X    Create the output file with appropriate permissions.  If we've gotten to
  752. X    this point and the file still exists, we have permission to blow it away.
  753. X  ---------------------------------------------------------------------------*/
  754. X
  755. X#ifndef DOS_OS2
  756. X    CR_flag = 0;   /* hack to get CR at end of buffer working */
  757. X#endif
  758. X
  759. X#if defined(UNIX) && !defined(AMIGA)
  760. X    {
  761. X        int mask;
  762. X
  763. X#ifndef VMS
  764. X        if (!stat(filename, &statbuf) && (unlink(filename) < 0)) {
  765. X            fprintf(stderr, "\n%s:  cannot delete old copy\n", filename);
  766. X            return 1;
  767. X        }
  768. X#  define EXTRA_ARGS
  769. X#else /* VMS */
  770. X#  define EXTRA_ARGS   ,"rfm=stmlf","rat=cr"
  771. X#endif /* ?VMS */
  772. X
  773. X        mask = umask(0);   /* now know we own it */
  774. X        outfd = creat(filename, 0777 & pInfo->unix_attr  EXTRA_ARGS);
  775. X        umask(mask);                                            /* VMS, Unix */
  776. X    }
  777. X#else /* !UNIX || AMIGA */  /* file permissions set after file closed */
  778. X#if defined(MACOS) && defined(MPW) && !defined(MCH_MACINTOSH)
  779. X    outfd = creat(filename);                         /* Mac MPW C compiler */
  780. X#else /* !(Macintosh MPW 3.2 C) */
  781. X    outfd = creat(filename, S_IWRITE | S_IREAD);     /* DOS, OS2, Mac, Amiga */
  782. X#endif /* ?(Macintosh MPW 3.2 C) */
  783. X#endif /* ?(UNIX && !AMIGA) */
  784. X
  785. X    if (outfd < 1) {
  786. X        fprintf(stderr, "\n%s:  cannot create\n", filename);
  787. X        return 1;
  788. X    }
  789. X
  790. X/*---------------------------------------------------------------------------
  791. X    If newly created file is in text mode and should be binary (to disable
  792. X    automatic CR/LF translations), either close it and reopen as binary or
  793. X    else change the mode to binary (DOS, OS/2).  If it is already binary and
  794. X    should be text, change the mode to text (Mac).
  795. X  ---------------------------------------------------------------------------*/
  796. X
  797. X#ifndef UNIX
  798. X#ifdef THINK_C
  799. X    /*
  800. X     * THINKC's stdio routines have the horrible habit of
  801. X     * making any file you open look like generic files.
  802. X     * This code tells the OS that it's a text file.
  803. X     */
  804. X    if (aflag) {
  805. X        fileParam pb;
  806. X        OSErr err;
  807. X
  808. X        CtoPstr(filename);
  809. X        pb.ioNamePtr = (StringPtr)filename;
  810. X        pb.ioVRefNum = 0;
  811. X        pb.ioFVersNum = 0;
  812. X        pb.ioFDirIndex = 0;
  813. X        err = PBGetFInfo(&pb,0);
  814. X        if (err == noErr) {
  815. X            pb.ioFlFndrInfo.fdCreator = '\?\?\?\?';
  816. X            pb.ioFlFndrInfo.fdType = 'TEXT';
  817. X            err = PBSetFInfo(&pb, 0);
  818. X        }
  819. X        PtoCstr(filename);
  820. X    }
  821. X#endif /* THINK_C */
  822. X
  823. X    if (!aflag) {
  824. X#ifdef DOS_OS2
  825. X        if (setmode(outfd, O_BINARY) == -1) {
  826. X#else /* !DOS_OS2 */
  827. X        close(outfd);
  828. X        if ((outfd = open(filename, O_RDWR | O_BINARY)) < 1) {
  829. X#endif /* ?DOS_OS2 */
  830. X            fprintf(stderr, "Can't make output file binary:  %s\n", filename);
  831. X            return 1;
  832. X        }
  833. X    }
  834. X#endif /* !UNIX */
  835. X
  836. X    return 0;
  837. X}
  838. X
  839. X#endif /* !VMS */
  840. X
  841. X
  842. X
  843. X
  844. X
  845. X/****************************/
  846. X/* Function FillBitBuffer() */
  847. X/****************************/
  848. X
  849. Xint FillBitBuffer()
  850. X{
  851. X    /*
  852. X     * Fill bitbuf, which is 32 bits.  This function is only used by the
  853. X     * READBIT and PEEKBIT macros (which are used by all of the uncompression
  854. X     * routines).
  855. X     */
  856. X    UWORD temp;
  857. X
  858. X    zipeof = 1;
  859. X    while (bits_left < 25 && ReadByte(&temp) == 8)
  860. X    {
  861. X      bitbuf |= (ULONG)temp << bits_left;
  862. X      bits_left += 8;
  863. X      zipeof = 0;
  864. X    }
  865. X    return 0;
  866. X}
  867. X
  868. X
  869. X
  870. X
  871. X
  872. X/***********************/
  873. X/* Function ReadByte() */
  874. X/***********************/
  875. X
  876. Xint ReadByte(x)
  877. XUWORD *x;
  878. X{
  879. X    /*
  880. X     * read a byte; return 8 if byte available, 0 if not
  881. X     */
  882. X
  883. X
  884. X    if (csize-- <= 0)
  885. X        return 0;
  886. X
  887. X    if (incnt == 0) {
  888. X        if ((incnt = read(zipfd, (char *)inbuf, INBUFSIZ)) <= 0)
  889. X            return 0;
  890. X        /* buffer ALWAYS starts on a block boundary:  */
  891. X        cur_zipfile_bufstart += INBUFSIZ;
  892. X        inptr = inbuf;
  893. X#ifdef CRYPT
  894. X        if (pInfo->encrypted) {
  895. X            byte *p;
  896. X            int n, t;
  897. X
  898. X        for (n = incnt > csize + 1 ? (int)csize + 1 : incnt, p = inptr;
  899. X                 n--; p++)
  900. X                *p = DECRYPT(*p);
  901. X        }
  902. X#endif /* CRYPT */
  903. X    }
  904. X    *x = *inptr++;
  905. X    --incnt;
  906. X    return 8;
  907. X}
  908. X
  909. X
  910. X
  911. X
  912. X
  913. X#ifndef VMS   /* for VMS use code in vms.c */
  914. X
  915. X/**************************/
  916. X/* Function FlushOutput() */
  917. X/**************************/
  918. X
  919. Xint FlushOutput()
  920. X{
  921. X    /*
  922. X     * flush contents of output buffer; return PK-type error code
  923. X     */
  924. X#ifndef DOS_OS2
  925. X#   define CTRLZ  26
  926. X    int saved_ctrlZ = FALSE;
  927. X#endif /* !DOS_OS2 */
  928. X    int len;
  929. X
  930. X
  931. X    if (disk_full) {
  932. X        outpos += outcnt;   /* fake emptied buffer */
  933. X        outcnt = 0;
  934. X        outptr = outbuf;
  935. X        return 50;          /* ignore rest of this file */
  936. X    }
  937. X
  938. X    if (outcnt) {
  939. X        UpdateCRC(outbuf, outcnt);
  940. X
  941. X        if (!tflag) {
  942. X#ifndef DOS_OS2
  943. X            if (aflag) {
  944. X                if (outbuf[outcnt-1] == CTRLZ) {
  945. X                    --outcnt;
  946. X                    saved_ctrlZ = TRUE;
  947. X                }
  948. X                len = dos2unix(outbuf, outcnt);
  949. X            } else
  950. X#endif /* !DOS_OS2 */
  951. X                len = outcnt;
  952. X            if (write(outfd, (char *)outout, len) != len)
  953. X#ifdef DOS_OS2
  954. X                if (!cflag)           /* ^Z treated as EOF, removed with -c */
  955. X#else /* !DOS_OS2 */
  956. X#ifdef MINIX
  957. X                if (errno == EFBIG)
  958. X                    if (write(fd, outout, len/2) != len/2  ||
  959. X                        write(fd, outout+len/2, len/2) != len/2)
  960. X#endif /* MINIX */
  961. X#endif /* ?DOS_OS2 */
  962. X                {
  963. X                    /* GRR: add test for force_flag when has its own switch */
  964. X                    fprintf(stderr,
  965. X                      "\n%s:  write error (disk full?).  Continue? (y/n/^C) ",
  966. X                      filename);
  967. X                    FFLUSH   /* for Amiga and Mac MPW */
  968. X                    fgets(answerbuf, 9, stdin);
  969. X                    if (*answerbuf == 'y')   /* stop writing to this file */
  970. X                        disk_full = 1;       /*  (outfd bad?), but new OK */
  971. X                    else
  972. X                        disk_full = 2;       /* no:  exit program */
  973. X                    return 50;    /* 50:  disk full */
  974. X                }
  975. X        }
  976. X        outpos += outcnt;
  977. X        outcnt = 0;
  978. X        outptr = outbuf;
  979. X#ifndef DOS_OS2
  980. X        if (saved_ctrlZ) {
  981. X            *outptr++ = CTRLZ;
  982. X            ++outcnt;
  983. X        }
  984. X#endif /* !DOS_OS2 */
  985. X    }
  986. X    return (0);                 /* 0:  no error */
  987. X}
  988. X
  989. X#endif /* !VMS */
  990. X
  991. X
  992. X
  993. X
  994. X
  995. X#ifndef DOS_OS2   /* GRR:  rewrite this for generic text conversions */
  996. X
  997. X/***********************/
  998. X/* Function dos2unix() */
  999. X/***********************/
  1000. X
  1001. Xstatic int dos2unix(buf, len)
  1002. Xunsigned char *buf;
  1003. Xint len;
  1004. X{
  1005. X    int new_len;
  1006. X    int i;
  1007. X    unsigned char *walker;
  1008. X
  1009. X    new_len = len;
  1010. X    walker = outout;
  1011. X#ifdef MACOS
  1012. X    /*
  1013. X     * Mac wants to strip LFs instead CRs from CRLF pairs
  1014. X     */
  1015. X    if (CR_flag && *buf == LF) {
  1016. X        buf++;
  1017. X        new_len--;
  1018. X        len--;
  1019. X        CR_flag = buf[len] == CR;
  1020. X    }
  1021. X    else
  1022. X        CR_flag = buf[len - 1] == CR;
  1023. X    for (i = 0; i < len; i += 1) {
  1024. X        *walker++ = ascii_to_native(*buf);
  1025. X        if (*buf == LF) walker[-1] = CR;
  1026. X        if (*buf++ == CR && *buf == LF) {
  1027. X            new_len--;
  1028. X            buf++;
  1029. X            i++;
  1030. X        }
  1031. X    }
  1032. X#else
  1033. X    if (CR_flag && *buf != LF)
  1034. X        *walker++ = ascii_to_native(CR);
  1035. X    CR_flag = buf[len - 1] == CR;
  1036. X    for (i = 0; i < len; i += 1) {
  1037. X        *walker++ = ascii_to_native(*buf);
  1038. X        if (*buf++ == CR && *buf == LF) {
  1039. X            new_len--;
  1040. X            walker[-1] = ascii_to_native(*buf++);
  1041. X            i++;
  1042. X        }
  1043. X    }
  1044. X    /*
  1045. X     * If the last character is a CR, then "ignore it" for now...
  1046. X     */
  1047. X    if (walker[-1] == ascii_to_native(CR))
  1048. X        new_len--;
  1049. X#endif
  1050. X    return new_len;
  1051. X}
  1052. X
  1053. X#endif /* !DOS_OS2 */
  1054. X
  1055. X
  1056. X
  1057. X
  1058. X
  1059. X#ifdef DOS_OS2
  1060. X
  1061. X/**************************************/
  1062. X/* Function set_file_time_and_close() */
  1063. X/**************************************/
  1064. X
  1065. Xvoid set_file_time_and_close()
  1066. X /*
  1067. X  * MS-DOS AND OS/2 VERSION (Mac, Unix/VMS versions are below)
  1068. X  *
  1069. X  * Set the output file date/time stamp according to information from the
  1070. X  * zipfile directory record for this member, then close the file and set
  1071. X  * its permissions (archive, hidden, read-only, system).  Aside from closing
  1072. X  * the file, this routine is optional (but most compilers support it).
  1073. X  */
  1074. X{
  1075. X/*---------------------------------------------------------------------------
  1076. X    Allocate local variables needed by OS/2 and Turbo C.
  1077. X  ---------------------------------------------------------------------------*/
  1078. X
  1079. X#ifdef OS2              /* (assuming only MSC or MSC-compatible compilers
  1080. X                         * for this part) */
  1081. X
  1082. X    union {
  1083. X        FDATE fd;               /* system file date record */
  1084. X        UWORD zdate;            /* date word */
  1085. X    } ud;
  1086. X
  1087. X    union {
  1088. X        FTIME ft;               /* system file time record */
  1089. X        UWORD ztime;            /* time word */
  1090. X    } ut;
  1091. X
  1092. X    FILESTATUS fs;
  1093. X
  1094. X#else                           /* !OS2 */
  1095. X#ifdef __TURBOC__
  1096. X
  1097. X    union {
  1098. X        struct ftime ft;        /* system file time record */
  1099. X        struct {
  1100. X            UWORD ztime;        /* date and time words */
  1101. X            UWORD zdate;        /* .. same format as in .ZIP file */
  1102. X        } zt;
  1103. X    } td;
  1104. X
  1105. X#endif                          /* __TURBOC__ */
  1106. X#endif                          /* !OS2 */
  1107. X
  1108. X/*---------------------------------------------------------------------------
  1109. X     Do not attempt to set the time stamp on standard output.
  1110. X  ---------------------------------------------------------------------------*/
  1111. X
  1112. X    if (cflag) {
  1113. X        close(outfd);
  1114. X        return;
  1115. X    }
  1116. X
  1117. X/*---------------------------------------------------------------------------
  1118. X    Copy and/or convert time and date variables, if necessary; then set the
  1119. X    file time/date.
  1120. X  ---------------------------------------------------------------------------*/
  1121. X
  1122. X#ifdef OS2
  1123. X    DosQFileInfo(outfd, 1, &fs, sizeof(fs));
  1124. X    ud.zdate = lrec.last_mod_file_date;
  1125. X    ut.ztime = lrec.last_mod_file_time;
  1126. X    fs.fdateLastWrite = ud.fd;
  1127. X    fs.ftimeLastWrite = ut.ft;
  1128. X    fs.attrFile = pInfo->dos_attr; /* hidden, system, archive, read-only */
  1129. X    DosSetFileInfo(outfd, 1, (PBYTE) &fs, sizeof(fs));
  1130. X#else /* !OS2 */
  1131. X#ifdef __TURBOC__
  1132. X    td.zt.ztime = lrec.last_mod_file_time;
  1133. X    td.zt.zdate = lrec.last_mod_file_date;
  1134. X    setftime(outfd, &td.ft);
  1135. X#else /* !__TURBOC__ */
  1136. X    _dos_setftime(outfd, lrec.last_mod_file_date, lrec.last_mod_file_time);
  1137. X#endif /* ?__TURBOC__ */
  1138. X#endif /* ?OS2 */
  1139. X
  1140. X/*---------------------------------------------------------------------------
  1141. X    And finally we can close the file...at least everybody agrees on how to
  1142. X    do *this*.  I think...  Oh yeah, also change the mode according to the
  1143. X    stored file attributes, since we didn't do that when we opened the dude.
  1144. X  ---------------------------------------------------------------------------*/
  1145. X
  1146. X    close(outfd);
  1147. X
  1148. X#ifdef OS2
  1149. X    if (longname)
  1150. X        SetLongNameEA(filename, longfilename);
  1151. X#else /* !OS2 */
  1152. X#ifdef __TURBOC__
  1153. X    if (_chmod(filename, 1, pInfo->dos_attr) != pInfo->dos_attr)
  1154. X        fprintf(stderr, "\nwarning:  file attributes may not be correct\n");
  1155. X#else /* !__TURBOC__ */
  1156. X    _dos_setfileattr(filename, pInfo->dos_attr);
  1157. X#endif /* ?__TURBOC__ */
  1158. X#endif /* ?OS2 */
  1159. X
  1160. X} /* end function set_file_time_and_close() (DOS, OS/2) */
  1161. X
  1162. X
  1163. X
  1164. X
  1165. X
  1166. X#else                           /* !DOS_OS2 */
  1167. X#ifdef MACOS                    /* Mac */
  1168. X
  1169. X/**************************************/
  1170. X/* Function set_file_time_and_close() */
  1171. X/**************************************/
  1172. X
  1173. Xvoid set_file_time_and_close()
  1174. X /*
  1175. X  * MAC VERSION
  1176. X  */
  1177. X{
  1178. X    long m_time;
  1179. X    DateTimeRec dtr;
  1180. X    ParamBlockRec pbr;
  1181. X    OSErr err;
  1182. X
  1183. X    if (outfd != 1) {
  1184. X        close(outfd);
  1185. X
  1186. X        /*
  1187. X         * Macintosh bases all file modification times on the number of seconds
  1188. X         * elapsed since Jan 1, 1904, 00:00:00.  Therefore, to maintain
  1189. X         * compatibility with MS-DOS archives, which date from Jan 1, 1980,
  1190. X         * with NO relation to GMT, the following conversions must be made:
  1191. X         *      the Year (yr) must be incremented by 1980;
  1192. X         *      and converted to seconds using the Mac routine Date2Secs(),
  1193. X         *      almost similar in complexity to the Unix version :-)
  1194. X         *                                     J. Lee
  1195. X         */
  1196. X
  1197. X        dtr.year = (((lrec.last_mod_file_date >> 9) & 0x7f) + 1980);
  1198. X        dtr.month = ((lrec.last_mod_file_date >> 5) & 0x0f);
  1199. X        dtr.day = (lrec.last_mod_file_date & 0x1f);
  1200. X
  1201. X        dtr.hour = ((lrec.last_mod_file_time >> 11) & 0x1f);
  1202. X        dtr.minute = ((lrec.last_mod_file_time >> 5) & 0x3f);
  1203. X        dtr.second = ((lrec.last_mod_file_time & 0x1f) * 2);
  1204. X
  1205. X        Date2Secs(&dtr, (unsigned long *)&m_time);
  1206. X        CtoPstr(filename);
  1207. X        pbr.fileParam.ioNamePtr = (StringPtr)filename;
  1208. X        pbr.fileParam.ioVRefNum = pbr.fileParam.ioFVersNum =
  1209. X          pbr.fileParam.ioFDirIndex = 0;
  1210. X        err = PBGetFInfo(&pbr, 0L);
  1211. X        pbr.fileParam.ioFlMdDat = pbr.fileParam.ioFlCrDat = m_time;
  1212. X        if (err == noErr)
  1213. X            err = PBSetFInfo(&pbr, 0L);
  1214. X        if (err != noErr)
  1215. X            printf("error:  can't set the time for %s\n", filename);
  1216. X
  1217. X        /* set read-only perms if needed */
  1218. X        if (err != noErr && pInfo->unix_attr != 0)
  1219. X            err = SetFLock((ConstStr255Param)filename, 0);
  1220. X        PtoCstr(filename);
  1221. X    }
  1222. X}
  1223. X
  1224. X
  1225. X
  1226. X
  1227. X
  1228. X#else                                /* !MACOS... */
  1229. X#if !defined(MTS) && !defined(VMS)   /* && !MTS (can't do) && !VMS: only one
  1230. X                                      * left is UNIX (for VMS use code in
  1231. X                                      * vms.c--old VMS code below is retained
  1232. X                                      * in case of problems and will be removed
  1233. X                                      * in a later release) */
  1234. X
  1235. X/**************************************/
  1236. X/* Function set_file_time_and_close() */
  1237. X/**************************************/
  1238. X
  1239. Xvoid set_file_time_and_close()
  1240. X /*
  1241. X  * UNIX AND VMS VERSION (MS-DOS & OS/2, Mac versions are above)
  1242. X  */
  1243. X{
  1244. X    static short yday[]={0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
  1245. X    long m_time;
  1246. X    int yr, mo, dy, hh, mm, ss, leap, days=0;
  1247. X#ifdef VMS
  1248. X#   define YRBASE  0
  1249. X    char timbuf[24];
  1250. X    static char *month[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
  1251. X                            "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
  1252. X    struct VMStimbuf {
  1253. X        char *actime;           /* VMS revision date, ASCII format */
  1254. X        char *modtime;          /* VMS creation date, ASCII format */
  1255. X    } ascii_times;
  1256. X#else /* !VMS */
  1257. X    struct utimbuf {
  1258. X        time_t actime;          /* new access time */
  1259. X        time_t modtime;         /* new modification time */
  1260. X    } tp;
  1261. X#ifdef AMIGA
  1262. X#   define YRBASE  1978         /* in AmigaDos, counting begins 01-Jan-1978 */
  1263. X    struct DateStamp myadate;
  1264. X/*  extern char *_TZ;   no longer used? */
  1265. X#else /* !AMIGA */
  1266. X#   define YRBASE  1970
  1267. X#ifdef BSD
  1268. X    static struct timeb tbp;
  1269. X#else /* !BSD */
  1270. X    extern long timezone;
  1271. X#endif /* ?BSD */
  1272. X#endif /* ?AMIGA */
  1273. X#endif /* ?VMS */
  1274. X
  1275. X
  1276. X    /*
  1277. X     * Close the file *before* setting its time under Unix, AmigaDos and VMS.
  1278. X     */
  1279. X#ifdef AMIGA
  1280. X    if (cflag)                  /* can't set time on stdout */
  1281. X        return;
  1282. X    close(outfd);
  1283. X#else /* !AMIGA */
  1284. X    close(outfd);
  1285. X    if (cflag)                  /* can't set time on stdout */
  1286. X        return;
  1287. X#endif /* ?AMIGA */
  1288. X
  1289. X    /*
  1290. X     * These date conversions look a little weird, so I'll explain.
  1291. X     * UNIX bases all file modification times on the number of seconds
  1292. X     * elapsed since Jan 1, 1970, 00:00:00 GMT.  Therefore, to maintain
  1293. X     * compatibility with MS-DOS archives, which date from Jan 1, 1980,
  1294. X     * with NO relation to GMT, the following conversions must be made:
  1295. X     *      the Year (yr) must be incremented by 10;
  1296. X     *      the Date (dy) must be decremented by 1;
  1297. X     *      and the whole mess must be adjusted by TWO factors:
  1298. X     *          relationship to GMT (ie.,Pacific Time adds 8 hrs.),
  1299. X     *          and whether or not it is Daylight Savings Time.
  1300. X     * Also, the usual conversions must take place to account for leap years,
  1301. X     * etc.
  1302. X     *                                     C. Seaman
  1303. X     */
  1304. X
  1305. X    /* dissect date */
  1306. X    yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
  1307. X    mo = ((lrec.last_mod_file_date >> 5) & 0x0f) - 1;
  1308. X    dy = (lrec.last_mod_file_date & 0x1f) - 1;
  1309. X
  1310. X    /* dissect time */
  1311. X    hh = (lrec.last_mod_file_time >> 11) & 0x1f;
  1312. X    mm = (lrec.last_mod_file_time >> 5) & 0x3f;
  1313. X    ss = (lrec.last_mod_file_time & 0x1f) * 2;
  1314. X
  1315. X#ifdef VMS
  1316. X    sprintf(timbuf, "%02d-%3s-%04d %02d:%02d:%02d.00", dy+1, month[mo],
  1317. X      yr, hh, mm, ss);
  1318. X
  1319. X    ascii_times.actime = timbuf;
  1320. X    ascii_times.modtime = timbuf;
  1321. X
  1322. X    if ((mm = VMSmunch(filename, SET_TIMES, &ascii_times)) != RMS$_NMF)
  1323. X        fprintf(stderr, "error %d:  can't set the time for %s\n", mm, filename);
  1324. X
  1325. X#else /* !VMS */
  1326. X    /* leap = # of leap years from BASE up to but not including current year */
  1327. X    leap = ((yr + YRBASE - 1) / 4);   /* leap year base factor */
  1328. X
  1329. X    /* How many days from BASE to this year? (& add expired days this year) */
  1330. X    days = (yr * 365) + (leap - 492) + yday[mo];
  1331. X
  1332. X    /* if year is a leap year and month is after February, add another day */
  1333. X    if ((mo > 1) && ((yr+YRBASE)%4 == 0) && ((yr+YRBASE) != 2100))
  1334. X        ++days;                 /* OK through 2199 */
  1335. X
  1336. X#ifdef AMIGA
  1337. X/*  _TZ = getenv("TZ"); does Amiga not have TZ and tzset() after all? */
  1338. X    myadate.ds_Days   =   days+dy-2;   /* off by one? */
  1339. X    myadate.ds_Minute =   hh*60+mm;
  1340. X    myadate.ds_Tick   =   ss*TICKS_PER_SECOND;
  1341. X
  1342. X    if (!(SetFileDate(filename, &myadate)))
  1343. X        fprintf(stderr, "error:  can't set the time for %s\n", filename);
  1344. X
  1345. X#else /* !AMIGA */
  1346. X    /* convert date & time to seconds relative to 00:00:00, 01/01/YRBASE */
  1347. X    m_time = ((days + dy) * 86400) + (hh * 3600) + (mm * 60) + ss;
  1348. X
  1349. X#ifdef BSD
  1350. X    ftime(&tbp);
  1351. X    m_time += tbp.timezone * 60L;
  1352. X#else /* !BSD */
  1353. X    tzset();                    /* set `timezone' */
  1354. X    m_time += timezone;         /* account for timezone differences */
  1355. X#endif /* ?BSD */
  1356. X
  1357. X    if (localtime(&m_time)->tm_isdst)
  1358. X        m_time -= 60L * 60L;    /* adjust for daylight savings time */
  1359. X
  1360. X    tp.actime = m_time;         /* set access time */
  1361. X    tp.modtime = m_time;        /* set modification time */
  1362. X
  1363. X    /* set the time stamp on the file */
  1364. X    if (utime(filename, &tp))
  1365. X        fprintf(stderr, "error:  can't set the time for %s\n", filename);
  1366. X#endif /* ?AMIGA */
  1367. X#endif /* ?VMS */
  1368. X}
  1369. X
  1370. X#endif                          /* !MTS && !VMS */
  1371. X#endif                          /* ?MACOS */
  1372. X#endif                          /* ?DOS_OS2 */
  1373. X
  1374. X
  1375. X
  1376. X
  1377. X
  1378. X/*******************************/
  1379. X/*  Non-echoing password code  */
  1380. X/*******************************/
  1381. X
  1382. X#ifdef EMX32
  1383. X#  undef DOS_OS2
  1384. X#  undef MSVMS
  1385. X#endif
  1386. X
  1387. X#ifdef CRYPT
  1388. X#ifndef DOS_OS2
  1389. X#ifdef VMS
  1390. X
  1391. Xint echo(opt)
  1392. X    int opt;
  1393. X{
  1394. X/*---------------------------------------------------------------------------
  1395. X    Based on VMSmunch.c, which in turn was based on Joe Meadows' file.c code.
  1396. X  ---------------------------------------------------------------------------
  1397. X     * For VMS v5.x:
  1398. X     *   IO$_SENSEMODE/SETMODE info:  Programming, Vol. 7A, System Programming,
  1399. X     *     I/O User's: Part I, sec. 8.4.1.1, 8.4.3, 8.4.5, 8.6
  1400. X     *   sys$assign(), sys$qio() info:  Programming, Vol. 4B, System Services,
  1401. X     *     System Services Reference Manual, pp. sys-23, sys-379
  1402. X     *   fixed-length descriptor info:  Programming, Vol. 3, System Services,
  1403. X     *     Intro to System Routines, sec. 2.9.2
  1404. X     * GRR, 15 Aug 91
  1405. X  ---------------------------------------------------------------------------*/
  1406. X    static struct dsc$descriptor_s DevDesc =
  1407. X        {9, DSC$K_DTYPE_T, DSC$K_CLASS_S, "SYS$INPUT"};
  1408. X     /* {dsc$w_length, dsc$b_dtype, dsc$b_class, dsc$a_pointer}; */
  1409. X    static short           DevChan, iosb[4];
  1410. X    static long            i, status;
  1411. X    static unsigned long   oldmode[2], newmode[2];   /* each = 8 bytes */
  1412. X  
  1413. X
  1414. X/*---------------------------------------------------------------------------
  1415. X    Assign a channel to standard input.
  1416. X  ---------------------------------------------------------------------------*/
  1417. X
  1418. X    status = sys$assign(&DevDesc, &DevChan, 0, 0);
  1419. X#ifdef DEBUG
  1420. X    printf("echo:  sys$assign returns status = %ld\n", status);
  1421. X#endif /* DEBUG */
  1422. X    if (!(status & 1)) return(status);
  1423. X
  1424. X/*---------------------------------------------------------------------------
  1425. X    Use sys$qio and the IO$_SENSEMODE function to determine the current tty
  1426. X    status (for password reading, could use IO$_READVBLK function instead,
  1427. X    but echo on/off will be more general).
  1428. X  ---------------------------------------------------------------------------*/
  1429. X
  1430. X    status = sys$qio(0, DevChan, IO$_SENSEMODE, &iosb, 0, 0,
  1431. X                     oldmode, 8, 0, 0, 0, 0);
  1432. X#ifdef DEBUG
  1433. X    printf("echo:  sys$qio(IO$_SENSEMODE) returns status = %ld\n", status);
  1434. X    printf("echo:  sys$qio(IO$_SENSEMODE) returns iosb status = %d\n", 
  1435. X      iosb[0]);
  1436. X#endif /* DEBUG */
  1437. X    if (!(status & 1)) return(status);
  1438. X    status = iosb[0];
  1439. X    if (!(status & 1)) return(status);
  1440. X
  1441. X/*---------------------------------------------------------------------------
  1442. X    Copy old mode into new-mode buffer, then modify to be either NOECHO or
  1443. X    ECHO (depending on function argument opt).
  1444. X  ---------------------------------------------------------------------------*/
  1445. X
  1446. X    newmode[0] = oldmode[0];
  1447. X    newmode[1] = oldmode[1];
  1448. X    if (opt == OFF)
  1449. X        newmode[1] |= TT$M_NOECHO;                      /* set NOECHO bit */
  1450. X    else
  1451. X        newmode[1] &= ~((unsigned long) TT$M_NOECHO);   /* clear NOECHO bit */
  1452. X#ifdef DEBUG
  1453. X    printf("echo:  current terminal status = %lx\n", oldmode[1]);
  1454. X    printf("echo:  current echo status = %s\n",
  1455. X      (oldmode[1] & TT$M_NOECHO)? "noecho" : "echo");
  1456. X    printf("echo:  new terminal status = %lx\n", newmode[1]);
  1457. X    printf("echo:  new echo status = %s\n",
  1458. X      (newmode[1] & TT$M_NOECHO)? "noecho" : "echo");
  1459. X#endif /* DEBUG */
  1460. X
  1461. X/*---------------------------------------------------------------------------
  1462. X    Use the IO$_SETMODE function to change the tty status.
  1463. X  ---------------------------------------------------------------------------*/
  1464. X
  1465. X    status = sys$qio(0, DevChan, IO$_SETMODE, &iosb, 0, 0,
  1466. X                     newmode, 8, 0, 0, 0, 0);
  1467. X#ifdef DEBUG
  1468. X    printf("echo:  sys$qio(IO$_SETMODE) returns status = %ld\n", status);
  1469. X    printf("echo:  sys$qio(IO$_SETMODE) returns iosb status = %d\n", iosb[0]);
  1470. X#endif /* DEBUG */
  1471. X    if (!(status & 1)) return(status);
  1472. X    status = iosb[0];
  1473. X    if (!(status & 1)) return(status);
  1474. X
  1475. X/*---------------------------------------------------------------------------
  1476. X    Deassign the sys$input channel by way of clean-up, then exit happily.
  1477. X  ---------------------------------------------------------------------------*/
  1478. X
  1479. X    status = sys$dassgn(DevChan);
  1480. X#ifdef DEBUG
  1481. X    printf("echo:  sys$dassgn returns status = %ld\n\n", status);
  1482. X#endif /* DEBUG */
  1483. X    if (!(status & 1)) return(status);
  1484. X
  1485. X    return SS$_NORMAL;   /* we be happy */
  1486. X
  1487. X} /* end function echo() */
  1488. X
  1489. X
  1490. X
  1491. X
  1492. X
  1493. X#else /* !VMS */
  1494. X
  1495. Xstatic int echofd = -1;    /* file descriptor whose echo is off */
  1496. X
  1497. Xvoid echoff(f)
  1498. Xint f;            /* file descriptor to turn echo off on */
  1499. X/* Turn echo off for file descriptor f.  Assumes that f is a tty device. */
  1500. X{
  1501. X  struct sgttyb sg;    /* tty device structure */
  1502. X
  1503. X  echofd = f;
  1504. X  GTTY(f, &sg);                    /* get settings */
  1505. X  sg.sg_flags &= ~ECHO;                /* turn echo off */
  1506. X  STTY(f, &sg);
  1507. X}
  1508. X
  1509. X
  1510. X
  1511. Xvoid echon()
  1512. X/* Turn echo back on for file descriptor echofd. */
  1513. X{
  1514. X  struct sgttyb sg;    /* tty device structure */
  1515. X
  1516. X  if (echofd != -1)
  1517. X  {
  1518. X    GTTY(echofd, &sg);                /* get settings */
  1519. X    sg.sg_flags |= ECHO;            /* turn echo on */
  1520. X    STTY(echofd, &sg);
  1521. X    echofd = -1;
  1522. X  }
  1523. X}
  1524. X
  1525. X#endif /* ?VMS */
  1526. X#endif /* !DOS_OS2 */
  1527. X
  1528. X
  1529. X
  1530. X
  1531. X
  1532. Xchar *getp(m, p, n)
  1533. Xchar *m;        /* prompt for password */
  1534. Xchar *p;        /* return value: line input */
  1535. Xint n;            /* bytes available in p[] */
  1536. X/* Get a password of length n-1 or less into *p using the prompt *m.
  1537. X   The entered password is not echoed.  Return p on success, NULL on
  1538. X   failure (can't get controlling tty). */
  1539. X{
  1540. X  char c;        /* one-byte buffer for read() to use */
  1541. X  int i;        /* number of characters input */
  1542. X  char *w;        /* warning on retry */
  1543. X
  1544. X#ifndef DOS_OS2
  1545. X#ifdef VMS
  1546. X  echo(OFF);                                    /* turn echo off */
  1547. X#else /* !VMS */
  1548. X  int f;        /* file decsriptor for tty device */
  1549. X
  1550. X  /* Turn off echo on tty */
  1551. X  if (!isatty(2))
  1552. X    return NULL;                /* error if not tty */
  1553. X  if ((f = open(ttyname(2), 0, 0)) == -1)
  1554. X    return NULL;
  1555. X  echoff(f);                    /* turn echo off */
  1556. X#endif /* ?VMS */
  1557. X#endif /* !DOS_OS2 */
  1558. X
  1559. X  /* Get password */
  1560. X  w = "";
  1561. X  do {
  1562. X#ifdef VMS   /* bug:  VMS adds '\n' to NULL fputs (apparently) */
  1563. X    if (*w)
  1564. X#endif /* VMS */
  1565. X    fputs(w, stderr);                /* warning if back again */
  1566. X    fputs(m, stderr);                /* prompt */
  1567. X    fflush(stderr);
  1568. X    i = 0;
  1569. X    do {                    /* read line, keeping n */
  1570. X#ifdef MSVMS
  1571. X      if ((c = (char)getch()) == '\r')
  1572. X        c = '\n';
  1573. X#else /* !MSVMS */
  1574. X      read(f, &c, 1);
  1575. X#endif /* ?MSVMS */
  1576. X      if (i < n)
  1577. X    p[i++] = c;
  1578. X    } while (c != '\n');
  1579. X    putc('\n', stderr);  fflush(stderr);
  1580. X    w = "(line too long--try again)\n";
  1581. X  } while (p[i-1] != '\n');
  1582. X  p[i-1] = 0;                    /* terminate at newline */
  1583. X
  1584. X#ifndef DOS_OS2
  1585. X#ifdef VMS
  1586. X  echo(ON);                                     /* turn echo back on */
  1587. X#else /* !VMS */
  1588. X  /* Turn echo back on */
  1589. X  echon();                    /* turn echo back on */
  1590. X  close(f);
  1591. X#endif /* ?VMS */
  1592. X#endif /* !DOS_OS2 */
  1593. X
  1594. X  /* Return pointer to password */
  1595. X  return p;
  1596. X}
  1597. X
  1598. X#endif /* CRYPT */
  1599. END_OF_FILE
  1600.   if test 29594 -ne `wc -c <'file_io.c'`; then
  1601.     echo shar: \"'file_io.c'\" unpacked with wrong size!
  1602.   fi
  1603.   # end of 'file_io.c'
  1604. fi
  1605. echo shar: End of archive 6 \(of 12\).
  1606. cp /dev/null ark6isdone
  1607. MISSING=""
  1608. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  1609.     if test ! -f ark${I}isdone ; then
  1610.     MISSING="${MISSING} ${I}"
  1611.     fi
  1612. done
  1613. if test "${MISSING}" = "" ; then
  1614.     echo You have unpacked all 12 archives.
  1615.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1616. else
  1617.     echo You still must unpack the following archives:
  1618.     echo "        " ${MISSING}
  1619. fi
  1620. exit 0
  1621. exit 0 # Just in case...
  1622.