From uunet!rsalz Tue May 19 14:14:35 1992
Received: from uunet.UUCP by sparky.IMD.Sterling.COM (5.65c/IDA-1.4.4)
	id AA03498; Tue, 19 May 1992 14:14:29 -0500
Return-Path: <uunet!rsalz>
Received: by rodan.UU.NET (5.61/UUNET-mail-drop)
	id AA17577; Tue, 19 May 92 14:35:12 -0400
Date: Tue, 19 May 92 14:35:12 -0400
From: uunet!rsalz (Rich Salz)
Message-Id: <9205191835.AA17577@rodan.UU.NET>
To: kent@imd.sterling.com
Subject: cshar/Part05
Status: O

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# Contents:  dirami.c dirami.h dirmsd.c dirmsd.h diros2.c diros2.h
#   dirvms.h dodoc.sh findsrc.man glue.c lcwd.c lfiles.c lhost.c
#   lmem.c luser.c parser.h shell.c shell.man unshar.man uudecode.man
#   uuencode.man uuenmain.c
# Wrapped by rsalz@rodan on Tue Apr  7 23:54:48 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
echo If this archive is complete, you will see the following message:
echo '          "shar: End of archive 5 (of 6)."'
if test -f 'dirami.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dirami.c'\"
else
  echo shar: Extracting \"'dirami.c'\" \(3482 characters\)
  sed "s/^X//" >'dirami.c' <<'END_OF_FILE'
X/*
X**  Readdir package for the Amiga.
X**
X**  [  I have not tried this at all, except to reformat it.  --r$  ]
X**  
X**  To: Richard Salz <rsalz@pineapple.bbn.com>
X**  Subject: Re: Amiga version of the dir library...
X**  Date: Mon, 13 Jul 87 21:54:25 PDT
X**  From: Mike (My watch has windows) Meyer <mwm@violet.Berkeley.EDU>
X**  
X**  Here is what I did. This is built to reflect the 4BSD manual pages, not
X**  the SysV/dpANS manual pages.
X**  
X**  I now know how to get the telldir/seekdir pair to work correctly with
X**  multiple tell()s, but do not have much motivation to do so. If someone
X**  out there does it, or is interested in doing it, I wouldd be interested in
X**  the results or willing to help.
X**  
X**  Final note: as with many micros, there is more than one C compiler.
X**  This was written for the Lattice compiler, and uses features known
X**  not to exist in other Amiga compilers. Fixing it should be trivial.
X**  
X**  	<mike
X**
X**  $Header$
X*/
X#include <dir.h>
X
X
XDIR		*AllocMem(int, int);
Xstruct FileLock	*Lock(char *, int);
Xstruct FileLock	*CurrentDir(struct FileLock *);
X
X
XDIR *
Xopendir(dirname)
X    char		*dirname;
X{
X    REGISTER DIR	*my_dir;
X
X    if ((my_dir = AllocMem(sizeof *my_dir, 0)) == NULL)
X	return NULL;
X
X    /* If we can't examine it, or it's not a directory, that's not good. */
X    if ((my_dir->d_lock = Lock(dirname, ACCESS_READ)) == NULL
X     || !Examine(my_dir->d_lock, &(my_dir->d_info))
X     || (my_dir->d_info.fib_DirEntryType < 0)) {
X	FreeMem(my_dir, sizeof *my_dir);
X	return NULL;
X    }
X    return my_dir;
X}
X
X
Xstruct direct *
Xreaddir(my_dir)
X    DIR				*my_dir;
X{
X    static struct direct	result;
X
X    if (!ExNext(my_dir->d_lock, &(my_dir->d_info)))
X	return NULL;
X
X    result.d_reclen = result.d_ino = 1;	/* Not NULL! */
X    (void)strcpy(result.d_name, my_dir->d_info.fib_FileName);
X    result.d_namlen = strlen(result.d_name);
X    return &result;
X}
X
X
Xvoid
Xclosedir(my_dir)
X    DIR		*my_dir;
X{
X    UnLock(my_dir->d_lock);
X    FreeMem(my_dir, sizeof *my_dir);
X}
X
X
X/*
X**  telldir and seekdir don't work quite right.  The problem is that you have
X**  to save more than a long's worth of stuff to indicate position, and it's
X**  socially unacceptable to alloc stuff that you don't free later under
X**  AmigaDOS.  So we fake it -- you get one level of seek, and that's all.
X**  As of now, these things are untested.
X*/
X#define DIR_SEEK_RETURN		((long)1)	/* Not 0! */
X
X
Xlong
Xtelldir(my_dir)
X    DIR		*my_dir;
X{
X    my_dir->d_seek = my_dir->d_info;
X    return DIR_SEEK_RETURN;
X}
X
X
Xvoid
Xseekdir(my_dir, where)
X    DIR		*my_dir;
X    long	 where;
X{
X    if (where == DIR_SEEK_RETURN)
X	my_dir->d_info = my_dir->d_seek;
X    else
X	/* Makes the next readdir fail */
X	setmem((char *)my_dir, sizeof *my_dir, 0);
X}
X
X
Xvoid
Xrewinddir(my_dir)
X    DIR		*my_dir;
X{
X    if (!Examine(my_dir->d_lock, &(my_dir->d_info)))
X	setmem((char *)my_dir, sizeof *my_dir, 0);
X}
X
X
X#ifdef	TEST
X/*
X * Simple code to list the files in the argument directory,
X *	lifted straight from the man page.
X */
X#include <stdio.h>
Xint
Xmain(ac, av)
X    int				ac;
X    char			*av[];
X{
X    register DIR		*dirp;
X    register struct direct	*dp;
X    register char		*name;
X
X    name = ac < 2 ? "" : av[1];
X    if ((dirp = opendir(name)) == NULL) {
X	(void)fprintf(stderr, "Bogus! Can't opendir %s\n", name);
X	exit(1);
X	/* NOTREACHED */
X    }
X
X    while (dp = readdir(dirp))
X	(void)printf("%s ", dp->d_name);
X    closedir(dirp);
X    putchar('\n');
X    exit(0);
X    /* NOTREACHED */
X}
X#endif	/* TEST */
END_OF_FILE
  if test 3482 -ne `wc -c <'dirami.c'`; then
    echo shar: \"'dirami.c'\" unpacked with wrong size!
  fi
  # end of 'dirami.c'
fi
if test -f 'dirami.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dirami.h'\"
else
  echo shar: Extracting \"'dirami.h'\" \(2761 characters\)
  sed "s/^X//" >'dirami.h' <<'END_OF_FILE'
X/*
X**  Readdir package for the Amiga.
X**
X**  [  I have not tried this at all except to reformat it.  --r$  ]
X**  
X**  To: Richard Salz <rsalz@pineapple.bbn.com>
X**  Subject: Re: Amiga version of the dir library... 
X**  Date: Mon, 13 Jul 87 21:54:25 PDT
X**  From: Mike (My watch has windows) Meyer <mwm@violet.Berkeley.EDU>
X**  
X**  Here's what I did. This is built to reflect the 4BSD manual pages, not
X**  the SysV/dpANS manual pages.
X**  
X**  I now know how to get the telldir/seekdir pair to work correctly with
X**  multiple tell()s, but don't have much motivation to do so. If someone
X**  out there does it, or is interested in doing it, I'd be interested in
X**  the results or willing to help.
X**  
X**  Final note: as with many micros, there's more than one C compiler.
X**  This was written for the Lattice compiler, and uses features known
X**  not to exist in other Amiga compilers. Fixing it should be trivial.
X**  
X**  	<mike
X**
X**  $Header$
X*/
X#ifndef	DIR_H
X#define DIR_H
X
X#ifndef	EXEC_TYPES_H
X#include "exec/types.h"
X#endif	/* EXEC_TYPES_H */
X
X#ifndef	LIBRARIES_DOS_H
X#include "libraries/dos.h"
X#endif /* LIBRARIES_DOS_H */
X
X#ifndef	LIBRARIES_DOSEXTENS_H
X#include "libraries/dosextens.h"
X#endif /* LIBRARIES_DOSEXTENS_H */
X
X
X/*
X**  MAXNAMELEN is the maximum length a file name can be. The direct structure
X**  is lifted from 4BSD, and has not been changed so that code which uses
X**  it will be compatable with 4BSD code. d_ino and d_reclen are unused,
X**  and will probably be set to some non-zero value.
X*/
X#define	MAXNAMLEN	31		/* AmigaDOS file max length */
X
Xstruct direct {
X	ULONG	d_ino;			/* unused - there for compatability */
X	USHORT	d_reclen;		/* ditto */
X	USHORT	d_namlen;		/* length of string in d_name */
X	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
X};
X
X
X/*
X**  The DIRSIZ macro gives the minimum record length which will hold
X**  the directory entry.  This requires the amount of space in struct direct
X**  without the d_name field, plus enough space for the name with a terminating
X**  null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
X*/
X#undef DIRSIZ
X#define DIRSIZ(dp)	\
X    ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen + 1 + 3) & ~3))
X
X
X/*
X**  The DIR structure holds the things that AmigaDOS needs to know about
X**  a file to keep track of where it is and what it's doing.
X*/
Xtypedef struct {
X	struct FileInfoBlock	d_info;	/* Default info block */
X	struct FileInfoBlock	d_seek;	/* Info block for seeks */
X	struct FileLock		*d_lock; /* Lock on directory */
X} DIR;
X	
Xextern DIR		*opendir(char *);
Xextern struct direct	*readdir(DIR *);
Xextern long		 telldir(DIR *);
Xextern void		 seekdir(DIR *, long);
Xextern void		 rewinddir(DIR *);
Xextern void		 closedir(DIR *);
X
X#endif	/* DIR_H */
END_OF_FILE
  if test 2761 -ne `wc -c <'dirami.h'`; then
    echo shar: \"'dirami.h'\" unpacked with wrong size!
  fi
  # end of 'dirami.h'
