home *** CD-ROM | disk | FTP | other *** search
- From: dhesi@bsu-cs.bsu.edu (Rahul Dhesi)
- Newsgroups: alt.sources
- Subject: zoo 2.1 source part 05/15
- Message-ID: <12771@bsu-cs.bsu.edu>
- Date: 10 Jul 91 09:34:00 GMT
-
- Checksum: 3273603874 (verify with "brik -cv")
- Submitted-by: dhesi@bsu-cs.bsu.edu
- Archive-name: zoo210/part05
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # This is part 05 of zoo210
- # ============= makefile ==============
- if test -f 'makefile' -a X"$1" != X"-c"; then
- echo 'x - skipping makefile (File already exists)'
- else
- echo 'x - extracting makefile (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'makefile' &&
- # derived from: @(#) makefile 2.2 88/01/27 19:37:59
- # $Id: makefile,v 1.22 91/07/09 04:10:38 dhesi Exp $
- # Make Zoo
- #
- #The contents of this makefile are hereby released to the public domain.
- # -- Rahul Dhesi 1991/07/05
- #
- # This makefile expects two macro names, `CFLAGS' and `EXTRA', to hold
- # all the switches to be supplied to the C compiler. It also expects
- # a macro `LDFLAGS' to hold the switch for the loader when invoked.
- # The macro "MODEL" holds switches needed for both compile and link,
- # such as "memory model" for Intel and Z8000 processors. OPTIM is the
- # optimize option and may be set on the make command line to -O2 or
- # whatever your compiler thinks is nice.
- #
- # To run lint, select an appropriate lint_* target (e.g. "make lint_sysv").
- X
- X
- MAKE = make # needed for some systems e.g. older BSD
- X
- CC = cc
- CFLAGS =
- MODEL =
- EXTRA = -DBIG_MEM -DNDEBUG
- LINTFLAGS = -DLINT
- OPTIM = -O
- DESTDIR = /usr/local/bin
- X
- #List of all object files created for Zoo
- ZOOOBJS = addbfcrc.o addfname.o basename.o comment.o crcdefs.o \
- X getfile.o lzc.o lzd.o machine.o makelist.o misc.o misc2.o \
- X nextfile.o needed.o options.o parse.o portable.o prterror.o \
- X version.o zoo.o zooadd.o zooadd2.o zoodel.o zooext.o zoofilt.o \
- X zoolist.o zoopack.o io.o lzh.o maketbl.o maketree.o huf.o \
- X encode.o decode.o
- X
- FIZOBJS = fiz.o addbfcrc.o portable.o crcdefs.o
- X
- .c.o :
- X $(CC) $(CFLAGS) $(MODEL) $(EXTRA) $*.c
- X
- all :
- X @echo 'There is no default. Please specify an appropriate target from'
- X @echo 'the makefile, or type "make help" for more information'
- X
- help :
- X @echo "Possible targets are as follows. Please examine the makefile"
- X @echo "for more information."
- X @echo ' '
- X @echo "generic: generic **IX environment, minimal functionlity"
- X @echo "bsd: 4.3BSD or reasonable equivalent"
- X @echo "bsdansi: 4.3BSD with ANSI C"
- X @echo "ultrix: ULTRIX 4.1"
- X @echo "convex: Convex C200 series"
- X @echo "sysv: System V Release 2 or 3; or SCO Xenix"
- X @echo "scodos: Cross-compiler under SCO Xenix/UNIX for MS-DOS"
- X @echo "xenix286: Older Xenix/286 (not tested)"
- X @echo "xenix68k: Xenix/68000 (not tested)"
- X @echo ' '
- X @echo "install: Move zoo to $(DESTDIR)/tzoo (alpha test)"
- X @echo "inst_beta: Move zoo to $(DESTDIR)/bzoo (beta test)"
- X @echo "inst_prod: Move zoo to $(DESTDIR)/zoo (production)"
- X @echo ' '
- X @echo "lint_sysv: Run lint for System V"
- X @echo "lint_bsd: Run lint for 4.3BSD"
- X @echo "lint_generic: Run lint for generic **IX"
- X @echo "lint_turboc: Run lint under **IX for checking Turbo C/MSDOS code"
- X
- # install alpha zoo as "tzoo"
- install:
- X mv zoo $(DESTDIR)/tzoo
- X
- # install beta zoo as "bzoo"
- inst_beta:
- X mv zoo $(DESTDIR)/bzoo
- X
- # install production zoo as "zoo"
- inst_prod:
- X mv zoo $(DESTDIR)/zoo
- X
- # executable targets
- TARGETS = zoo fiz
- X
- #######################################################################
- # SYSTEM-SPECIFIC TARGETS
- #######################################################################
- X
- # A generic system -- may have less than full functionality.
- # Compile with -g, since debugging will probably be needed.
- generic:
- X $(MAKE) CFLAGS="-c -g -DGENERIC" $(TARGETS)
- X
- # Reasonably generic BSD 4.3
- bsd:
- X $(MAKE) CFLAGS="-c $(OPTIM) -DBSD4_3" $(TARGETS)
- X
- # ULTRIX 4.1
- ultrix:
- X $(MAKE) CFLAGS="-c $(OPTIM) -DULTRIX" $(TARGETS)
- X
- # BSD with ANSI C - works on MIPS and Ultrix/RISC compilers
- bsdansi:
- X $(MAKE) CFLAGS="-c $(OPTIM) -DBSD4_3 -DANSI_HDRS" $(TARGETS)
- X
- # Convex C200 series
- convex:
- X $(MAKE) CFLAGS="-c $(OPTIM) -DBSD4_3 -DANSI_HDRS" $(TARGETS)
- X
- # SysV.2, V.3, SCO Xenix
- sysv:
- X $(MAKE) CFLAGS="-c $(OPTIM) -DSYS_V" $(TARGETS)
- X
- # DOS version cross compiled from SCO Xenix/UNIX
- scodos:
- X $(MAKE) CFLAGS="-c $(OPTIM) -DTURBOC -DANSI_HDRS -DBIG_MEM" \
- X EXTRA="-dos -Ml" LDFLAGS="-o zoo.exe" $(TARGETS)
- X
- # Tested for zoo 2.01 on: Xenix 3.4 on Greg Laskin's Intel 310/286;
- # SCO Xenix 2.2 on Robert Cliff's AT.
- # `-Ml' for large memory model, `-M2' to generate code for 80286 cpu,
- # `-F xxxx' for xxxx (hex) bytes of stack space.
- xenix286:
- X @echo "Warning: xenix286 is not fully functional"
- X $(MAKE) CFLAGS="-c $(OPTIM) -DSYS_V" \
- X MODEL="-Ml -M2 -Md" \
- X LDFLAGS="-s -n -Md -Mt500 -F 5000" $(TARGETS)
- X
- # Radio Shack Model 16 with Xenix/68000 3.01.01. "-DM_VOID" tells not
- # to try to do a typedef of `void'. "-Dvoid=int" because compiler doesn't
- # know about `void'. `-s -n' strips and makes it shareable. Used to work
- # with zoo 2.01; not tested with 2.1.
- xenix68k:
- X $(MAKE) CFLAGS="-c $(OPTIM) -DSYS_V -DM_VOID -Dvoid=int" \
- X LDFLAGS="-s -n" $(TARGETS)
- X
- #######################################################################
- # CLEANUP TARGETS
- #######################################################################
- X
- # standard clean -- remove all transient files
- clean :
- X rm -f core a.out $(ZOOOBJS) $(FIZOBJS)
- X
- # object clean only -- just remove object files
- objclean:
- X rm -f *.o
- X
- #######################################################################
- # BINARY TARGETS
- #######################################################################
- X
- zoo: $(ZOOOBJS)
- X $(CC) -o zoo $(MODEL) $(LDFLAGS) $(ZOOOBJS)
- X
- fiz: $(FIZOBJS)
- X $(CC) -o fiz $(MODEL) $(LDFLAGS) $(FIZOBJS)
- X
- #######################################################################
- # SELECTED TARGETS FOR LINT
- #######################################################################
- X
- # generic system V
- lint_sysv:
- X echo $(ZOOOBJS) | sed -e 's/\.o/.c/g' | \
- X xargs lint -DSYS_V $(EXTRA) $(LINTFLAGS) | \
- X grep -v 'possible pointer alignment problem'
- X
- # generic BSD
- lint_bsd:
- X echo $(ZOOOBJS) | sed -e 's/\.o/.c/g' | \
- X xargs lint -DBSD4_3 $(EXTRA) $(LINTFLAGS) | \
- X grep -v 'possible pointer alignment problem'
- X
- # generic **IX
- lint_generic:
- X echo $(ZOOOBJS) | sed -e 's/\.o/.c/g' | \
- X xargs lint -DGENERIC $(EXTRA) $(LINTFLAGS) | \
- X grep -v 'possible pointer alignment problem'
- X
- # Cross-lint for checking Turbo C code under **IX. For checking only;
- # compilation requires separate makefile called "makefile.tcc"
- lint_turboc:
- X echo $(ZOOOBJS) turboc.c | sed -e 's/\.o/.c/g' | \
- X xargs lint -DTURBOC -DCROSS_LINT $(EXTRA) $(LINTFLAGS)
- X
- #######################################################################
- # DEPENDENCIES
- #######################################################################
- # DO NOT DELETE THIS LINE -- it marks the beginning of this dependency list
- X
- addbfcrc.o: options.h
- addfname.o: /usr/include/stdio.h options.h various.h zoo.h zoofns.h zooio.h
- addfname.o: zoomem.h
- basename.o: /usr/include/stdio.h assert.h debug.h options.h parse.h various.h
- basename.o: zoo.h zoofns.h zooio.h
- bsd.o: /usr/include/sys/stat.h /usr/include/sys/time.h
- bsd.o: /usr/include/sys/types.h nixmode.i nixtime.i
- comment.o: /usr/include/signal.h /usr/include/stdio.h
- comment.o: /usr/include/sys/signal.h errors.i options.h portable.h various.h
- comment.o: zoo.h zoofns.h zooio.h
- crcdefs.o: options.h
- decode.o: /usr/include/stdio.h ar.h lzh.h options.h zoo.h
- encode.o: /usr/include/assert.h /usr/include/stdio.h ar.h errors.i lzh.h
- encode.o: options.h zoo.h
- fiz.o: /usr/include/stdio.h options.h portable.h various.h zoo.h zoofns.h
- fiz.o: zooio.h
- generic.o: /usr/include/sys/stat.h /usr/include/sys/types.h
- generic.o: /usr/include/time.h nixmode.i nixtime.i
- getfile.o: /usr/include/stdio.h options.h various.h zoo.h zoofns.h zooio.h
- getfile.o: zoomem.h
- huf.o: /usr/include/stdio.h ar.h errors.i lzh.h options.h zoo.h
- io.o: /usr/include/stdio.h ar.h errors.i lzh.h options.h portable.h zoo.h
- io.o: zooio.h
- lzc.o: /usr/include/stdio.h assert.h debug.h lzconst.h options.h various.h
- lzc.o: zoo.h zoofns.h zooio.h zoomem.h
- lzd.o: /usr/include/stdio.h assert.h debug.h lzconst.h options.h various.h
- lzd.o: zoo.h zoofns.h zooio.h zoomem.h
- lzh.o: /usr/include/stdio.h ar.h errors.i options.h zoo.h
- machine.o: /usr/include/stdio.h options.h various.h zoo.h zoofns.h zooio.h
- makelist.o: /usr/include/stdio.h assert.h debug.h errors.i options.h
- makelist.o: portable.h various.h zoo.h zoofns.h zooio.h
- maketbl.o: /usr/include/stdio.h ar.h lzh.h options.h zoo.h
- maketree.o: /usr/include/stdio.h ar.h lzh.h options.h zoo.h
- misc.o: /usr/include/signal.h /usr/include/stdio.h /usr/include/sys/signal.h
- misc.o: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
- misc2.o: /usr/include/stdio.h errors.i options.h portable.h various.h zoo.h
- misc2.o: zoofns.h zooio.h zoomem.h
- msdos.o: /usr/include/stdio.h errors.i options.h zoo.h zoofns.h zooio.h
- needed.o: /usr/include/stdio.h debug.h options.h portable.h various.h zoo.h
- needed.o: zoofns.h zooio.h
- nextfile.o: /usr/include/stdio.h options.h various.h zoo.h
- options.o: /usr/include/stdio.h errors.i options.h various.h zoo.h zoofns.h
- options.o: zooio.h
- parse.o: /usr/include/stdio.h assert.h options.h parse.h various.h zoo.h
- parse.o: zoofns.h zooio.h
- portable.o: /usr/include/stdio.h assert.h debug.h machine.h options.h
- portable.o: portable.h various.h zoo.h zoofns.h zooio.h
- prterror.o: /usr/include/stdio.h /usr/include/varargs.h options.h various.h
- prterror.o: zoofns.h zooio.h
- sysv.o: /usr/include/sys/stat.h /usr/include/sys/types.h /usr/include/time.h
- sysv.o: nixmode.i nixtime.i
- turboc.o: /usr/include/signal.h /usr/include/stdio.h /usr/include/sys/signal.h
- vms.o: /usr/include/time.h
- vmstime.o: /usr/include/stdio.h
- zoo.o: /usr/include/stdio.h errors.i options.h various.h zoo.h zoofns.h
- zoo.o: zooio.h zoomem.h
- zooadd.o: /usr/include/stdio.h debug.h errors.i options.h parse.h portable.h
- zooadd.o: various.h zoo.h zoofns.h zooio.h zoomem.h
- zooadd2.o: /usr/include/stdio.h assert.h debug.h errors.i options.h parse.h
- zooadd2.o: various.h zoo.h zoofns.h zooio.h
- zoodel.o: /usr/include/signal.h /usr/include/stdio.h /usr/include/sys/signal.h
- zoodel.o: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
- zooext.o: /usr/include/signal.h /usr/include/stdio.h /usr/include/sys/signal.h
- zooext.o: errors.i machine.h options.h parse.h portable.h various.h zoo.h
- zooext.o: zoofns.h zooio.h
- zoofilt.o: options.h
- zoolist.o: /usr/include/stdio.h errors.i options.h portable.h various.h zoo.h
- zoolist.o: zoofns.h zooio.h zoomem.h
- zoopack.o: /usr/include/signal.h /usr/include/stdio.h
- zoopack.o: /usr/include/sys/signal.h errors.i options.h portable.h various.h
- zoopack.o: zoo.h zoofns.h zooio.h
- SHAR_EOF
- chmod 0644 makefile ||
- echo 'restore of makefile failed'
- Wc_c="`wc -c < 'makefile'`"
- test 10232 -eq "$Wc_c" ||
- echo 'makefile: original size 10232, current size' "$Wc_c"
- fi
- # ============= makefile.tcc ==============
- if test -f 'makefile.tcc' -a X"$1" != X"-c"; then
- echo 'x - skipping makefile.tcc (File already exists)'
- else
- echo 'x - extracting makefile.tcc (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'makefile.tcc' &&
- # $Source: /usr/home/dhesi/zoo/RCS/makefile.tcc,v $
- # $Id: makefile.tcc,v 1.6 91/07/07 18:39:28 dhesi Exp $
- # Make Zoo -- works with Turbo C++ 1.0 under MS-DOS and
- # Don Kneller's NDMAKE version 4.31.
- #
- # compile is tcc (Turbo C++ 1.0)
- CC = tcc
- # assembler is tasm
- AS = tasm
- ASFLAGS =
- CFLAGS = -c -DTURBOC -DLINT
- X
- # char representing memory model (l = large, c = compact)
- MCHAR = c
- #
- #
- model = -m$(MCHAR) # compiler switch
- CRT0 = c:\tc\lib\c0$(MCHAR).obj # C runtime object
- STDLIB = \tc\lib\c$(MCHAR).lib # C standard library
- X
- EXTRA = -DBIG_MEM -DNDEBUG
- OPTIM = -O
- X
- .SUFFIXES : .exe .obj .asm .c
- X
- # Object files for zoo
- ZOOOBJS = addbftcc.obj addfname.obj basename.obj comment.obj \
- X crcdefs.obj getfile.obj lzc.obj lzd.obj machine.obj \
- X makelist.obj misc.obj misc2.obj nextfile.obj needed.obj \
- X options.obj parse.obj portable.obj prterror.obj \
- X version.obj zoo.obj zooadd.obj zooadd2.obj zoodel.obj \
- X zooext.obj zoofilt.obj zoolist.obj zoopack.obj \
- X io.obj lzh.obj maketbl.obj maketree.obj huf.obj \
- X encode.obj decode.obj \
- X msdos.obj
- X
- # Object files for fiz
- FIZOBJS = fiz.obj addbftcc.obj portable.obj crcdefs.obj
- X
- #################################################################
- # default rule for assembly and compilation
- #################################################################
- X
- ## assembly
- ## .asm.obj :
- ## $(AS) $(ASFLAGS) $*.asm
- X
- # C compilation
- .c.obj :
- X $(CC) $(CFLAGS) $(model) $(EXTRA) $*.c
- X
- #################################################################
- # final link
- #################################################################
- X
- zoo.exe: $(ZOOOBJS)
- X link /c /m /s $(CRT0) \
- X $(ZOOOBJS),zoo.exe,zoo.map,$(STDLIB)
- X
- #################################################################
- # miscellaneous targets: install and cleanup
- #################################################################
- X
- install: zoo.exe
- X copy zoo.exe \bin\tzoo.exe
- X
- clean :
- X del *.obj
- X
- #################################################################
- # dependencies
- #################################################################
- X
- addfname.obj: options.h various.h zoo.h zoofns.h zooio.h zoomem.h
- basename.obj: assert.h debug.h options.h parse.h various.h
- basename.obj: zoo.h zoofns.h zooio.h
- comment.obj: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
- crcdefs.obj: options.h
- decode.obj: ar.h lzh.h options.h zoo.h
- encode.obj: ar.h errors.i lzh.h options.h zoo.h
- fiz.obj: options.h portable.h various.h zoo.h zoofns.h zooio.h
- generic.obj: nixmode.i nixtime.i
- getfile.obj: options.h various.h zoo.h zoofns.h zooio.h zoomem.h
- huf.obj: ar.h errors.i lzh.h options.h zoo.h
- io.obj: ar.h errors.i lzh.h options.h portable.h zoo.h zooio.h
- lzc.obj: assert.h debug.h lzconst.h options.h various.h
- lzc.obj: zoo.h zoofns.h zooio.h zoomem.h
- lzd.obj: assert.h debug.h lzconst.h options.h various.h
- lzd.obj: zoo.h zoofns.h zooio.h zoomem.h
- lzh.obj: ar.h errors.i options.h zoo.h
- machine.obj: options.h various.h zoo.h zoofns.h zooio.h
- makelist.obj: assert.h debug.h errors.i options.h
- makelist.obj: portable.h various.h zoo.h zoofns.h zooio.h
- maketbl.obj: ar.h lzh.h options.h zoo.h
- maketree.obj: ar.h lzh.h options.h zoo.h
- misc.obj: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
- misc2.obj: errors.i options.h portable.h various.h zoo.h
- misc2.obj: zoofns.h zooio.h zoomem.h
- msdos.obj: errors.i options.h zoo.h zoofns.h zooio.h
- needed.obj: debug.h options.h portable.h various.h zoo.h
- needed.obj: zoofns.h zooio.h
- nextfile.obj: options.h various.h zoo.h
- options.obj: errors.i options.h various.h zoo.h zoofns.h zooio.h
- parse.obj: assert.h options.h parse.h various.h zoo.h
- parse.obj: zoofns.h zooio.h
- portable.obj: assert.h debug.h machine.h options.h
- portable.obj: portable.h various.h zoo.h zoofns.h zooio.h
- prterror.obj: options.h various.h zoofns.h zooio.h
- zoo.obj: errors.i options.h various.h zoo.h zoofns.h
- zoo.obj: zooio.h zoomem.h
- zooadd.obj: debug.h errors.i options.h parse.h portable.h
- zooadd.obj: various.h zoo.h zoofns.h zooio.h zoomem.h
- zooadd2.obj: assert.h debug.h errors.i options.h parse.h
- zooadd2.obj: various.h zoo.h zoofns.h zooio.h
- zoodel.obj: errors.i options.h portable.h various.h zoo.h zoofns.h zooio.h
- zooext.obj: errors.i machine.h options.h parse.h portable.h various.h zoo.h
- zooext.obj: zoofns.h zooio.h
- zoofilt.obj: options.h
- zoolist.obj: errors.i options.h portable.h various.h zoo.h
- zoolist.obj: zoofns.h zooio.h zoomem.h
- zoopack.obj: errors.i options.h portable.h various.h
- zoopack.obj: zoo.h zoofns.h zooio.h
- SHAR_EOF
- chmod 0644 makefile.tcc ||
- echo 'restore of makefile.tcc failed'
- Wc_c="`wc -c < 'makefile.tcc'`"
- test 4490 -eq "$Wc_c" ||
- echo 'makefile.tcc: original size 4490, current size' "$Wc_c"
- fi
- # ============= makelist.c ==============
- if test -f 'makelist.c' -a X"$1" != X"-c"; then
- echo 'x - skipping makelist.c (File already exists)'
- else
- echo 'x - extracting makelist.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'makelist.c' &&
- #ifndef LINT
- /* @(#) makelist.c 2.3 88/01/24 12:46:44 */
- static char sccsid[]="@(#) makelist.c 2.3 88/01/24 12:46:44";
- #endif /* LINT */
- X
- /*
- Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
- (C) Copyright 1988 Rahul Dhesi -- All rights reserved
- */
- X
- #include "options.h"
- #include "portable.h"
- #include "errors.i"
- #include "zoo.h"
- #include "zooio.h"
- #include "various.h"
- X
- #include "zoofns.h"
- #include "assert.h"
- #include "debug.h"
- X
- char *nameptr PARMS((char *));
- void modpath PARMS((char *));
- X
- /*******************/
- /*
- makelist() gets all pathnames corresponding to a set of filespecs and
- adds them to a list. Not more than "flistsize" pathnames are added.
- Into `longest' it returns the length of the longest name added, or
- zero if none added.
- X
- Files ignore1, ignore2, and ignore3 are not added to the list.
- A file that is a device/directory is also not added to the list.
- X
- However, if ignore1 is NULL, both these tests are skipped and all files
- will be added to the list.
- */
- X
- void makelist (argc, argv, flist, flistsize, ignore1, ignore2, ignore3, longest)
- int argc; /* number of filespec supplied */
- char *argv[]; /* array of pointers to supplied filespecs */
- register char *flist[]; /* array of pointers to filenames we will add */
- int flistsize; /* home many names we can use */
- char *ignore1, *ignore2, *ignore3; /* files to exclude from list */
- int *longest; /* length of longest name in list */
- {
- X char *this_path; /* current pathname */
- X int fptr; /* pointer to within flist */
- X register int i, j; /* loop counters */
- X
- #ifdef WILDCARD
- X char *pat_name; /* filename part of pattern */
- #endif
- X
- X int gap; /* for Shell sort */
- X
- X flistsize--; /* allow for one terminating NULL entry */
- X fptr = *longest = 0;
- X
- X assert(argc > 0);
- X
- #define WCLEN 4 /* length needed for wildcard, and a little extra */
- X
- X while (argc > 0) {
- #ifdef WILDCARD
- X int argok = 0; /* arg not matched yet */
- #endif
- X char *this_arg;
- X this_arg = emalloc (strlen (*argv) + WCLEN);
- X strcpy (this_arg, *argv);
- X
- X /* Initialize fileset 0. Select all files -- we will later
- X filter out the ones wanted */
- #ifdef FOLD
- X str_lwr (this_arg);
- #endif
- X
- #ifdef WILDCARD
- X pat_name = str_dup (nameptr (this_arg)); /* pattern without path */
- #ifdef VER_CH /* trailing version field */
- {
- X static char version_field[] = " *";
- X char *p;
- X p = strrchr (pat_name, VER_CH);
- X if (p == NULL) {
- X *version_field = VER_CH;
- X pat_name = newcat (pat_name, version_field); /* adds trailing ";*" */
- X }
- }
- #endif
- X /*
- X replace filename by wildcard; however, if argument ends in slash,
- X then simply append wildcard so we get all files in that directory
- X */
- #ifdef FORCESLASH
- X fixslash (this_arg); /* convert backslashes to slashes */
- #endif
- X
- X if (*lastptr(this_arg) == *(char *) PATH_CH) {
- X strcat (this_arg, WILDCARD);
- X pat_name = "*"; /* and select all files */
- X } else
- #ifdef SPEC_WILD
- X spec_wild (this_arg);
- #else
- X strcpy (nameptr (this_arg), WILDCARD);
- #endif /* SPEC_WILD */
- #endif /* WILDCARD */
- X
- X nextfile (0, this_arg, 0);
- X while (fptr < flistsize &&
- X (this_path = nextfile(1, (char *) NULL, 0)) != NULL) {
- X char *this_name = nameptr (this_path);
- X modpath (this_path); /* do any needed changes to path */
- X
- #ifdef IGNORECASE
- #define COMPARE str_icmp
- #else
- #define COMPARE strcmp
- #endif
- X if (ignore1 != NULL) {
- X if (samefile (this_name,ignore1) || /* exclude ignored files */
- X samefile (this_name,ignore2) ||
- X samefile (this_name,ignore3))
- X continue;
- X
- #ifdef CHEKUDIR
- X if (isuadir(this_path))
- X continue;
- #else /* CHEKUDIR */
- # ifdef CHEKDIR
- X if (isfdir(this_path))
- X continue;
- # endif /* CHEKDIR */
- #endif /* CHEKUDIR */
- X } /* end if ignore1 ! = NULL */
- X
- /*
- If WILDCARD is defined (e.g. AmigaDOS, MS-DOS, VAX/VMS), then nextfile()
- returns all filenames and we must now select the ones we need by pattern
- matching. If WILDCARD is not defined (e.g. **IX), filenames have already been
- selected by the shell and need not be tested again.
- */
- #ifdef WILDCARD
- X if (match_half (this_name,pat_name) ||
- X match_half (pat_name, "?-?") && /* character range */
- X *this_name >= *pat_name && *this_name <= pat_name[2])
- #endif
- X {
- #ifdef WILDCARD
- X argok = 1; /* remember arg matched */
- #endif
- X flist[fptr++] = str_dup (this_path);
- X if (*longest < strlen(this_path))
- X *longest = strlen(this_path);
- X }
- X
- X } /* end while */
- #ifdef WILDCARD
- X if (argok == 0) { /* no match for argument */
- X prterror ('e', "Could not open %s\n", *argv);
- X }
- #endif
- X argc--;
- X argv++;
- X }
- X /* fptr is now 1 + index of last item in array */
- X
- X if (this_path != NULL && fptr >= flistsize)
- X prterror ('w', too_many_files, flistsize);
- #ifndef DONT_SORT
- X /* Shell sort -- K&R p. 58 */
- X for (gap = fptr/2; gap > 0; gap /= 2)
- X for (i = gap; i < fptr; i++)
- X for (j = i - gap; j >= 0 &&
- X strcmp(flist[j],flist[j+gap]) > 0; j -= gap) {
- X char *t = flist[j]; flist[j] = flist[j+gap]; flist[j+gap] = t;
- X }
- #endif /* DONT_SORT */
- X
- X fptr--; /* fptr is now index of last item in array */
- X
- X /* Remove duplicates */
- X for (i = 0; i < fptr; i++) {
- X while (i<fptr && COMPARE(flist[i],flist[i+1]) == 0) {
- X for (j = i; j < fptr; j++)
- X flist[j] = flist[j+1];
- X fptr--;
- X }
- X }
- X
- X flist[++fptr] = NULL; /* NULL entry terminates list */
- }
- X
- /*******
- modpath() makes any changes needed before pathname is stored;
- currently these could involve folding it to lower case and
- converting backslashes to forward slashes
- */
- X
- /*ARGSUSED*/
- void modpath (path)
- char *path;
- {
- #ifdef FOLD
- X str_lwr (path);
- #endif
- X
- #ifdef FORCESLASH
- X fixslash (path); /* convert backslashes to slashes */
- #endif
- }
- X
- #ifdef CHEKDIR
- /* Function isfdir returns 1 if pathname is a directory else 0 */
- int isfdir (this_path)
- char *this_path;
- {
- X int dir;
- X ZOOFILE f;
- X f = zooopen (this_path, Z_READ);
- X if (f == NOFILE)
- X return 0;
- X else {
- X dir = isadir(f); zooclose(f);
- X }
- X return (dir);
- }
- #endif
- SHAR_EOF
- chmod 0644 makelist.c ||
- echo 'restore of makelist.c failed'
- Wc_c="`wc -c < 'makelist.c'`"
- test 6198 -eq "$Wc_c" ||
- echo 'makelist.c: original size 6198, current size' "$Wc_c"
- fi
- # ============= maketbl.c ==============
- if test -f 'maketbl.c' -a X"$1" != X"-c"; then
- echo 'x - skipping maketbl.c (File already exists)'
- else
- echo 'x - extracting maketbl.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'maketbl.c' &&
- /*$Source: /usr/home/dhesi/zoo/RCS/maketbl.c,v $*/
- /*$Id: maketbl.c,v 1.8 91/07/09 01:39:52 dhesi Exp $*/
- /***********************************************************
- X maketbl.c -- make table for decoding
- X
- Adapted from "ar" archiver written by Haruhiko Okumura.
- ***********************************************************/
- #include "options.h"
- #include "zoo.h"
- #include "ar.h"
- #include "lzh.h"
- X
- extern void prterror();
- X
- void make_table(nchar, bitlen, tablebits, table)
- int nchar;
- uchar bitlen[];
- int tablebits;
- ushort table[];
- {
- X ushort count[17], weight[17], start[18], *p;
- X uint i, k, len, ch, jutbits, avail, nextcode, mask;
- X
- X for (i = 1; i <= 16; i++) count[i] = 0;
- X for (i = 0; i < nchar; i++) count[bitlen[i]]++;
- X
- X start[1] = 0;
- X for (i = 1; i <= 16; i++)
- X start[i + 1] = start[i] + (count[i] << (16 - i));
- X if (start[17] != (ushort)((unsigned) 1 << 16))
- X prterror('f', "Bad decode table\n");
- X
- X jutbits = 16 - tablebits;
- X for (i = 1; i <= tablebits; i++) {
- X start[i] >>= jutbits;
- X weight[i] = (unsigned) 1 << (tablebits - i);
- X }
- X while (i <= 16) {
- X weight[i] = (unsigned) 1 << (16 - i);
- X i++;
- X }
- X
- X i = start[tablebits + 1] >> jutbits;
- X if (i != (ushort)((unsigned) 1 << 16)) {
- X k = 1 << tablebits;
- X while (i != k) table[i++] = 0;
- X }
- X
- X avail = nchar;
- X mask = (unsigned) 1 << (15 - tablebits);
- X for (ch = 0; ch < nchar; ch++) {
- X if ((len = bitlen[ch]) == 0) continue;
- X nextcode = start[len] + weight[len];
- X if (len <= tablebits) {
- X for (i = start[len]; i < nextcode; i++) table[i] = ch;
- X } else {
- X k = start[len];
- X p = &table[k >> jutbits];
- X i = len - tablebits;
- X while (i != 0) {
- X if (*p == 0) {
- X right[avail] = left[avail] = 0;
- X *p = avail++;
- X }
- X if (k & mask) p = &right[*p];
- X else p = &left[*p];
- X k <<= 1; i--;
- X }
- X *p = ch;
- X }
- X start[len] = nextcode;
- X }
- }
- SHAR_EOF
- chmod 0644 maketbl.c ||
- echo 'restore of maketbl.c failed'
- Wc_c="`wc -c < 'maketbl.c'`"
- test 1836 -eq "$Wc_c" ||
- echo 'maketbl.c: original size 1836, current size' "$Wc_c"
- fi
- # ============= maketree.c ==============
- if test -f 'maketree.c' -a X"$1" != X"-c"; then
- echo 'x - skipping maketree.c (File already exists)'
- else
- echo 'x - extracting maketree.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'maketree.c' &&
- /*$Source: /usr/home/dhesi/zoo/RCS/maketree.c,v $*/
- /*$Id: maketree.c,v 1.6 91/07/09 01:39:51 dhesi Exp $*/
- /***********************************************************
- X maketree.c -- make Huffman tree
- X
- Adapted from "ar" archiver written by Haruhiko Okumura.
- ***********************************************************/
- #include "options.h"
- #include "zoo.h"
- #include "ar.h"
- #include "lzh.h"
- X
- static int n, heapsize;
- static short heap[NC + 1];
- static ushort *freq, *sortptr, len_cnt[17];
- static uchar *len;
- X
- static void count_len(i) /* call with i = root */
- int i;
- {
- X static int depth = 0;
- X
- X if (i < n) len_cnt[(depth < 16) ? depth : 16]++;
- X else {
- X depth++;
- X count_len((int) left [i]);
- X count_len((int) right[i]);
- X depth--;
- X }
- }
- X
- static void make_len(root)
- int root;
- {
- X int i, k;
- X uint cum;
- X
- X for (i = 0; i <= 16; i++) len_cnt[i] = 0;
- X count_len(root);
- X cum = 0;
- X for (i = 16; i > 0; i--)
- X cum += len_cnt[i] << (16 - i);
- X while (cum != ((unsigned) 1 << 16)) {
- X (void) fprintf(stderr, "17");
- X len_cnt[16]--;
- X for (i = 15; i > 0; i--) {
- X if (len_cnt[i] != 0) {
- X len_cnt[i]--; len_cnt[i+1] += 2; break;
- X }
- X }
- X cum--;
- X }
- X for (i = 16; i > 0; i--) {
- X k = len_cnt[i];
- X while (--k >= 0) len[*sortptr++] = i;
- X }
- }
- X
- static void downheap(i)
- int i;
- X /* priority queue; send i-th entry down heap */
- {
- X int j, k;
- X
- X k = heap[i];
- X while ((j = 2 * i) <= heapsize) {
- X if (j < heapsize && freq[heap[j]] > freq[heap[j + 1]])
- X j++;
- X if (freq[k] <= freq[heap[j]]) break;
- X heap[i] = heap[j]; i = j;
- X }
- X heap[i] = k;
- }
- X
- static void make_code(j, length, code)
- int j;
- uchar length[];
- ushort code[];
- {
- X int i;
- X ushort start[18];
- X
- X start[1] = 0;
- X for (i = 1; i <= 16; i++)
- X start[i + 1] = (start[i] + len_cnt[i]) << 1;
- X for (i = 0; i < j; i++) code[i] = start[length[i]]++;
- }
- X
- int make_tree(nparm, freqparm, lenparm, codeparm)
- int nparm;
- ushort freqparm[];
- uchar lenparm[];
- ushort codeparm[];
- X /* make tree, calculate len[], return root */
- {
- X int i, j, k, avail;
- X
- X n = nparm; freq = freqparm; len = lenparm;
- X avail = n; heapsize = 0; heap[1] = 0;
- X for (i = 0; i < n; i++) {
- X len[i] = 0;
- X if (freq[i]) heap[++heapsize] = i;
- X }
- X if (heapsize < 2) {
- X codeparm[heap[1]] = 0; return heap[1];
- X }
- X for (i = heapsize / 2; i >= 1; i--)
- X downheap(i); /* make priority queue */
- X sortptr = codeparm;
- X do { /* while queue has at least two entries */
- X i = heap[1]; /* take out least-freq entry */
- X if (i < n) *sortptr++ = i;
- X heap[1] = heap[heapsize--];
- X downheap(1);
- X j = heap[1]; /* next least-freq entry */
- X if (j < n) *sortptr++ = j;
- X k = avail++; /* generate new node */
- X freq[k] = freq[i] + freq[j];
- X heap[1] = k; downheap(1); /* put into queue */
- X left[k] = i; right[k] = j;
- X } while (heapsize > 1);
- X sortptr = codeparm;
- X make_len(k);
- X make_code(nparm, lenparm, codeparm);
- X return k; /* return root */
- }
- SHAR_EOF
- chmod 0644 maketree.c ||
- echo 'restore of maketree.c failed'
- Wc_c="`wc -c < 'maketree.c'`"
- test 2836 -eq "$Wc_c" ||
- echo 'maketree.c: original size 2836, current size' "$Wc_c"
- fi
- # ============= misc.c ==============
- if test -f 'misc.c' -a X"$1" != X"-c"; then
- echo 'x - skipping misc.c (File already exists)'
- else
- echo 'x - extracting misc.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'misc.c' &&
- #ifndef LINT
- /* derived from: misc.c 2.6 88/08/15 16:17:23 */
- static char sccsid[]="$Source: /usr/home/dhesi/zoo/RCS/misc.c,v $\n\
- $Id: misc.c,v 1.8 91/07/09 01:54:08 dhesi Exp $";
- #endif /* LINT */
- X
- /*
- Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
- (C) Copyright 1988 Rahul Dhesi -- All rights reserved
- */
- #include "options.h"
- /* Miscellaneous functions needed by Zoo but not by Ooz */
- X
- #include "zoo.h"
- #include "zooio.h"
- #include "various.h"
- X
- #include "errors.i"
- #include "zoofns.h"
- #ifndef NOSIGNAL
- #include <signal.h>
- #endif
- X
- #ifdef NEEDCTYP
- #include <ctype.h>
- #else
- #include "portable.h"
- #endif
- X
- int ver_too_high PARMS((struct zoo_header *));
- X
- /*
- calc_ofs() is given a string that (supposedly) begins with a string
- of digits. It returns a corresponding numeric value. If no such
- string, it aborts the program with a fatal error message.
- */
- long calc_ofs(str)
- char *str;
- {
- X long retval;
- X char *p;
- X retval = 0L;
- X p = str; /* save for error message */
- X while (isdigit(*str)) {
- X retval = retval * 10L + (*str-'0');
- X str++;
- X }
- X if (*str != '\0')
- X prterror ('f', "Invalid number %s\n", p);
- X return (retval);
- }
- X
- /*
- choosefname() decides which filename to use. If a long filename is present,
- and if the syntax is that of UNIX, MS-DOS or the portable form, we use it;
- else we use the short filename.
- */
- X
- char *choosefname(direntry)
- struct direntry *direntry;
- {
- X char *retptr; /* pointer to name that we will return */
- X switch (direntry->system_id) {
- X case SYSID_NIX:
- X case SYSID_PORTABLE:
- X case SYSID_MS:
- X retptr = (direntry->namlen != 0) ? direntry->lfname : direntry->fname;
- X break;
- X default:
- X retptr = direntry->fname;
- X break;
- X }
- X return (retptr);
- } /* choosefname() */
- X
- /*
- combine() combines a directory name and a filename, making sure the
- two are separated by a path separator
- */
- char *combine(result, dirname, fname)
- char result[], *dirname, *fname;
- {
- X *result = '\0';
- X if (*dirname != '\0') {
- #ifdef DIR_LBRACK /* hack for VMS */
- X strcat (result, DIR_LBRACK);
- X
- X /* "/" => "[", "./" => "[." others => "[." */
- X
- X if (dirname[0] == '/') { /* absolute path => "[" */
- X strcat (result, dirname + 1);
- X } else if (dirname[0] == '.' && dirname[1] == '/') {
- X strcat (result, CUR_DIR);
- X strcat (result, dirname + 2);
- X } else {
- X strcat (result, CUR_DIR);
- X strcat (result, dirname);
- X }
- X
- /* folowing #ifdef block ought to be outside #ifdef DIR_LBRACK, and
- X for loop should then start with p=result. This is currently
- X just a hack for VMS.
- */
- #ifdef DIR_SEP
- X if (DIR_SEP != '/') { /* if char separating dirs is not "/", */
- X char *p;
- X for (p = result+2; *p != '\0'; p++) /* change it to underscore */
- X if (*p == DIR_SEP)
- X *p = '_';
- X }
- #endif
- X
- X {
- X char *p;
- X for (p = result; *p != '\0'; p++)
- X if (*p == '/')
- X *p = '.';
- X }
- #else
- X strcat (result, dirname);
- #endif
- X if (*lastptr(result) != *PATH_CH)
- X strcat(result, PATH_CH);
- X }
- X
- X strcat(result, fname);
- X return (result);
- }
- X
- /*
- fullpath() accepts a pointer to a directory entry and returns the
- combined directory name + filename. The long filename is used
- if available, else the short filename is used.
- */
- char *fullpath (direntry)
- struct direntry *direntry;
- {
- X static char result[PATHSIZE];
- X combine (result,
- X direntry->dirlen != 0 ? direntry->dirname : "",
- X (direntry->namlen != 0) ? direntry->lfname : direntry->fname
- X );
- X return (result);
- }
- X
- /*
- ver_too_high returns true if version of provided archive header is
- too high for us to manipulate archive
- */
- X
- int ver_too_high (header)
- struct zoo_header *header;
- {
- X return (header->major_ver > MAJOR_VER ||
- X (header->major_ver == MAJOR_VER &&
- X header->minor_ver > MINOR_VER));
- }
- X
- /*
- rwheader() reads archive header, checks consistency, makes sure its
- version number is not too high, updates it if too low, and seeks to
- beginning of first directory entr. If `preserve' is 1, it preserves
- the header type; if `preserve' is 0, it gives a fatal error message
- if type is 0.
- */
- X
- void rwheader (header, zoo_file, preserve)
- register struct zoo_header *header;
- ZOOFILE zoo_file;
- int preserve;
- {
- X
- X frd_zooh (header, zoo_file);
- X
- X if ((header->zoo_start + header->zoo_minus) != 0L)
- X prterror ('f', failed_consistency);
- X if (ver_too_high (header))
- X prterror ('f', wrong_version, header->major_ver, header->minor_ver);
- X
- X if (preserve == 0 && header->type == 0)
- X prterror ('f', packfirst);
- X
- X /* We reach here if the archive version is not too high. Now, if it
- X isn't the same as ours, we bring it up to ours so the modified archive
- X will be safe from previous versions of Zoo */
- X
- X if (header->major_ver != MAJOR_VER || header->minor_ver != MINOR_VER) {
- X header->major_ver = MAJOR_VER;
- X header->minor_ver = MINOR_VER;
- X zooseek (zoo_file, 0L, 0); /* seek to beginning */
- X fwr_zooh (header, zoo_file);
- X }
- X zooseek (zoo_file, header->zoo_start, 0); /* seek to where data begins */
- } /* rwheader */
- X
- /*
- writedir() write a directory entry with keyboard interrupt disabled
- */
- void writedir (direntry, zoo_file)
- struct direntry *direntry;
- ZOOFILE zoo_file;
- {
- #ifndef NOSIGNAL
- X T_SIGNAL (*oldsignal)();
- X oldsignal = signal (SIGINT, SIG_IGN);
- #endif
- X if (fwr_dir (direntry, zoo_file) == -1)
- X prterror ('f', disk_full);
- #ifndef NOSIGNAL
- X signal (SIGINT, oldsignal);
- #endif
- }
- X
- /*
- readdir() reads a directory entry from an archive. If the directory
- entry is invalid and if fail is 1, it causes a fatal error;
- else it returns. Return value is 0 if no error else -1;
- */
- X
- int readdir (direntry, zoo_file, fail) /* read directory entry */
- register struct direntry *direntry;
- ZOOFILE zoo_file;
- int fail; /* 0 -> return, 1 -> abort on error */
- {
- X if (frd_dir (direntry, zoo_file) < 0) {
- X if (fail) {
- X prterror ('f', bad_directory);
- X } else
- X return (-1);
- X }
- X if (direntry->zoo_tag != ZOO_TAG) {
- X if (fail)
- X prterror ('f', bad_directory);
- X else
- X return (-1);
- X }
- X return (0);
- }
- X
- /* use pointer version below */
- #ifdef COMMENT
- /* instr() searches a string for a substring */
- instr (s, t) /* return index of string t in string s, -1 if none */
- char s[], t[]; /* .. from K&R page 67 */
- {
- X int i;
- X register int j, k;
- X for (i = 0; s[i] != '\0'; i++) {
- X for (j = i, k = 0; t[k] != '\0' && s[j]==t[k]; j++, k++)
- X ;
- X if (t[k] == '\0')
- X return (i);
- X }
- X return (-1);
- }
- #endif /* COMMENT */
- X
- /* instr() searches a string for a substring */
- /* from J. Brian Waters */
- int instr (s, t) /* return the position of t in s, -1 if none */
- char *s, *t; /* a pointer version of K&R index function p.67 */
- { /* renamed to instr() to avoid conflicts with C RTL - JBW */
- X
- X register char *i, *j, *k;
- X
- X for (i = s; *i; i++) {
- X for (j = i, k = t; (*k) && (*j++ == *k); k++)
- X ;
- X if (!*k)
- X return ((int) (i - s));
- X }
- X return(-1);
- }
- X
- /* cfactor() calculates the compression factor given a directory entry */
- int cfactor (org_size, size_now)
- long org_size, size_now;
- {
- X register int size_factor;
- X while ((unsigned long) org_size > 32000) { /* avoid later overflow */
- X org_size = (unsigned long) org_size / 1024;
- X size_now = (unsigned long) size_now / 1024;
- X }
- X if (org_size == 0) /* avoid division by zero */
- X size_factor = 0;
- X else {
- X size_factor = (int)
- X (
- X (1000 *
- X ((unsigned long) org_size - (unsigned long) size_now)
- X ) / org_size + 5
- X ) / 10;
- X }
- X return (size_factor);
- }
- X
- /***********
- str_dup() duplicates a string using dynamic memory.
- */
- X
- char *str_dup (str)
- register char *str;
- {
- X return (strcpy (emalloc (strlen(str)+1), str));
- }
- X
- /**************
- cmpnum() compares two pairs of unsigned integers and returns a negative,
- zero, or positive value as the comparison yields less than, equal, or
- greater than result. Each pair of unsigned integers is considered to be the
- more significant and the less significant half of a longer unsigned number.
- X
- Note: cmpnum is used to compare dates and times.
- */
- X
- int cmpnum (hi1, lo1, hi2, lo2)
- register unsigned int hi1, hi2;
- unsigned int lo1, lo2;
- {
- X if (hi1 != hi2)
- X return (hi1 > hi2 ? 1 : -1);
- X else {
- X if (lo1 == lo2)
- X return (0);
- X else
- X return (lo1 > lo2 ? 1 : -1);
- X }
- }
- X
- /*******************/
- /* writenull() */
- /* writes a null directory entry to an open archive */
- void writenull (file, length)
- ZOOFILE file;
- int length;
- {
- #ifndef NOSIGNAL
- X T_SIGNAL (*oldsignal)();
- #endif
- X struct direntry newentry;
- X memset ((char *) &newentry, 0, sizeof (newentry));
- X newentry.zoo_tag = ZOO_TAG;
- X newentry.type = 2;
- X /* Force entry to be the required length plus possibly 2 stray bytes
- X by dividing up the needed padding into dirlen and namlen. */
- X if (length > SIZ_DIRL)
- X newentry.dirlen = newentry.namlen = (length-SIZ_DIRL)/2 + 2;
- X else
- X newentry.dirlen = newentry.namlen = 0;
- #ifndef NOSIGNAL
- X oldsignal = signal (SIGINT, SIG_IGN);
- #endif
- X if (fwr_dir (&newentry, file) == -1)
- X prterror ('f', disk_full);
- #ifndef NOSIGNAL
- X signal (SIGINT, oldsignal);
- #endif
- }
- X
- #ifdef FORCESLASH
- /*******************/
- /*
- fixslash() changes all "\" characters in the supplied string to "/".
- */
- X
- void fixslash (str)
- char *str;
- {
- X register char *p;
- X for (p = str; *p != '\0'; p++)
- X if (*p == '\\')
- X *p = '/';
- }
- #endif /* FORCESLASH */
- SHAR_EOF
- chmod 0644 misc.c ||
- echo 'restore of misc.c failed'
- Wc_c="`wc -c < 'misc.c'`"
- test 9679 -eq "$Wc_c" ||
- echo 'misc.c: original size 9679, current size' "$Wc_c"
- fi
- # ============= misc2.c ==============
- if test -f 'misc2.c' -a X"$1" != X"-c"; then
- echo 'x - skipping misc2.c (File already exists)'
- else
- echo 'x - extracting misc2.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'misc2.c' &&
- #ifndef LINT
- /* @(#) misc2.c 2.7 88/01/24 12:47:36 */
- static char sccsid[]="@(#) misc2.c 2.7 88/01/24 12:47:36";
- #endif /* LINT */
- X
- /*
- Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
- (C) Copyright 1988 Rahul Dhesi -- All rights reserved
- */
- #include "options.h"
- /* Miscellaneous routines */
- #include "portable.h"
- #include "zooio.h"
- #include "various.h"
- #include "errors.i"
- #include "zoomem.h"
- #include "zoo.h"
- #include "zoofns.h" /* only for malloc */
- X
- void makepath PARMS((char *));
- X
- /**********************/
- /* memerr() */
- /* Give error message on memory error and abort */
- void memerr(i)
- unsigned int i;
- {
- #ifdef OOZ
- X prterror ('f', no_memory, "", "");
- #else
- X if (i != 0)
- X prterror ('f', no_memory);
- X else
- X prterror('f', "needed %u bytes: %s", no_memory);
- #endif
- }
- X
- /**********************/
- /*
- emalloc() allocates memory like malloc() does (and it calls malloc). However,
- it automatically calls the error function memerr() if memory couldn't be
- allocated. It also assumes that memory will never be freed and conserves it
- by allocating memory in large chunks and then partitioning it out with no
- administrative overhead. This avoids many problems due to various bugs in
- various implementations of malloc, and also avoids a very high amount of
- malloc overhead for repeated allocations to store numerous filenames etc.
- The down side is that we can't use free().
- X
- WARNING: No alignment of allocated memory is attempted, so memory
- allocated through emalloc should be used only for storing strings.
- For allocating memory for other data types use ealloc(). */
- X
- VOIDPTR emalloc (size)
- unsigned int size;
- {
- #define BLOCK_SIZE 512 /* memory allocation granularity */
- X
- #ifdef USE_MALLOC
- /* Pass on memory requests to malloc() */
- X char *ptr;
- X if ((ptr = malloc (size)) == NULL)
- X memerr(size);
- X return (ptr);
- #else
- X static char *memptr;
- X static unsigned avail = 0;
- X unsigned malloc_incr;
- X char *retval;
- X
- X if (size == 0)
- X return (NULL);
- X
- X /* if not enough space avail get some more */
- X if (avail < size) {
- X malloc_incr = BLOCK_SIZE;
- X if (malloc_incr < size)
- X malloc_incr = size;
- X while (malloc_incr >= size && (memptr = malloc (malloc_incr)) == NULL)
- X malloc_incr = (malloc_incr / 6) * 5;
- X avail = malloc_incr;
- X }
- X
- X if (avail < size)
- X memerr(size); /* no return from this */
- X retval = memptr;
- X memptr += size;
- X avail -= size;
- X return (retval);
- #endif /* end of not USE_MALLOC */
- }
- X
- /**********************/
- /*
- ealloc() is just a wrapper around malloc(), which causes memerr() to be
- called if memory cannot be allocated. All memory requests are passed on
- to malloc. Allocated memory can later be freed. */
- X
- VOIDPTR ealloc(size)
- unsigned int size;
- {
- X char *ptr;
- X if ((ptr = malloc (size)) == NULL)
- X memerr(size);
- X return ptr;
- }
- X
- /**********************/
- /* erealloc() is a wrapper around realloc() the way ealloc is a wrapper
- around malloc(). It calls memerr() on error. */
- X
- VOIDPTR erealloc(p, size)
- VOIDPTR p;
- unsigned int size;
- {
- X char *ptr;
- X if ((ptr = realloc (p, size)) == NULL)
- X memerr(size);
- X return ptr;
- }
- X
- /**********************/
- /* putstr()
- This function prints a string to standard output. If the received
- string pointer is NULL, it is handled safely. This function is here
- for historical reasons: Ooz was once coded to not use printf under
- MSDOS to save space, and at that time putstr() printed a string
- without using printf. It should eventually be eliminated and all
- calls to it replaced with calls to printf directly.
- */
- void putstr (str)
- register char *str;
- {
- X if (str == NULL)
- X return;
- X printf ("%s", str);
- }
- X
- /**********************/
- /* exists()
- This function checks the existence of a file.
- X
- If the symbol EXISTS is defined, that is called as a macro and
- supplied the filename. It must return 1 if the file exists and
- 0 if it does not.
- X
- If EXISTS is not defined, exists() tests to see if the file can be
- opened for reading or writing; if so, it returns 1 else it returns 0.
- X
- Because of the delay between the time existence is checked and the time Zoo
- creates a files, a race condition exists. It would be better to
- use open() with the O_EXCL flag but that will not work for many
- systems.
- */
- X
- int exists (fname)
- char *fname;
- {
- #ifdef EXISTS
- X return EXISTS(fname);
- #else
- X ZOOFILE f;
- X
- X if ( (f = zooopen (fname, Z_READ )) != NOFILE ||
- X (f = zooopen (fname, Z_WRITE)) != NOFILE ) {
- X zooclose (f);
- X return (1);
- X } else
- X return (0);
- #endif /* ifdef EXISTS */
- }
- X
- /****************
- newcat() allocates enough space to concatenate two strings then returns
- a pointer to the concatenated result */
- X
- char *newcat (r, s)
- char *r, *s;
- {
- X char *temp = emalloc (strlen (r) + strlen (s) + 2); /* 1 spare */
- X strcpy (temp, r);
- X strcat (temp, s);
- X return (temp);
- }
- X
- X
- /* Creates a path */
- void makepath(path)
- char *path;
- {
- X char tmppath[PATHSIZE];
- X char *slashpos;
- X if (path == NULL)
- X return;
- X while (*lastptr(path) == *(char *) PATH_CH) /* remove trailing slashes */
- X *lastptr(path) = '\0';
- X if (*path == '\0')
- X return;
- X
- X slashpos = findlast(path, PATH_CH); /* find last slash */
- X if (slashpos == NULL) { /* if not, just create dir. */
- X MKDIR(path);
- X return;
- X } else { /* otherwise... */
- X if (slashpos == path) { /* if leading slash */
- X MKDIR(slashpos); /* make that directory */
- X return; /* and done */
- X } else {
- X strcpy(tmppath,path); /* save path */
- X *slashpos = '\0'; /* split into prefix & suffix */
- #ifdef DEBUG
- X printf("making path from [%s]\n", path);
- #endif
- X makepath(path); /* make path from prefix */
- #ifdef DEBUG
- X printf("making dir from [%s]\n", tmppath);
- #endif
- X MKDIR(tmppath); /* make dir from suffix */
- X }
- X }
- } /* makepath() */
- X
- /*
- If no extension in filename add supplied extension
- */
- char *addext (fname, ext)
- char *fname;
- char *ext;
- {
- X if (strchr (nameptr (fname), EXT_CH) == NULL)
- X return (newcat (fname, ext));
- X else
- X return (fname);
- }
- X
- #ifdef VER_CH /* remove any trailing extension field */
- char *strip_ver (fname)
- char *fname;
- {
- X char *p = strchr (fname, VER_CH);
- X if (p != NULL)
- X *p = '\0';
- }
- #endif
- X
- /*
- Function samefile() compares two filenames to see if they are the
- same file. Just strcmp() or str_icmp() could have been used, except
- that if the filenames have trailing version fields, we want to
- compare those always equal. samefile() is called by routines
- that want to avoid adding an archive to itself.
- */
- int samefile (f1, f2)
- char *f1;
- char *f2;
- {
- #ifdef IGNORECASE
- #define COMPARE str_icmp
- #else
- #define COMPARE strcmp
- #endif
- X
- #ifdef VER_CH
- X char tf1[LFNAMESIZE];
- X char tf2[LFNAMESIZE];
- X strcpy (tf1, f1);
- X strcpy (tf2, f2);
- X strip_ver (tf1); /* strip version fields */
- X strip_ver (tf2);
- X return (COMPARE (tf1, tf2) == 0);
- #else
- /* if no version fields, just use strcmp(i) */
- X return (COMPARE (f1, f2) == 0);
- #endif
- }
- X
- #ifdef USE_ASCII
- int isdigit (c)
- int c;
- {
- X return (c >= '0' && c <= '9');
- }
- int isupper (c)
- int c;
- {
- X return (c >= 'A' && c <= 'Z');
- }
- X
- int toascii (c)
- int c;
- {
- X return (c & 0x7f);
- }
- X
- int tolower (c)
- int c;
- {
- X return (isupper(c) ? (c | 0x20) : c);
- }
- #endif
- X
- #ifdef GETTZ
- /****************
- Function tzadj() accepts a directory entry and adjusts its timestamp
- to reflect its timezone. Uses function mstime() from mstime.i
- and mstonix() from nixtime.i.
- */
- X
- long mstonix();
- long gettz();
- #include "mstime.i" /* get mstime() */
- X
- void tzadj (direntry)
- struct direntry *direntry;
- {
- X long diff_tz;
- X long longtime;
- X if (direntry->tz == NO_TZ) /* none stored */
- X return;
- X diff_tz = (long) direntry->tz * (3600/4) - gettz(); /* diff. in seconds */
- X longtime = mstonix (direntry->date, direntry->time) + diff_tz; /* adj tz */
- X mstime (longtime, &direntry->date, &direntry->time);
- }
- #endif /* GETTZ */
- X
- /* how long an int can be in text form -- allow 64-bit ints */
- #define INT_TEXT 21
- X
- /* Function add_version adds a version suffix to a filename, given
- the directory entry corresponding to the file */
- void add_version (fname, direntry)
- char *fname;
- struct direntry *direntry;
- {
- X char verstr[INT_TEXT]; /* string buffer for conversion to text */
- X if (direntry->vflag & VFL_ON) {
- X sprintf (verstr, "%u", direntry->version_no);
- X strcat (fname, VER_DISPLAY);
- X strcat (fname, verstr);
- X }
- }
- SHAR_EOF
- chmod 0644 misc2.c ||
- echo 'restore of misc2.c failed'
- Wc_c="`wc -c < 'misc2.c'`"
- test 8587 -eq "$Wc_c" ||
- echo 'misc2.c: original size 8587, current size' "$Wc_c"
- fi
- true || echo 'restore of msdos.c failed'
- echo End of part 5, continue with part 6
- exit 0
-