home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
3
/
3615
< prev
next >
Wrap
Internet Message Format
|
1991-07-10
|
32KB
From: dhesi@bsu-cs.bsu.edu (Rahul Dhesi)
Newsgroups: alt.sources
Subject: zoo 2.1 source part 14/15
Message-ID: <12781@bsu-cs.bsu.edu>
Date: 10 Jul 91 11:50:18 GMT
Checksum: 4111504653 (verify with "brik -cv")
Submitted-by: dhesi@bsu-cs.bsu.edu
Archive-name: zoo210/part14
---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is part 14 of zoo210
# ============= zooext.c ==============
if test -f 'zooext.c' -a X"$1" != X"-c"; then
echo 'x - skipping zooext.c (File already exists)'
else
echo 'x - extracting zooext.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'zooext.c' &&
#ifndef LINT
/* derived from: zooext.c 2.21 88/08/24 02:39:04 */
/*$Source: /usr/home/dhesi/zoo/RCS/zooext.c,v $*/
/*$Id: zooext.c,v 1.9 91/07/09 01:54:13 dhesi Exp $*/
static char sccsid[]="$Source: /usr/home/dhesi/zoo/RCS/zooext.c,v $\n\
$Id: zooext.c,v 1.9 91/07/09 01:54:13 dhesi Exp $";
#endif /* LINT */
X
/*
Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
(C) Copyright 1988 Rahul Dhesi -- All rights reserved
(C) Copyright 1991 Rahul Dhesi -- All rights reserved
*/
/* Extract file from archive. Extracts files specified in parameter-list
X from archive zoo_path. If none specified, extracts all files from
X archive. */
X
#include "options.h"
#include "zoo.h"
#include "parse.h" /* defines struct for parse() */
X
#include "portable.h" /* portable I/O definitions */
#include "machine.h" /* machine-specific declarations */
X
#include "zooio.h"
#include "various.h"
X
#ifndef NOSIGNAL
#include <signal.h>
#endif
X
#include "zoofns.h"
X
#ifdef MODE_BIN /* will need fileno() from stdio.h */
# include <stdio.h>
#endif
X
void makepath PARMS((char *));
int needed PARMS((char *, struct direntry *, struct zoo_header *));
void putstr PARMS((char *));
X
#ifdef FATTR
int setfattr PARMS ((char *, unsigned long));
#endif /* FATTR */
X
extern int quiet;
X
#include "errors.i"
X
/* Following two are used by ctrl_c() also, hence declared here */
char extfname[LFNAMESIZE]; /* filename of extracted file */
char prtfname[LFNAMESIZE]; /* name of extracted file on screen */
static ZOOFILE this_file; /* file to extract */
X
static int tofile; /* true if not pipe or null device */
extern unsigned int crccode;
extern char *out_buf_adr; /* address of output buffer */
X
void zooext(zoo_path, option)
char *zoo_path, *option;
{
char *whichname; /* which name to extract */
char matchname[PATHSIZE]; /* for pattern matching only */
#ifndef NOSIGNAL
T_SIGNAL (*oldsignal)(); /* to save previous SIGINT handler */
#endif
ZOOFILE zoo_file; /* open archive */
long next_ptr; /* pointer to within archive */
struct zoo_header zoo_header; /* header for archive */
int status; /* error status */
int exit_status = 0; /* exit status */
int error_message; /* Whether to give error message */
unsigned long disk_space; /* disk space left */
int matched = 0; /* Any files matched? */
int overwrite = 0; /* force overwrite of files? */
int supersede = 0; /* supersede newer files? */
int needdel = 0; /* extract deleted files too */
int usepath = 2; /* use path for extraction */
int todot = 0; /* extract relative to . */
int badcrc_count = 0; /* how many files with bad CRC */
int bad_header = 0; /* to avoid spurious messages later */
long fiz_ofs = 0; /* offset where to start */
long dat_ofs = 0; /* .. and offset of file data */
int pipe = 0; /* are we piping output? */
int null_device = 0; /* are we sending to null device? */
#ifndef PORTABLE
int fast_ext = 0; /* fast extract as *.?Z? */
int alloc_size; /* disk allocation unit size */
#endif
struct direntry direntry; /* directory entry */
int first_dir = 1; /* first dir entry seen? */
X
static char extract_ver[] = "Zoo %d.%d is needed to extract %s.\n";
static char no_space[] = "Insufficient disk space to extract %s.\n";
X
while (*option) {
X switch (*option) {
#ifndef PORTABLE
X case 'z': fast_ext++; break;
#endif
X case 'x':
X case 'e': break;
X case 'N': null_device++; break;
X case 'O': overwrite += 2; break;
X case 'o': overwrite++; break;
X case 'p': pipe++; break;
X case 'S': supersede++; break;
X case 'd': needdel++; break;
X case 'q': quiet++; break;
X case ':': usepath = 0; break;
X case '/': usepath++; break;
X case '.': todot++; break;
X case '@': /* if @m,n specified, fiz_ofs = m, dat_ofs = n */
X {
X char *comma_pos;
X ++option;
X comma_pos = strchr(option, ',');
X if (comma_pos != NULL) {
X dat_ofs = calc_ofs (comma_pos + 1);
X *comma_pos = '\0';
X }
X fiz_ofs = calc_ofs(option);
X goto no_more;
X }
X default:
X prterror ('f', inv_option, *option);
X /* break; */
X }
X option++;
}
X
no_more: /* come from exit in while loop above */
X
X
if (overwrite == 1) /* must be at least 2 to begin with */
X overwrite--;
X
if (null_device && pipe) {
X prterror ('f', inv_option, 'p');
X pipe = 0;
}
X
if (overwrite && pipe)
X prterror ('w', option_ignored, 'O');
X
#ifndef PORTABLE
if (null_device && fast_ext) {
X prterror ('w', inv_option, 'N');
X null_device = 0;
}
#endif
X
tofile = !pipe && !null_device; /* sending to actual file */
X
zoo_file = zooopen(zoo_path, Z_READ);
X
if (zoo_file == NOFILE)
X prterror ('f', could_not_open, zoo_path);
X
if (fiz_ofs != 0L) { /* if offset specified, start there */
X prterror ('m', start_ofs, fiz_ofs, dat_ofs);
X zooseek (zoo_file, fiz_ofs, 0);
} else {
X /* read header */
X frd_zooh (&zoo_header, zoo_file);
X if ((zoo_header.zoo_start + zoo_header.zoo_minus) != 0L) {
X prterror ('w', failed_consistency);
X bad_header++;
X exit_status = 1;
X }
X zooseek (zoo_file, zoo_header.zoo_start, 0); /* seek to where data begins */
}
X
#ifndef PORTABLE
disk_space = space (0, &alloc_size); /* remember disk space left */
#else
disk_space = MAXLONG; /* infinite disk space */
#endif
X
/* if piping output we open the output device just once */
if (null_device) {
X this_file = NULLFILE;
} else if (pipe)
X this_file = STDOUT; /* standard output */
X
while (1) {
X frd_dir (&direntry, zoo_file);
X if (direntry.zoo_tag != ZOO_TAG) {
X long currpos, zoolength;
X prterror ('F', invalid_header);
X
X /* Note: if header was bad, there's no point trying to find
X how many more bytes aren't processed -- our seek position is
X likely very wrong */
X
X if (!bad_header)
X if ((currpos = zootell (zoo_file)) != -1L)
X if (zooseek (zoo_file, 0L, 2) != -1)
X if ((zoolength = zootell (zoo_file)) != -1L)
X printf (cant_process, zoolength - currpos);
X zooexit (1);
X }
X if (direntry.next == 0L) { /* END OF CHAIN */
X break; /* EXIT on end of chain */
X }
X /* when first direntry read, change dat_ofs from abs. pos. to rel. offset */
X if (first_dir && dat_ofs != 0) {
X dat_ofs -= direntry.offset;
X first_dir = 0;
X }
X next_ptr = direntry.next + dat_ofs; /* ptr to next dir entry */
X
X whichname = choosefname(&direntry); /* which filename */
X whichname = str_dup(whichname); /* bug fix */
X fixfname(whichname); /* fix syntax */
X strcpy (matchname, fullpath (&direntry)); /* get full pathname */
X if (zoo_header.vdata & VFL_ON)
X add_version (matchname, &direntry); /* add version suffix */
X
/* if extraction to subtree rooted at curr dir, modify pathname */
#if 0
#ifdef DIR_LBRACK
X if (todot && direntry.dirname[0] == *DIR_LBRACK &&
X direntry.dirname[1] != *CUR_DIR) {
X char tmpstr[PATHSIZE];
X strcpy (tmpstr, DIR_LBRACK);
X strcat (tmpstr, CUR_DIR);
X strcat (tmpstr, &direntry.dirname[1]);
X strcpy (direntry.dirname, tmpstr);
X }
#endif
#endif
X
X /* hard-coded '/' should be eventually removed */
X if (todot && *direntry.dirname == '/') {
X char tmpstr[PATHSIZE];
X strcpy(tmpstr, direntry.dirname);
X strcpy(direntry.dirname,CUR_DIR);
X strcat(direntry.dirname, tmpstr);
X }
X
X /* matchname now holds the full pathname for pattern matching */
X
X if ( ( (needdel && direntry.deleted) ||
X (needdel < 2 && !direntry.deleted)
X ) && needed(matchname, &direntry, &zoo_header)) {
X matched++; /* update count of files extracted */
X
X if (direntry.major_ver > MAJOR_LZH_VER ||
X (direntry.major_ver == MAJOR_LZH_VER &&
X direntry.minor_ver > MINOR_LZH_VER)) {
X prterror ('e', extract_ver, direntry.major_ver,
X direntry.minor_ver, whichname);
X exit_status = 1;
X goto loop_again;
X }
X
X /*
X If extracting to null device, or if user requested extraction
X of entire path, include any directory name in filename.
X If extraction to current directory requested, and if extfname
X begins with path separator, fix it */
X
X strcpy (extfname, whichname);
X if ((usepath || null_device) && direntry.dirlen != 0) {
X combine(extfname, direntry.dirname, whichname);
X if (usepath > 1 && !null_device)
X makepath(direntry.dirname); /* make dir prefix */
X }
X
X strcpy(prtfname, extfname);
X if (zoo_header.vdata & VFL_ON)
X add_version (prtfname, &direntry);
X
X if (tofile) {
X int present = 0;
X
#ifndef PORTABLE
X /*
X if Z format (fast) extraction, extension is created as
X follows: for no current extension, new extension is "zzz";
X for current extension "a", new extension is "azz"; for
X current extension "ab", new extension is "azb"; and for
X current extension "abc", new extension is "azc".
X */
X
X if (fast_ext) {
X int length;
X struct path_st path_st;
X parse (&path_st, extfname); /* split filename */
X strcpy (extfname, path_st.fname); /* just root filename */
X length = strlen (path_st.ext);
X strcat (extfname, ".");
X if (length == 0)
X strcat (extfname, "zzz"); /* no ext -> .zzz */
X else if (length == 1) {
X strcat (extfname, path_st.ext);
X strcat (extfname, "zz"); /* *.? -> *.?zz */
X } else { /* length is 2 or 3 */
X if (length == 2) /* allow .aa, .ab, etc. */
X path_st.ext[2] = path_st.ext[1];
X path_st.ext[1] = 'z';
X strcat (extfname, path_st.ext); /* *.?? -> *.?z? */
X }
X strcpy(prtfname, direntry.fname);
X add_version (prtfname, &direntry);
X }
#endif /* ifndef PORTABLE */
X
X /* don't extract if archived file is older than disk copy */
X if (!supersede && exists(extfname)) {
X unsigned int ddate, dtime;
#ifdef GETUTIME
X getutime (extfname, &ddate, &dtime);
#else
X ZOOFILE tfile;
X ddate = dtime = 0xffff; /* assume maximum */
X tfile = zooopen(extfname, Z_READ);
X if (tfile == NOFILE)
X goto loop_again;
X gettime (tfile, &ddate, &dtime);
X zooclose (tfile);
#endif
X if (cmpnum (direntry.date, direntry.time, ddate, dtime) <= 0) {
X prterror ('m', "%-14s -- skipped\n", prtfname);
X goto loop_again;
X }
X }
X
X if (overwrite) {
X this_file = zoocreate (extfname);
#ifdef FATTR
X /* if can't open file, and OO option, make it writable first */
X if (this_file == NOFILE && overwrite >= 4 &&
X (direntry.fattr >> 22) == 1 && exists(extfname)) {
X setfattr (extfname, (unsigned long) (1L << 7) | direntry.fattr);
X this_file = zoocreate (extfname);
X }
#endif /* FATTR */
X } else {
X if (exists (extfname)) {
X present = 1;
X this_file = NOFILE;
X } else
X this_file = zoocreate (extfname);
X }
X error_message = 1;
X if (this_file == NOFILE) {
X if (present == 1) { /* if file exists already */
X char ans[20]; /* answer to "Overwrite?" */
X do {
#ifdef EXT_ANYWAY
X printf ("%s exists; extract anyway? [Yes/No/All] ",
X extfname);
#else
X printf ("Overwrite %s (Yes/No/All)? ", extfname);
#endif
X fflush (stdin);
X fgets (ans, sizeof(ans), stdin);
X str_lwr (ans);
X } while (*ans != 'y' && *ans != 'n' && *ans != 'a');
X
X if (*ans == 'a')
X overwrite++;
X if (*ans == 'y' || *ans == 'a') {
X this_file = zoocreate(extfname);
X error_message = 1; /* give error message if open fails */
X } else {
X error_message = 0; /* user said 'n', so no error message */
X }
X } else {
X error_message = 1; /* Real error -- give error message */
X }
X } /* end if */
X } /* end if */
X
X if (this_file == NOFILE) { /* file couldn't be opened */
X if (error_message == 1) {
X prterror ('e', "Can't open %s for output.\n", extfname);
X exit_status = 1;
X
#ifndef PORTABLE
X /* if error was due to full disk, abort */
X if (space(0, &alloc_size) < alloc_size)
X prterror ('f', disk_full);
#endif
X
X }
X } else if (zooseek (zoo_file, (direntry.offset + dat_ofs), 0) == -1L) {
X prterror ('e', "Could not seek to file data.\n");
X exit_status = 1;
X close_file (this_file);
X } else {
#ifndef PORTABLE
X /* check msdos's free disk space if we seem to be running low
X (within 1 cluster of being full) */
X if (tofile && disk_space < direntry.org_size + alloc_size) {
X disk_space = space (0, &alloc_size);
X if (disk_space < alloc_size) {
X close_file (this_file);
X unlink (extfname);
X prterror ('f', disk_full);
X }
X }
#endif
X if (tofile && disk_space < direntry.org_size) {
#ifdef PORTABLE
X ;
#else
X prterror ('e', no_space, prtfname);
X unlink (extfname); /* delete any created file */
#endif /* portable */
X
X } else {
X
#ifndef PORTABLE
X if (fast_ext) { /* fast ext -> create header */
X void make_tnh PARMS((struct tiny_header *, struct direntry *));
X struct tiny_header tiny_header;
X make_tnh(&tiny_header, &direntry);
X zoowrite (this_file, (char *) &tiny_header, sizeof(tiny_header));
X
X if (direntry.cmt_size != 0) { /* copy comment */
X long save_pos;
X save_pos = zootell (zoo_file);
X zooseek (zoo_file, direntry.comment, 0);
X getfile (zoo_file, this_file,
X (long) direntry.cmt_size, 0);
X zooseek (zoo_file, save_pos, 0);
X }
X }
#endif /* ifndef PORTABLE */
X
X crccode = 0; /* Initialize CRC before extraction */
X if (!pipe) {
#ifdef PORTABLE
X prterror ('m', "%-14s -- ", prtfname);
#else
X if (fast_ext)
X prterror ('m', "%-12s ==> %-12s -- ",
X prtfname, extfname);
X else
X prterror ('m', "%-12s -- ", prtfname);
#endif /* PORTABLE */
X
X } else { /* must be pipe */
X prterror ('M',"\n\n********\n%s\n********\n",prtfname);
X
#ifdef SETMODE
X MODE_BIN(this_file); /* make std output binary so
X ^Z won't cause error */
#endif
X }
#ifndef NOSIGNAL
X if (tofile)
X {
X oldsignal = signal (SIGINT, SIG_IGN);
X if (oldsignal != SIG_IGN)
X signal (SIGINT, ctrl_c); /* Trap ^C & erase partial file */
X }
#endif /* not NOSIGNAL */
X
X if (direntry.packing_method == 0)
X /* 4th param 1 means CRC update */
X status = getfile (zoo_file, this_file, direntry.size_now, 1);
X
#ifndef PORTABLE
X else if (fast_ext)
X /* 4th param 0 means no CRC update */
X status = getfile (zoo_file, this_file, direntry.size_now, 0);
#endif
X
X else if (direntry.packing_method == 1) {
#ifdef UNBUF_IO
#include "ERROR"
X /* NOT PORTABLE -- DO NOT TRY THIS AT HOME */
X long lseek PARMS ((int, long, int));
X long tell PARMS ((int));
X int this_fd, zoo_fd;
X
X /* get file descriptors */
X this_fd = null_device ? -2 : fileno (this_file);
X zoo_fd = fileno (zoo_file);
X
X zooseek (zoo_file, zootell (zoo_file), 0); /* synch */
X lseek (zoo_fd, zootell (zoo_file), 0); /* ..again */
X if (!null_device) {
X zooseek (this_file, zootell (this_file), 0); /* synch */
X lseek (this_fd, zootell (this_file), 0); /* ..again */
X }
X status = lzd(zoo_fd, this_fd); /* uncompress */
X zooseek (zoo_file, tell (zoo_fd), 0); /* resynch */
X if (!null_device)
X zooseek (this_file, tell (this_fd), 0);/* resynch */
#else
X status = lzd (zoo_file, this_file); /* uncompress */
#endif
X } else if (direntry.packing_method == 2) {
X status = lzh_decode (zoo_file, this_file);
X } else {
X prterror ('e', "File %s: impossible packing method.\n",
X whichname);
X unlink(extfname);
X goto loop_again;
X }
X
X
#ifndef NOSIGNAL
X if (tofile)
X signal (SIGINT, oldsignal);
#endif /* not NOSIGNAL */
X
#ifdef SETMODE
X if (pipe)
X MODE_TEXT(this_file); /* restore text mode */
#endif
X
X if (tofile) {
X /* set date/time of file being extracted */
#ifdef GETTZ
X void tzadj();
X /* adjust for original timezone */
X tzadj (&direntry);
#endif
#ifdef NIXTIME
X close_file (this_file);
X setutime (extfname, direntry.date, direntry.time);
#else
X settime (this_file, direntry.date, direntry.time);
X close_file (this_file);
#endif
#ifdef FATTR
/* Restore file attributes. Bit 23==1 means system-specific; we currently
don't recognize this. Bit 23==0 means use portable format, in which case
bit 22==0 means ignore attributes. Thus attributes are ignored if both
bits 23 and 22 are zero, which is the effect of a zero-filled file
attribute field. Currently we restore file attributes if and only if
bit 23==0 and bit 22==1. */
X
X if ((direntry.fattr >> 22) == 1) {
X setfattr (extfname, direntry.fattr);
X }
#endif /* FATTR */
X } /* end of if (tofile) ... */
X if (status != 0) {
X exit_status = 1;
X if (tofile)
X unlink (extfname);
X if (status == 2) { /* was 1 (wrong) */
X memerr(0);
X /* To avoid spurious errors due to ^Z being sent to screen,
X we don't check for I/O error if output was piped */
X } else if (!pipe && (status == 2 || status == 3)) {
X prterror ('e', no_space, prtfname);
X }
X } else {
X /* file extracted, so update disk space. */
X /* we subtract the original size of the file, rounded
X UP to the nearest multiple of the disk allocation
X size. */
#ifndef PORTABLE
X {
X unsigned long temp;
X temp = (direntry.org_size + alloc_size) / alloc_size;
X disk_space -= temp * alloc_size;
X }
#endif
X
X if (
#ifndef PORTABLE
X !fast_ext &&
#endif
X direntry.file_crc != crccode
X ) {
X badcrc_count++;
X exit_status = 1;
X if (!pipe) {
X if (!null_device)
X prterror ('M', "extracted ");
X prterror ('w', bad_crc, prtfname);
X }
X else { /* duplicate to standard error */
X static char stars[] = "\n******\n";
X putstr (stars);
X prterror ('w', bad_crc, prtfname);
X putstr (stars);
X fprintf (stderr, "WARNING: ");
X fprintf (stderr, bad_crc, prtfname);
X }
X } else
X if (!pipe)
X prterror ('M', null_device ? "OK\n" : "extracted\n");
X
X } /* end if */
X } /* end if */
X } /* end if */
X } /* end if */
X
loop_again:
X zooseek (zoo_file, next_ptr, 0); /* ..seek to next dir entry */
} /* end while */
X
close_file (zoo_file);
if (!matched)
X putstr (no_match);
X
if (badcrc_count) {
X prterror ('w', "%d File(s) with bad CRC.\n", badcrc_count);
} else if (null_device)
X prterror ('m', "Archive seems OK.\n");
X
zooexit (exit_status);
X
} /* end zooext */
X
/* close_file() */
/* closes a file if and only if we aren't sending output to
X a pipe or to the null device */
X
void close_file (file)
ZOOFILE file;
{
X if (tofile)
X zooclose (file);
}
X
/* Ctrl_c() is called if ^C is hit while a file is being extracted.
X It closes the files, deletes it, and exits. */
T_SIGNAL ctrl_c()
{
#ifndef NOSIGNAL
X signal (SIGINT, SIG_IGN); /* ignore any more */
#endif
X zooclose (this_file);
X unlink (extfname);
X zooexit (1);
}
X
#ifndef PORTABLE
/* make_tnh copies creates a tiny_header */
void make_tnh (tiny_header, direntry)
struct tiny_header *tiny_header;
struct direntry *direntry;
{
X tiny_header->tinytag = TINYTAG;
X tiny_header->type = 1;
X tiny_header->packing_method = direntry->packing_method;
X tiny_header->date = direntry->date;
X tiny_header->time = direntry->time;
X tiny_header->file_crc = direntry->file_crc;
X tiny_header->org_size = direntry->org_size;
X tiny_header->size_now = direntry->size_now;
X tiny_header->major_ver = direntry->major_ver;
X tiny_header->minor_ver = direntry->minor_ver;
X tiny_header->cmt_size = direntry->cmt_size;
X strcpy (tiny_header->fname, direntry->fname);
}
#endif /* ifndef PORTABLE */
SHAR_EOF
chmod 0644 zooext.c ||
echo 'restore of zooext.c failed'
Wc_c="`wc -c < 'zooext.c'`"
test 22207 -eq "$Wc_c" ||
echo 'zooext.c: original size 22207, current size' "$Wc_c"
fi
# ============= zoofilt.c ==============
if test -f 'zoofilt.c' -a X"$1" != X"-c"; then
echo 'x - skipping zoofilt.c (File already exists)'
else
echo 'x - extracting zoofilt.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'zoofilt.c' &&
/* derived from: zoofilt.c 1.8 88/01/30 23:47:05 */
X
#ifndef LINT
static char sccsid[]="@(#) $Id: zoofilt.c,v 1.5 91/07/09 01:54:15 dhesi Exp $";
#endif
X
/*
(C) Copyright 1988 Rahul Dhesi -- All rights reserved
(C) Copyright 1991 Rahul Dhesi -- All rights reserved
X
Filter mode -- compress or decompress standard input and write
to standard output.
*/
X
#include "options.h"
X
#ifdef FILTER
X
#include "zooio.h"
#include "errors.i"
#include "zoofns.h"
X
/* action */
#define COMPRESS 0
#define UNCOMPRESS 1
X
#define FTAG ((unsigned int) 0x5a32) /* magic number */
X
extern unsigned int crccode;
X
int rdint PARMS((unsigned int *)); /* read an unsigned int */
int wrint PARMS((unsigned int)); /* write an unsigned int */
X
/* global variable used to pass two bytes (CRC value) back from lzd to here */
unsigned int filt_lzd_word;
X
void zoofilt (option)
char *option;
{
X int choice; /* what to do -- [de]compress */
X unsigned int filetag; /* tag stored in input */
X int stat1, stat2, stat3; /* status codes */
X int use_lzh = 0; /* use lzh instead */
X extern lzc(), lzh_encode(); /* possible encoders */
X extern lzd(), lzh_decode(); /* and decoders */
X
X while (*++option) {
X switch (*option) {
X case 'c': choice = COMPRESS; break;
X case 'u': choice = UNCOMPRESS; break;
X case 'h': use_lzh = 1; break;
X default:
X prterror ('f', inv_option, *option); /* fatal error -- abort */
X }
X }
X
X crccode = 0; /* needed whether compressing or uncompressing */
X
X switch (choice) {
X case COMPRESS:
X stat1 = wrint (FTAG);
X stat2 = (use_lzh ? lzh_encode : lzc) (STDIN, STDOUT);
X stat3 = wrint (crccode);
X if (stat1 == 0 && stat2 == 0 && stat3 == 0)
X zooexit (0);
X else {
X fprintf (stderr, "Zoo: FATAL: Compression error.\n");
X zooexit (1);
X }
X break;
X case UNCOMPRESS:
X stat1 = rdint (&filetag);
X if (stat1 != 0 || filetag != FTAG)
X zooexit (1);
X stat2 = (use_lzh ? lzh_decode : lzd) (STDIN, STDOUT);
X if (stat2 == 0 && filt_lzd_word == crccode)
X zooexit (0);
X else {
X fprintf (stderr, "Zoo: FATAL: Uncompression error.\n");
X zooexit (1);
X }
X break;
X }
} /* zoofilt */
X
#endif /* FILTER */
SHAR_EOF
chmod 0644 zoofilt.c ||
echo 'restore of zoofilt.c failed'
Wc_c="`wc -c < 'zoofilt.c'`"
test 2179 -eq "$Wc_c" ||
echo 'zoofilt.c: original size 2179, current size' "$Wc_c"
fi
# ============= zoofns.h ==============
if test -f 'zoofns.h' -a X"$1" != X"-c"; then
echo 'x - skipping zoofns.h (File already exists)'
else
echo 'x - extracting zoofns.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'zoofns.h' &&
/* @(#) zoofns.h 2.5 88/01/16 19:03:13 */
/* @(#) zoofns.h 2.7 88/01/27 19:39:18 */
X
/*
The contents of this file are hereby released to the public domain.
X
X -- Rahul Dhesi 1986/11/14
*/
X
/* Defines function declarations for all Zoo functions */
X
#ifndef PARMS
#ifdef LINT_ARGS
#define PARMS(x) x
#else
#define PARMS(x) ()
#endif
#endif
X
/*
:.,$s/(PARMS\(.*\));/PARMS\1;/
*/
#ifdef ANSI_HDRS
#include <stdlib.h>
#else
char *memset PARMS ((char *, int, unsigned));
#endif /* ANSI_HDRS */
X
long calc_ofs PARMS ((char *));
char *addext PARMS ((char *, char *));
char *combine PARMS ((char[], char *, char *));
VOIDPTR emalloc PARMS ((unsigned int));
VOIDPTR ealloc PARMS ((unsigned int));
VOIDPTR erealloc PARMS ((VOIDPTR, unsigned int));
char *findlast PARMS ((char *, char *));
char *fixfname PARMS ((char *));
char *getstdin PARMS ((void));
char *lastptr PARMS ((char *));
char *nameptr PARMS ((char *));
char *newcat PARMS ((char *, char *));
char *nextfile PARMS ((int, char *, int));
int cfactor PARMS ((long, long));
int chname PARMS ((char *, char *));
int cmpnum PARMS ((unsigned int, unsigned int, unsigned int, unsigned int));
T_SIGNAL ctrl_c PARMS ((void));
int exists PARMS ((char *));
int getfile PARMS ((ZOOFILE, ZOOFILE, long, int));
int getutime PARMS ((char *, unsigned *, unsigned *));
int gettime PARMS ((ZOOFILE, unsigned *, unsigned *));
T_SIGNAL handle_break PARMS ((void));
X
#ifdef USE_ASCII
int isupper PARMS ((int));
int isdigit PARMS ((int));
#endif /* USE_ASCII */
X
int kill_files PARMS ((char *[], int));
#ifdef UNBUF_IO
int lzc PARMS ((int, int));
int lzd PARMS ((int, int));
#else
int lzc PARMS ((ZOOFILE, ZOOFILE));
int lzd PARMS ((ZOOFILE, ZOOFILE));
#endif
X
int lzh_encode PARMS((FILE *infile, FILE *outfile));
int lzh_decode PARMS((FILE *infile, FILE *outfile));
X
int match_half PARMS ((char *, char *));
int samefile PARMS ((char *, char *));
int settime PARMS ((ZOOFILE, unsigned, unsigned));
int setutime PARMS ((char *, unsigned, unsigned));
int str_icmp PARMS ((char *, char *));
X
#ifdef USE_ASCII
int tolower PARMS ((int));
int toascii PARMS ((int));
#endif /* USE_ASCII */
X
void zooexit PARMS ((int));
long inlist PARMS ((char *, unsigned int *, unsigned int *, unsigned *,
X unsigned *, unsigned *, long *, int));
unsigned long space PARMS ((int, int *));
void addbfcrc PARMS ((char *, int));
void addfname PARMS ((char *, long, unsigned int, unsigned int,
X unsigned, unsigned));
void add_version PARMS ((char *, struct direntry *));
void basename PARMS ((char *, char []));
void break_off PARMS ((void));
void close_file PARMS ((ZOOFILE));
void comment PARMS ((char *, char *));
void extension PARMS ((char *, char []));
void exit PARMS ((int));
void fixslash PARMS ((char *));
void makelist PARMS ((int, char *[], char *[], int, char *, char *, char *, int *));
void memerr PARMS ((unsigned int));
void prterror PARMS ((int, char *, ...));
void rootname PARMS ((char *, char *));
void skip_files PARMS ((ZOOFILE, unsigned int *, unsigned int *, int *,
X char [], long *));
void writenull PARMS ((ZOOFILE, int));
void zooadd PARMS ((char *, int, char **, char *));
void zoodel PARMS ((char *, char *, int));
void zoofilt PARMS ((char *));
void zooext PARMS ((char *, char *));
void zoolist PARMS ((char **, char *, int));
void zoopack PARMS ((char *, char *));
X
char *str_dup PARMS ((char *));
char *str_lwr PARMS ((char *));
X
SHAR_EOF
chmod 0644 zoofns.h ||
echo 'restore of zoofns.h failed'
Wc_c="`wc -c < 'zoofns.h'`"
test 3423 -eq "$Wc_c" ||
echo 'zoofns.h: original size 3423, current size' "$Wc_c"
fi
# ============= zooio.h ==============
if test -f 'zooio.h' -a X"$1" != X"-c"; then
echo 'x - skipping zooio.h (File already exists)'
else
echo 'x - extracting zooio.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'zooio.h' &&
/* @(#) zooio.h 2.7 88/01/27 19:39:24 */
X
/*
Declarations for portable I/O
X
The contents of this file are hereby placed in the public domain.
X
X -- Rahul Dhesi 1988/01/24
*/
#ifndef OK_STDIO
#include <stdio.h>
#define OK_STDIO
#endif
X
#ifndef PARMS
#ifdef LINT_ARGS
#define PARMS(x) x
#else
#define PARMS(x) ()
#endif
#endif
X
/*
In theory, all I/O using buffered files could be replaced with unbuffered
I/O simply by changing the following definitions. This has not been tried
out yet, and there may be some remaining holes in the scheme. On systems
with limited memory, it might prove necessary to use unbuffered I/O
only.
*/
typedef FILE *ZOOFILE;
#define NOFILE ((ZOOFILE) 0)
#define NULLFILE ((ZOOFILE) -1) /* or any unique value */
#define STDOUT stdout
X
#ifdef FILTER
#define STDIN stdin
#endif
X
#ifdef IO_MACROS
#define zooread(file, buffer, count) fread (buffer, 1, count, file)
#define zoowrite(file, buffer, count) \
X (file == NULLFILE ? count : fwrite (buffer, 1, count, file))
#define zooseek(file, offset, whence) fseek (file, offset, whence)
#define zootell(file) ftell (file)
#else
int zooread PARMS((ZOOFILE, char *, int));
int zoowrite PARMS((ZOOFILE, char *, int));
long zooseek PARMS((ZOOFILE, long, int));
long zootell PARMS((ZOOFILE));
#endif /* IO_MACROS */
X
ZOOFILE zooopen PARMS((char *, char *));
ZOOFILE zoocreate PARMS((char *));
int zooclose PARMS((ZOOFILE));
int zootrunc PARMS((ZOOFILE));
X
char *choosefname PARMS((struct direntry *));
char *fullpath PARMS((struct direntry *));
int frd_zooh PARMS((struct zoo_header *, ZOOFILE));
int frd_dir PARMS((struct direntry *, ZOOFILE));
int fwr_dir PARMS((struct direntry *, ZOOFILE));
int fwr_zooh PARMS((struct zoo_header *, ZOOFILE));
int readdir PARMS((struct direntry *, ZOOFILE, int));
void rwheader PARMS((struct zoo_header *, ZOOFILE, int));
void newdir PARMS((struct direntry *));
void writedir PARMS((struct direntry *, ZOOFILE));
SHAR_EOF
chmod 0644 zooio.h ||
echo 'restore of zooio.h failed'
Wc_c="`wc -c < 'zooio.h'`"
test 1939 -eq "$Wc_c" ||
echo 'zooio.h: original size 1939, current size' "$Wc_c"
fi
true || echo 'restore of zoolist.c failed'
echo End of part 14, continue with part 15
exit 0