fi
if test -f 'dirmsd.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dirmsd.c'\"
else
  echo shar: Extracting \"'dirmsd.c'\" \(4054 characters\)
  sed "s/^X//" >'dirmsd.c' <<'END_OF_FILE'
X/*
X**  Readdir package for MS-DOS.
X**  
X**  [  I have not tried this at all except to reformat it.  --r$  ]
X**
X**  Public domain implementation Michael Rendell <garfield!michael>
X**  August 1897.
X**
X**  $Header$
X*/
X#include "ndir.h"
X#include <sys/stat.h>
X#include <malloc.h>
X#include <string.h>
X#include <dos.h>
X
X#ifndef	NULL
X#define NULL		0
X#endif	/* NULL */
X
X#ifndef	MAXPATHLEN
X#define MAXPATHLEN	255
X#endif	/* MAXPATHLEN */
X
X/*
X**  Attribute stuff.
X*/
X#define A_RONLY		0x01
X#define A_HIDDEN	0x02
X#define A_SYSTEM	0x04
X#define A_LABEL		0x08
X#define A_DIR		0x10
X#define A_ARCHIVE	0x20
X
X/*
X**  DOS call values.
X*/
X#define DOSI_FINDF	0x4e
X#define DOSI_FINDN	0x4f
X#define DOSI_SDTA	0x1a
X
X#define ATTRIBUTES	(A_DIR | A_HIDDEN | A_SYSTEM)
X
X/*
X**  What the "find first" and "find next" calls use.
X*/
Xtypedef struct _dtabuf {
X    char		d_buf[21];
X    char		d_attribute;
X    unsigned short	d_time;
X    unsigned short	d_date;
X    long		d_size;
X    char		d_name[13];
X} DTABUF;
X
X
Xstatic DTABUF		dtabuf;
Xstatic DTABUF		*dtapnt = &dtabuf;
Xstatic union REGS	reg;
Xstatic union REGS	nreg;
X
X#ifdef	M_I86LM
Xstatic struct SREGS	sreg;
X#endif	/* M_I86LM */
X
X
Xstatic char *
Xgetdirent(dir)
X    char	*dir;
X{
X    if (dir) {
X	/* get first entry */
X	reg.h.ah = DOSI_FINDF;
X	reg.h.cl = ATTRIBUTES;
X#ifdef	M_I86LM
X	reg.x.dx = FP_OFF(dir);
X	sreg.ds = FP_SEG(dir);
X#else
X	reg.x.dx = (unsigned int)dir;
X#endif	/* M_I86LM */
X    }
X    else {
X	/* get next entry */
X	reg.h.ah = DOSI_FINDN;
X#ifdef	M_I86LM
X	reg.x.dx = FP_OFF(dtapnt);
X	sreg.ds = FP_SEG(dtapnt);
X#else
X	reg.x.dx = (unsigned int)dtapnt;
X#endif	/* M_I86LM */
X    }
X#ifdef	M_I86LM
X    intdosx(&reg, &nreg, &sreg);
X#else
X    intdos(&reg, &nreg);
X#endif	/* M_I86LM */
X
X    return nreg.x.cflag ? NULL : dtabuf.d_name;
X}
X
X
Xstatic void
Xfree_dircontents(dp)
X    _DIRCONTENTS	*dp;
X{
X    _DIRCONTENTS	*new;
X
X    for (; dp; dp = new) {
X	if (dp->_d_entry)
X	    free(dp->_d_entry);
X	new = dp->_d_next;
X	free((char *)dp);
X    }
X}
X
Xstatic void
Xsetdta()
X{
X    reg.h.ah = DOSI_SDTA;
X#ifdef	M_I86LM
X    reg.x.dx = FP_OFF(dtapnt);
X    sreg.ds = FP_SEG(dtapnt);
X    intdosx(&reg, &nreg, &sreg);
X#else
X    reg.x.dx = (int)dtapnt;
X    intdos(&reg, &nreg);
X#endif	/* M_I86LM */
X}
X
X
XDIR *
Xopendir(name)
X    char		*name;
X{
X    DIR			*dirp;
X    _DIRCONTENTS	*dp;
X    struct stat		statb;
X    char		*s;
X    char		c;
X    char		nbuf[MAXPATHLEN + 1];
X
X    if (stat(name, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR)
X	return NULL;
X    if ((dirp = (DIR *)malloc(sizeof (DIR))) == NULL)
X	return NULL;
X
X    if (*name && (c = name[strlen(name) - 1]) != '\\' && c != '/')
X	(void)strcat(strcpy(nbuf, name), "\\*.*");
X    else
X	(void)strcat(strcpy(nbuf, name), "*.*");
X
X    dirp->dd_loc = 0;
X    setdta();
X    dirp->dd_contents = dirp->dd_cp = NULL;
X    if ((s = getdirent(nbuf)) == NULL)
X	return dirp;
X
X    do {
X	if ((dp = (_DIRCONTENTS *)malloc(sizeof (_DIRCONTENTS))) == NULL
X	|| (dp->_d_entry = malloc((unsigned int)(strlen(s) + 1))) == NULL) {
X	    if (dp)
X		free((char *)dp);
X	    free_dircontents(dirp->dd_contents);
X	    return NULL;
X	}
X	if (dirp->dd_contents)
X	    dirp->dd_cp = dirp->dd_cp->_d_next = dp;
X	else
X	    dirp->dd_cp = dirp->dd_contents = dp;
X	(void) strcpy(dp->_d_entry, s);
X	dp->_d_next = NULL;
X    } while (s = getdirent((char *)NULL));
X    dirp->dd_cp = dirp->dd_contents;
X
X    return dirp;
X}
X
X
Xvoid
Xclosedir(dirp)
X    DIR		*dirp;
X{
X    free_dircontents(dirp->dd_contents);
X    free((char *)dirp);
X}
X
Xstruct direct *
Xreaddir(dirp)
X    DIR				*dirp;
X{
X    static struct direct	dp;
X
X    if (dirp->dd_cp == NULL)
X	return NULL;
X    dp.d_namlen = dp.d_reclen =
X	    strlen(strcpy(dp.d_name, dirp->dd_cp->_d_entry));
X    dp.d_ino = 0;
X    dirp->dd_cp = dirp->dd_cp->_d_next;
X    dirp->dd_loc++;
X    return &dp;
X}
X
X
Xvoid
Xseekdir(dirp, off)
X    DIR			*dirp;
X    long		off;
X{
X    long		i;
X    _DIRCONTENTS	*dp;
X
X    if (off < 0)
X	return;
X    for (i = off, dp = dirp->dd_contents; --i >= 0 && dp; dp = dp->_d_next)
X	;
X    dirp->dd_loc = off - (i + 1);
X    dirp->dd_cp = dp;
X}
X
X
Xlong
Xtelldir(dirp)
X    DIR		*dirp;
X{
X    return dirp->dd_loc;
X}
END_OF_FILE
  if test 4054 -ne `wc -c <'dirmsd.c'`; then
    echo shar: \"'dirmsd.c'\" unpacked with wrong size!
  fi
  # end of 'dirmsd.c'
fi
if test -f 'dirmsd.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dirmsd.h'\"
else
  echo shar: Extracting \"'dirmsd.h'\" \(979 characters\)
  sed "s/^X//" >'dirmsd.h' <<'END_OF_FILE'
X/*
X**  Readdir package for MS-DOS.
X**  
X**  [  I have not tried this at all except to reformat it.  --r$  ]
X**
X**  Public domain implementation Michael Rendell <garfield!michael>
X**  August 1897.
X**
X**  $Header$
X*/
X#include <sys/types.h>
X
X#define MAXNAMLEN	12
X
Xtypedef struct _dircontents {
X	char			*_d_entry;
X	struct _dircontents	*_d_next;
X} _DIRCONTENTS;
X
Xstruct direct {
X	ino_t	d_ino;			/* a bit of a farce */
X	int	d_reclen;		/* more farce */
X	int	d_namlen;		/* length of d_name */
X	char	d_name[MAXNAMLEN + 1];	/* gaurantee null termination */
X};
X
Xtypedef struct _dir {
X	int		 dd_id;		/* identify each open directory */
X	long		 dd_loc;	/* where we are in directory entry */
X	_DIRCONTENTS	*dd_contents;	/* pointer to contents of dir */
X	_DIRCONTENTS	*dd_cp;		/* pointer to current position */
X} DIR;
X
X#define rewinddir(dirp)		seekdir(dirp, 0L)
Xextern DIR		*opendir();
Xextern struct direct	*readdir();
Xextern void		 seekdir();
Xextern long		 telldir();
Xextern void		 closedir();
END_OF_FILE
  if test 979 -ne `wc -c <'dirmsd.h'`; then
    echo shar: \"'dirmsd.h'\" unpacked with wrong size!
  fi
  # end of 'dirmsd.h'
fi
if test -f 'diros2.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'diros2.c'\"
else
  echo shar: Extracting \"'diros2.c'\" \(3432 characters\)
  sed "s/^X//" >'diros2.c' <<'END_OF_FILE'
X/*
X**  Readdir package for OS/2.
X**
X**  [  I have not tried this at all, except to reformat it.  --r$  ]
X**
X**  A public domain implementation of BSD directory routines for
X**  MS-DOS.  Written by Michael Rendell ({uunet,utai}michael@garfield),
X**  August 1897
X**  Ported to OS/2 by Kai Uwe Rommel
X**  December 1989
X*/
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <sys/dir.h>
X#include <stdio.h>
X#include <malloc.h>
X#include <string.h>
X#define INCL_NOPM
X#include <os2.h>
X
X
Xint			attributes = A_DIR | A_HIDDEN;
Xstatic HDIR		hdir;
Xstatic USHORT		count;
Xstatic FILEFINDBUF	find;
X
X
Xstatic char *
Xgetdirent(char *dir)
X{
X    int		done;
X
X    if (dir != NULL) {
X	hdir = HDIR_CREATE;
X	count = 1;
X	done = DosFindFirst(dir, &hdir, attributes,
X		    &find, sizeof find, &count, 0L);
X    }
X    else
X	done = DosFindNext(hdir, &find, sizeof find, &count);
X    if (done == 0)
X	return find.achName;
X    DosFindClose(hdir);
X    return NULL;
X}
X
X
Xstatic void free_dircontents(struct _dircontents *dp)
X{
X    struct _dircontents	*next;
X
X    for ( dp; dp = next) {
X	if (dp->_d_entry)
X	    free(dp->_d_entry);
X	next = dp->_d_next;
X	free(dp);
X    }
X}
X
X
XDIR *
Xopendir(char *name)
X{
X    struct stat		Sb;
X    DIR			*dirp;
X    char		c;
X    char		*p;
X    struct _dircontents	*dp;
X    char		buff[MAXPATHLEN + 1];
X
X    strcpy(buff, name);
X
X    if ((c = buff[strlen(buff) - 1]) == '\\' || c == '/') {
X	buff[strlen(buff) - 1] = 0;
X	if (buff[strlen(buff) - 1] == ':')
X	    strcat(buff, "\\.");
X    }
X    else if (buff[strlen(buff) - 1] == ':')
X	strcat(buff, ".");
X
X    if (stat(buff, &Sb) < 0
X     || (Sb.st_mode & S_IFMT) != S_IFDIR)
X     || (dirp = malloc(sizeof (DIR))) == NULL)
X	return NULL;
X
X    if (buff[strlen(buff) - 1] == '.')
X	strcpy(buff + strlen(buff) - 1, "*.*");
X    else
X	strcat(buff, "\\*.*");
X
X    dirp->dd_loc = 0;
X    dirp->dd_contents = dirp->dd_cp = NULL;
X    if ((p = getdirent(buff)) == NULL)
X	return dirp;
X
X    do {
X	if ((dp = malloc(sizeof(struct _dircontents))) == NULL
X	 || (dp->_d_entry = malloc(strlen(p) + 1)) == NULL) {
X	    if (dp)
X		free(dp);
X	    free_dircontents(dirp->dd_contents);
X	    return NULL;
X	}
X
X	if (dirp->dd_contents)
X	    dirp->dd_cp = dirp->dd_cp->_d_next = dp;
X	else
X	    dirp->dd_contents = dirp->dd_cp = dp;
X
X	strcpy(dp->_d_entry, p);
X	dp->_d_next = NULL;
X	dp->_d_size = find.cbFile;
X	dp->_d_mode = find.attrFile;
X	dp->_d_time = *(unsigned int *) &(find.ftimeLastWrite);
X	dp->_d_date = *(unsigned int *) &(find.fdateLastWrite);
X    } while ((p = getdirent(NULL)) != NULL);
X
X    dirp->dd_cp = dirp->dd_contents;
X    return dirp;
X}
X
X
Xvoid
Xclosedir(DIR *dirp)
X{
X    free_dircontents(dirp->dd_contents);
X    free(dirp);
X}
X
X
Xstruct direct *
Xreaddir(DIR *dirp)
X{
X    static struct direct	dp;
X
X    if (dirp->dd_cp == NULL)
X	return NULL;
X
X    strcpy(dp.d_name, dirp->dd_cp->_d_entry));
X    dp.d_namlen = dp.d_reclen = strlen(dp.d_name);
X
X    strlwr(dp.d_name);
X    dp.d_ino = 0;
X    dp.d_size = dirp->dd_cp->_d_size;
X    dp.d_mode = dirp->dd_cp->_d_mode;
X    dp.d_time = dirp->dd_cp->_d_time;
X    dp.d_date = dirp->dd_cp->_d_date;
X    dirp->dd_cp = dirp->dd_cp->_d_next;
X    dirp->dd_loc++;
X
X    return &dp;
X}
X
X
Xvoid
Xseekdir(DIR *dirp, long off)
X{
X    struct _dircontents	*dp;
X    long		i;
X
X    i = off;
X    if (off >= 0) {
X	for (dp = dirp->dd_contents; --i >= 0 && dp; dp = dp->_d_next)
X	    continue;
X	dirp->dd_loc = off - (i + 1);
X	dirp->dd_cp = dp;
X    }
X}
X
X
Xlong
Xtelldir(DIR *dirp)
X{
X    return dirp->dd_loc;
X}
END_OF_FILE
  if test 3432 -ne `wc -c <'diros2.c'`; then
    echo shar: \"'diros2.c'\" unpacked with wrong size!
  fi
  # end of 'diros2.c'
