home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume25
/
pdksh
/
part07
< prev
next >
Wrap
Text File
|
1991-11-12
|
56KB
|
2,059 lines
Newsgroups: comp.sources.misc
From: sjg@zen.void.oz.au (Simon J. Gerraty)
Subject: v25i053: pdksh - Public Domain Korn Shell, v4, Part07/09
Message-ID: <1991Nov13.031220.16258@sparky.imd.sterling.com>
X-Md4-Signature: 0422b4f08c0fd6aac06682fe010c3e5d
Date: Wed, 13 Nov 1991 03:12:20 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: sjg@zen.void.oz.au (Simon J. Gerraty)
Posting-number: Volume 25, Issue 53
Archive-name: pdksh/part07
Environment: UNIX
#! /bin/sh
# 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: MANIFEST Changes.jrm ReadMe.sjg etc/ksh.kshrc
# etc/sys_config.sh sh/ReadMe sh/alloc.h sh/edit.h sh/expand.h
# sh/getopts.c sh/io.c sh/lex.h sh/table.h sh/trace.h sh/trap.c
# sh/tree.h std/posix/io.h std/stdc/stdio.h_std
# Wrapped by kent@sparky on Tue Nov 12 20:44:34 1991
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 7 (of 9)."'
if test -f 'MANIFEST' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(3689 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X File Name Archive # Description
X-----------------------------------------------------------
X README 1 Please read
X Changes.jrm 1
X Changes.mlj 1
X MANIFEST 1 This shipping list
X Makefile 1
X PATCHDATES 1 C-News style patch tracking
X ReadMe.jrm 1 General info and Install instructions
X ReadMe.sjg 1
X ReadMe.vimode 1
X etc 1
X etc/ksh.kshrc 1 global .kshrc, WARNING contains ESC chars
X etc/profile 1
X etc/sys_config.sh 1
X ksh.1 2 Manual page
X sh 1 ksh source
X sh/ChangeLog 1 Current change list
X sh/Changes 1
X sh/Makefile 1
X sh/ReadMe 1 Original ReadMe (out of date)
X sh/alloc.c 1
X sh/alloc.h 1
X sh/c_ksh.c 2
X sh/c_sh.c 2
X sh/c_test.c 3
X sh/config.h 1
X sh/edit.c 3
X sh/edit.h 1
X sh/emacs.c 3
X sh/eval.c 4
X sh/exec.c 4
X sh/expand.h 1
X sh/expr.c 3
X sh/getopts.c 4
X sh/history.c 4
X sh/io.c 4
X sh/jobs.c 5
X sh/lex.c 5
X sh/lex.h 4
X sh/mail.c 4
X sh/main.c 5
X sh/misc.c 5
X sh/sh.h 5
X sh/syn.c 6
X sh/table.c 6
X sh/table.h 6
X sh/trace.c 6 Simple trace facilty
X sh/trace.h 6
X sh/trap.c 6
X sh/tree.c 6
X sh/tree.h 6
X sh/tty.h 2
X sh/ulimit.c 6
X sh/var.c 7
X sh/version.c 4
X sh/vi.c 7
X std 1 libraries
X std/Makefile 5
X std/posix 2
X std/posix 2 posix lib source
X std/posix/Makefile 6
X std/posix/dirent.C 6
X std/posix/dirent.H 6
X std/posix/dirent.h 2
X std/posix/dup2.c 4
X std/posix/fcntl.c 6
X std/posix/fcntl.h 6
X std/posix/fixincludes 6
X std/posix/io.h 6
X std/posix/time.h 6
X std/posix/times.c 6
X std/posix/times.h 6
X std/posix/unistd.c 6
X std/posix/unistd.h 7
X std/posix/wait.h 7
X std/stdc 3 stdc lib source
X std/stdc/Makefile 7
X std/stdc/clock.c 7
X std/stdc/fprintf.c 7
X std/stdc/limits.h 7
X std/stdc/memchr.c 6
X std/stdc/memcmp.c 7
X std/stdc/memcpy.c 7
X std/stdc/memmove.c 7
X std/stdc/memset.c 7
X std/stdc/setvbuf.c 7
X std/stdc/sprintf.c 7
X std/stdc/stdarg.h 8
X std/stdc/stddef.h 8
X std/stdc/stdio.c 8
X std/stdc/stdio.h_std 8
X std/stdc/stdio.sed 8
X std/stdc/stdlib.h 8
X std/stdc/strcat.c 8
X std/stdc/strchr.c 8
X std/stdc/strcmp.c 8
X std/stdc/strcpy.c 8
X std/stdc/strcspn.c 8
X std/stdc/strerror.c 8
X std/stdc/string.h 8
X std/stdc/strlen.c 8
X std/stdc/strncat.c 8
X std/stdc/strncmp.c 8
X std/stdc/strncpy.c 8
X std/stdc/strpbrk.c 8
X std/stdc/strrchr.c 8
X std/stdc/strspn.c 8
X std/stdc/strstr.c 8
X std/stdc/strtok.c 8
X std/stdc/time.h 8
X std/stdc/types.h 8
X std/stdc/vprintf.c 8
END_OF_FILE
if test 3689 -ne `wc -c <'MANIFEST'`; then
echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'Changes.jrm' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Changes.jrm'\"
else
echo shar: Extracting \"'Changes.jrm'\" \(2367 characters\)
sed "s/^X//" >'Changes.jrm' <<'END_OF_FILE'
XChanges to the PD ksh since last time:
X
X- clean up the option configuration stuff. Options in config.h should
X now just be #define'd or not, not #define'd to 1 if you want them
X and 0 if you don't
X
X- ksh now uses the shell specified by the variable EXECSHELL to run
X shell scripts. If EXECSHELL is unset or null it defaults to
X /bin/sh. It does a path lookup on the value, so if you set it to
X ``ksh'' the ksh will run all scripts that don't start with #!. It
X seems to run most sh scripts fine (now). I'd be very interested to
X hear your experiences if you try this out, as for my next trick I'd
X like to make ksh just fork itself to run scripts, which would speed
X things up, and allow exportable functions and aliases (like he real
X ksh). Just to assure you that it can do some hairy sh scripts, both
X CC and coco work with ksh.
X
X EXECSHELL won't work if the system's exec(2) call runs scripts...
X
X- the ``let'' builtin now evaluates null or unset vars to 0, as per
X The Book
X
X- Various memory allocation/use problems were cleaned up. Hopefully
X you'll never see the ``freeing free object'' error again (if you've
X ever seen it).
X
X- the ``test'' builtin is now much more tolerant in parsing its
X arguments. This was to make it like the /bin/sh test.
X
X- Temp files (for here documents or ``fc'') are now mode 0600
X
X- Some format strings in the tree printing routines got ``expanded''
X into SCCS keywords, so the results of``type <function>'' were
X gave you interesting things like the time I last checked in the
X file. This has been fixed.
X
X- ``unset -f'' now really does unset functions.
X
X- the ``trailing blank or tab in alias definition'' feature now works.
X
X- A bug in command completion was fixed. Note command completion only
X works on commands that have been hashed, so you want to ``set -h''
X in your .kshrc, and you may wish to force hashing of some common
X commands with the ``hash'' builtin.
X
X- ``echo $$ | cat'' now works as in /bin/sh
X
XNot new features, but newly discovered bugs:
X
X- Local functions don't work correctly. This shouldn't be much
X problem, since sh doesn't have them.
X
X- Here documents in functions don't work. This is a problem with the
X temp file allocation that requires more work to fix than I've gotten
X around to doing. So avoid things like:
X
Xfoo() {
X cat <<- HereDoc
XThis is a test
XHereDoc
X}
END_OF_FILE
if test 2367 -ne `wc -c <'Changes.jrm'`; then
echo shar: \"'Changes.jrm'\" unpacked with wrong size!
fi
# end of 'Changes.jrm'
fi
if test -f 'ReadMe.sjg' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'ReadMe.sjg'\"
else
echo shar: Extracting \"'ReadMe.sjg'\" \(2747 characters\)
sed "s/^X//" >'ReadMe.sjg' <<'END_OF_FILE'
XHORIZONTAL SCROLLING
X====================
X
XI have migrated my 3.2 ksh edit.c mods into the 3.3 ksh
XThis file describes the mods in general and really only applies
X(at this stage) to emacs-mode. I have not touched vi-mode apart
Xfrom making it use pprompt() so that '!' is correctly expanded
Xas in emacs-mode.
X
XI would prefer to see both vi.c and emacs.c use a common set of
Xprimatives in edit.c - but that looks like a lot of work.
X
XBasically my mods affect the functions that move the cursor
Xabout and redraw the edit line.
X
XThe input buffer "buf" is pointed to by "xbuf" and its end is
Xpointed to by "xend". The current position in "xbuf" and end of
Xthe edit line are pointed to by "xcp" and "xep" respectively.
XI have added "xbp" which points to the start of a display window
Xwithin "xbuf".
X
X[A] starting position
X
Xbuf
X|<-------- $COLUMNS --------->|
X| |<---- x_displen ------->|
X| PS1|
X +==========+==============--------+.......+
X |\ \ \ \
X xbuf xbp xcp xep xend
X
X[B] scrolled
X
Xbuf
X| |<----- COLUMNS -------->|
X| |<----- x_displen ------>|
X|
X+-----------+==========+==============--------+.......+
X \ \ \ \ \
X xbuf xbp xcp xep xend
X
XIn the above -------- represents the current edit line while
X===== represents that portion which is visible on the screen.
XNote that initially xbp == xbuf and PS1 is displayed.
XPS1 uses some of the screen width and thus "x_displen" is less
Xthan $COLUMNS.
X
XAny time that "xcp" moves outside the region bounded by "xbp"
Xand "xbp" + "x_displen", the function x_adjust() is called to
Xrelocate "xbp" appropriately and redraw the line.
X
XExcessive I/O is avoided where possible. x_goto() for instance
Xcalculates whether the destination is outside the visible
Xregion, and if so simply adjusts "xcp" and calls x_adjust()
Xdirectly. Normally though x_adjust() is called from x_putc().
X
XThe above mechanism has be updated to use a function x_lastcp()
Xthat returns a pointer that accurately reflects the last
Xvisible char in the edit buffer. That is a more accurate
Xversion of xbp + x_displen which does not account for TABS.
X
XOther changes
X=============
X
XI have also added some emacs mode functions.
XM-[0-9]
X Set a numeric arg (positive only).
X Used by all word related commands.
XM-_
XM-.
X Retrieve word from previous command (default is last
X word). Use M-[1-9] to select word.
XM-u
XM-l
XM-c
X UPPER,lower,Capitalize word.
X
X
XCommands like delete-word now push the deleted text so that it
Xmay be yanked back into place.
X
XBUGS?
X=====
X
XThere are bound to be some. Please report same to me:
X
XSimon J. Gerraty <sjg@zen.void.oz.au>
X
END_OF_FILE
if test 2747 -ne `wc -c <'ReadMe.sjg'`; then
echo shar: \"'ReadMe.sjg'\" unpacked with wrong size!
fi
# end of 'ReadMe.sjg'
fi
if test -f 'etc/ksh.kshrc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'etc/ksh.kshrc'\"
else
echo shar: Extracting \"'etc/ksh.kshrc'\" \(2425 characters\)
sed "s/^X//" >'etc/ksh.kshrc' <<'END_OF_FILE'
X:
X# NAME:
X# ksh.kshrc - global initialization for ksh
X#
X# DESCRIPTION:
X# Each invocation of /bin/ksh processes the file pointed
X# to by $ENV (usually $HOME/.kshrc).
X# This file is intended as a global .kshrc file for the
X# Korn shell. A user's $HOME/.kshrc file simply requires
X# the line:
X# . /etc/ksh.kshrc
X# at or near the start to pick up the defaults in this
X# file which can then be overridden as desired.
X#
X# SEE ALSO:
X# $HOME/.kshrc
X#
X# AMENDED:
X# 91/11/12 19:39:44 (sjg)
X#
X# RELEASED:
X# 91/11/12 19:39:46 v2.4
X#
X# SCCSID:
X# @(#)ksh.kshrc 2.4 91/11/12 19:39:44 (sjg)
X#
X# @(#)Copyright (c) 1991 Simon J. Gerraty
X#
X# This file is provided in the hope that it will
X# be of use. There is absolutely NO WARRANTY.
X# Permission to copy, redistribute or otherwise
X# use this file is hereby granted provided that
X# the above copyright notice and this notice are
X# left intact.
X
Xcase "$-" in
X*i*) # we are interactive
X # we may have su'ed so reset these
X # NOTE: SCO-UNIX doesn't have whoami,
X # install whoami.sh
X USER=`whoami`
X PROMPT="<$USER@$HOSTNAME:!>$ "
X PPROMPT='<$USER@$HOSTNAME:$PWD:!>$ '
X PS1=$PPROMPT
X # $TTY is the tty we logged in on,
X # $tty is that which we are in now (might by pty)
X tty=`tty`
X tty=`basename $tty`
X
X set -o $EDITOR
X
X alias ls='ls -CF'
X alias h='fc -l | more'
X # the PD ksh is not 100% compatible
X case "$KSH_VERSION" in
X *PD*) # PD ksh
X builtin=builtin
X bind ^?=delete-char-backward
X bind ^[^?=delete-word-backward
X ;;
X *) # real ksh ?
X builtin=""
X ;;
X esac
X case "$TERM" in
X sun*)
X # these are not as neat as their csh equivalents
X if [ "$tty" != console ]; then
X ilabel () { print -n "\033]L$*\033\\"; }
X label () { print -n "\033]l$*\033\\"; }
X alias stripe='label $USER @ $HOSTNAME \($tty\) - $PWD'
X cds () { "cd" $*; eval stripe; }
X alias cd=cds
X eval stripe
X eval ilabel "$USER@$HOSTNAME"
X PS1=$PROMPT
X fi
X ;;
X xterm*)
X # these are not as neat as their csh equivalents
X ilabel () { print -n "\033]1;$*\007"; }
X label () { print -n "\033]2;$*\007"; }
X alias stripe='label xterm: $USER @ $HOSTNAME \($tty\) - $PWD'
X cds () { "cd" $*; eval stripe; }
X alias cd=cds
X eval stripe
X eval ilabel "$USER@$HOSTNAME"
X PS1=$PROMPT
X ;;
X *) ;;
X esac
X alias quit=exit
X alias cls=clear
X alias logout=exit
X alias bye=exit
X
X
X# add your favourite aliases here
X;;
X*) # non-interactive
X;;
Xesac
X# commands for both interactive and non-interactive shells
END_OF_FILE
if test 2425 -ne `wc -c <'etc/ksh.kshrc'`; then
echo shar: \"'etc/ksh.kshrc'\" unpacked with wrong size!
fi
# end of 'etc/ksh.kshrc'
fi
if test -f 'etc/sys_config.sh' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'etc/sys_config.sh'\"
else
echo shar: Extracting \"'etc/sys_config.sh'\" \(1539 characters\)
sed "s/^X//" >'etc/sys_config.sh' <<'END_OF_FILE'
X:
X# NAME:
X# sys_config.sh - set system specific variables
X#
X# SYNOPSIS:
X# . /etc/sys_config.sh
X#
X# DESCRIPTION:
X# Source this script into shell scripts that want to handle
X# various system types.
X# You may well want to edit this on a particular system replacing
X# `uname -s` etc with the result. So that the facility will work
X# even when in single user mode and uname et al are not available.
X#
X# SEE ALSO:
X# /etc/profile
X#
X# AMENDED:
X# 91/11/05 22:09:08 (rook)
X#
X# RELEASED:
X# 91/11/05 22:09:09 v1.3
X#
X# SCCSID:
X# @(#)sys_config.sh 1.3 91/11/05 22:09:08 (rook)
X#
X# @(#)Copyright (c) 1991 Simon J. Gerraty
X#
X# This file is provided in the hope that it will
X# be of use. There is absolutely NO WARRANTY.
X# Permission to copy, redistribute or otherwise
X# use this file is hereby granted provided that
X# the above copyright notice and this notice are
X# left intact.
X#
X
X# determin machine type
Xif [ -f /usr/bin/arch ]; then
X ARCH=`arch`
Xelif [ -f /usr/bin/uname -o -f /bin/uname ]; then
X ARCH=`uname -m`
Xfi
X#
Xcase "$ARCH" in
Xsun386) uname=/usr/5bin/uname
X OS=SunOS
X ;;
X*) uname=uname;;
Xesac
X
X# set the operating system type
X# you can't use `uname -s` with SCO UNIX
X# it returns the same string as `uname -n`
X# so set it manually
X# OS=SCO-UNIX
X# The eval below is a workaround for a bug in the PD ksh.
XOS=${OS:-`eval $uname -s`}
XHOSTNAME=${HOSTNAME:-`eval $uname -n`}
X
X# set which ever is required to not produce a linefeed
X# in an echo(1)
Xcase $OS in
XSunOS) C="\c"; N="";
X ;;
X*) C="\c"; N=""
X ;;
Xesac
Xexport OS ARCH HOSTNAME C N uname
END_OF_FILE
if test 1539 -ne `wc -c <'etc/sys_config.sh'`; then
echo shar: \"'etc/sys_config.sh'\" unpacked with wrong size!
fi
# end of 'etc/sys_config.sh'
fi
if test -f 'sh/ReadMe' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/ReadMe'\"
else
echo shar: Extracting \"'sh/ReadMe'\" \(1604 characters\)
sed "s/^X//" >'sh/ReadMe' <<'END_OF_FILE'
X Public Domain KornShell
X
X Quick installation notes for PD KornShell
X
XPD KornShell can be installed on 4.2+ BSD systems, System V, and
XPOSIX-compatable systems. The makefiles all define _BSD, change
Xthis to _SYSV, or _POSIX. The makefiles also contain CC=gcc,
Xdelete this if you don't have GNU C. The ksh makefile also
Xcontains some options, including JOBS (BSD/POSIX job control)
Xand EDIT (emacs command editing).
X
XPD KornShell assumes you have standard C (ANSI) and POSIX header
Xfiles and functions. Since you probably don't, they are provided
Xin the "std" directory.
X
XThe Alpha test version will probably come as two tar files.
Xstd.tar contains standard C and POSIX emulation and must be
Xextracted into a directory called std. ksh.tar contains the ksh
Xsource and should be extracted into a directory called src or
Xksh.
X
XSee std/ReadMe and install it. Only then can you make ksh in the
X"src" directory.
X
XTo clear up questions about the origin of this shell, this shell
Xis NOT based on the "Minix shell". It is based on Charles
XForsyth's public domain V7 shell, which he later contributed to
XMinix.
X
XI have permission directly from Charles Forsyth to use his shell.
X
X Eric Gisin, egisin@math.UWaterloo.CA (or Waterloo.EDU)
X
X Things to do
X- add sxt-based job control (see Brown's contribution on the Usenix 87 tape).
X- add arrays and variable attributes.
X- add MAILPATH and CDPATH.
X- add vi editing mode (apparently someone has a PD version).
X- add new features described in Korn's book.
X
X Machines ported to
XVAX, 68000, 80386
X
X OS's ported to
XBSD 4.2, BSD 4.3 (with and without YP and NFS
XSys V.3
END_OF_FILE
if test 1604 -ne `wc -c <'sh/ReadMe'`; then
echo shar: \"'sh/ReadMe'\" unpacked with wrong size!
fi
# end of 'sh/ReadMe'
fi
if test -f 'sh/alloc.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/alloc.h'\"
else
echo shar: Extracting \"'sh/alloc.h'\" \(455 characters\)
sed "s/^X//" >'sh/alloc.h' <<'END_OF_FILE'
X/*
X * area-based allocation built on malloc/free
X */
X
Xtypedef struct Area {
X struct Block *free; /* free list */
X} Area;
X
XArea *ainit ARGS((Area *ap));
Xvoid afreeall ARGS((Area *ap));
Xvoid ashrink ARGS((Area *ap));
Xvoid aerror ARGS((Area *ap, const char *msg));
Xvoid awarn ARGS((Area *ap, const char *msg));
X
XVoid *alloc ARGS((size_t size, Area *ap));
XVoid *aresize ARGS((Void *ptr, size_t size, Area *ap));
Xvoid afree ARGS((Void *ptr, Area *ap));
X
END_OF_FILE
if test 455 -ne `wc -c <'sh/alloc.h'`; then
echo shar: \"'sh/alloc.h'\" unpacked with wrong size!
fi
# end of 'sh/alloc.h'
fi
if test -f 'sh/edit.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/edit.h'\"
else
echo shar: Extracting \"'sh/edit.h'\" \(2292 characters\)
sed "s/^X//" >'sh/edit.h' <<'END_OF_FILE'
X/* NAME:
X * edit.h - globals for edit modes
X *
X * DESCRIPTION:
X * This header defines various global edit objects.
X *
X * SEE ALSO:
X *
X *
X * AMENDED:
X * 91/09/17 23:28:04 (sjg)
X *
X * RELEASED:
X * 91/11/09 15:36:18 v1.3
X *
X * SCCSID:
X * @(#)edit.h 1.3 91/09/17 23:28:04 (sjg)
X *
X */
X
X/* some useful #defines */
X#ifdef EXTERN
X# define _I_(i) = i
X#else
X# define _I_(i)
X# define EXTERN extern
X# define EXTERN_DEFINED
X#endif
X
X#define BEL 0x07
X
X/*
X * The following are used for my horizontal scrolling stuff
X */
XEXTERN char *xbuf; /* beg input buffer */
XEXTERN char *xend; /* end input buffer */
XEXTERN char *xcp; /* current position */
XEXTERN char *xep; /* current end */
XEXTERN char *xbp; /* start of visible portion of input buffer */
XEXTERN char *xlp; /* last char visible on screen */
XEXTERN int x_adj_ok;
X/*
X * we use x_adj_done so that functions can tell
X * whether x_adjust() has been called while they are active.
X */
XEXTERN int x_adj_done;
X
XEXTERN int x_cols;
XEXTERN int x_col;
XEXTERN int x_displen;
XEXTERN int x_arg; /* general purpose arg */
X
XEXTERN int x_do_init; /* set up tty modes */
XEXTERN int ed_erase, ed_kill, ed_werase, ed_intr, ed_quit;
X
X#if defined(__STDC__) || defined(PROTO)
X# define _P_(p) p
X#else
X# define _P_(p) ()
X#endif /* __STDC__ || PROTO */
X#ifdef DEBUG
X# define _D_(x) x
X#else
X# define _D_(x)
X#endif
X
X/**** edit.c ****/
Xint x_read _P_((int fd, char *buf, size_t len));
Xint x_getc _P_((void));
Xvoid x_flush _P_((void));
Xvoid x_adjust _P_((void));
Xvoid x_putc _P_((int c));
Xint x_debug_info _P_((void));
Xvoid x_puts _P_((char *s));
Xvoid x_init _P_((void));
Xbool_t x_mode _P_((bool_t onoff));
Xbool_t x_mode _P_((bool_t onoff));
Xint promptlen _P_((char *cp));
X
X/**** emacs.c ****/
Xvoid x_redraw _P_((int limit));
Xchar* x_lastcp _P_((void));
XEXTERN int xlp_valid _I_(0);
X
X/* This lot goes at the END */
X/* be sure not to interfere with anyone else's idea about EXTERN */
X#ifdef EXTERN_DEFINED
X# undef EXTERN_DEFINED
X# undef EXTERN
X#endif
X/*
X * Local Variables:
X * version-control:t
X * comment-column:40
X * End:
X */
END_OF_FILE
if test 2292 -ne `wc -c <'sh/edit.h'`; then
echo shar: \"'sh/edit.h'\" unpacked with wrong size!
fi
# end of 'sh/edit.h'
fi
if test -f 'sh/expand.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/expand.h'\"
else
echo shar: Extracting \"'sh/expand.h'\" \(2216 characters\)
sed "s/^X//" >'sh/expand.h' <<'END_OF_FILE'
X/*
X * Expanding strings
X */
X
X#if 0 /* Usage */
X XString xs;
X char *xp;
X
X Xinit(xs, xp, 128); /* allocate initial string */
X while ((c = generate()) {
X Xcheck(xs, xp); /* expand string if neccessary */
X Xput(xs, xp, c); /* add character */
X }
X return Xclose(xs, xp); /* resize string */
X#endif
X
Xtypedef struct XString {
X char *end, *beg; /* end, begin of string */
X#if 1
X char *oth, *old; /* togo, adjust */
X#endif
X size_t len; /* length */
X} XString;
X
Xtypedef char * XStringP;
X
X/* initialize expandable string */
X#define Xinit(xs, xp, length) { \
X (xs).len = length; \
X (xs).beg = alloc((xs).len + 8, ATEMP); \
X (xs).end = (xs).beg + (xs).len; \
X xp = (xs).beg; \
X }
X
X/* stuff char into string */
X#define Xput(xs, xp, c) *xp++ = (c)
X
X/* check for overflow, expand string */
X#define Xcheck(xs, xp) if (xp >= (xs).end) { \
X char *old_beg = (xs).beg; \
X (xs).len += (xs).len; /* double size */ \
X (xs).beg = aresize((xs).beg, (xs).len + 8, ATEMP); \
X (xs).end = (xs).beg + (xs).len; \
X xp = (xs).beg + (xp - old_beg); /* adjust pointer */ \
X }
X
X/* free string */
X#define Xfree(xs, xp) afree((Void*) (xs).beg, ATEMP)
X
X/* close, return string */
X#define Xclose(xs, xp) (char*) aresize((Void*)(xs).beg, \
X (size_t)(xp - (xs).beg), ATEMP)
X/* begin of string */
X#define Xstring(xs, xp) ((xs).beg)
X
X#define Xsavepos(xs, xp) (xp - (xs).beg)
X#define Xrestpos(xs, xp, n) ((xs).beg + (n))
X
X/*
X * expandable vector of generic pointers
X */
X
Xtypedef struct XPtrV {
X Void **cur; /* next avail pointer */
X Void **beg, **end; /* begin, end of vector */
X} XPtrV;
X
X#define XPinit(x, n) { \
X register Void **vp; \
X vp = (Void**) alloc(sizeofN(Void*, n), ATEMP); \
X (x).cur = (x).beg = vp; \
X (x).end = vp + n; \
X }
X
X#define XPput(x, p) { \
X if ((x).cur >= (x).end) { \
X int n = XPsize(x); \
X (x).beg = (Void**) aresize((Void*) (x).beg, \
X sizeofN(Void*, n*2), ATEMP); \
X (x).cur = (x).beg + n; \
X (x).end = (x).cur + n; \
X } \
X *(x).cur++ = (p); \
X }
X
X#define XPptrv(x) ((x).beg)
X#define XPsize(x) ((x).cur - (x).beg)
X
X#define XPclose(x) (Void**) aresize((Void*)(x).beg, \
X sizeofN(Void*, XPsize(x)), ATEMP)
X
X#define XPfree(x) afree((Void*) (x).beg, ATEMP)
X
END_OF_FILE
if test 2216 -ne `wc -c <'sh/expand.h'`; then
echo shar: \"'sh/expand.h'\" unpacked with wrong size!
fi
# end of 'sh/expand.h'
fi
if test -f 'sh/getopts.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/getopts.c'\"
else
echo shar: Extracting \"'sh/getopts.c'\" \(3479 characters\)
sed "s/^X//" >'sh/getopts.c' <<'END_OF_FILE'
X/*
X * Reimplementation of SysVr3 sh builtin command "getopts" for S5R2 shell.
X *
X * created by Arnold Robbins
X * modified by Doug Gwyn
X * modified for PD ksh by Eric Gisin
X */
X
Xstatic char *RCSid = "$Id: getopts.c,v 3.3 89/03/27 15:50:27 egisin Exp $";
X
X#include <stddef.h>
X#include <string.h>
X#include <errno.h>
X#include <setjmp.h>
X#include "sh.h"
X#include "table.h"
X
X/*
X * The following is derived from getopt() source placed into the public
X * domain by AT&T (the only time they're known to have done that).
X *
X * It has been modified somewhat to fit into the context of the shell.
X *
X * -D"FASCIST" if you really want to strictly enforce ALL the
X * Command Syntax Standard rules (not recommended).
X */
X
X#define GETOPTEOF (-1)
X#define ERR(S, C) shellf("%s%c\n", (S), (C))
X
Xstatic int optind;
Xstatic char *optarg;
Xstatic int sp;
X
Xstatic int
Xgetopt(argc, argv, opts)
X int argc;
X register char **argv, *opts;
X{
X register int c;
X register char *cp;
X
X if (sp == 1)
X if (optind >= argc ||
X argv[optind][0] != '-' || argv[optind][1] == '\0')
X return(GETOPTEOF);
X else if (strcmp(argv[optind], "--") == 0) {
X optind++;
X return(GETOPTEOF);
X }
X c = argv[optind][sp];
X if (c == ':' || (cp=strchr(opts, c)) == NULL) {
X ERR("illegal option -- ", c);
X if (argv[optind][++sp] == '\0') {
X optind++;
X sp = 1;
X }
X optarg = NULL;
X return('?');
X }
X if (*++cp == ':') {
X#ifdef FASCIST
X if (sp != 1) {
X ERR("option must not be grouped -- ", c );
X optind++;
X sp = 1;
X optarg = NULL;
X return('?');
X } else
X#endif
X if (argv[optind][sp+1] != '\0') {
X#ifdef FASCIST
X ERR("option must be followed by whitespace -- ", c );
X optind++;
X sp = 1;
X optarg = NULL;
X return('?');
X#else
X optarg = &argv[optind++][sp+1];
X#endif
X } else if (++optind >= argc) {
X ERR("option requires an argument -- ", c);
X sp = 1;
X optarg = NULL;
X return('?');
X } else
X optarg = argv[optind++];
X sp = 1;
X } else {
X if (argv[optind][++sp] == '\0') {
X sp = 1;
X optind++;
X }
X optarg = NULL;
X }
X return(c);
X}
X
X/*
X * The following were created by Arnold Robbins.
X */
X
X/* resetopts --- magic code for when OPTIND is reset to 1 */
X
Xvoid
Xresetopts ()
X{
X optind = 1;
X sp = 1;
X}
X
Xint
Xc_getopts(wp)
X char **wp;
X{
X int ret;
X register int argc;
X char temp[2];
X char *optstr; /* list of options */
X char *name; /* variable to get flag val */
X char **argv;
X
X if ((optstr = *++wp) == NULL || (name = *++wp) == NULL)
X errorf("missing arguments\n");
X
X for (argc = 1; wp[argc] != NULL; argc++)
X ;
X
X if (argc > 1)
X ret = getopt(argc, wp, optstr);
X else {
X if (**(e.loc->argv) == '\0') {
X /*
X * When c_getopts gets called from comexec() it
X * doesn't set up argc/argv in the local block.
X * Maybe this should be done in newblock() but
X * I'm not sure about the implications, and this
X * is the only place I've been bitten so far...
X * JRM
X */
X argc = e.loc->next->argc;
X argv = e.loc->next->argv;
X } else {
X argc = e.loc->argc;
X argv = e.loc->argv;
X }
X ret = getopt(argc+1, argv, optstr);
X
X }
X
X /*
X * set the OPTIND variable in any case, to handle "--" skipping
X * unless it's 1, which would trigger a reset
X */
X
X if (optind != 1)
X setint(global("OPTIND"), (long)optind);
X
X if (ret == GETOPTEOF) /* end of args */
X return (1);
X
X /*
X * else, got an arg, set the various shell variables
X */
X
X if (optarg != NULL)
X setstr(global("OPTARG"), optarg);
X
X temp[0] = (char) ret;
X temp[1] = '\0';
X setstr(global(name), temp);
X
X return (0);
X}
END_OF_FILE
if test 3479 -ne `wc -c <'sh/getopts.c'`; then
echo shar: \"'sh/getopts.c'\" unpacked with wrong size!
fi
# end of 'sh/getopts.c'
fi
if test -f 'sh/io.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/io.c'\"
else
echo shar: Extracting \"'sh/io.c'\" \(3185 characters\)
sed "s/^X//" >'sh/io.c' <<'END_OF_FILE'
X/*
X * shell buffered IO and formatted output
X */
X
Xstatic char *RCSid = "$Id: io.c,v 3.4 89/03/27 15:50:52 egisin Exp $";
X
X#include <stddef.h>
X#include <stdlib.h>
X#include <stdio.h>
X#include <errno.h>
X#include <unistd.h>
X#include <fcntl.h>
X#include <signal.h>
X#include <setjmp.h>
X#if __STDC__
X#include <stdarg.h>
X#else
X#include <varargs.h>
X#endif
X#include "sh.h"
X
X#if 0
X/* fputc with ^ escaping */
Xstatic void
Xfzotc(c, f)
X register int c;
X register FILE *f;
X{
X if ((c&0x60) == 0) { /* C0|C1 */
X putc((c&0x80) ? '$' : '^', f);
X putc((c&0x7F|0x40), f);
X } else if ((c&0x7F) == 0x7F) { /* DEL */
X putc((c&0x80) ? '$' : '^', f);
X putc('?', f);
X } else
X putc(c, f);
X}
X#endif
X
X/*
X * formatted output functions
X */
X
X/* shellf(...); error() */
Xint
X#if __STDC__
Xerrorf(Const char *fmt, ...) {
X#else
Xerrorf(va_alist) va_dcl
X{
X char *fmt;
X#endif
X va_list va;
X
X#if __STDC__
X va_start(va, fmt);
X#else
X va_start(va);
X fmt = va_arg(va, char *);
X#endif
X vfprintf(shlout, fmt, va);
X va_end(va);
X /*fflush(shlout);*/
X error();
X}
X
X/* printf to shlout (stderr) */
Xint
X#if __STDC__
Xshellf(Const char *fmt, ...) {
X#else
Xshellf(va_alist) va_dcl
X{
X char *fmt;
X#endif
X va_list va;
X
X#if __STDC__
X va_start(va, fmt);
X#else
X va_start(va);
X fmt = va_arg(va, char *);
X#endif
X vfprintf(shlout, fmt, va);
X va_end(va);
X return 0;
X}
X
X/*
X * We have a stdio stream for any open shell file descriptors (0-9)
X */
XFILE * shf [NUFILE]; /* map shell fd to FILE * */
X
X/* open stream for shell fd */
Xvoid
Xfopenshf(fd)
X int fd;
X{
X if (shf[fd] != NULL)
X return;
X if (fd <= 2)
X _iob[fd]._flag = 0; /* re-use stdin, stdout, stderr */
X shf[fd] = fdopen(fd, "r+");
X if (shf[fd] == NULL)
X return;
X setvbuf(shf[fd], (char*)NULL, _IOFBF, (size_t)BUFSIZ);
X}
X
X/* flush stream assoc with fd */
X/* this must invalidate input and output buffers */
Xvoid
Xflushshf(fd)
X int fd;
X{
X if (shf[fd] != NULL) {
X fseek(shf[fd], 0L, 1); /* V7 derived */
X fflush(shf[fd]); /* standard C */
X }
X}
X
X/*
X * move fd from user space (0<=fd<10) to shell space (fd>=10)
X */
Xint
Xsavefd(fd)
X int fd;
X{
X int nfd;
X
X if (fd < FDBASE) {
X flushshf(fd);
X nfd = fcntl(fd, F_DUPFD, FDBASE);
X if (nfd < 0)
X if (errno == EBADF)
X return -1;
X else
X errorf("too many files open in shell\n");
X (void) fcntl(nfd, F_SETFD, FD_CLEXEC);
X close(fd);
X } else
X nfd = fd;
X return nfd;
X}
X
Xvoid
Xrestfd(fd, ofd)
X int fd, ofd;
X{
X if (ofd == 0) /* not saved (e.savefd) */
X return;
X flushshf(fd);
X close(fd);
X if (ofd < 0) /* original fd closed */
X return;
X (void) fcntl(ofd, F_DUPFD, fd);
X close(ofd);
X}
X
Xvoid
Xopenpipe(pv)
X register int *pv;
X{
X if (pipe(pv) < 0)
X errorf("can't create pipe - try again\n");
X pv[0] = savefd(pv[0]);
X pv[1] = savefd(pv[1]);
X}
X
Xvoid
Xclosepipe(pv)
X register int *pv;
X{
X close(pv[0]);
X close(pv[1]);
X}
X
X/*
X * temporary files
X */
X
Xstruct temp *
Xmaketemp(ap)
X Area *ap;
X{
X register struct temp *tp;
X static unsigned int inc = 0;
X char path [PATH];
X
X sprintf(path, "/tmp/sh%05u%02u", (unsigned)getpid(), inc++);
X#if defined(_SYSV) || defined(_BSD)
X close(creat(path, 0600)); /* to get appropriate permissions */
X#endif
X tp = (struct temp *) alloc(sizeof(struct temp), ap);
X tp->next = NULL;
X tp->name = strsave(path, ap);
X return tp;
X}
END_OF_FILE
if test 3185 -ne `wc -c <'sh/io.c'`; then
echo shar: \"'sh/io.c'\" unpacked with wrong size!
fi
# end of 'sh/io.c'
fi
if test -f 'sh/lex.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/lex.h'\"
else
echo shar: Extracting \"'sh/lex.h'\" \(3466 characters\)
sed "s/^X//" >'sh/lex.h' <<'END_OF_FILE'
X/*
X * Source input, lexer and parser
X */
X
X/* Id: /u/egisin/sh/src/RCS/lex.h,v 3.3 89/01/28 15:29:42 egisin Exp $ */
X
X#define IDENT 64
X
Xtypedef struct source Source;
Xstruct source {
X char *str; /* input pointer */
X int type; /* input type */
X union {
X char **strv; /* string [] */
X FILE *file; /* file */
X struct tbl *tblp; /* alias */
X } u;
X int line; /* line number */
X char *file; /* input file name */
X int echo; /* echo input to shlout */
X Source *next; /* stacked source */
X};
X
X/* Source.type values */
X#define SEOF 0 /* input EOF */
X#define STTY 1 /* terminal input */
X#define SFILE 2 /* file input */
X#define SSTRING 4 /* string */
X#define SWSTR 3 /* string without \n */
X#define SWORDS 5 /* string[] */
X#define SWORDSEP 8 /* string[] seperator */
X#define SALIAS 6 /* alias expansion */
X#define SHIST 7 /* history expansion */
X
XSource *pushs ARGS((int stype)); /* push Source */
Xstruct op *compile ARGS((Source *s)); /* compile tree */
X
X/*
X * states while lexing word
X */
X#define SBASE 0 /* outside any lexical constructs */
X#define SWORD 6 /* implicit quoting for substitute() */
X#define SDPAREN 7 /* inside (( )), implicit quoting */
X#define SSQUOTE 1 /* inside '' */
X#define SDQUOTE 2 /* inside "" */
X#define SBRACE 3 /* inside ${} */
X#define SPAREN 4 /* inside $() */
X#define SBQUOTE 5 /* inside `` */
X
XExtern int multiline; /* \n changed to ; */
X
Xtypedef union {
X int i;
X char *cp;
X char **wp;
X struct op *o;
X struct ioword *iop;
X} YYSTYPE;
X
X#define LWORD 256
X#define LOGAND 257
X#define LOGOR 258
X#define BREAK 259
X#define IF 260
X#define THEN 261
X#define ELSE 262
X#define ELIF 263
X#define FI 264
X#define CASE 265
X#define ESAC 266
X#define FOR 267
X#define WHILE 268
X#define UNTIL 269
X#define DO 270
X#define DONE 271
X#define IN 272
X#define FUNCTION 273
X#define TIME 274
X#define REDIR 275
X#define MPAREN 276 /* () */
X#define MDPAREN 277 /* (( )) */
X#define YYERRCODE 300
X
X/* flags to yylex */
X#define CONTIN BIT(0) /* skip new lines to complete command */
X#define ONEWORD BIT(1) /* single word for substitute() */
X#define ALIAS BIT(2) /* recognize alias */
X#define KEYWORD BIT(3) /* recognize keywords */
X#define LETEXPR BIT(4) /* get expression inside (( )) */
X
X#define SYNTAXERR zzerr()
X#define HERES 10 /* max << in line */
X
XExtern char line [LINE+1]; /* input line */
XExtern Source *source; /* yyparse/yylex source */
XExtern YYSTYPE yylval; /* result from yylex */
XExtern int yynerrs;
XExtern struct ioword *heres [HERES], **herep;
XExtern char ident [IDENT+1];
X
Xextern int yylex ARGS((int flags));
Xextern void yyerror ARGS((Const char *msg));
X
X#define HISTORY 100 /* size of saved history */
X
Xextern char *history [HISTORY]; /* saved commands */
Xextern char **histptr; /* last history item */
Xextern int histpush; /* number of pushed fc commands */
X
Xextern char **histget();
Xextern char **histpos();
Xextern int histnum();
Xextern char *findhist();
Xextern int histN();
X
X#ifdef EDIT
X
Xextern void x_init ARGS ((void)); /* setup tty modes */
Xextern void x_init_emacs ARGS ((void));
Xextern void x_emacs_keys ();
Xextern void x_bind();
X
Xextern int x_read ARGS ((int fd, char *buf, size_t len));
Xextern int x_emacs ARGS ((char *buf, size_t len));
Xextern int x_vi ARGS ((char *buf, size_t len));
X
Xextern bool_t x_mode ARGS ((bool_t)); /* set/clear cbreak mode */
Xextern int x_getc(); /* get tty char */
Xextern void x_flush(), x_putc(), x_puts(); /* put tty char */
X
Xextern int x_cols; /* tty columns */
X
X#endif
END_OF_FILE
if test 3466 -ne `wc -c <'sh/lex.h'`; then
echo shar: \"'sh/lex.h'\" unpacked with wrong size!
fi
# end of 'sh/lex.h'
fi
if test -f 'sh/table.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/table.h'\"
else
echo shar: Extracting \"'sh/table.h'\" \(3500 characters\)
sed "s/^X//" >'sh/table.h' <<'END_OF_FILE'
X/* $Id: table.h,v 3.2 89/03/27 15:46:52 egisin Exp $ */
X
X/*
X * generic hashed associative table for commands and variables.
X */
X
Xstruct table {
X Area *areap; /* area to allocate entries */
X int size, free; /* hash size (always 2^^n), free entries */
X struct tbl **tbls; /* hashed table items */
X};
X
Xstruct tbl { /* table item */
X int flag; /* flags */
X int type; /* command type or base, see below */
X union {
X char *s; /* string */
X long i; /* integer */
X int (*f) ARGS ((char**)); /* int function */
X struct op *t; /* "function" tree */
X } val; /* value */
X char name[4]; /* name -- variable length */
X};
X
X/* flag bits */
X#define ALLOC BIT(0) /* val.s has been allocated */
X#define DEFINED BIT(1) /* is defined in block */
X#define ISSET BIT(2) /* has value, vp->val.[si] */
X#define SPECIAL BIT(3) /* PATH, IFS, SECONDS, etc */
X#define INTEGER BIT(4) /* val.i contains integer value */
X#define RDONLY BIT(8) /* read-only variable */
X#define EXPORT BIT(9) /* exported variable */
X#define LOCAL BIT(10) /* for local typeset() */
X#define TRACE BIT(11) /* trace (-t) */
X#define FUNCT BIT(12) /* function */
X#define EXPALIAS BIT(13) /* expanding this alias */
X
X/* command types */
X#define CNONE 0 /* undefined */
X#define CSHELL 1 /* built-in */
X#define CFUNC 2 /* function */
X#define CEXEC 4 /* executable command */
X#define CALIAS 5 /* alias */
X#define CKEYWD 6 /* keyword */
X
Xvoid tinit ARGS((struct table *, Area *)); /* initialize table */
Xunsigned int hash(); /* name hash function */
Xstruct tbl *tsearch(); /* table lookup primative */
Xstruct tbl *tenter(); /* table lookup/enter primative */
Xvoid tdelete(); /* mark tbl entry for deletion */
Xvoid twalk(); /* initialize walk of table */
Xstruct tbl *tnext(); /* walk table returning table time */
Xstruct tbl **tsort(); /* sort table entries by name */
X
X/*
X * activation record for function blocks
X */
Xstruct block {
X Area area; /* area to allocate things */
X int argc; /* current $# */
X char ** argv; /* current $* */
X struct table vars; /* local variables */
X struct table funs; /* local functions */
X#if 1
X char * error; /* error handler */
X char * exit; /* exit handler */
X#else
X struct trap error, exit;
X#endif
X struct block *next; /* enclosing block */
X};
X
XExtern struct block globals; /* global variables and functions */
XExtern struct table commands; /* hashed commands */
XExtern struct table builtins; /* built-in commands */
XExtern struct table lexicals; /* keywords and aliases */
XExtern struct table homedirs; /* homedir() cache */
X
Xstruct builtin {
X char *name;
X int (*func)();
X};
XExtern Const struct builtin shbuiltins [], kshbuiltins [];
X
X/* var spec values */
X#define V_NONE 0
X#define V_PATH 1
X#define V_IFS 2
X#define V_SECONDS 3
X#define V_OPTIND 4
X#define V_MAIL 5
X#define V_MAILPATH 6
X#define V_RANDOM 7
X
XExtern Area *lastarea; /* area of last variable/function looked up */
XExtern char *path; /* PATH value */
XExtern char *prompt; /* PS1 or PS2 */
X
Xvoid newblock();
Xvoid popblock();
Xstruct tbl *global(/* char *s */);
Xstruct tbl *local(/* char *s */);
Xstruct tbl *typeset(/* char *var; int set, clr */);
Xstruct tbl *setvar(/* struct tbl *vdst, *vsrc */);
Xstruct tbl *strint(/* struct tbl *vdst, *vsrc */);
Xlong intval(/* struct tbl *vp */);
Xvoid setint(/* struct tbl *vp; long n */);
Xchar *strval(/* struct tbl *vp */);
Xvoid setstr(/* struct tbl *vp; char *s */);
Xvoid unset(/* struct tbl *vp */);
Xint import(/* char *s */);
Xchar **makenv();
Xint isassign(/* char *s */);
X
END_OF_FILE
if test 3500 -ne `wc -c <'sh/table.h'`; then
echo shar: \"'sh/table.h'\" unpacked with wrong size!
fi
# end of 'sh/table.h'
fi
if test -f 'sh/trace.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/trace.h'\"
else
echo shar: Extracting \"'sh/trace.h'\" \(2121 characters\)
sed "s/^X//" >'sh/trace.h' <<'END_OF_FILE'
X/* NAME:
X * trace.h - definitions for a simple trace facility
X *
X * SYNOPSIS:
X * #include "trace.h"
X *
X * DESCRIPTION:
X * Defines the macro _TRACE().
X * Also declares Trace_log and Trace_level.
X *
X * SEE ALSO:
X *
X *
X * AMENDED:
X * %E% %U% (%Y%)
X *
X * RELEASED:
X * %D% %T% v%I%
X *
X * SCCSID:
X * %Z%%M% %I% %E% %U% (%Y%)
X *
X * @(#)Copyright (c) 1990 Simon J. Gerraty.
X */
X
X/* some useful #defines */
X#ifndef EXTERN
X# define EXTERN extern
X# define EXTERN_DEFINED
X#endif
X
X#ifndef TRUE
X# define TRUE 1
X# define FALSE 0
X#endif
X#ifndef _P_
X# if defined(__STDC__) || defined(PROTO)
X# define _P_(p) p
X# else
X# define _P_(p) ()
X# endif
X#endif
X
X/*
X * this garbage is sometimes needed when mixing
X * langauges or calling conventions under DOS.
X */
X#ifndef _CDECL
X# if defined(MSDOS) || defined(MSC)
X# ifndef NO_EXT_KEYS
X# define _CDECL cdecl
X# define _NEAR near
X# else
X# define _CDECL
X# define _NEAR
X# endif
X# else /* not DrOS */
X# define _CDECL
X# define _NEAR
X# endif /* DOS */
X#endif /* _CDECL */
X
X/* manifest constants */
X
X/* struct / union */
X
X/* macros */
X
X
X#ifdef USE_TRACE
XEXTERN char * _CDECL Trace_log;
XEXTERN int _CDECL Trace_level;
X
Xvoid _CDECL checkpoint _P_((char *fmt, ...));
X
X/*
X * This macro takes a variabel number of args.
X * examples:
X * _TRACE(5, ("The current Debug level is %d\n", Debug));
X * Note that if more than two args are provided, all but the
X * first (which should be an integer indicating the Trace-level
X * required for this message to be printed) must be enclosed in
X * parenthesis.
X */
X# define _TRACE(lev, args) if (Trace_level >= lev) checkpoint args
X#else /* don't USE_TRACE */
X /*
X * this macro evaluates to a harmless no entry
X * loop that most optimizers will remove all together.
X */
X# define _TRACE(l, args) while (0)
X#endif /* USE_TRACE */
X
X
X/* This lot goes at the END */
X/* be sure not to interfere with anyone else's idea about EXTERN */
X#ifdef EXTERN_DEFINED
X# undef EXTERN_DEFINED
X# undef EXTERN
X#endif
X/*
X * Local Variables:
X * version-control:t
X * comment-column:40
X * End:
X */
END_OF_FILE
if test 2121 -ne `wc -c <'sh/trace.h'`; then
echo shar: \"'sh/trace.h'\" unpacked with wrong size!
fi
# end of 'sh/trace.h'
fi
if test -f 'sh/trap.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/trap.c'\"
else
echo shar: Extracting \"'sh/trap.c'\" \(3128 characters\)
sed "s/^X//" >'sh/trap.c' <<'END_OF_FILE'
X/*
X * signal handling
X */
X
Xstatic char *RCSid = "$Id: trap.c,v 3.2 89/03/27 15:52:06 egisin Exp $";
X
X#include <stddef.h>
X#include <string.h>
X#include <errno.h>
X#include <signal.h>
X#include <setjmp.h>
X#include "sh.h"
X
XTrap sigtraps [SIGNALS] = {
X {0, "EXIT", "Signal 0"}, /* todo: belongs in e.loc->exit */
X {SIGHUP, "HUP", "Hangup"},
X {SIGINT, "INT", "Interrupt"},
X {SIGQUIT, "QUIT", "Quit"},
X {SIGILL, "ILL", "Illegal instruction"},
X {SIGTRAP, "TRAP", "Trace trap"},
X#ifdef SIGABRT
X {SIGIOT, "ABRT", "Abort"},
X#else
X {SIGIOT, "IOT", "IOT instruction"},
X#endif
X {SIGEMT, "EMT", "EMT trap"},
X {SIGFPE, "FPE", "Floating exception"},
X {SIGKILL, "KILL", "Killed"},
X {SIGBUS, "BUS", "Bus error"},
X {SIGSEGV, "SEGV", "Memory fault"},
X {SIGSYS, "SYS", "Bad system call"},
X {SIGPIPE, "PIPE", "Broken pipe"},
X {SIGALRM, "ALRM", "Alarm clock"},
X {SIGTERM, "TERM", "Terminated"},
X#ifdef _SYSV
X {SIGUSR1, "USR1", "User defined signal 1"},
X {SIGUSR2, "USR2", "User defined signal 2"},
X {SIGCLD, "CLD", "Death of a child"},
X {SIGPWR, "PWR", "Power-fail restart"},
X#else
X#ifdef JOBS /* todo: need to be more portable */
X {SIGURG, "URG", "Urgent condition"}, /* BSDism */
X {SIGSTOP, "STOP", "Stop (signal)"},
X {SIGTSTP, "TSTP", "Stop"},
X {SIGCONT, "CONT", "Continue"},
X {SIGCHLD, "CHLD", "Waiting children"},
X {SIGTTIN, "TTIN", "Stop (tty input)"},
X {SIGTTOU, "TTOU", "Stop (tty output)"},
X#endif
X#endif
X};
X
XTrap *
Xgettrap(name)
X char *name;
X{
X int i;
X register Trap *p;
X
X if (digit(*name)) {
X i = getn(name);
X return (0 <= i && i < SIGNALS) ? &sigtraps[getn(name)] : NULL;
X }
X#if 0
X if (strcmp("ERR", name) == 0)
X return &e.loc->err;
X if (strcmp("EXIT", name) == 0)
X return &e.loc->exit;
X#endif
X for (p = sigtraps, i = SIGNALS; --i >= 0; p++)
X if (p->name != NULL && strcmp(p->name, name) == 0)
X return p;
X return NULL;
X}
X
X/*
X * trap signal handler
X */
Xvoid
Xtrapsig(i)
X int i;
X{
X trap = sigtraps[i].set = 1;
X if (i == SIGINT && e.type == E_PARSE)
X /* dangerous but necessary to deal with BSD silly signals */
X longjmp(e.jbuf, 1);
X (void) signal(i, trapsig); /* todo: use sigact */
X}
X
X/*
X * run any pending traps
X */
Xruntraps()
X{
X int i;
X register Trap *p;
X
X for (p = sigtraps, i = SIGNALS; --i >= 0; p++)
X if (p->set)
X runtrap(p);
X trap = 0;
X}
X
Xruntrap(p)
X Trap *p;
X{
X char *trapstr;
X
X p->set = 0;
X if ((trapstr = p->trap) == NULL)
X if (p->signal == SIGINT)
X unwind(); /* return to shell() */
X else
X return;
X if (p->signal == 0) /* ??? */
X p->trap = 0;
X command(trapstr);
X}
X
X/* restore signals for children */
Xcleartraps()
X{
X int i;
X register Trap *p;
X
X if ((p = sigtraps)->trap != NULL) { /* Maybe put in exchild() */
X afree((Void *)p->trap,APERM); /* Necessary? */
X p->trap = NULL;
X }
X for (i = SIGNALS, p = sigtraps; --i >= 0; p++) {
X p->set = 0;
X if (p->ourtrap && signal(p->signal, SIG_IGN) != SIG_IGN)
X (void) signal(p->signal, SIG_DFL);
X }
X}
X
Xignoresig(i)
X int i;
X{
X if (signal(i, SIG_IGN) != SIG_IGN)
X sigtraps[i].sig_dfl = 1;
X}
X
Xrestoresigs()
X{
X int i;
X register Trap *p;
X
X for (p = sigtraps, i = SIGNALS; --i >= 0; p++)
X if (p->sig_dfl) {
X p->sig_dfl = 0;
X (void) signal(p->signal, SIG_DFL);
X }
X}
X
END_OF_FILE
if test 3128 -ne `wc -c <'sh/trap.c'`; then
echo shar: \"'sh/trap.c'\" unpacked with wrong size!
fi
# end of 'sh/trap.c'
fi
if test -f 'sh/tree.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sh/tree.h'\"
else
echo shar: Extracting \"'sh/tree.h'\" \(3570 characters\)
sed "s/^X//" >'sh/tree.h' <<'END_OF_FILE'
X/*
X * command trees for compile/execute
X */
X
X/* $Id: tree.h,v 3.3 89/03/27 15:46:57 egisin Exp $ */
X
X#define NOBLOCK ((struct op *)NULL)
X#define NOWORD ((char *)NULL)
X#define NOWORDS ((char **)NULL)
X
X/*
X * Description of a command or an operation on commands.
X */
Xstruct op {
X int type; /* operation type, see below */
X char **args; /* arguments to a command */
X char **vars; /* variable assignments */
X struct ioword **ioact; /* IO actions (eg, < > >>) */
X struct op *left, *right; /* descendents */
X char *str; /* identifier for case and for (use vars[0]) */
X};
X
X/* Tree.type values */
X#define TEOF 0
X#define TCOM 1 /* command */
X#define TPAREN 2 /* (c-list) */
X#define TPIPE 3 /* a | b */
X#define TLIST 4 /* a [&;] b */
X#define TOR 5 /* || */
X#define TAND 6 /* && */
X#define TFOR 7
X#define TCASE 9
X#define TIF 10
X#define TWHILE 11
X#define TUNTIL 12
X#define TELIF 13
X#define TPAT 14 /* pattern in case */
X#define TBRACE 15 /* {c-list} */
X#define TASYNC 16 /* c & */
X#define TFUNCT 17 /* function name { command; } */
X#define TTIME 18 /* time pipeline */
X#define TEXEC 19 /* fork/exec eval'd TCOM */
X
X/*
X * prefix codes for words in command tree
X */
X#define EOS 0 /* end of string */
X#define CHAR 1 /* unquoted character */
X#define QCHAR 2 /* quoted character */
X#define COMSUB 3 /* $() substitution (0 terminated) */
X#define OQUOTE 4 /* opening " or ' */
X#define CQUOTE 5 /* closing " or ' */
X#define OSUBST 6 /* opening ${ substitution */
X#define CSUBST 7 /* closing } of above */
X
X/*
X * IO redirection
X */
Xstruct ioword {
X int unit; /* unit affected */
X int flag; /* action (below) */
X char *name; /* file name */
X};
X
X/* ioword.flag - type of redirection */
X#define IOTYPE 0xF /* type: bits 0:3 */
X#define IOREAD 0x1 /* < */
X#define IOWRITE 0x2 /* > */
X#define IORDWR 0x3 /* <>: todo */
X#define IOHERE 0x4 /* << (here file) */
X#define IOCAT 0x5 /* >> */
X#define IODUP 0x6 /* <&/>& */
X#define IOEVAL BIT(4) /* expand in << */
X#define IOSKIP BIT(5) /* <<-, skip ^\t* */
X#define IOCLOB BIT(6) /* >!, override -o noclob */
X
X/* values for E_LOOP longjmp */
X#define LBREAK 1
X#define LCONTIN 2
X
X/* execute/exchild flags */
X#define XEXEC BIT(0) /* execute without forking */
X#define XFORK BIT(5) /* fork before executing */
X#define XBGND BIT(1) /* command & */
X#define XPIPEI BIT(2) /* input is pipe */
X#define XPIPEO BIT(3) /* output is pipe */
X#define XPIPE (XPIPEI|XPIPEO) /* member of pipe */
X#define XXCOM BIT(4) /* dup2 xcomfd to 1 */
X
X/*
X * flags to control expansion of words
X */
X#define DOBLANK BIT(1) /* perform blank interpretation */
X#define DOGLOB BIT(2) /* expand [?* */
X#define DOPAT BIT(3) /* quote *?[ */
X#define DOTILDE BIT(5) /* expand ~ */
X
X/* job.c: job control primatives */
Xint execute ARGS((struct op *, int flags)); /* execute tree */
Xint exchild ARGS((struct op *, int flags)); /* execute tree as child */
Xint waitfor ARGS((int job)); /* wait for job completion */
Xint waitlast ARGS((void)); /* wait for last job */
X
X/* eval.c: word expansion */
Xchar **eval ARGS((char **wv, int flag)); /* expand words */
Xchar *evalstr ARGS((char *wp, int flags)); /* expand word */
Xchar *substitute ARGS((Const char *s, int flags)); /* compile and expand string */
X
X/* tree.c: command trees */
Xvoid ptree ARGS((struct op *t, FILE *f)); /* print tree */
Xchar *wdscan ARGS((char *wp, int c)); /* scan word for prefix */
Xchar *wdcopy ARGS((char *wp, Area *)); /* copy word */
Xstruct op *tcopy ARGS((struct op *t, Area *)); /* copy tree */
Xvoid tfree ARGS((struct op *t, Area *)); /* free tree */
X
END_OF_FILE
if test 3570 -ne `wc -c <'sh/tree.h'`; then
echo shar: \"'sh/tree.h'\" unpacked with wrong size!
fi
# end of 'sh/tree.h'
fi
if test -f 'std/posix/io.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'std/posix/io.h'\"
else
echo shar: Extracting \"'std/posix/io.h'\" \(1499 characters\)
sed "s/^X//" >'std/posix/io.h' <<'END_OF_FILE'
X/* POSIX IO functions */
X
X/*
X * the incomplete type "struct stat"
X * will get warnings from GCC,
X * errors from Turbo C. Too bad.
X */
X
X/* include <unistd.h> to get this */
X
X#if ! _IO_H
X#define _IO_H 1
X
X#include <unistd.h>
X
X#if _ST /* dLibs hack */
X#define unlink remove
X#endif
X
Xstruct stat; /* create global incompletely-typed structure */
X
Xint chdir ARGS ((const char *path));
X#ifndef sparc
Xint umask ARGS ((int mode));
X#endif
X
Xint open ARGS ((const char *path, int flags, ... /*mode*/));
Xint creat ARGS ((const char *path, int mode));
Xint pipe ARGS ((int pv[2]));
Xint close ARGS ((int fd));
X
Xint fcntl ARGS ((int fd, int cmd, int arg));
Xint dup ARGS ((int fd));
Xint dup2 ARGS ((int ofd, int nfd));
X
Xint link ARGS ((const char *opath, const char *npath));
Xint unlink ARGS ((const char *path));
Xint rename ARGS ((const char *opath, const char *npath));
Xint mkdir ARGS ((const char *path, int mode));
X
Xlong lseek ARGS ((int fd, long off, int how));
Xint read ARGS ((int fd, char *buf, unsigned len));
Xint write ARGS ((int fd, char *buf, unsigned len));
X
Xint access ARGS ((const char *path, int mode));
Xint stat ARGS ((const char *path, struct stat *sp));
Xint fstat ARGS ((int fd, struct stat *sp));
X
Xint chmod ARGS ((const char *path, int mode));
Xint chown ARGS ((const char *path, int uid));
Xint chgrp ARGS ((const char *path, int gid));
Xint utime ARGS ((const char *path, long tv[2]));
X
X#if _BSD || _V7
Xint ioctl ARGS ((int fd, int cmd, void *argp)); /* BSD is "uns long cmd" */
X#endif
X
X#endif
END_OF_FILE
if test 1499 -ne `wc -c <'std/posix/io.h'`; then
echo shar: \"'std/posix/io.h'\" unpacked with wrong size!
fi
# end of 'std/posix/io.h'
fi
if test -f 'std/stdc/stdio.h_std' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'std/stdc/stdio.h_std'\"
else
echo shar: Extracting \"'std/stdc/stdio.h_std'\" \(2290 characters\)
sed "s/^X//" >'std/stdc/stdio.h_std' <<'END_OF_FILE'
X/*
X * ANSI stream IO
X *
X * Heavily dependent on /usr/include/stdio.h being AT&T derived.
X * todo: needs L_* constants.
X */
X
X/* $Header: stdio.h,v 1.2 88/06/23 18:32:35 egisin Locked $ */
X
X#if ! _STDIO_H
X#define _STDIO_H 1
X
X#include <stddef.h>
X
X/* system stdio.h goes here ... %%% */
X/* ... end system stdio.h */
X#line 15 "stdio.h"
X
X#ifndef _IOFBF
X#define _IOFBF 00000
X#endif
X#ifndef _IOLBF
X#define _IOLBF 00000 /* same as _IOFBF */
X#endif
X
X#define SEEK_SET 0
X#define SEEK_CUR 1
X#define SEEK_END 2
X
X#if _SYSV
X#define _EXTERN extern
X#else
X#define _EXTERN
X#endif
X
X_EXTERN int remove ARGS((const char *name));
X_EXTERN int rename ARGS((const char *oname, const char *nname));
X_EXTERN FILE *tmpfile ARGS((void));
X_EXTERN char *tmpnam ARGS((char *s));
X
X_EXTERN FILE *fopen ARGS((const char *name, const char *mode));
X_EXTERN FILE *freopen ARGS((const char *name, const char *mode, FILE *f));
X_EXTERN FILE *fdopen ARGS((int fd, const char *mode));
X_EXTERN int fflush ARGS((FILE *f));
X_EXTERN int fclose ARGS((FILE *f));
X_EXTERN void setbuf ARGS((FILE *f, char *buf));
X_EXTERN int setvbuf ARGS((FILE *f, char *buf, int flags, size_t len));
X
X_EXTERN int fseek ARGS((FILE *f, long off, int how));
X_EXTERN long ftell ARGS((FILE *f));
X_EXTERN void rewind ARGS((FILE *f));
X
X_EXTERN int printf ARGS((const char *fmt, ...));
X_EXTERN int fprintf ARGS((FILE *f, const char *fmt, ...));
X_EXTERN int sprintf ARGS((char *s, const char *fmt, ...));
X/* we do not include <stdarg.h> to prevent <varargs.h> conflicts */
X_EXTERN int vprintf ARGS((const char *fmt, Void *va));
X_EXTERN int vfprintf ARGS((FILE *f, const char *fmt, Void *va));
X_EXTERN int vsprintf ARGS((char *s, const char *fmt, Void *va));
X_EXTERN int scanf ARGS((const char *fmt, ...));
X_EXTERN int fscanf ARGS((FILE *f, const char *fmt, ...));
X_EXTERN int sscanf ARGS((const char *s, const char *fmt, ...));
X
X_EXTERN size_t fread ARGS((void *ptr, size_t size, size_t n, FILE *f));
X_EXTERN size_t frwrite ARGS((const void *ptr, size_t size, size_t n, FILE *f));
X_EXTERN int fgetc ARGS((FILE *f));
X_EXTERN int fputc ARGS((int c, FILE *f));
X_EXTERN char *fgets ARGS((char *s, int len, FILE *f));
X_EXTERN int fputs ARGS((const char *s, FILE *f));
X_EXTERN char *gets ARGS((char *s));
X_EXTERN int puts ARGS((const char *s));
X
X#endif
X
END_OF_FILE
if test 2290 -ne `wc -c <'std/stdc/stdio.h_std'`; then
echo shar: \"'std/stdc/stdio.h_std'\" unpacked with wrong size!
fi
# end of 'std/stdc/stdio.h_std'
fi
echo shar: End of archive 7 \(of 9\).
cp /dev/null ark7isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 9 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still must unpack the following archives:
echo " " ${MISSING}
fi
exit 0
exit 0 # Just in case...
--
Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD UUCP: uunet!sparky!kent
Phone: (402) 291-8300 FAX: (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.