home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3605 < prev    next >
Internet Message Format  |  1991-07-10  |  48KB

  1. From: dhesi@bsu-cs.bsu.edu (Rahul Dhesi)
  2. Newsgroups: alt.sources
  3. Subject: zoo 2.1 source part 05/15
  4. Message-ID: <12771@bsu-cs.bsu.edu>
  5. Date: 10 Jul 91 09:34:00 GMT
  6.  
  7. Checksum: 3273603874 (verify with "brik -cv")
  8. Submitted-by: dhesi@bsu-cs.bsu.edu
  9. Archive-name: zoo210/part05
  10.  
  11. ---- Cut Here and feed the following to sh ----
  12. #!/bin/sh
  13. # This is part 05 of zoo210
  14. # ============= makefile ==============
  15. if test -f 'makefile' -a X"$1" != X"-c"; then
  16.     echo 'x - skipping makefile (File already exists)'
  17. else
  18. echo 'x - extracting makefile (Text)'
  19. sed 's/^X//' << 'SHAR_EOF' > 'makefile' &&
  20. # derived from: @(#) makefile 2.2 88/01/27 19:37:59 
  21. # $Id: makefile,v 1.22 91/07/09 04:10:38 dhesi Exp $
  22. # Make Zoo
  23. #
  24. #The contents of this makefile are hereby released to the public domain.
  25. #                                  -- Rahul Dhesi 1991/07/05
  26. #
  27. # This makefile expects two macro names, `CFLAGS' and `EXTRA', to hold
  28. # all the switches to be supplied to the C compiler.  It also expects
  29. # a macro `LDFLAGS' to hold the switch for the loader when invoked.
  30. # The macro "MODEL" holds switches needed for both compile and link, 
  31. # such as "memory model" for Intel and Z8000 processors. OPTIM is the 
  32. # optimize option and may be set on the make command line to -O2 or 
  33. # whatever your compiler thinks is nice.
  34. #
  35. # To run lint, select an appropriate lint_* target (e.g. "make lint_sysv").
  36. X
  37. X
  38. MAKE = make          # needed for some systems e.g. older BSD
  39. X
  40. CC = cc
  41. CFLAGS =
  42. MODEL =
  43. EXTRA = -DBIG_MEM -DNDEBUG
  44. LINTFLAGS = -DLINT
  45. OPTIM = -O
  46. DESTDIR = /usr/local/bin
  47. X
  48. #List of all object files created for Zoo
  49. ZOOOBJS = addbfcrc.o addfname.o basename.o comment.o crcdefs.o \
  50. X        getfile.o lzc.o lzd.o machine.o makelist.o misc.o misc2.o \
  51. X        nextfile.o needed.o options.o parse.o portable.o prterror.o \
  52. X        version.o zoo.o zooadd.o zooadd2.o zoodel.o zooext.o zoofilt.o \
  53. X        zoolist.o zoopack.o io.o lzh.o maketbl.o maketree.o huf.o \
  54. X        encode.o decode.o
  55. X
  56. FIZOBJS = fiz.o addbfcrc.o portable.o crcdefs.o
  57. X
  58. .c.o :
  59. X    $(CC) $(CFLAGS) $(MODEL) $(EXTRA) $*.c
  60. X
  61. all : 
  62. X    @echo 'There is no default.  Please specify an appropriate target from'
  63. X    @echo 'the makefile, or type "make help" for more information'
  64. X
  65. help :
  66. X    @echo "Possible targets are as follows.  Please examine the makefile"
  67. X    @echo "for more information."
  68. X    @echo ' '
  69. X    @echo "generic:      generic **IX environment, minimal functionlity"
  70. X    @echo "bsd:          4.3BSD or reasonable equivalent"
  71. X    @echo "bsdansi:      4.3BSD with ANSI C"
  72. X    @echo "ultrix:       ULTRIX 4.1"
  73. X    @echo "convex:       Convex C200 series"
  74. X    @echo "sysv:         System V Release 2 or 3; or SCO Xenix"
  75. X    @echo "scodos:       Cross-compiler under SCO Xenix/UNIX for MS-DOS"
  76. X    @echo "xenix286:     Older Xenix/286 (not tested)"
  77. X    @echo "xenix68k:     Xenix/68000 (not tested)"
  78. X    @echo ' '
  79. X    @echo "install:      Move zoo to $(DESTDIR)/tzoo (alpha test)"
  80. X    @echo "inst_beta:    Move zoo to $(DESTDIR)/bzoo (beta test)"
  81. X    @echo "inst_prod:    Move zoo to $(DESTDIR)/zoo  (production)"
  82. X    @echo ' '
  83. X    @echo "lint_sysv:    Run lint for System V"
  84. X    @echo "lint_bsd:     Run lint for 4.3BSD"
  85. X    @echo "lint_generic: Run lint for generic **IX"
  86. X    @echo "lint_turboc:  Run lint under **IX for checking Turbo C/MSDOS code"
  87. X
  88. # install alpha zoo as "tzoo"
  89. install:
  90. X    mv zoo $(DESTDIR)/tzoo
  91. X
  92. # install beta zoo as "bzoo"
  93. inst_beta:
  94. X    mv zoo $(DESTDIR)/bzoo
  95. X
  96. # install production zoo as "zoo"
  97. inst_prod:
  98. X    mv zoo $(DESTDIR)/zoo
  99. X
  100. # executable targets
  101. TARGETS = zoo fiz
  102. X
  103. #######################################################################
  104. # SYSTEM-SPECIFIC TARGETS
  105. #######################################################################
  106. X
  107. # A generic system -- may have less than full functionality.
  108. # Compile with -g, since debugging will probably be needed.
  109. generic:
  110. X    $(MAKE) CFLAGS="-c -g -DGENERIC" $(TARGETS)
  111. X
  112. # Reasonably generic BSD 4.3
  113. bsd:
  114. X    $(MAKE) CFLAGS="-c $(OPTIM) -DBSD4_3" $(TARGETS)
  115. X
  116. # ULTRIX 4.1
  117. ultrix:
  118. X    $(MAKE) CFLAGS="-c $(OPTIM) -DULTRIX" $(TARGETS)
  119. X
  120. # BSD with ANSI C - works on MIPS and Ultrix/RISC compilers
  121. bsdansi:
  122. X    $(MAKE) CFLAGS="-c $(OPTIM) -DBSD4_3 -DANSI_HDRS" $(TARGETS)
  123. X
  124. # Convex C200 series
  125. convex:
  126. X    $(MAKE) CFLAGS="-c $(OPTIM) -DBSD4_3 -DANSI_HDRS" $(TARGETS)
  127. X
  128. # SysV.2, V.3, SCO Xenix
  129. sysv:
  130. X    $(MAKE) CFLAGS="-c $(OPTIM) -DSYS_V" $(TARGETS)
  131. X
  132. # DOS version cross compiled from SCO Xenix/UNIX
  133. scodos:
  134. X    $(MAKE) CFLAGS="-c $(OPTIM) -DTURBOC -DANSI_HDRS -DBIG_MEM" \
  135. X        EXTRA="-dos -Ml" LDFLAGS="-o zoo.exe" $(TARGETS)
  136. X
  137. # Tested for zoo 2.01 on: Xenix 3.4 on Greg Laskin's Intel 310/286;
  138. # SCO Xenix 2.2 on Robert Cliff's AT.
  139. # `-Ml' for large memory model, `-M2' to generate code for 80286 cpu,
  140. # `-F xxxx' for xxxx (hex) bytes of stack space.
  141. xenix286:
  142. X    @echo "Warning: xenix286 is not fully functional"
  143. X    $(MAKE) CFLAGS="-c $(OPTIM) -DSYS_V" \
  144. X        MODEL="-Ml -M2 -Md" \
  145. X        LDFLAGS="-s -n -Md -Mt500 -F 5000" $(TARGETS)
  146. X
  147. # Radio Shack Model 16 with Xenix/68000 3.01.01. "-DM_VOID" tells not 
  148. # to try to do a typedef of `void'. "-Dvoid=int" because compiler doesn't 
  149. # know about `void'.  `-s -n' strips and makes it shareable.  Used to work
  150. # with zoo 2.01; not tested with 2.1.
  151. xenix68k:
  152. X    $(MAKE) CFLAGS="-c $(OPTIM) -DSYS_V -DM_VOID -Dvoid=int" \
  153. X        LDFLAGS="-s -n" $(TARGETS)
  154. X
  155. #######################################################################
  156. # CLEANUP TARGETS
  157. #######################################################################
  158. X
  159. # standard clean -- remove all transient files
  160. clean :
  161. X    rm -f core a.out $(ZOOOBJS) $(FIZOBJS)
  162. X
  163. # object clean only -- just remove object files
  164. objclean:
  165. X    rm -f *.o
  166. X
  167. #######################################################################
  168. # BINARY TARGETS
  169. #######################################################################
  170. X
  171. zoo: $(ZOOOBJS)
  172. X    $(CC) -o zoo $(MODEL) $(LDFLAGS) $(ZOOOBJS)
  173. X
  174. fiz: $(FIZOBJS)
  175. X    $(CC) -o fiz $(MODEL) $(LDFLAGS) $(FIZOBJS)
  176. X
  177. #######################################################################
  178. # SELECTED TARGETS FOR LINT
  179. #######################################################################
  180. X
  181. # generic system V
  182. lint_sysv:
  183. X    echo $(ZOOOBJS) | sed -e 's/\.o/.c/g' | \
  184. X    xargs lint -DSYS_V $(EXTRA) $(LINTFLAGS) | \
  185. X    grep -v 'possible pointer alignment problem'
  186. X
  187. # generic BSD
  188. lint_bsd:
  189. X    echo $(ZOOOBJS) | sed -e 's/\.o/.c/g' | \
  190. X    xargs lint -DBSD4_3 $(EXTRA) $(LINTFLAGS) | \
  191. X    grep -v 'possible pointer alignment problem'
  192. X
  193. # generic **IX
  194. lint_generic:
  195. X    echo $(ZOOOBJS) | sed -e 's/\.o/.c/g' | \
  196. X    xargs lint -DGENERIC $(EXTRA) $(LINTFLAGS) | \
  197. X    grep -v 'possible pointer alignment problem'
  198. X
  199. # Cross-lint for checking Turbo C code under **IX.  For checking only;
  200. # compilation requires separate makefile called "makefile.tcc"
  201. lint_turboc:
  202. X    echo $(ZOOOBJS) turboc.c | sed -e 's/\.o/.c/g' | \
  203. X    xargs lint -DTURBOC -DCROSS_LINT $(EXTRA) $(LINTFLAGS)
  204. X
  205. #######################################################################
  206. # DEPENDENCIES
  207. #######################################################################
  208. # DO NOT DELETE THIS LINE -- it marks the beginning of this dependency list
  209. X
  210. addbfcrc.o: options.h
  211. addfname.o: /usr/include/stdio.h options.h various.h zoo.h zoofns.h zooio.h
  212. addfname.o: zoomem.h
  213. basename.o: /usr/include/stdio.h assert.h debug.h options.h parse.h various.h
  214. basename.o: zoo.h zoofns.h zooio.h
  215. bsd.o: /usr/include/sys/stat.h /usr/include/sys/time.h
  216. bsd.o: /usr/include/sys/types.h nixmode.i nixtime.i
  217. comment.o: /usr/include/signal.h /usr/include/stdio.h
  218. comment.o: /usr/include/sys/signal.h errors.i options.h portable.h various.h
  219. comment.o: zoo.h zoofns.h zooio.h
  220. crcdefs.o: options.h
  221. decode.o: /usr/include/stdio.h ar.h lzh.h options.h zoo.h
  222. encode.o: /usr/include/assert.h /usr/include/stdio.h ar.h errors.i lzh.h
  223. encode.o: options.h zoo.h
  224. fiz.o: /usr/include/stdio.h options.h portable.h various.h zoo.h zoofns.h
  225. fiz.o: zooio.h
  226. generic.o: /usr/include/sys/stat.h /usr/include/sys/types.h
  227. generic.o: /usr/include/time.h nixmode.i nixtime.i
  228. getfile.o: /usr/include/stdio.h options.h various.h zoo.h zoofns.h zooio.h
  229. getfile.o: zoomem.h
  230. huf.o: /usr/include/stdio.h ar.h errors.i lzh.h options.h zoo.h
  231. io.o: /usr/include/stdio.h ar.h errors.i lzh.h options.h portable.h zoo.h
  232. io.o: zooio.h
  233. lzc.o: /usr/include/stdio.h assert.h debug.h lzconst.h options.h various.h
  234. lzc.o: zoo.h zoofns.h zooio.h zoomem.h
  235. lzd.o: /usr/include/stdio.h assert.h debug.h lzconst.h options.h various.h
  236. lzd.o: zoo.h zoofns.h zooio.h zoomem.h
  237. lzh.o: /usr/include/stdio.h ar.h errors.i options.h zoo.h
  238. machine.o: /usr/include/stdio.h options.h various.h zoo.h zoofns.h zooio.h
  239. makelist.o: /usr/include/stdio.h assert.h debug.h errors.i options.h
  240. makelist.o: portable.h various.h zoo.h zoofns.h zooio.h
  241. maketbl.o: /usr/include/stdio.h ar.h lzh.h options.h zoo.h
  242. maketree.o: /usr/include/stdio.h ar.h lzh.h options.h zoo.h
  243. misc.o: /usr/include/signal.h /usr/include/stdio.h /usr/include/sys/signal.h
  244. misc.o: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
  245. misc2.o: /usr/include/stdio.h errors.i options.h portable.h various.h zoo.h
  246. misc2.o: zoofns.h zooio.h zoomem.h
  247. msdos.o: /usr/include/stdio.h errors.i options.h zoo.h zoofns.h zooio.h
  248. needed.o: /usr/include/stdio.h debug.h options.h portable.h various.h zoo.h
  249. needed.o: zoofns.h zooio.h
  250. nextfile.o: /usr/include/stdio.h options.h various.h zoo.h
  251. options.o: /usr/include/stdio.h errors.i options.h various.h zoo.h zoofns.h
  252. options.o: zooio.h
  253. parse.o: /usr/include/stdio.h assert.h options.h parse.h various.h zoo.h
  254. parse.o: zoofns.h zooio.h
  255. portable.o: /usr/include/stdio.h assert.h debug.h machine.h options.h
  256. portable.o: portable.h various.h zoo.h zoofns.h zooio.h
  257. prterror.o: /usr/include/stdio.h /usr/include/varargs.h options.h various.h
  258. prterror.o: zoofns.h zooio.h
  259. sysv.o: /usr/include/sys/stat.h /usr/include/sys/types.h /usr/include/time.h
  260. sysv.o: nixmode.i nixtime.i
  261. turboc.o: /usr/include/signal.h /usr/include/stdio.h /usr/include/sys/signal.h
  262. vms.o: /usr/include/time.h
  263. vmstime.o: /usr/include/stdio.h
  264. zoo.o: /usr/include/stdio.h errors.i options.h various.h zoo.h zoofns.h
  265. zoo.o: zooio.h zoomem.h
  266. zooadd.o: /usr/include/stdio.h debug.h errors.i options.h parse.h portable.h
  267. zooadd.o: various.h zoo.h zoofns.h zooio.h zoomem.h
  268. zooadd2.o: /usr/include/stdio.h assert.h debug.h errors.i options.h parse.h
  269. zooadd2.o: various.h zoo.h zoofns.h zooio.h
  270. zoodel.o: /usr/include/signal.h /usr/include/stdio.h /usr/include/sys/signal.h
  271. zoodel.o: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
  272. zooext.o: /usr/include/signal.h /usr/include/stdio.h /usr/include/sys/signal.h
  273. zooext.o: errors.i machine.h options.h parse.h portable.h various.h zoo.h
  274. zooext.o: zoofns.h zooio.h
  275. zoofilt.o: options.h
  276. zoolist.o: /usr/include/stdio.h errors.i options.h portable.h various.h zoo.h
  277. zoolist.o: zoofns.h zooio.h zoomem.h
  278. zoopack.o: /usr/include/signal.h /usr/include/stdio.h
  279. zoopack.o: /usr/include/sys/signal.h errors.i options.h portable.h various.h
  280. zoopack.o: zoo.h zoofns.h zooio.h
  281. SHAR_EOF
  282. chmod 0644 makefile ||
  283. echo 'restore of makefile failed'
  284. Wc_c="`wc -c < 'makefile'`"
  285. test 10232 -eq "$Wc_c" ||
  286.     echo 'makefile: original size 10232, current size' "$Wc_c"
  287. fi
  288. # ============= makefile.tcc ==============
  289. if test -f 'makefile.tcc' -a X"$1" != X"-c"; then
  290.     echo 'x - skipping makefile.tcc (File already exists)'
  291. else
  292. echo 'x - extracting makefile.tcc (Text)'
  293. sed 's/^X//' << 'SHAR_EOF' > 'makefile.tcc' &&
  294. # $Source: /usr/home/dhesi/zoo/RCS/makefile.tcc,v $
  295. # $Id: makefile.tcc,v 1.6 91/07/07 18:39:28 dhesi Exp $
  296. # Make Zoo -- works with Turbo C++ 1.0 under MS-DOS and
  297. # Don Kneller's NDMAKE version 4.31.
  298. #
  299. # compile is tcc (Turbo C++ 1.0)
  300. CC = tcc
  301. # assembler is tasm
  302. AS = tasm
  303. ASFLAGS =
  304. CFLAGS = -c -DTURBOC -DLINT
  305. X
  306. # char representing memory model (l = large, c = compact)
  307. MCHAR = c
  308. #
  309. #
  310. model = -m$(MCHAR)                    # compiler switch
  311. CRT0 = c:\tc\lib\c0$(MCHAR).obj    # C runtime object
  312. STDLIB = \tc\lib\c$(MCHAR).lib    # C standard library
  313. X
  314. EXTRA = -DBIG_MEM -DNDEBUG
  315. OPTIM = -O
  316. X
  317. .SUFFIXES : .exe .obj .asm .c
  318. X
  319. # Object files for zoo
  320. ZOOOBJS =     addbftcc.obj addfname.obj basename.obj comment.obj \
  321. X        crcdefs.obj getfile.obj lzc.obj lzd.obj machine.obj \
  322. X        makelist.obj misc.obj misc2.obj nextfile.obj needed.obj \
  323. X        options.obj parse.obj portable.obj prterror.obj \
  324. X        version.obj zoo.obj zooadd.obj zooadd2.obj zoodel.obj \
  325. X        zooext.obj zoofilt.obj zoolist.obj zoopack.obj \
  326. X        io.obj lzh.obj maketbl.obj maketree.obj huf.obj \
  327. X        encode.obj decode.obj \
  328. X        msdos.obj
  329. X
  330. # Object files for fiz
  331. FIZOBJS = fiz.obj addbftcc.obj portable.obj crcdefs.obj
  332. X
  333. #################################################################
  334. # default rule for assembly and compilation
  335. #################################################################
  336. X
  337. ## assembly
  338. ## .asm.obj :
  339. ##     $(AS) $(ASFLAGS) $*.asm
  340. X
  341. # C compilation
  342. .c.obj :
  343. X    $(CC) $(CFLAGS) $(model) $(EXTRA) $*.c
  344. X
  345. #################################################################
  346. # final link
  347. #################################################################
  348. X
  349. zoo.exe: $(ZOOOBJS)
  350. X    link /c /m /s $(CRT0) \
  351. X        $(ZOOOBJS),zoo.exe,zoo.map,$(STDLIB)
  352. X
  353. #################################################################
  354. # miscellaneous targets: install and cleanup
  355. #################################################################
  356. X
  357. install:  zoo.exe
  358. X    copy zoo.exe \bin\tzoo.exe
  359. X
  360. clean :
  361. X    del *.obj
  362. X
  363. #################################################################
  364. # dependencies
  365. #################################################################
  366. X
  367. addfname.obj: options.h various.h zoo.h zoofns.h zooio.h zoomem.h
  368. basename.obj: assert.h debug.h options.h parse.h various.h
  369. basename.obj: zoo.h zoofns.h zooio.h
  370. comment.obj: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
  371. crcdefs.obj: options.h
  372. decode.obj: ar.h lzh.h options.h zoo.h
  373. encode.obj: ar.h errors.i lzh.h options.h zoo.h
  374. fiz.obj: options.h portable.h various.h zoo.h zoofns.h zooio.h
  375. generic.obj: nixmode.i nixtime.i
  376. getfile.obj: options.h various.h zoo.h zoofns.h zooio.h zoomem.h
  377. huf.obj: ar.h errors.i lzh.h options.h zoo.h
  378. io.obj: ar.h errors.i lzh.h options.h portable.h zoo.h zooio.h
  379. lzc.obj: assert.h debug.h lzconst.h options.h various.h
  380. lzc.obj: zoo.h zoofns.h zooio.h zoomem.h
  381. lzd.obj: assert.h debug.h lzconst.h options.h various.h
  382. lzd.obj: zoo.h zoofns.h zooio.h zoomem.h
  383. lzh.obj: ar.h errors.i options.h zoo.h
  384. machine.obj: options.h various.h zoo.h zoofns.h zooio.h
  385. makelist.obj: assert.h debug.h errors.i options.h
  386. makelist.obj: portable.h various.h zoo.h zoofns.h zooio.h
  387. maketbl.obj: ar.h lzh.h options.h zoo.h
  388. maketree.obj: ar.h lzh.h options.h zoo.h
  389. misc.obj: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
  390. misc2.obj: errors.i options.h portable.h various.h zoo.h
  391. misc2.obj: zoofns.h zooio.h zoomem.h
  392. msdos.obj: errors.i options.h zoo.h zoofns.h zooio.h
  393. needed.obj: debug.h options.h portable.h various.h zoo.h
  394. needed.obj: zoofns.h zooio.h
  395. nextfile.obj: options.h various.h zoo.h
  396. options.obj: errors.i options.h various.h zoo.h zoofns.h zooio.h
  397. parse.obj: assert.h options.h parse.h various.h zoo.h
  398. parse.obj: zoofns.h zooio.h
  399. portable.obj: assert.h debug.h machine.h options.h
  400. portable.obj: portable.h various.h zoo.h zoofns.h zooio.h
  401. prterror.obj: options.h various.h zoofns.h zooio.h
  402. zoo.obj: errors.i options.h various.h zoo.h zoofns.h
  403. zoo.obj: zooio.h zoomem.h
  404. zooadd.obj: debug.h errors.i options.h parse.h portable.h
  405. zooadd.obj: various.h zoo.h zoofns.h zooio.h zoomem.h
  406. zooadd2.obj: assert.h debug.h errors.i options.h parse.h
  407. zooadd2.obj: various.h zoo.h zoofns.h zooio.h
  408. zoodel.obj: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
  409. zooext.obj: errors.i machine.h options.h parse.h portable.h various.h zoo.h
  410. zooext.obj: zoofns.h zooio.h
  411. zoofilt.obj: options.h
  412. zoolist.obj: errors.i options.h portable.h various.h zoo.h
  413. zoolist.obj: zoofns.h zooio.h zoomem.h
  414. zoopack.obj: errors.i options.h portable.h various.h
  415. zoopack.obj: zoo.h zoofns.h zooio.h
  416. SHAR_EOF
  417. chmod 0644 makefile.tcc ||
  418. echo 'restore of makefile.tcc failed'
  419. Wc_c="`wc -c < 'makefile.tcc'`"
  420. test 4490 -eq "$Wc_c" ||
  421.     echo 'makefile.tcc: original size 4490, current size' "$Wc_c"
  422. fi
  423. # ============= makelist.c ==============
  424. if test -f 'makelist.c' -a X"$1" != X"-c"; then
  425.     echo 'x - skipping makelist.c (File already exists)'
  426. else
  427. echo 'x - extracting makelist.c (Text)'
  428. sed 's/^X//' << 'SHAR_EOF' > 'makelist.c' &&
  429. #ifndef LINT
  430. /* @(#) makelist.c 2.3 88/01/24 12:46:44 */
  431. static char sccsid[]="@(#) makelist.c 2.3 88/01/24 12:46:44";
  432. #endif /* LINT */
  433. X
  434. /*
  435. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  436. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  437. */
  438. X
  439. #include "options.h"
  440. #include "portable.h"
  441. #include "errors.i"
  442. #include "zoo.h"
  443. #include "zooio.h"
  444. #include "various.h"
  445. X
  446. #include "zoofns.h"
  447. #include "assert.h"
  448. #include "debug.h"
  449. X
  450. char *nameptr PARMS((char *));
  451. void modpath PARMS((char *));
  452. X
  453. /*******************/
  454. /*
  455. makelist() gets all pathnames corresponding to a set of filespecs and
  456. adds them to a list.  Not more than "flistsize" pathnames are added.
  457. Into `longest' it returns the length of the longest name added, or
  458. zero if none added.
  459. X
  460. Files ignore1, ignore2, and ignore3 are not added to the list.
  461. A file that is a device/directory is also not added to the list.
  462. X
  463. However, if ignore1 is NULL, both these tests are skipped and all files
  464. will be added to the list.
  465. */
  466. X
  467. void makelist (argc, argv, flist, flistsize, ignore1, ignore2, ignore3, longest)
  468. int argc;               /* number of filespec supplied */
  469. char *argv[];           /* array of pointers to supplied filespecs */
  470. register char *flist[]; /* array of pointers to filenames we will add */
  471. int flistsize;          /* home many names we can use */
  472. char *ignore1, *ignore2, *ignore3; /* files to exclude from list */
  473. int *longest;        /* length of longest name in list */
  474. {
  475. X   char *this_path;        /* current pathname */
  476. X   int fptr;               /* pointer to within flist */
  477. X   register int i, j;      /* loop counters */
  478. X
  479. #ifdef WILDCARD
  480. X   char *pat_name;         /* filename part of pattern */
  481. #endif
  482. X
  483. X   int gap;                /* for Shell sort */
  484. X   
  485. X   flistsize--;            /* allow for one terminating NULL entry */
  486. X   fptr = *longest = 0;
  487. X
  488. X   assert(argc > 0);
  489. X
  490. #define WCLEN    4    /* length needed for wildcard, and a little extra */
  491. X
  492. X   while (argc > 0) {
  493. #ifdef WILDCARD
  494. X        int argok = 0;                                            /* arg not matched yet */
  495. #endif
  496. X      char *this_arg;
  497. X        this_arg = emalloc (strlen (*argv) + WCLEN);
  498. X        strcpy (this_arg, *argv);
  499. X
  500. X      /* Initialize fileset 0.  Select all files -- we will later
  501. X             filter out the ones wanted */
  502. #ifdef FOLD
  503. X      str_lwr (this_arg);
  504. #endif
  505. X
  506. #ifdef WILDCARD
  507. X      pat_name = str_dup (nameptr (this_arg));        /* pattern without path */
  508. #ifdef VER_CH /* trailing version field */
  509. {
  510. X   static char version_field[] = " *";
  511. X   char *p;
  512. X   p = strrchr (pat_name, VER_CH);
  513. X   if (p == NULL) {
  514. X      *version_field = VER_CH;
  515. X      pat_name = newcat (pat_name, version_field); /* adds trailing ";*" */
  516. X   }
  517. }
  518. #endif
  519. X        /*
  520. X        replace filename by wildcard;  however, if argument ends in slash, 
  521. X        then simply append wildcard so we get all files in that directory
  522. X        */
  523. #ifdef FORCESLASH
  524. X            fixslash (this_arg);                /* convert backslashes to slashes */
  525. #endif
  526. X
  527. X        if (*lastptr(this_arg) == *(char *) PATH_CH) {
  528. X            strcat (this_arg, WILDCARD);
  529. X            pat_name = "*";                    /* and select all files */
  530. X        } else
  531. #ifdef SPEC_WILD
  532. X            spec_wild (this_arg);
  533. #else
  534. X          strcpy (nameptr (this_arg), WILDCARD);
  535. #endif /* SPEC_WILD */
  536. #endif /* WILDCARD */
  537. X
  538. X      nextfile (0, this_arg, 0);
  539. X      while (fptr < flistsize && 
  540. X            (this_path = nextfile(1, (char *) NULL, 0)) != NULL) {
  541. X         char *this_name = nameptr (this_path);
  542. X            modpath (this_path);                    /* do any needed changes to path */
  543. X
  544. #ifdef IGNORECASE
  545. #define    COMPARE    str_icmp
  546. #else
  547. #define    COMPARE    strcmp
  548. #endif
  549. X            if (ignore1 != NULL) {
  550. X                if (samefile (this_name,ignore1)  ||    /* exclude ignored files */
  551. X                     samefile (this_name,ignore2)  ||
  552. X                     samefile (this_name,ignore3))
  553. X                    continue;
  554. X
  555. #ifdef CHEKUDIR
  556. X                if (isuadir(this_path))
  557. X                    continue;
  558. #else /* CHEKUDIR */
  559. # ifdef CHEKDIR
  560. X                if (isfdir(this_path))
  561. X                    continue;
  562. # endif /* CHEKDIR */
  563. #endif /* CHEKUDIR */
  564. X            } /* end if ignore1 ! = NULL */
  565. X
  566. /* 
  567. If WILDCARD is defined (e.g. AmigaDOS, MS-DOS, VAX/VMS), then nextfile()
  568. returns all filenames and we must now select the ones we need by pattern
  569. matching.  If WILDCARD is not defined (e.g. **IX), filenames have already been
  570. selected by the shell and need not be tested again. 
  571. */
  572. #ifdef WILDCARD
  573. X            if (match_half (this_name,pat_name) ||
  574. X                match_half (pat_name, "?-?") &&     /* character range */
  575. X                    *this_name >= *pat_name && *this_name <= pat_name[2])
  576. #endif
  577. X            {
  578. #ifdef WILDCARD
  579. X                argok = 1;                                    /* remember arg matched */
  580. #endif
  581. X                flist[fptr++] = str_dup (this_path);
  582. X                if (*longest < strlen(this_path))
  583. X                    *longest = strlen(this_path);
  584. X            }
  585. X
  586. X        } /* end while */
  587. #ifdef WILDCARD
  588. X        if (argok == 0) {                                    /* no match for argument */
  589. X            prterror ('e', "Could not open %s\n", *argv);
  590. X        }
  591. #endif
  592. X      argc--;
  593. X      argv++;
  594. X   }
  595. X   /* fptr is now 1 + index of last item in array */
  596. X
  597. X   if (this_path != NULL && fptr >= flistsize)
  598. X      prterror ('w', too_many_files, flistsize);
  599. #ifndef  DONT_SORT
  600. X   /* Shell sort -- K&R p. 58 */
  601. X   for (gap = fptr/2; gap > 0; gap /= 2)
  602. X      for (i = gap; i < fptr; i++)
  603. X         for (j = i - gap; j >= 0 && 
  604. X            strcmp(flist[j],flist[j+gap]) > 0; j -= gap) {
  605. X            char *t = flist[j]; flist[j] = flist[j+gap]; flist[j+gap] = t;
  606. X         }
  607. #endif /* DONT_SORT */
  608. X
  609. X   fptr--;     /* fptr is now index of last item in array */
  610. X
  611. X   /* Remove duplicates */
  612. X   for (i = 0; i < fptr; i++) {
  613. X      while (i<fptr && COMPARE(flist[i],flist[i+1]) == 0) {
  614. X         for (j = i; j < fptr; j++)
  615. X            flist[j] = flist[j+1];
  616. X         fptr--;
  617. X      }
  618. X   }
  619. X
  620. X   flist[++fptr] = NULL;      /* NULL entry terminates list */
  621. }
  622. X
  623. /*******
  624. modpath() makes any changes needed before pathname is stored;
  625. currently these could involve folding it to lower case and
  626. converting backslashes to forward slashes
  627. */
  628. X
  629. /*ARGSUSED*/
  630. void modpath (path)
  631. char *path;
  632. {
  633. #ifdef FOLD
  634. X    str_lwr (path);
  635. #endif
  636. X
  637. #ifdef FORCESLASH
  638. X    fixslash (path);                /* convert backslashes to slashes */
  639. #endif
  640. }
  641. X
  642. #ifdef CHEKDIR
  643. /* Function isfdir returns 1 if pathname is a directory else 0 */
  644. int isfdir (this_path)
  645. char *this_path;
  646. {
  647. X    int dir;
  648. X    ZOOFILE f;  
  649. X    f = zooopen (this_path, Z_READ);
  650. X    if (f == NOFILE)
  651. X        return 0;
  652. X    else {
  653. X        dir = isadir(f);  zooclose(f);
  654. X    }
  655. X    return (dir);
  656. }
  657. #endif
  658. SHAR_EOF
  659. chmod 0644 makelist.c ||
  660. echo 'restore of makelist.c failed'
  661. Wc_c="`wc -c < 'makelist.c'`"
  662. test 6198 -eq "$Wc_c" ||
  663.     echo 'makelist.c: original size 6198, current size' "$Wc_c"
  664. fi
  665. # ============= maketbl.c ==============
  666. if test -f 'maketbl.c' -a X"$1" != X"-c"; then
  667.     echo 'x - skipping maketbl.c (File already exists)'
  668. else
  669. echo 'x - extracting maketbl.c (Text)'
  670. sed 's/^X//' << 'SHAR_EOF' > 'maketbl.c' &&
  671. /*$Source: /usr/home/dhesi/zoo/RCS/maketbl.c,v $*/
  672. /*$Id: maketbl.c,v 1.8 91/07/09 01:39:52 dhesi Exp $*/
  673. /***********************************************************
  674. X    maketbl.c -- make table for decoding
  675. X
  676. Adapted from "ar" archiver written by Haruhiko Okumura.
  677. ***********************************************************/
  678. #include "options.h"
  679. #include "zoo.h"
  680. #include "ar.h"
  681. #include "lzh.h"
  682. X
  683. extern void prterror();
  684. X
  685. void make_table(nchar, bitlen, tablebits, table)
  686. int nchar;
  687. uchar bitlen[];
  688. int tablebits;
  689. ushort table[];
  690. {
  691. X    ushort count[17], weight[17], start[18], *p;
  692. X    uint i, k, len, ch, jutbits, avail, nextcode, mask;
  693. X
  694. X    for (i = 1; i <= 16; i++) count[i] = 0;
  695. X    for (i = 0; i < nchar; i++) count[bitlen[i]]++;
  696. X
  697. X    start[1] = 0;
  698. X    for (i = 1; i <= 16; i++)
  699. X        start[i + 1] = start[i] + (count[i] << (16 - i));
  700. X    if (start[17] != (ushort)((unsigned) 1 << 16))
  701. X        prterror('f', "Bad decode table\n");
  702. X
  703. X    jutbits = 16 - tablebits;
  704. X    for (i = 1; i <= tablebits; i++) {
  705. X        start[i] >>= jutbits;
  706. X        weight[i] = (unsigned) 1 << (tablebits - i);
  707. X    }
  708. X    while (i <= 16) {
  709. X       weight[i] = (unsigned) 1 << (16 - i);
  710. X       i++;
  711. X        }
  712. X
  713. X    i = start[tablebits + 1] >> jutbits;
  714. X    if (i != (ushort)((unsigned) 1 << 16)) {
  715. X        k = 1 << tablebits;
  716. X        while (i != k) table[i++] = 0;
  717. X    }
  718. X
  719. X    avail = nchar;
  720. X    mask = (unsigned) 1 << (15 - tablebits);
  721. X    for (ch = 0; ch < nchar; ch++) {
  722. X        if ((len = bitlen[ch]) == 0) continue;
  723. X        nextcode = start[len] + weight[len];
  724. X        if (len <= tablebits) {
  725. X            for (i = start[len]; i < nextcode; i++) table[i] = ch;
  726. X        } else {
  727. X            k = start[len];
  728. X            p = &table[k >> jutbits];
  729. X            i = len - tablebits;
  730. X            while (i != 0) {
  731. X                if (*p == 0) {
  732. X                    right[avail] = left[avail] = 0;
  733. X                    *p = avail++;
  734. X                }
  735. X                if (k & mask) p = &right[*p];
  736. X                else          p = &left[*p];
  737. X                k <<= 1;  i--;
  738. X            }
  739. X            *p = ch;
  740. X        }
  741. X        start[len] = nextcode;
  742. X    }
  743. }
  744. SHAR_EOF
  745. chmod 0644 maketbl.c ||
  746. echo 'restore of maketbl.c failed'
  747. Wc_c="`wc -c < 'maketbl.c'`"
  748. test 1836 -eq "$Wc_c" ||
  749.     echo 'maketbl.c: original size 1836, current size' "$Wc_c"
  750. fi
  751. # ============= maketree.c ==============
  752. if test -f 'maketree.c' -a X"$1" != X"-c"; then
  753.     echo 'x - skipping maketree.c (File already exists)'
  754. else
  755. echo 'x - extracting maketree.c (Text)'
  756. sed 's/^X//' << 'SHAR_EOF' > 'maketree.c' &&
  757. /*$Source: /usr/home/dhesi/zoo/RCS/maketree.c,v $*/
  758. /*$Id: maketree.c,v 1.6 91/07/09 01:39:51 dhesi Exp $*/
  759. /***********************************************************
  760. X    maketree.c -- make Huffman tree
  761. X
  762. Adapted from "ar" archiver written by Haruhiko Okumura.
  763. ***********************************************************/
  764. #include "options.h"
  765. #include "zoo.h"
  766. #include "ar.h"
  767. #include "lzh.h"
  768. X
  769. static int    n, heapsize;
  770. static short  heap[NC + 1];
  771. static ushort *freq, *sortptr, len_cnt[17];
  772. static uchar  *len;
  773. X
  774. static void count_len(i)  /* call with i = root */
  775. int i;
  776. {
  777. X    static int depth = 0;
  778. X
  779. X    if (i < n) len_cnt[(depth < 16) ? depth : 16]++;
  780. X    else {
  781. X        depth++;
  782. X        count_len((int) left [i]);
  783. X        count_len((int) right[i]);
  784. X        depth--;
  785. X    }
  786. }
  787. X
  788. static void make_len(root)
  789. int root;
  790. {
  791. X    int i, k;
  792. X    uint cum;
  793. X
  794. X    for (i = 0; i <= 16; i++) len_cnt[i] = 0;
  795. X    count_len(root);
  796. X    cum = 0;
  797. X    for (i = 16; i > 0; i--)
  798. X        cum += len_cnt[i] << (16 - i);
  799. X    while (cum != ((unsigned) 1 << 16)) {
  800. X        (void) fprintf(stderr, "17");
  801. X        len_cnt[16]--;
  802. X        for (i = 15; i > 0; i--) {
  803. X            if (len_cnt[i] != 0) {
  804. X                len_cnt[i]--;  len_cnt[i+1] += 2;  break;
  805. X            }
  806. X        }
  807. X        cum--;
  808. X    }
  809. X    for (i = 16; i > 0; i--) {
  810. X        k = len_cnt[i];
  811. X        while (--k >= 0) len[*sortptr++] = i;
  812. X    }
  813. }
  814. X
  815. static void downheap(i)
  816. int i;
  817. X    /* priority queue; send i-th entry down heap */
  818. {
  819. X    int j, k;
  820. X
  821. X    k = heap[i];
  822. X    while ((j = 2 * i) <= heapsize) {
  823. X        if (j < heapsize && freq[heap[j]] > freq[heap[j + 1]])
  824. X             j++;
  825. X        if (freq[k] <= freq[heap[j]]) break;
  826. X        heap[i] = heap[j];  i = j;
  827. X    }
  828. X    heap[i] = k;
  829. }
  830. X
  831. static void make_code(j, length, code)
  832. int j;
  833. uchar length[];
  834. ushort code[];
  835. {
  836. X    int    i;
  837. X    ushort start[18];
  838. X
  839. X    start[1] = 0;
  840. X    for (i = 1; i <= 16; i++)
  841. X        start[i + 1] = (start[i] + len_cnt[i]) << 1;
  842. X    for (i = 0; i < j; i++) code[i] = start[length[i]]++;
  843. }
  844. X
  845. int make_tree(nparm, freqparm, lenparm, codeparm)
  846. int nparm;
  847. ushort freqparm[];
  848. uchar lenparm[];
  849. ushort codeparm[];
  850. X    /* make tree, calculate len[], return root */
  851. {
  852. X    int i, j, k, avail;
  853. X
  854. X    n = nparm;  freq = freqparm;  len = lenparm;
  855. X    avail = n;  heapsize = 0;  heap[1] = 0;
  856. X    for (i = 0; i < n; i++) {
  857. X        len[i] = 0;
  858. X        if (freq[i]) heap[++heapsize] = i;
  859. X    }
  860. X    if (heapsize < 2) {
  861. X        codeparm[heap[1]] = 0;  return heap[1];
  862. X    }
  863. X    for (i = heapsize / 2; i >= 1; i--)
  864. X        downheap(i);  /* make priority queue */
  865. X    sortptr = codeparm;
  866. X    do {  /* while queue has at least two entries */
  867. X        i = heap[1];  /* take out least-freq entry */
  868. X        if (i < n) *sortptr++ = i;
  869. X        heap[1] = heap[heapsize--];
  870. X        downheap(1);
  871. X        j = heap[1];  /* next least-freq entry */
  872. X        if (j < n) *sortptr++ = j;
  873. X        k = avail++;  /* generate new node */
  874. X        freq[k] = freq[i] + freq[j];
  875. X        heap[1] = k;  downheap(1);  /* put into queue */
  876. X        left[k] = i;  right[k] = j;
  877. X    } while (heapsize > 1);
  878. X    sortptr = codeparm;
  879. X    make_len(k);
  880. X    make_code(nparm, lenparm, codeparm);
  881. X    return k;  /* return root */
  882. }
  883. SHAR_EOF
  884. chmod 0644 maketree.c ||
  885. echo 'restore of maketree.c failed'
  886. Wc_c="`wc -c < 'maketree.c'`"
  887. test 2836 -eq "$Wc_c" ||
  888.     echo 'maketree.c: original size 2836, current size' "$Wc_c"
  889. fi
  890. # ============= misc.c ==============
  891. if test -f 'misc.c' -a X"$1" != X"-c"; then
  892.     echo 'x - skipping misc.c (File already exists)'
  893. else
  894. echo 'x - extracting misc.c (Text)'
  895. sed 's/^X//' << 'SHAR_EOF' > 'misc.c' &&
  896. #ifndef LINT
  897. /* derived from: misc.c 2.6 88/08/15 16:17:23 */
  898. static char sccsid[]="$Source: /usr/home/dhesi/zoo/RCS/misc.c,v $\n\
  899. $Id: misc.c,v 1.8 91/07/09 01:54:08 dhesi Exp $";
  900. #endif /* LINT */
  901. X
  902. /*
  903. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  904. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  905. */
  906. #include "options.h"
  907. /* Miscellaneous functions needed by Zoo but not by Ooz */
  908. X
  909. #include "zoo.h"
  910. #include "zooio.h"
  911. #include "various.h"
  912. X
  913. #include "errors.i"
  914. #include "zoofns.h"
  915. #ifndef NOSIGNAL
  916. #include <signal.h>
  917. #endif
  918. X
  919. #ifdef NEEDCTYP
  920. #include <ctype.h>
  921. #else
  922. #include "portable.h"
  923. #endif
  924. X
  925. int ver_too_high PARMS((struct zoo_header *));
  926. X
  927. /*
  928. calc_ofs() is given a string that (supposedly) begins with a string
  929. of digits.  It returns a corresponding numeric value.  If no such
  930. string, it aborts the program with a fatal error message.
  931. */
  932. long calc_ofs(str)
  933. char *str;
  934. {
  935. X   long retval;
  936. X   char *p;
  937. X   retval = 0L;
  938. X   p = str; /* save for error message */
  939. X   while (isdigit(*str)) {
  940. X      retval = retval * 10L + (*str-'0');
  941. X      str++;
  942. X   }
  943. X   if (*str != '\0')
  944. X      prterror ('f', "Invalid number %s\n", p);
  945. X   return (retval);
  946. }
  947. X
  948. /*
  949. choosefname() decides which filename to use.  If a long filename is present,
  950. and if the syntax is that of UNIX, MS-DOS or the portable form, we use it;
  951. else we use the short filename. 
  952. */
  953. X
  954. char *choosefname(direntry)
  955. struct direntry *direntry;
  956. {
  957. X   char *retptr;                 /* pointer to name that we will return */
  958. X   switch (direntry->system_id) {
  959. X      case SYSID_NIX:
  960. X      case SYSID_PORTABLE:
  961. X      case SYSID_MS:
  962. X         retptr = (direntry->namlen != 0) ? direntry->lfname : direntry->fname;
  963. X         break;
  964. X      default:
  965. X         retptr = direntry->fname;
  966. X         break;
  967. X   }
  968. X   return (retptr);
  969. } /* choosefname() */
  970. X
  971. /* 
  972. combine() combines a directory name and a filename, making sure the
  973. two are separated by a path separator 
  974. */
  975. char *combine(result, dirname, fname)
  976. char result[], *dirname, *fname;
  977. {
  978. X   *result = '\0';
  979. X   if (*dirname != '\0') {
  980. #ifdef DIR_LBRACK /* hack for VMS */
  981. X      strcat (result, DIR_LBRACK);
  982. X
  983. X      /*  "/" => "[",  "./" => "[."  others => "[." */
  984. X
  985. X      if (dirname[0] == '/') {        /* absolute path => "[" */
  986. X         strcat (result, dirname + 1);
  987. X      } else if (dirname[0] == '.' && dirname[1] == '/') {
  988. X         strcat (result, CUR_DIR);
  989. X         strcat (result, dirname + 2);
  990. X      } else {
  991. X         strcat (result, CUR_DIR);
  992. X         strcat (result, dirname);
  993. X      }
  994. X
  995. /* folowing #ifdef block ought to be outside #ifdef DIR_LBRACK, and
  996. X   for loop should then start with p=result.  This is currently
  997. X   just a hack for VMS.
  998. */
  999. #ifdef DIR_SEP
  1000. X   if (DIR_SEP != '/') {   /* if char separating dirs is not "/",  */
  1001. X      char *p;
  1002. X      for (p = result+2;  *p != '\0';  p++) /* change it to underscore */
  1003. X        if (*p == DIR_SEP)
  1004. X           *p = '_';
  1005. X   }
  1006. #endif
  1007. X
  1008. X      {
  1009. X         char *p;
  1010. X         for (p = result; *p != '\0';  p++)
  1011. X         if (*p == '/')
  1012. X            *p = '.';
  1013. X      }
  1014. #else
  1015. X      strcat (result, dirname);
  1016. #endif
  1017. X      if (*lastptr(result) != *PATH_CH)
  1018. X         strcat(result, PATH_CH);
  1019. X   }
  1020. X
  1021. X   strcat(result, fname);
  1022. X   return (result);
  1023. }
  1024. X
  1025. /*
  1026. fullpath() accepts a pointer to a directory entry and returns the
  1027. combined directory name + filename.  The long filename is used
  1028. if available, else the short filename is used.
  1029. */
  1030. char *fullpath (direntry)
  1031. struct direntry *direntry;
  1032. {
  1033. X    static char result[PATHSIZE];
  1034. X    combine (result,
  1035. X                direntry->dirlen != 0 ? direntry->dirname : "", 
  1036. X                (direntry->namlen != 0) ? direntry->lfname : direntry->fname
  1037. X              );
  1038. X    return (result);
  1039. }
  1040. X
  1041. /* 
  1042. ver_too_high returns true if version of provided archive header is
  1043. too high for us to manipulate archive
  1044. */
  1045. X
  1046. int ver_too_high (header)
  1047. struct zoo_header *header;
  1048. {
  1049. X   return (header->major_ver > MAJOR_VER ||
  1050. X            (header->major_ver == MAJOR_VER &&
  1051. X             header->minor_ver > MINOR_VER));
  1052. }
  1053. X
  1054. /* 
  1055. rwheader() reads archive header, checks consistency, makes sure its
  1056. version number is not too high, updates it if too low, and seeks to
  1057. beginning of first directory entr.  If `preserve' is 1, it preserves
  1058. the header type;  if `preserve' is 0, it gives a fatal error message
  1059. if type is 0.
  1060. */
  1061. X
  1062. void rwheader (header, zoo_file, preserve)
  1063. register struct zoo_header *header;
  1064. ZOOFILE zoo_file;
  1065. int preserve;
  1066. {
  1067. X
  1068. X   frd_zooh (header, zoo_file);
  1069. X
  1070. X   if ((header->zoo_start + header->zoo_minus) != 0L)
  1071. X      prterror ('f', failed_consistency);
  1072. X   if (ver_too_high (header))
  1073. X      prterror ('f', wrong_version, header->major_ver, header->minor_ver);
  1074. X
  1075. X    if (preserve == 0 && header->type == 0)
  1076. X        prterror ('f', packfirst);
  1077. X
  1078. X   /* We reach here if the archive version is not too high.  Now, if it
  1079. X   isn't the same as ours, we bring it up to ours so the modified archive
  1080. X   will be safe from previous versions of Zoo */
  1081. X
  1082. X   if (header->major_ver != MAJOR_VER || header->minor_ver != MINOR_VER) {
  1083. X      header->major_ver = MAJOR_VER;
  1084. X      header->minor_ver = MINOR_VER;
  1085. X      zooseek (zoo_file, 0L, 0);            /* seek to beginning */
  1086. X      fwr_zooh (header, zoo_file);
  1087. X   }
  1088. X   zooseek (zoo_file, header->zoo_start, 0); /* seek to where data begins */
  1089. } /* rwheader */
  1090. X
  1091. /*
  1092. writedir() write a directory entry with keyboard interrupt disabled
  1093. */
  1094. void writedir (direntry, zoo_file)
  1095. struct direntry *direntry;
  1096. ZOOFILE zoo_file;
  1097. {
  1098. #ifndef NOSIGNAL  
  1099. X   T_SIGNAL (*oldsignal)();
  1100. X   oldsignal = signal (SIGINT, SIG_IGN);
  1101. #endif
  1102. X   if (fwr_dir (direntry, zoo_file) == -1)
  1103. X      prterror ('f', disk_full);
  1104. #ifndef NOSIGNAL
  1105. X   signal (SIGINT, oldsignal);
  1106. #endif
  1107. }
  1108. X
  1109. /* 
  1110. readdir() reads a directory entry from an archive.  If the directory
  1111. entry is invalid and if fail is 1, it causes a fatal error;
  1112. else it returns.  Return value is 0 if no error else -1;
  1113. */
  1114. X
  1115. int readdir (direntry, zoo_file, fail)    /* read directory entry */
  1116. register struct direntry *direntry;
  1117. ZOOFILE zoo_file;
  1118. int fail;                              /* 0 -> return, 1 -> abort on error */
  1119. {
  1120. X   if (frd_dir (direntry, zoo_file) < 0) {
  1121. X      if (fail) {
  1122. X         prterror ('f', bad_directory);
  1123. X      } else
  1124. X         return (-1);
  1125. X   }
  1126. X   if (direntry->zoo_tag != ZOO_TAG) {
  1127. X      if (fail)
  1128. X         prterror ('f', bad_directory);
  1129. X      else
  1130. X         return (-1);
  1131. X   }
  1132. X   return (0);
  1133. }
  1134. X
  1135. /* use pointer version below */
  1136. #ifdef COMMENT
  1137. /* instr() searches a string for a substring */
  1138. instr (s, t)      /* return index of string t in string s, -1 if none */
  1139. char s[], t[];    /*  .. from K&R page 67 */
  1140. {
  1141. X   int i;
  1142. X   register int j, k;
  1143. X   for (i = 0; s[i] != '\0'; i++) {
  1144. X      for (j = i, k = 0; t[k] != '\0' && s[j]==t[k]; j++, k++)
  1145. X         ;
  1146. X      if (t[k] == '\0')
  1147. X         return (i);
  1148. X   }
  1149. X   return (-1);
  1150. }
  1151. #endif /* COMMENT */
  1152. X
  1153. /* instr() searches a string for a substring */
  1154. /* from J. Brian Waters */
  1155. int instr (s, t)           /* return the position of t in s, -1 if none */
  1156. char *s, *t;                /*  a pointer version of K&R index function p.67 */
  1157. {               /* renamed to instr() to avoid conflicts with C RTL - JBW */
  1158. X
  1159. X   register char *i, *j, *k;
  1160. X
  1161. X   for (i = s; *i; i++) {
  1162. X      for (j = i, k = t; (*k) && (*j++ == *k); k++)
  1163. X         ;
  1164. X       if (!*k)
  1165. X         return ((int) (i - s));
  1166. X   }
  1167. X   return(-1);
  1168. }
  1169. X
  1170. /* cfactor() calculates the compression factor given a directory entry */
  1171. int cfactor (org_size, size_now)
  1172. long org_size, size_now;
  1173. {
  1174. X   register int size_factor;
  1175. X   while ((unsigned long) org_size > 32000) { /* avoid later overflow */
  1176. X      org_size = (unsigned long) org_size / 1024;
  1177. X      size_now = (unsigned long) size_now / 1024;
  1178. X   }
  1179. X   if (org_size == 0)         /* avoid division by zero */
  1180. X      size_factor = 0;
  1181. X   else {
  1182. X      size_factor = (int)
  1183. X         (
  1184. X            (1000 * 
  1185. X               ((unsigned long) org_size - (unsigned long) size_now)
  1186. X            ) / org_size + 5
  1187. X         ) / 10;
  1188. X   }
  1189. X   return (size_factor);
  1190. }
  1191. X
  1192. /***********
  1193. str_dup() duplicates a string using dynamic memory.
  1194. */
  1195. X
  1196. char *str_dup (str)
  1197. register char *str;
  1198. {
  1199. X   return (strcpy (emalloc (strlen(str)+1), str));
  1200. }
  1201. X
  1202. /**************
  1203. cmpnum() compares two pairs of unsigned integers and returns a negative,
  1204. zero, or positive value as the comparison yields less than, equal, or
  1205. greater than result.  Each pair of unsigned integers is considered to be the
  1206. more significant and the less significant half of a longer unsigned number.
  1207. X
  1208. Note:  cmpnum is used to compare dates and times.
  1209. */
  1210. X
  1211. int cmpnum (hi1, lo1, hi2, lo2)
  1212. register unsigned int hi1, hi2;
  1213. unsigned int lo1, lo2;
  1214. {
  1215. X   if (hi1 != hi2)
  1216. X      return (hi1 > hi2 ? 1 : -1);
  1217. X   else {
  1218. X        if (lo1 == lo2)
  1219. X            return (0);
  1220. X        else
  1221. X            return (lo1 > lo2 ? 1 : -1);
  1222. X    }
  1223. }
  1224. X
  1225. /*******************/
  1226. /* writenull() */
  1227. /* writes a null directory entry to an open archive */
  1228. void writenull (file, length)
  1229. ZOOFILE file;
  1230. int length;
  1231. {
  1232. #ifndef NOSIGNAL
  1233. X   T_SIGNAL (*oldsignal)();
  1234. #endif
  1235. X   struct direntry newentry;
  1236. X   memset ((char *) &newentry, 0, sizeof (newentry));
  1237. X   newentry.zoo_tag = ZOO_TAG;
  1238. X   newentry.type = 2;
  1239. X   /* Force entry to be the required length plus possibly 2 stray bytes
  1240. X   by dividing up the needed padding into dirlen and namlen. */
  1241. X   if (length > SIZ_DIRL)
  1242. X      newentry.dirlen = newentry.namlen = (length-SIZ_DIRL)/2 + 2;
  1243. X   else
  1244. X      newentry.dirlen = newentry.namlen = 0;
  1245. #ifndef NOSIGNAL
  1246. X   oldsignal = signal (SIGINT, SIG_IGN);
  1247. #endif
  1248. X   if (fwr_dir (&newentry, file) == -1)
  1249. X      prterror ('f', disk_full);
  1250. #ifndef NOSIGNAL
  1251. X   signal (SIGINT, oldsignal);
  1252. #endif
  1253. }
  1254. X
  1255. #ifdef FORCESLASH
  1256. /*******************/
  1257. /*
  1258. fixslash() changes all "\" characters in the supplied string to "/".
  1259. */
  1260. X
  1261. void fixslash (str)
  1262. char *str;
  1263. {
  1264. X   register char *p;
  1265. X   for (p = str; *p != '\0'; p++)
  1266. X      if (*p == '\\')
  1267. X         *p = '/';
  1268. }
  1269. #endif /* FORCESLASH */
  1270. SHAR_EOF
  1271. chmod 0644 misc.c ||
  1272. echo 'restore of misc.c failed'
  1273. Wc_c="`wc -c < 'misc.c'`"
  1274. test 9679 -eq "$Wc_c" ||
  1275.     echo 'misc.c: original size 9679, current size' "$Wc_c"
  1276. fi
  1277. # ============= misc2.c ==============
  1278. if test -f 'misc2.c' -a X"$1" != X"-c"; then
  1279.     echo 'x - skipping misc2.c (File already exists)'
  1280. else
  1281. echo 'x - extracting misc2.c (Text)'
  1282. sed 's/^X//' << 'SHAR_EOF' > 'misc2.c' &&
  1283. #ifndef LINT
  1284. /* @(#) misc2.c 2.7 88/01/24 12:47:36 */
  1285. static char sccsid[]="@(#) misc2.c 2.7 88/01/24 12:47:36";
  1286. #endif /* LINT */
  1287. X
  1288. /*
  1289. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  1290. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  1291. */
  1292. #include "options.h"
  1293. /* Miscellaneous routines */
  1294. #include "portable.h"
  1295. #include "zooio.h"
  1296. #include "various.h"
  1297. #include "errors.i"
  1298. #include "zoomem.h"
  1299. #include "zoo.h"
  1300. #include "zoofns.h"     /* only for malloc */
  1301. X
  1302. void makepath PARMS((char *));
  1303. X
  1304. /**********************/
  1305. /* memerr() */
  1306. /* Give error message on memory error and abort */
  1307. void memerr(i)
  1308. unsigned int i;
  1309. {
  1310. #ifdef OOZ
  1311. X   prterror ('f', no_memory, "", "");
  1312. #else
  1313. X    if (i != 0)
  1314. X        prterror ('f', no_memory);
  1315. X    else
  1316. X        prterror('f', "needed %u bytes: %s", no_memory);
  1317. #endif
  1318. }
  1319. X
  1320. /**********************/
  1321. /*
  1322. emalloc() allocates memory like malloc() does (and it calls malloc).  However,
  1323. it automatically calls the error function memerr() if memory couldn't be
  1324. allocated.  It also assumes that memory will never be freed and conserves it
  1325. by allocating memory in large chunks and then partitioning it out with no
  1326. administrative overhead.  This avoids many problems due to various bugs in
  1327. various implementations of malloc, and also avoids a very high amount of
  1328. malloc overhead for repeated allocations to store numerous filenames etc.
  1329. The down side is that we can't use free().
  1330. X
  1331. WARNING:  No alignment of allocated memory is attempted, so memory
  1332. allocated through emalloc should be used only for storing strings.
  1333. For allocating memory for other data types use ealloc().  */
  1334. X
  1335. VOIDPTR emalloc (size)
  1336. unsigned int size;
  1337. {
  1338. #define  BLOCK_SIZE  512      /* memory allocation granularity */
  1339. X
  1340. #ifdef USE_MALLOC
  1341. /* Pass on memory requests to malloc() */
  1342. X   char *ptr;
  1343. X   if ((ptr = malloc (size)) == NULL)
  1344. X      memerr(size);
  1345. X   return (ptr);
  1346. #else
  1347. X   static char *memptr;
  1348. X   static unsigned avail = 0;
  1349. X   unsigned malloc_incr;
  1350. X   char *retval;
  1351. X
  1352. X   if (size == 0)
  1353. X      return (NULL);
  1354. X
  1355. X   /* if not enough space avail get some more */
  1356. X   if (avail < size) {
  1357. X      malloc_incr = BLOCK_SIZE;
  1358. X      if (malloc_incr < size)
  1359. X         malloc_incr = size;
  1360. X      while (malloc_incr >= size && (memptr = malloc (malloc_incr)) == NULL)
  1361. X         malloc_incr = (malloc_incr / 6) * 5;
  1362. X      avail = malloc_incr;
  1363. X   }
  1364. X
  1365. X   if (avail < size)
  1366. X      memerr(size);                             /* no return from this */
  1367. X   retval = memptr;
  1368. X   memptr += size;
  1369. X   avail -= size;
  1370. X   return (retval);
  1371. #endif  /* end of not USE_MALLOC */
  1372. }
  1373. X
  1374. /**********************/
  1375. /*
  1376. ealloc() is just a wrapper around malloc(), which causes memerr() to be
  1377. called if memory cannot be allocated.  All memory requests are passed on
  1378. to malloc.   Allocated memory can later be freed.  */
  1379. X
  1380. VOIDPTR ealloc(size)
  1381. unsigned int size;
  1382. {
  1383. X   char *ptr;
  1384. X   if ((ptr = malloc (size)) == NULL)
  1385. X      memerr(size);
  1386. X   return ptr;
  1387. }
  1388. X
  1389. /**********************/
  1390. /* erealloc() is a wrapper around realloc() the way ealloc is a wrapper
  1391. around malloc().  It calls memerr() on error. */
  1392. X
  1393. VOIDPTR erealloc(p, size)
  1394. VOIDPTR p;
  1395. unsigned int size;
  1396. {
  1397. X   char *ptr;
  1398. X   if ((ptr = realloc (p, size)) == NULL)
  1399. X      memerr(size);
  1400. X   return ptr;
  1401. }
  1402. X
  1403. /**********************/
  1404. /* putstr()
  1405. This function prints a string to standard output.  If the received
  1406. string pointer is NULL, it is handled safely.  This function is here
  1407. for historical reasons:  Ooz was once coded to not use printf under
  1408. MSDOS to save space, and at that time putstr() printed a string
  1409. without using printf.  It should eventually be eliminated and all
  1410. calls to it replaced with calls to printf directly.
  1411. */
  1412. void putstr (str)
  1413. register char *str;
  1414. {
  1415. X   if (str == NULL)
  1416. X      return;
  1417. X    printf ("%s", str);
  1418. }
  1419. X
  1420. /**********************/
  1421. /* exists()
  1422. This function checks the existence of a file.  
  1423. X
  1424. If the symbol EXISTS is defined, that is called as a macro and
  1425. supplied the filename.  It must return 1 if the file exists and
  1426. 0 if it does not.
  1427. X
  1428. If EXISTS is not defined, exists() tests to see if the file can be 
  1429. opened for reading or writing;  if so, it returns 1 else it returns 0. 
  1430. X
  1431. Because of the delay between the time existence is checked and the time Zoo
  1432. creates a files, a race condition exists.  It would be better to
  1433. use open() with the O_EXCL flag but that will not work for many
  1434. systems.
  1435. */
  1436. X
  1437. int exists (fname)
  1438. char *fname;
  1439. {
  1440. #ifdef EXISTS
  1441. X    return EXISTS(fname);
  1442. #else
  1443. X   ZOOFILE f;
  1444. X
  1445. X   if ( (f = zooopen (fname, Z_READ )) != NOFILE ||
  1446. X          (f = zooopen (fname, Z_WRITE)) != NOFILE ) {
  1447. X      zooclose (f);
  1448. X      return (1);
  1449. X   } else
  1450. X      return (0);
  1451. #endif /* ifdef EXISTS */
  1452. }
  1453. X
  1454. /****************
  1455. newcat() allocates enough space to concatenate two strings then returns
  1456. a pointer to the concatenated result */
  1457. X
  1458. char *newcat (r, s)
  1459. char *r, *s;
  1460. {
  1461. X   char *temp = emalloc (strlen (r) + strlen (s) + 2); /* 1 spare */
  1462. X   strcpy (temp, r);
  1463. X   strcat (temp, s);
  1464. X   return (temp);
  1465. }
  1466. X
  1467. X
  1468. /* Creates a path */
  1469. void makepath(path)
  1470. char *path;
  1471. {
  1472. X   char tmppath[PATHSIZE];
  1473. X   char *slashpos;
  1474. X   if (path == NULL)
  1475. X      return;
  1476. X   while (*lastptr(path) == *(char *) PATH_CH)  /* remove trailing slashes */
  1477. X      *lastptr(path) = '\0';
  1478. X   if (*path == '\0')
  1479. X      return;
  1480. X
  1481. X   slashpos = findlast(path, PATH_CH);    /* find last slash */
  1482. X   if (slashpos == NULL) {                /* if not, just create dir. */
  1483. X      MKDIR(path);
  1484. X      return;
  1485. X   } else {                               /* otherwise...         */
  1486. X      if (slashpos == path) {             /* if leading slash */
  1487. X         MKDIR(slashpos);                 /* make that directory */
  1488. X         return;                          /* and done */
  1489. X      } else {
  1490. X         strcpy(tmppath,path);            /* save path */
  1491. X         *slashpos = '\0';                /* split into prefix & suffix */
  1492. #ifdef DEBUG
  1493. X         printf("making path from [%s]\n", path);
  1494. #endif
  1495. X         makepath(path);                     /* make path from prefix */
  1496. #ifdef DEBUG
  1497. X         printf("making dir from [%s]\n", tmppath);
  1498. #endif
  1499. X         MKDIR(tmppath);                  /* make dir from suffix */
  1500. X      }
  1501. X   }
  1502. } /* makepath() */
  1503. X
  1504. /*
  1505. If no extension in filename add supplied extension
  1506. */
  1507. char *addext (fname, ext)
  1508. char *fname;
  1509. char *ext;
  1510. {
  1511. X   if (strchr (nameptr (fname), EXT_CH) == NULL)
  1512. X      return (newcat (fname, ext));
  1513. X   else
  1514. X      return (fname);
  1515. }
  1516. X
  1517. #ifdef VER_CH       /* remove any trailing extension field */
  1518. char *strip_ver (fname)
  1519. char *fname;
  1520. {
  1521. X   char *p = strchr (fname, VER_CH);
  1522. X   if (p != NULL)
  1523. X      *p = '\0';
  1524. }
  1525. #endif
  1526. X
  1527. /*
  1528. Function samefile() compares two filenames to see if they are the
  1529. same file.  Just strcmp() or str_icmp() could have been used, except
  1530. that if the filenames have trailing version fields, we want to
  1531. compare those always equal.  samefile() is called by routines
  1532. that want to avoid adding an archive to itself.
  1533. */
  1534. int samefile (f1, f2)
  1535. char *f1;
  1536. char *f2;
  1537. {
  1538. #ifdef IGNORECASE
  1539. #define COMPARE str_icmp
  1540. #else
  1541. #define COMPARE strcmp
  1542. #endif
  1543. X
  1544. #ifdef VER_CH
  1545. X   char tf1[LFNAMESIZE];
  1546. X   char tf2[LFNAMESIZE];
  1547. X   strcpy (tf1, f1);
  1548. X   strcpy (tf2, f2);
  1549. X   strip_ver (tf1);   /* strip version fields */
  1550. X   strip_ver (tf2);
  1551. X   return (COMPARE (tf1, tf2) == 0);
  1552. #else
  1553. /* if no version fields, just use strcmp(i) */
  1554. X   return (COMPARE (f1, f2) == 0);
  1555. #endif
  1556. }
  1557. X
  1558. #ifdef USE_ASCII
  1559. int isdigit (c)
  1560. int c;
  1561. {
  1562. X    return (c >= '0' && c <= '9');
  1563. }
  1564. int isupper (c)
  1565. int c;
  1566. {
  1567. X    return (c >= 'A' && c <= 'Z');
  1568. }
  1569. X
  1570. int toascii (c)
  1571. int c;
  1572. {
  1573. X    return (c & 0x7f);
  1574. }
  1575. X
  1576. int tolower (c)
  1577. int c;
  1578. {
  1579. X    return (isupper(c) ? (c | 0x20) : c);
  1580. }
  1581. #endif
  1582. X
  1583. #ifdef GETTZ
  1584. /****************
  1585. Function tzadj() accepts a directory entry and adjusts its timestamp
  1586. to reflect its timezone.  Uses function mstime() from mstime.i
  1587. and mstonix() from nixtime.i.
  1588. */
  1589. X
  1590. long mstonix();
  1591. long gettz();
  1592. #include "mstime.i"    /* get mstime() */
  1593. X
  1594. void tzadj (direntry)
  1595. struct direntry *direntry;
  1596. {
  1597. X    long diff_tz;
  1598. X    long longtime;
  1599. X    if (direntry->tz == NO_TZ)        /* none stored */
  1600. X        return;
  1601. X    diff_tz = (long) direntry->tz * (3600/4) - gettz(); /* diff. in seconds */
  1602. X    longtime = mstonix (direntry->date, direntry->time) + diff_tz; /* adj tz */
  1603. X    mstime (longtime, &direntry->date, &direntry->time);
  1604. }
  1605. #endif /* GETTZ */
  1606. X
  1607. /* how long an int can be in text form -- allow 64-bit ints */
  1608. #define INT_TEXT 21
  1609. X
  1610. /* Function add_version adds a version suffix to a filename, given
  1611. the directory entry corresponding to the file */
  1612. void add_version (fname, direntry)
  1613. char *fname;
  1614. struct direntry *direntry;
  1615. {
  1616. X    char verstr[INT_TEXT];    /* string buffer for conversion to text */
  1617. X    if (direntry->vflag & VFL_ON) {
  1618. X        sprintf (verstr, "%u", direntry->version_no);
  1619. X        strcat (fname, VER_DISPLAY);
  1620. X        strcat (fname, verstr);
  1621. X    }
  1622. }
  1623. SHAR_EOF
  1624. chmod 0644 misc2.c ||
  1625. echo 'restore of misc2.c failed'
  1626. Wc_c="`wc -c < 'misc2.c'`"
  1627. test 8587 -eq "$Wc_c" ||
  1628.     echo 'misc2.c: original size 8587, current size' "$Wc_c"
  1629. fi
  1630. true || echo 'restore of msdos.c failed'
  1631. echo End of part 5, continue with part 6
  1632. exit 0
  1633.