fi
if test -f 'diros2.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'diros2.h'\"
else
  echo shar: Extracting \"'diros2.h'\" \(1774 characters\)
  sed "s/^X//" >'diros2.h' <<'END_OF_FILE'
X/*
X**  Readdir package for OS/2.
X**
X**  [  I have not tried this at all, except to reformat it.  --r$  ]
X**
X**  A public domain implementation of BSD directory routines for
X**  MS-DOS.  Written by Michael Rendell ({uunet,utai}michael@garfield),
X**  August 1987
X**
X**  Enhanced and ported to OS/2 by Kai Uwe Rommel; added scandir() prototype
X**  December 1989, February 1990
X*/
X
X#define MAXNAMLEN	 12
X#define MAXPATHLEN	128
X
X#define A_RONLY		0x01
X#define A_HIDDEN	0x02
X#define A_SYSTEM	0x04
X#define A_LABEL		0x08
X#define A_DIR		0x10
X#define A_ARCHIVE	0x20
X
X
Xstruct direct {
X    ino_t		d_ino;                   /* a bit of a farce */
X    int			d_reclen;                /* more farce */
X    int     		d_namlen;                /* length of d_name */
X    char    		d_name[MAXNAMLEN + 1];   /* null terminated */
X    /* nonstandard fields -- d_size and d_mode are given back free of
X     * chage by find_first and can save time over a stat() call. */
X    long    		d_size;                  /* size in bytes */
X    unsigned int	d_mode;                  /* file attributes */
X    unsigned int	d_time;
X    unsigned int	d_date;
X};
X
Xstruct _dircontents {
X    char		*_d_entry;
X    long		_d_size;
X    unsigned int	_d_mode;
X    unsigned int	_d_time;
X    unsigned int	_d_date;
X    struct _dircontents	*_d_next;
X};
X
Xtypedef struct _dirdesc {
X    int			dd_id;		/* unique identity */
X    long		dd_loc;		/* where we are in directory entry */
X    struct _dircontents	*dd_contents;	/* pointer to contents of dir */
X    struct _dircontents	*dd_cp;		/* pointer to current position */
X} DIR;
X
X
Xextern DIR		*opendir(char *);
Xextern struct direct	*readdir(DIR *);
Xextern void		seekdir(DIR *, long);
Xextern long		telldir(DIR *);
Xextern void		closedir(DIR *);
X#define rewinddir(dirp) seekdir(dirp, 0L)
END_OF_FILE
  if test 1774 -ne `wc -c <'diros2.h'`; then
    echo shar: \"'diros2.h'\" unpacked with wrong size!
  fi
  # end of 'diros2.h'
fi
if test -f 'dirvms.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dirvms.h'\"
else
  echo shar: Extracting \"'dirvms.h'\" \(933 characters\)
  sed "s/^X//" >'dirvms.h' <<'END_OF_FILE'
X/*
X**  Header file for VMS readdir() routines.
X**  Written by Rich $alz, <rsalz@bbn.com> in August, 1990.
X**  This code has no copyright.
X**
X**  You must #include <descrip.h> before this file.
X*/
X
X    /* Data structure returned by READDIR(). */
Xstruct dirent {
X    char	d_name[100];		/* File name		*/
X    int		vms_verscount;		/* Number of versions	*/
X    int		vms_versions[20];	/* Version numbers	*/
X};
X
X    /* Handle returned by opendir(), used by the other routines.  You
X     * are not supposed to care what's inside this structure. */
Xtypedef struct _dirdesc {
X    long			context;
X    long			count;
X    int				vms_wantversions;
X    char			*pattern;
X    struct dirent		entry;
X    struct dsc$descriptor_s	pat;
X} DIR;
X
X
X#define rewinddir(dirp)		seekdir((dirp), 0L)
X
X
Xextern DIR		*opendir();
Xextern struct dirent	*readdir();
Xextern long		telldir();
Xextern void		seekdir();
Xextern void		closedir();
Xextern void		vmsreaddirversions();
END_OF_FILE
  if test 933 -ne `wc -c <'dirvms.h'`; then
    echo shar: \"'dirvms.h'\" unpacked with wrong size!
  fi
  # end of 'dirvms.h'
fi
if test -f 'dodoc.sh' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dodoc.sh'\"
else
  echo shar: Extracting \"'dodoc.sh'\" \(901 characters\)
  sed "s/^X//" >'dodoc.sh' <<'END_OF_FILE'
X#! /bin/sh
X##  Script to generate simple formatted documentation for distribution
X##  to BBS's and other non-Unix systems.  It's basically a de-paginator
X##  for not-very-long manual pages (five pages or so).
X##
X##  This runs on SunOS 3.4, and might need tweaking if you go to a system
X##  where the -man macros have been munged differently.
X##
X##  $Header$
X##
X
Xcase $# in
X0)
X    echo "Usage: `basename $0` files..." >&2
X    exit 1
X    ;;
Xesac
X
Xfor I in "$@" ; do
X    echo ".pl 40i" \
X	| nroff -man - ${I}.man \
X	| col -b \
X	| awk '
X	  /SEE ALSO/ { F = 1 }
X	  {
X	    if (F == 1 && length == 0) { F = 2 }
X	    if (F != 2) { print }
X	  }' \
X	| sed \
X	  -e 's/^\([A-Z]*\)(1L)/\1    /' \
X	  -e 's/\([A-Z]*\)(1L)$/    \1/' \
X	  -e 's/^/     /' \
X	  -e 's/MISC. REFERENCE MANUAL PAGES/                            /' \
X	  -e 's/UNKNOWN SECTION OF THE MANUAL/                             /' \
X	>${I}.doc
Xdone
END_OF_FILE
  if test 901 -ne `wc -c <'dodoc.sh'`; then
    echo shar: \"'dodoc.sh'\" unpacked with wrong size!
  fi
  chmod +x 'dodoc.sh'
  # end of 'dodoc.sh'
fi
if test -f 'findsrc.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'findsrc.man'\"
else
  echo shar: Extracting \"'findsrc.man'\" \(3730 characters\)
  sed "s/^X//" >'findsrc.man' <<'END_OF_FILE'
X.TH FINDSRC 1L
X.\" $Header: findsrc.man,v 2.0 88/05/27 13:28:20 rsalz Exp $
X.SH NAME
Xfindsrc \- walk directories, trying to find source files
X.SH SYNOPSIS
X.RS
X.na
X.ti -.5i
X.B findsrc
X[
X.BI \-d\| y_or_n
X] [
X.BI \-h\| #
X] [
X.B \-l
X] [
X.B \-m
X] [
X.BI \-n\| pattern
X] [
X.BI \-N\| pattern
X] [
X.BI \-o\| name
X] [
X.B \-r
X] [
X.B \-s
X] [
X.B \-v
X] [
X.B \-x
X] [
X.BI \-y\| pattern
X] [
X.BI \-Y\| pattern
X] [ file... ]
X.ad
X.RE
X.SH DESCRIPTION
X.I Findsrc
Xrecursively examines all directories and files specified on the command
Xline, and determines, based on the file name, whether the file contains
Xsource code or not.
XAll directories are listed first, followed by all regular files,
Xwith one item per line.
X.PP
X.I Findsrc
Xhas a built-in table of shell wildcard patterns that it uses to determine
Xwhether or not a file is source or not.
XTo add to the table, use the ``\-y'' or ``\-n'' options.
XBoth options take a shell pattern; the ``\-y'' indicates that the pattern
Xis to be included, and the ``\-n'' indicates that files matching the
Xpattern are to be excluded.
XFor the patterns, an asterisk means any zero or more characters, and
Xsquare brackets match any characters in the brackets.
XFor example, ``\-yconfig.*'' will add the configuration files distributed
Xwith the shar package, while ``\-nPart0[0-9]'' will exclude shar kits.
XTo just see the pattern table, use the ``\-x'' option.
XThe order in the table is important, so patterns added on the
Xcommand line will be inserted at the start of the table.
XNote that patterns are added in the order in which they appear in the
Xcommand line, so to exclude all but one log file, use this order
X\&``\-n\e*.log\ -ypatch.log.''
X.PP
XThe ``\-y'' or ``\-n'' options only look at the last component of
Xthe filename.
XTo compare the full pathname of the file against the pattern, use
Xthe uppercase version of the letter.
XFor example, ``\-N*/junk/*'' will skip all files in any directory named ``junk.''
X.PP
XNote that since the patterns used contain shell wildcard characters, they
Xwill have to be quoted to prevent the shell from trying to do the expansion.
X.PP
XIf
X.I findsrc
Xis unable to make a decision, it invokes the
X.IR file (1)
Xcommand, and prompts the user for a decision.
XIn reply to the prompt, type the letter ``y'' or ``n'' (either case);
Xa simple return is taken to mean ``yes.''
XIf the reply starts with an exclamation point, the rest of the line
Xis passed off to a sub-shell and the question is repeated.
XThe ``\-d'' option may be used with an argument of ``y'' or ``n''
Xto by-pass the interaction and provide a default answer.
X.PP
XThe ``\-o'' option may be used to specify an output filename.
XThis is designed to prevent confusion if a command like the following
Xis executed:
X.RS
Xfindsrc . * >LIST
X.RE
X.PP
XAs a convenience to
X.IR maniscan (1L)
Xand
X.IR makekit (1L),
X.I findsrc
Xcan put some leading blank lines at the top of its output.
XThese are normally skipped by
X.I maniscan
Xand turned into manifest headers by
X.IR makekit .
XThe ``\-h'' option may be used to indicate the number of header lines to
Xgenerate.
XThe ``\-m'' option is the same as giving the options
X\&``-oMANIFEST -h2.''
X.PP
XBy default,
X.I findsrc
Xignores RCS and SCCS files and directories; using either the ``\-r''
Xor ``\-s'' option causes both to be included.
X.PP
X.I Findsrc
Xnormally lists only the names of those files that have been selected.
XIf the ``\-l'' option is used, rejected files are logged to the output
Xpreceeded by the word ``REJECTED.''
X.PP
XIf no files are specified on the command line, the program operates as
Xa filter, reading a list of files and directories from the standard
Xinput, one per line.
X.PP
XThe ``\-v'' option prints out the current version and exits.
X.SH "SEE ALSO"
Xmakekit(1L), maniscan(1L).
END_OF_FILE
  if test 3730 -ne `wc -c <'findsrc.man'`; then
    echo shar: \"'findsrc.man'\" unpacked with wrong size!
  fi
  # end of 'findsrc.man'
fi
if test -f 'glue.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'glue.c'\"
else
  echo shar: Extracting \"'glue.c'\" \(1857 characters\)
  sed "s/^X//" >'glue.c' <<'END_OF_FILE'
X/*
X**  Subroutine to call the shell archive parser.  This is "glue" that holds
X**  unshar and parser together.
X*/
X#include "parser.h"
X#ifdef	RCSID
Xstatic char RCS[] =
X	"$Header: glue.c,v 2.0 88/05/27 13:26:14 rsalz Locked $";
X#endif	/* RCSID */
X
X
X#ifdef	USE_MY_SHELL
X
X#ifdef	MSDOS
X/*
X**  MS-DOS has a global filemode variable that we need to flip around a bit.
X*/
Xstatic int	OldMode;
X#endif	/* MSDOS */
X
X/*
X**  Cleanup routine after BinSh is done
X*/
Xvoid
XBSclean()
X{
X    (void)fclose(Input);
X#ifdef	MSDOS
X    _fmode = OldMode;
X#endif	/* MSDOS */
X    if (File[0])
X	(void)unlink(File);
X}
X
X
X/*
X**  Copy the input to a temporary file, then call the shell parser.
X*/
XBinSh(Name, Stream, Pushback, KillReturns)
X    char		*Name;
X    REGISTER FILE	*Stream;
X    char		*Pushback;
X    int			KillReturns;
X{
X    REGISTER FILE	*F;
X    REGISTER char	*p;
X    char		buff[BUFSIZ];
X    char		*vec[MAX_WORDS];
X
X    Interactive = Name == NULL;
X
X#ifdef	MSDOS
X    onexit(BSclean);
X    old_fmode = _fmode;
X    _fmode = O_BINARY;
X#endif	/* MSDOS */
X
X    MakeTempName(File, TEMP_NAME1);
X    if ((F = fopen(File, "w")) == NULL) {
X	Fprintf(stderr," Can't create \"%s\" as temp file, %s.\n",
X		File, strerror(errno));
X	exit(1);
X	/* NOTREACHED */
X    }
X
X    (void)fputs(Pushback, F);
X    while (fgets(buff, sizeof buff, Stream)) {
X	if (KillReturns) {
X	    p = buff + strlen(buff);
X	    if (p > &buff[2] && *--p == '\n' && *--p == '\r') {
X		*p = '\n';
X		*++p = '\0';
X	    }
X	}
X	(void)fputs(buff, F);
X    }
X    (void)fclose(Stream);
X    (void)fclose(F);
X
X    if ((Input = fopen(File, "r")) == NULL)
X	Fprintf(stderr, "Can't open %s, %s!?\n", File, strerror(errno));
X    else {
X	while (GetLine(TRUE)) {
X#ifdef	USE_JMPBUF
X	    if (setjmp(jEnv))
X		break;
X#endif	/* USE_JMPBUF */
X	    if (Argify(vec) && Exec(vec) == OOB_FALSE)
X		    break;
X	}
X    }
X
X    BSclean();
X}
X#endif	/* USE_MY_SHELL */
END_OF_FILE
  if test 1857 -ne `wc -c <'glue.c'`; then
    echo shar: \"'glue.c'\" unpacked with wrong size!
  fi
  # end of 'glue.c'
fi
if test -f 'lcwd.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lcwd.c'\"
else
  echo shar: Extracting \"'lcwd.c'\" \(1112 characters\)
  sed "s/^X//" >'lcwd.c' <<'END_OF_FILE'
X/*
X**  Return current working directory.  Something for everyone.
X*/
X/* LINTLIBRARY */
X#include "shar.h"
X#ifdef	RCSID
Xstatic char RCS[] =
X	"$Header: lcwd.c,v 2.0 88/05/27 13:26:24 rsalz Exp $";
X#endif	/* RCSID */
X
X
X#ifdef	PWDGETENV
X/* ARGSUSED */
Xchar *
XGetDir(p, i)
X    char	*p;
X    int		i;
X{
X    char	*q;
X
X    return (q = getenv(PWDGETENV)) ? strcpy(p, q) : NULL;
X}
X#endif	/* PWDGETENV */
X
X
X#ifdef	GETWD
X/* ARGSUSED1 */
Xchar *
XGetDir(p, size)
X    char	*p;
X    int		size;
X{
X    extern char	*getwd();
X
X    return getwd(p) ? p : NULL;
X}
X#endif	/* GETWD */
X
X
X#ifdef	GETCWD
Xchar *
XGetDir(p, size)
X    char	*p;
X    int		size;
X{
X    extern char	*getcwd();
X
X    return getcwd(p, size) ? p : NULL;
X}
X#endif	/* GETCWD */
X
X
X#ifdef	PWDPOPEN
Xchar *
XGetDir(p, size)
X    char	*p;
X    int		size;
X{
X    extern FILE	*popen();
X    FILE	*F;
X    int		i;
X
X    /* This string could be "exec /bin/pwd" if you want... */
X    if (F = popen("pwd", "r")) {
X	if (fgets(p, size, F) && p[i = strlen(p) - 1] == '\n') {
X	    p[i] = '\0';
X	    (void)fclose(F);
X	    return p;
X	}
X	(void)fclose(F);
X    }
X    return NULL;
X}
X#endif	/* PWDPOPEN */
END_OF_FILE
  if test 1112 -ne `wc -c <'lcwd.c'`; then
    echo shar: \"'lcwd.c'\" unpacked with wrong size!
  fi
  # end of 'lcwd.c'
fi
if test -f 'lfiles.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lfiles.c'\"
else
  echo shar: Extracting \"'lfiles.c'\" \(4233 characters\)
  sed "s/^X//" >'lfiles.c' <<'END_OF_FILE'
X/*
X**  File-related routines.
X*/
X/* LINTLIBRARY */
X#include "shar.h"
X#ifndef	VMS
X#include <sys/stat.h>
X#else
X#include <stat.h>
X#endif	/* VMS */
X#ifdef	RCSID
Xstatic char RCS[] =
X	"$Header: lfiles.c,v 2.0 88/05/27 13:26:47 rsalz Locked $";
X#endif	/* RCSID */
X
X
X#ifndef	F_OK
X#define F_OK	0
X#endif	/* F_OK */
X
X/* Mask of executable bits. */
X#define	EXE_MASK	(S_IEXEC | (S_IEXEC >> 3) | (S_IEXEC >> 6))
X
X/* Stat buffer for last file. */
Xstatic struct stat	Sb;
X
X
X/*
X**  Stat the file.  We used to save the old name and only do the stat(2)
X**  if the name changed, but that's wrong -- we could open and write to
X**  the file between stat() calls.
X*/
Xint
XGetStat(p)
X    char	*p;
X{
X    return stat(p, &Sb) < 0 ? FALSE : TRUE;
X}
X
X
X/*
X**  See if the file exists.  Dumb test, not suitable for use everywhere.
X*/
Xint
XFexists(p)
X    char	*p;
X{
X    return access(p, F_OK) >= 0 || GetStat(p);
X}
X
X
X/*
X**  Return the file type -- directory or regular file.
X*/
Xint
XFtype(p)
X    char	*p;
X{
X    return GetStat(p) && ((Sb.st_mode & S_IFMT) == S_IFDIR) ? F_DIR : F_FILE;
X}
X
X
X/*
X**  Return the file size.
X*/
Xoff_t
XFsize(p)
X    char	*p;
X{
X#ifdef	UNIX_FILES
X    return GetStat(p) ? Sb.st_size : 0;
X#else
X    REGISTER FILE	*F;
X    REGISTER off_t	 i;
X
X    if ((F = fopen(p, "r")) == NULL)
X	return 0;
X    for (i = 0; getc(F) != EOF; i++)
X	;
X    (void)fclose(F);
X    return i;
X#endif	/* UNIX_FILES */
X}
X
X
X/*
X**  Is a file executable?
X*/
Xint
XFexecute(p)
X    char	*p;
X{
X    return GetStat(p) && (Sb.st_mode & EXE_MASK) ? TRUE : FALSE;
X}
X
X
X/*
X**  Does it look like a source file (ends with *.[cFflpy])?
X*/
Xint
XIsProbablySource(p)
X    register char	*p;
X{
X    if ((p = RDX(p, '.')) && p[1] != '\0' && p[2] == '\0')
X	switch (p[1]) {
X	case 'c':
X	case 'F':
X	case 'f':
X	case 'l':
X	case 'p':
X	case 'y':
X	    return TRUE;
X	}
X
X    return FALSE;
X}
X
X
X/*
X**  Rename a file so that we don't overwrite it.
X*/
X#ifdef	BU_NONE
Xvoid
XSafeRename(Name)
X    char	*Name;
X{
X    Name = Name;
X}
X
X#else
X
Xvoid
XSafeRename(Name)
X    char		*Name;
X{
X#ifdef	BU_VIA_COPY
X    REGISTER FILE	*In;
X    REGISTER FILE	*Out;
X#endif	/* BU_VIA_COPY */
X#ifdef	BU_NAME_LEN
X    REGISTER char	*p;
X#endif	/* BU_NAME_LEN */
X    char		buff[BUFSIZ];
X
X#ifdef	BU_PREFIX
X    /* Turn /foo/bar/baz into /foo/bar/B-baz. */
X    if (p = RDX(buff, '/')) {
X	*p = '\0';
X	Sprintf(buff, "%s/%s%s", buff, BU_PREFIX, p + 1);
X	*p = '/';
X    }
X    else
X	Sprintf(buff, "%s%s", BU_PREFIX, Name);
X#endif	/* BU_PREFIX */
X
X#ifdef	BU_SUFFIX
X    /* Turn /foo/bar/baz into /foo/bar/baz.BAK */
X    Sprintf(buff, "%s%s", Name, BU_SUFFIX);
X#ifdef	BU_NAME_LEN
X    /* If on a shortname system, turn longfilename.BAK into longfilena.BAK */
X    p = (p = RDX(buff, '/')) ? p + 1 : buff;
X    if (strlen(p) > BU_NAME_LEN)
X	(void)strcpy(&p[BU_NAME_LEN - strlen(BU_SUFFIX)], BU_SUFFIX);
X#endif	/* BU_NAME_LEN */
X#endif	/* BU_SUFFIX */
X
X#ifdef	BU_VIA_RENAME
X    (void)rename(Name, buff);
X#endif	/* BU_VIA_RENAME */
X
X#ifdef	BU_VIA_LINK
X    (void)unlink(buff);
X    (void)link(Name, buff);
X    unlink(Name);
X#endif	/* BU_VIA_LINK */
X
X#ifdef	BU_VIA_COPY
X    /* Open the old and new files. */
X    if ((In = fopen(Name, "r")) == NULL) {
X	Fprintf(stderr, "Can't open \"%s\" for reading to copy, %s.\n",
X		Name, strerror(errno));
X	exit(1);
X	/* NOTREACHED */
X    }
X    if ((Out = fopen(buff, "w")) == NULL) {
X	Fprintf(stderr, "Can't open \"%s\" for writing to copy, %s.\n",
X		Name, strerror(errno));
X	(void)fclose(In);
X	exit(1);
X	/* NOTREACHED */
X    }
X
X    /* Slurp and spew. */
X    while (fgets(buff, sizeof buff, In))
X	(void)fputs(buff, Out);
X
X    /* Close. */
X    (void)fclose(In);
X    (void)fclose(Out);
X#endif	/* BU_VIA_COPY */
X}
X#endif	/* BU_NONE */
X
X
X/*
X**  Make a complete pathname to a temporary file.
X*/
Xvoid
XMakeTempName(buff, Name)
X    char		*buff;
X    char		*Name;
X{
X#ifdef	TEMPVAR
X    register char	*p;
X    register int	i;
X
X    /* find the temporary directory */
X    if ((p = getenv(TEMPVAR)) == NULL)
X	(void)strcpy(buff, Name);
X    else {
X	/* Guarantee a directory separator. */
X	i = strlen(p);
X	if (p[i - 1] != '/' && p[i - 1] != '\\' && *Name != '/' && *Name != '\\')
X	    Sprintf(buff, "%s/%s", p, Name);
X	else
X	    Sprintf(buff, "%s%s", p, Name);
X    }
X    (void)mktemp(buff);
X#else
X    (void)mktemp(strcpy(buff, Name));
X#endif	/* TEMPVAR */
X}
END_OF_FILE
  if test 4233 -ne `wc -c <'lfiles.c'`; then
    echo shar: \"'lfiles.c'\" unpacked with wrong size!
  fi
  # end of 'lfiles.c'
fi
if test -f 'lhost.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lhost.c'\"
else
  echo shar: Extracting \"'lhost.c'\" \(1846 characters\)
  sed "s/^X//" >'lhost.c' <<'END_OF_FILE'
X/*
X**  Return the name of this host.  Something for everyone.
X*/
X/* LINTLIBRARY */
X#include "shar.h"
X#ifdef	RCSID
Xstatic char RCS[] =
X	"$Header: lhost.c,v 2.0 88/05/27 13:27:01 rsalz Locked $";
X#endif	/* RCSID */
X
X
X#ifdef	HOSTENV
Xchar *
XHost()
X{
X    char	*p;
X
X    return (p = getenv(HOSTENV)) ? p : DEF_HOST;
X}
X#endif	/* HOSTENV */
X
X
X#ifdef	HOST_STRING
Xchar *
XHost()
X{
X    return DEF_HOST;
X}
X#endif	/* HOST_STRING */
X
X
X#ifdef	GETHOSTNAME
Xchar *
XHost()
X{
X    static char		buff[64];
X
X    (void)gethostname(buff, sizeof buff);
X    return buff;
X}
X#endif	/* GETHOSTNAME */
X
X
X#ifdef	UNAME
X#include <sys/utsname.h>
Xchar *
XHost()
X{
X    static struct utsname	U;
X
X    return uname(&U) < 0 ? DEF_HOST : U.nodename;
X}
X#endif	/* UNAME */
X
X
X#ifdef	UUNAME
Xchar *
XHost()
X{
X    static char		buff[50];
X    extern FILE		*popen();
X    FILE		*F;
X    char		*p;
X
X    if (F = popen("exec uuname -l", "r")) {
X	if (fgets(buff, sizeof buff, F) == buff && (p = IDX(buff, '\n'))) {
X	    (void)pclose(F);
X	    *p = '\0';
X	    return buff;
X	}
X	(void)pclose(F);
X    }
X    return DEF_HOST;
X}
X#endif	/* UUNAME */
X
X
X#ifdef	WHOAMI
Xchar *
XHost()
X{
X    static char		name[64];
X    REGISTER FILE	*F;
X    REGISTER char	*p;
X    char		buff[100];
X
X    /* Try /etc/whoami; look for a single well-formed line. */
X    if (F = fopen(WHOAMI, "r")) {
X	if (fgets(name, sizeof name, F) && (p = IDX(name, '\n'))) {
X	    (void)fclose(F);
X	    *p = '\0';
X	    return name;
X	}
X	(void)fclose(F);
X    }
X
X    /* Try /usr/include/whoami.h; look for #define sysname "foo" somewhere. */
X    if (F = fopen("/usr/include/whoami.h", "r")) {
X	while (fgets(buff, sizeof buff, F))
X	    /* I don't like sscanf, nor do I trust it.  Sigh. */
X	    if (sscanf(buff, "#define sysname \"%[^\"]\"", name) == 1) {
X		(void)fclose(F);
X		return name;
X	    }
X	(void)fclose(F);
X    }
X
X    return DEF_HOST;
X}
X#endif	/* WHOAMI */
END_OF_FILE
  if test 1846 -ne `wc -c <'lhost.c'`; then
    echo shar: \"'lhost.c'\" unpacked with wrong size!
  fi
  # end of 'lhost.c'
fi
if test -f 'lmem.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'lmem.c'\"
else
  echo shar: Extracting \"'lmem.c'\" \(977 characters\)
  sed "s/^X//" >'lmem.c' <<'END_OF_FILE'
X/*
X**  Get some memory or die trying.
X*/
X/* LINTLIBRARY */
X#include "shar.h"
X#include "patchlog.h"
X#ifdef	RCSID
Xstatic char RCS[] =
X	"$Header: lmem.c,v 2.0 88/05/27 13:27:16 rsalz Locked $";
X#endif	/* RCSID */
X
X
Xalign_t
Xshar_getmem(i, j)
X    int			i;
X    unsigned int	j;
X{
X#ifndef	ANSI_HDRS
X    extern char		*malloc();
X#endif	/* ANSI_HDRS */
X    align_t		p;
X
X    /* NOSTRICT *//* "possible pointer alignment problem" */
X    if ((p = (align_t)malloc(i * j)) == NULL) {
X	/* Print the unsigned values as int's so ridiculous values show up. */
X	Fprintf(stderr, "Can't getmem(%d,%d), %s.\n", i, j, strerror(errno));
X	exit(1);
X	/* NOTREACHED */
X    }
X    return p;
X}
X
X
X/*
X**  Print out the version string and exit.  Also print out the RCS string
X**  for the heck of it.
X*/
Xvoid
XVersion(p)
X    char	*p;
X{
X    Printf(
X      "This is Version %d, patchlevel %d of the public-domain cshar package\n",
X      VERSION, PATCHLEVEL);
X    Printf("%s\n", p);
X    exit(0);
X    /* NOTREACHED */
X}
END_OF_FILE
  if test 977 -ne `wc -c <'lmem.c'`; then
    echo shar: \"'lmem.c'\" unpacked with wrong size!
  fi
  # end of 'lmem.c'
fi
if test -f 'luser.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'luser.c'\"
else
  echo shar: Extracting \"'luser.c'\" \(762 characters\)
  sed "s/^X//" >'luser.c' <<'END_OF_FILE'
X/*
X**  Get user name.  Something for everyone.
X*/
X/* LINTLIBRARY */
X#include "shar.h"
X#ifdef	USE_GETPWUID
X#include <pwd.h>
X#endif	/* USE_GETPWUID */
X#ifdef	RCSID
Xstatic char RCS[] =
X	"$Header: luser.c,v 2.0 88/05/27 13:27:23 rsalz Exp $";
X#endif	/* RCSID */
X
X
X/*
X**  Get user name.  Not secure, but who sends nastygrams as shell archives?
X*/
Xchar *
XUser()
X{
X#ifdef	USE_GETPWUID
X    extern struct passwd	*getpwuid();
X    struct passwd		*p;
X#endif	/* USE_GETPWUID */
X    char			*g;
X
X    if ((g = getenv("USER")) != NULL)
X	return g;
X    if ((g = getenv("LOGNAME")) != NULL)
X	return g;
X    if ((g = getenv("NAME")) != NULL)
X	return g;
X#ifdef	USE_GETPWUID
X    if ((p = getpwuid(getuid())) != NULL)
X	return p->pw_name;
X#endif	/* USE_GETPWUID */
X    return USERNAME;
X}
END_OF_FILE
  if test 762 -ne `wc -c <'luser.c'`; then
    echo shar: \"'luser.c'\" unpacked with wrong size!
  fi
  # end of 'luser.c'
fi
if test -f 'parser.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'parser.h'\"
else
  echo shar: Extracting \"'parser.h'\" \(2064 characters\)
  sed "s/^X//" >'parser.h' <<'END_OF_FILE'
X/*
X**  Header file for the shell/shar parser.
X**
X**  $Header$
X*/
X#include "shar.h"
X
X
X/*
X**  Manifest constants, handy shorthands.
X*/
X
X/* Character classes used in the syntax table. */
X#define C_LETR		1		/* A letter within a word	*/
X#define C_WHIT		2		/* Whitespace to separate words	*/
X#define C_WORD		3		/* A single-character word	*/
X#define C_DUBL		4		/* Something like <<, e.g.	*/
X#define C_QUOT		5		/* Quotes to group a word	*/
X#define C_META		6		/* Heavy magic character	*/
X#define C_TERM		7		/* Line terminator		*/
X
X/* Macros used to query character class. */
X#define ISletr(c)	(SynTable[(c)] == C_LETR)
X#define ISwhit(c)	(SynTable[(c)] == C_WHIT)
X#define ISword(c)	(SynTable[(c)] == C_WORD)
X#define ISdubl(c)	(SynTable[(c)] == C_DUBL)
X#define ISquot(c)	(SynTable[(c)] == C_QUOT)
X#define ISmeta(c)	(SynTable[(c)] == C_META)
X#define ISterm(c)	(SynTable[(c)] == C_TERM)
X
X
X/* Safety-checking. */
X#ifdef	MAX_FOPENS
X#ifndef	OPEN_OVERHEAD
X#define OPEN_OVERHEAD
X#endif	/* OPEN_OVERHEAD */
X#endif	/* MAX_FOPENS */
X
X#ifdef	PATH_CHECK
X#ifndef	OPEN_OVERHEAD
X#define OPEN_OVERHEAD
X#endif	/* OPEN_OVERHEAD */
X#endif	/* PATH_CHECK */
X
X
X#ifdef	NAME_CHECK
X#ifndef	OPEN_OVERHEAD
X#define OPEN_OVERHEAD
X#endif	/* OPEN_OVERHEAD */
X#endif	/* NAME_CHECK */
X
X/*
X**  Data types
X*/
X
X/* Command dispatch table. */
Xtypedef struct _comtab {
X    char	  Name[10];		/* Text of command name		*/
X    int		(*Func)();		/* Function that implements it	*/
X} COMTAB;
X
X/* A shell variable.  We only have a few of these. */
Xtypedef struct _var {
X    char	 *Name;
X    char	 *Value;
X} VAR;
X
X
X/*
X**  Parser variables and declarations.
X*/
X#ifdef	PARSER_DATA
X#define PEXTERN		/* NULL */
X#else
X#define PEXTERN		extern
X#endif	/* PARSER_DATA */
X
X#ifdef	USE_JMPBUF
XPEXTERN jmp_buf	 jEnv;			/* Pop out of main loop		*/
X#endif	/* USE_JMPBUF */
XPEXTERN FILE	*Input;			/* Current input stream		*/
XPEXTERN char	 File[TEMPSIZE];	/* Input filename		*/
XPEXTERN int	 Interactive;		/* isatty(fileno(stdin))?	*/
X
Xextern void	 SetVar();		/* Shell variable assignment	*/
Xextern void	 SynErr();		/* Fatal syntax error		*/
END_OF_FILE
  if test 2064 -ne `wc -c <'parser.h'`; then
    echo shar: \"'parser.h'\" unpacked with wrong size!
  fi
  # end of 'parser.h'
fi
if test -f 'shell.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'shell.c'\"
else
  echo shar: Extracting \"'shell.c'\" \(1271 characters\)
  sed "s/^X//" >'shell.c' <<'END_OF_FILE'
X/*
X**  SHELL
X**
X**  Stand-alone driver for shell/shar interpreter.
X*/
X#include "parser.h"
Xstatic char RCS[] =
X	"$Header: shell.c,v 2.0 88/05/27 13:28:06 rsalz Locked $";
X
X
Xint
Xmain(ac, av)
X    REGISTER int	ac;
X    REGISTER char	*av[];
X{
X    char		*vec[MAX_WORDS];
X    char		buff[VAR_VALUE_SIZE];
X    int			Oops;
X    int			i;
X
X    for (Oops = FALSE; (i = getopt(ac, av, "v")) != EOF; )
X	switch (i) {
X	default:
X	    Oops = TRUE;
X	    break;
X	case 'v':		/* Print version			*/
X	    Version(RCS);
X	    /* NOTREACHED */
X	}
X    ac -= optind;
X    av += optind;
X
X    if (Oops) {
X	Fprintf(stderr, "Usage:\n  shell [file [parameters] ]\n");
X	exit(1);
X	/* NOTREACHED */
X    }
X
X    Interactive = ac == 0;
X    if (Interactive) {
X	Fprintf(stderr, "Testing shell interpreter...\n");
X	Input = stdin;
X	(void)strcpy(File, "stdin");
X    }
X    else {
X	(void)strcpy(File, av[0]);
X	if ((Input = fopen(av[0], "r")) == NULL)
X	    SynErr("UNREADABLE INPUT");
X	/* Build the positional parameters. */
X	for (ac = 0; av[ac]; ac++) {
X	    Sprintf(buff, "%d", ac);
X	    SetVar(buff, av[ac]);
X	}
X    }
X
X    /* Read, parse, and execute. */
X    while (GetLine(TRUE))
X	if (Argify(vec) && Exec(vec) == OOB_FALSE)
X	    break;
X
X    /* That's it. */
X    (void)fclose(Input);
X    exit(0);
X    /* NOTREACHED */
X}
END_OF_FILE
  if test 1271 -ne `wc -c <'shell.c'`; then
    echo shar: \"'shell.c'\" unpacked with wrong size!
  fi
  # end of 'shell.c'
fi
if test -f 'shell.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'shell.man'\"
else
  echo shar: Extracting \"'shell.man'\" \(1199 characters\)
  sed "s/^X//" >'shell.man' <<'END_OF_FILE'
X.TH SHELL 1L
X.\" $Header: shell.man,v 2.0 88/05/27 13:28:55 rsalz Locked $
X.SH NAME
Xshell \- Interpreter for shell archives
X.SH SYNOPSIS
X.RS
X.na
X.ti -.5i
X.B shell
X[
X.B \-v
X] [ file [parameters] ]
X.ad
X.RE
X.SH DESCRIPTION
XThis program interprets enough
X.IR /bin/sh (1)
Xsyntax, and common command usage, to enable it to unpack many different
Xtypes of
X.\" NOSTRICT "Unmatched .SM"
X.SM UNIX
Xshell archives,
Xor ``shar's.''
XIt is primarily intended to be used on non-UNIX systems that need to
Xunpack such archives.
X.PP
X.I Shell
Xdoes
X.B some
Xsecurity checking, but to believe that it will protect against all
Xtrojan horses is probably naive.
X.PP
XThe program's parser is line-based, where lines are then split into
Xtokens; it is not a true token-based parser.
XIn general, it is best if all
X.I /bin/sh
Xkeywords that can appear alone on a line do so, and that compound
Xcommands (i.e., using a semi-colon) be avoided.
XFor more details on the syntax, see the source (sorry...).
X.PP
XThe ``\-v'' option prints out the current version and exits.
X.SH BUGS
XIt is probably easier to write a true portable replacement for /bin/sh
Xthan it is to write something which understands all shar formats.
X.SH SEE ALSO
Xshar(1L).
END_OF_FILE
  if test 1199 -ne `wc -c <'shell.man'`; then
    echo shar: \"'shell.man'\" unpacked with wrong size!
  fi
  # end of 'shell.man'
fi
if test -f 'unshar.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'unshar.man'\"
else
  echo shar: Extracting \"'unshar.man'\" \(2555 characters\)
  sed "s/^X//" >'unshar.man' <<'END_OF_FILE'
X.TH UNSHAR 1L
X.\" $Header: unshar.man,v 2.0 88/05/27 13:29:02 rsalz Exp $
X.SH NAME
Xunshar \- unpack shell archives from news, mail, notes, etc.
X.SH SYNOPSIS
X.RS
X.na
X.ti -.5i
X.B unshar
X[
X.BI \-c\| path
X] [
X.BI \-d\| path
X] [
X.BI \-h\| file
X] [
X.B \-f
X] [
X.B \-r
X] [
X.B \-n
X] [
X.B \-s
X] [
X.B \-v
X] [ file... ]
X.ad
X.RE
X.SH DESCRIPTION
X.I Unshar
Xremoves mail and news header lines from its input, and feeds the remainder
Xto
X.IR /bin/sh (1)
Xso that a shell archive can be properly unpacked.
XIf no files are specified,
X.I unshar
Xreads from standard input.
XThe program is designed to be useful when unpacking archives directly
Xfrom the news or mail systems (e.g., s | unshar).
X.PP
X.I Unshar
Xnormally unpacks its files in the current directory.
XUse the ``\-c'' option to have the program change to a new directory
Xbefore invoking the shell.
XIf the directory does not exist,
X.I unshar
Xwill try to create it.
XIf the directory name starts with a question mark, then
X.I unshar
Xwill ask for the directory name before doing anything; this is most useful
Xwith the environment variable UNSHAREDIR.
XIf the directory name starts with a tilde, then the value of the HOME
Xenvironment variable is inserted in place of that character.
XFor convenience, the ``\-d'' option is a synonym for the ``\-c'' option.
X.PP
X.I Unshar
Xnormally complains if the input looks like something other than a shar file.
X(Among other things, it checks for files that resemble C, and Pascal code).
XIt can be fooled, however, by nonstandard versions of news, notes, etc.
XThe ``\-f'' option forces
X.I unshar
Xto try unpacking files, even if they look like something else.
XIf the ``\-r'' option is used, then
X.I unshar
Xwill remove any trailing carriage-returns that appear at the
Xbeginning of each line.
X.PP
XDepending on how the program is installed,
X.I unshar
Xmay or may not try to preserve the header part of file ``foo''
Xinto the name ``foo.hdr'' (if the file is standard input, the name
Xwill be ``UNSHAR.HDR'').
XUsing the ``\-s'' option forces the program to save the headers, while
Xusing the ``\-n'' option forces it to discard the headers.
XThe file is appended to, if it already exists, so all headers can be easily
Xsaved in one file.
XThe name of the file may be given by using the ``\-h'' option; this is
Xparticularly useful when processing more than one file at a time.
X.PP
XThe ``\-v'' option prints out the current version and exits.
X.SH ENVIRONMENT
X.ta \w'UNSHAREDIR  'u
XHOME	Used if directory name starts with a tilde.
X.br
XUNSHAREDIR	Default value for ``\-c'' option.
X.SH "SEE ALSO"
Xshar(1L).
END_OF_FILE
  if test 2555 -ne `wc -c <'unshar.man'`; then
    echo shar: \"'unshar.man'\" unpacked with wrong size!
  fi
  # end of 'unshar.man'
fi
if test -f 'uudecode.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'uudecode.man'\"
else
  echo shar: Extracting \"'uudecode.man'\" \(1462 characters\)
  sed "s/^X//" >'uudecode.man' <<'END_OF_FILE'
X.\" $Header$
X.TH UUDECODE 1L
X.SH NAME
Xuudecode \- reconstruct a binary file from printable encoding
X.SH SYNOPSIS
X.B uudecode
X[
X.B \-v
X] [ 
X.I input
X]
X.SH DESCRIPTION
X.I Uudecode
Xtranslates a text file created by
X.IR uuencode (1L)
Xinto a replica of the original (binary) file.
XIt reads the named file (or standard input if none is given), and skips
Xany headers or trailers that might surround the data, and parses
Xthe data to create the file named in the message.
XNo attempt is made to verify the file to be created, or the permission
Xmodes to be assigned to it, so it is wise to manually inspect the
Xinput before feeding it into
X.IR uudecode .
XOn
X.\" NOSTRICT "Unmatched .SM"
X.SM UNIX ,
Xthis can be done by the following command:
X.RS
Xprompt% grep '^begin'
X.I input
X.RE
X.PP
XSeveral versions of the original
X.I uuencode
Xand
X.I uudecode
Xprograms are available and have been widely distributed; luckily, all
Xthe changes seem to have been made in a compatible manner.
XThis distribution does not provide all the features of other versions,
Xjust the basic format and the ``translation table.''
XFor more detailed information, see the
X.I uuencode
Xmanual page.
X.PP
XIf more than one data file appears in the input, all others but the
Xfirst one are ignored.
X.PP
XNote that the encoded file is about 35% bigger (three bytes become four,
Xplus control information) than the original.
X.PP
XThe ``\-v'' option prints out the current version and exits.
X.SH "SEE ALSO"
Xuuencode(1L).
END_OF_FILE
  if test 1462 -ne `wc -c <'uudecode.man'`; then
    echo shar: \"'uudecode.man'\" unpacked with wrong size!
  fi
  # end of 'uudecode.man'
fi
if test -f 'uuencode.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'uuencode.man'\"
else
  echo shar: Extracting \"'uuencode.man'\" \(1516 characters\)
  sed "s/^X//" >'uuencode.man' <<'END_OF_FILE'
X.\" $Header$
X.TH UUENCODE 1L
X.SH NAME
Xuuencode \- decode a binary file into printable encoding
X.SH SYNOPSIS
X.B uuencode
X[
X.B \-v
X]
X.I input
X.I output
X.SH DESCRIPTION
X.I Uuencode
Xreads the named binary input file and writes a printable version of it
Xto the named output file.
XThe output file is an ordinary text file and can be edited by any
Xtext editor to change the destination name, add introductory matter,
Xand the like.
XIn particular, it is very common to use
X.I uuencode
Xand
X.I uudecode
Xto send binary files around as electronic mail, Usenet, or general
Xbulletin-board messages.
X.PP
XSeveral versions of the original
X.I uuencode
Xand
X.I uudecode
Xprograms are available and have been widely distributed; luckily, all
Xthe changes seem to have been made in a compatible manner.
XThis distribution does not provide all the features of other versions,
Xjust the basic format and the ``translation table.''
XNo per-line or per-file checksumming is performed, and the
X.\" NOSTRICT "Unmatched .SM"
X.SM UNIX
X\&``tilde'' syntax to represent a home directory (e.g.,
X.I \&~rsalz/vmunix
Xrepresents the file named
X.I vmunix
Xin the home directory of the user
X.IR rsalz )
Xis not supported.
XOnly one file can be sent per message; use
X.IR shar (1L)
Xto bundle multiple binary files.
X.PP
X.I "describe translation table"
X.PP
XNote that the encoded file is about 35% bigger (three bytes become four,
Xplus control information) than the original.
X.PP
XThe ``\-v'' option prints out the current version and exits.
X.SH "SEE ALSO"
Xuudecode(1L).
END_OF_FILE
  if test 1516 -ne `wc -c <'uuencode.man'`; then
    echo shar: \"'uuencode.man'\" unpacked with wrong size!
  fi
  # end of 'uuencode.man'
fi
if test -f 'uuenmain.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'uuenmain.c'\"
else
  echo shar: Extracting \"'uuenmain.c'\" \(770 characters\)
  sed "s/^X//" >'uuenmain.c' <<'END_OF_FILE'
X/*
X**  UUENCODE
X**
X**  Uuencode a file.  This is based on the public-domain implementation that
X**  Mark Horton released to mod.sources with the translation table written
X**  by Jean-Pierre H. Dumas.
X*/
X#include "shar.h"
Xstatic char RCS[] =
X	"$Header$";
X
X
Xint
Xmain(ac, av)
X    int		ac;
X    char	*av[];
X{
X    int		Oops;
X    int		i;
X
X    /* Parse JCL. */
X    for (Oops = FALSE; (i = getopt(ac, av, "v")) != EOF; )
X	switch (i) {
X	default:
X	    Oops = TRUE;
X	    break;
X	case 'v':		/* Print version			*/
X	    Version(RCS);
X	    /* NOTREACHED */
X	}
X    ac -= optind;
X    av += optind;
X
X    if (Oops || ac != 2) {
X	Fprintf(stderr, "Usage:\n  uuencode %s\n", "infile outfile");
X	exit(1);
X	/* NOTREACHED */
X    }
X
X    uuencode(av[0], av[1]);
X    exit(0);
X    /* NOTREACHED */
X}
END_OF_FILE
  if test 770 -ne `wc -c <'uuenmain.c'`; then
    echo shar: \"'uuenmain.c'\" unpacked with wrong size!
  fi
  # end of 'uuenmain.c'
fi
echo shar: End of archive 5 \(of 6\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 6 archives.
    rm -f ark[1-9]isdone
else
    echo You still must unpack the following archives:
    echo "        " ${MISSING}
fi
exit 0

