Index: trunk/minix/commands/ash/Makefile
===================================================================
--- trunk/minix/commands/ash/Makefile	(revision 9)
+++ 	(revision )
@@ -1,105 +1,0 @@
-# Makefile for ash.
-
-SRCS=	builtins.c cd.c dirent.c error.c eval.c exec.c expand.c input.c \
-	jobs.c mail.c main.c memalloc.c miscbltin.c mystring.c nodes.c \
-	options.c parser.c redir.c show.c signames.c syntax.c trap.c \
-	output.c var.c
-
-OBJS=	builtins.o cd.o dirent.o error.o eval.o exec.o expand.o input.o \
-	jobs.o mail.o main.o memalloc.o miscbltin.o mystring.o nodes.o \
-	options.o parser.o redir.o show.o signames.o syntax.o trap.o \
-	output.o var.o init.o \
-	bltin/echo.o bltin/expr.o bltin/operators.o bltin/regexp.o
-
-#
-# Set READLINE in shell.h and add -ledit to LIBS if you want to use the
-# editline package by Simmule Turner and Rich Salz.  (The big, bloated
-# and GPL contaminated FSF readline should work too.)
-#
-CPPFLAGS= -DSHELL -I. -D_MINIX -D_POSIX_SOURCE
-CFLAGS=	-wo -i $(CPPFLAGS)
-LIBS=	-ledit
-CC = exec cc
-
-CLEANFILES= $(OBJS) \
-	builtins.c builtins.h init.c mkinit mknodes mksignames mksyntax \
-	nodes.c nodes.h signames.c signames.h syntax.c syntax.h token.def \
-	bltin/operators.h bltin/operators.c
-
-all:	sh
-
-sh:	$(OBJS)
-	$(CC) $(CFLAGS) -o sh $(OBJS) $(LIBS)
-	install -S 100k sh
-
-install:	/usr/bin/ash /usr/bin/sh /bin/sh /bin/bigsh
-
-/usr/bin/ash:	sh
-	install -cs -o bin $? $@
-
-/usr/bin/sh:	/usr/bin/ash
-	install -l $? $@
-
-/bin/sh:	/usr/bin/ash
-	install -lcs $? $@
-
-/bin/bigsh:	/usr/bin/ash
-	install -S 1500000 -lcs $? $@
-
-clean:
-	rm -f $(CLEANFILES) sh core
-
-parser.o: token.def
-
-token.def: mktokens
-	sh mktokens
-
-builtins.c builtins.h: builtins.table shell.h
-	sh mkbuiltins shell.h builtins.table
-
-init.o: mkinit $(SRCS)
-	./mkinit '$(CC) -c $(CFLAGS) init.c' $(SRCS)
-
-mkinit: mkinit.c
-	$(CC) $(CFLAGS) mkinit.c -o $@
-
-nodes.c nodes.h: mknodes nodetypes nodes.c.pat
-	./mknodes nodetypes nodes.c.pat
-
-mknodes: mknodes.c
-	$(CC) $(CFLAGS) mknodes.c -o $@
-
-signames.c signames.h: mksignames
-	./mksignames
-
-mksignames: mksignames.c
-	$(CC) $(CFLAGS) mksignames.c -o $@
-
-syntax.c syntax.h: mksyntax
-	./mksyntax
-
-mksyntax: mksyntax.c parser.h
-	$(CC) $(CFLAGS) mksyntax.c -o $@
-
-bltin/operators.h:	bltin/mkexpr bltin/binary_op bltin/unary_op
-	cd bltin && sh mkexpr
-
-bltin/echo.o:	bltin/echo.c
-	cd bltin && $(CC) -I.. $(CFLAGS) -c echo.c
-
-bltin/expr.o:	bltin/expr.c
-	cd bltin && $(CC) -I.. $(CFLAGS) -c expr.c
-
-bltin/operators.o:	bltin/operators.c
-	cd bltin && $(CC) -I.. $(CFLAGS) -c operators.c
-
-bltin/regexp.o:	bltin/regexp.c
-	cd bltin && $(CC) -I.. $(CFLAGS) -c regexp.c
-
-# Dependencies you say?  This will have to do.
-$(OBJS): error.h eval.h exec.h expand.h init.h input.h \
-	jobs.h machdep.h mail.h main.h memalloc.h mystring.h options.h \
-	output.h parser.h redir.h shell.h trap.h var.h \
-	builtins.h nodes.h signames.h syntax.h
-
-bltin/expr.o bltin/operators.o:	bltin/operators.h
Index: trunk/minix/commands/ash/TOUR
===================================================================
--- trunk/minix/commands/ash/TOUR	(revision 9)
+++ 	(revision )
@@ -1,348 +1,0 @@
-#	@(#)TOUR	5.1 (Berkeley) 3/7/91
-
-                       A Tour through Ash
-
-               Copyright 1989 by Kenneth Almquist.
-
-
-DIRECTORIES:  The subdirectory bltin contains commands which can
-be compiled stand-alone.  The rest of the source is in the main
-ash directory.
-
-SOURCE CODE GENERATORS:  Files whose names begin with "mk" are
-programs that generate source code.  A complete list of these
-programs is:
-
-        program         intput files        generates
-        -------         ------------        ---------
-        mkbuiltins      builtins            builtins.h builtins.c
-        mkinit          *.c                 init.c
-        mknodes         nodetypes           nodes.h nodes.c
-        mksignames          -               signames.h signames.c
-        mksyntax            -               syntax.h syntax.c
-        mktokens            -               token.def
-        bltin/mkexpr    unary_op binary_op  operators.h operators.c
-
-There are undoubtedly too many of these.  Mkinit searches all the
-C source files for entries looking like:
-
-        INIT {
-              x = 1;    /* executed during initialization */
-        }
-
-        RESET {
-              x = 2;    /* executed when the shell does a longjmp
-                           back to the main command loop */
-        }
-
-        SHELLPROC {
-              x = 3;    /* executed when the shell runs a shell procedure */
-        }
-
-It pulls this code out into routines which are when particular
-events occur.  The intent is to improve modularity by isolating
-the information about which modules need to be explicitly
-initialized/reset within the modules themselves.
-
-Mkinit recognizes several constructs for placing declarations in
-the init.c file.
-        INCLUDE "file.h"
-includes a file.  The storage class MKINIT makes a declaration
-available in the init.c file, for example:
-        MKINIT int funcnest;    /* depth of function calls */
-MKINIT alone on a line introduces a structure or union declara-
-tion:
-        MKINIT
-        struct redirtab {
-              short renamed[10];
-        };
-Preprocessor #define statements are copied to init.c without any
-special action to request this.
-
-INDENTATION:  The ash source is indented in multiples of six
-spaces.  The only study that I have heard of on the subject con-
-cluded that the optimal amount to indent is in the range of four
-to six spaces.  I use six spaces since it is not too big a jump
-from the widely used eight spaces.  If you really hate six space
-indentation, use the adjind (source included) program to change
-it to something else.
-
-EXCEPTIONS:  Code for dealing with exceptions appears in
-exceptions.c.  The C language doesn't include exception handling,
-so I implement it using setjmp and longjmp.  The global variable
-exception contains the type of exception.  EXERROR is raised by
-calling error.  EXINT is an interrupt.  EXSHELLPROC is an excep-
-tion which is raised when a shell procedure is invoked.  The pur-
-pose of EXSHELLPROC is to perform the cleanup actions associated
-with other exceptions.  After these cleanup actions, the shell
-can interpret a shell procedure itself without exec'ing a new
-copy of the shell.
-
-INTERRUPTS:  In an interactive shell, an interrupt will cause an
-EXINT exception to return to the main command loop.  (Exception:
-EXINT is not raised if the user traps interrupts using the trap
-command.)  The INTOFF and INTON macros (defined in exception.h)
-provide uninterruptable critical sections.  Between the execution
-of INTOFF and the execution of INTON, interrupt signals will be
-held for later delivery.  INTOFF and INTON can be nested.
-
-MEMALLOC.C:  Memalloc.c defines versions of malloc and realloc
-which call error when there is no memory left.  It also defines a
-stack oriented memory allocation scheme.  Allocating off a stack
-is probably more efficient than allocation using malloc, but the
-big advantage is that when an exception occurs all we have to do
-to free up the memory in use at the time of the exception is to
-restore the stack pointer.  The stack is implemented using a
-linked list of blocks.
-
-STPUTC:  If the stack were contiguous, it would be easy to store
-strings on the stack without knowing in advance how long the
-string was going to be:
-        p = stackptr;
-        *p++ = c;       /* repeated as many times as needed */
-        stackptr = p;
-The folloing three macros (defined in memalloc.h) perform these
-operations, but grow the stack if you run off the end:
-        STARTSTACKSTR(p);
-        STPUTC(c, p);   /* repeated as many times as needed */
-        grabstackstr(p);
-
-We now start a top-down look at the code:
-
-MAIN.C:  The main routine performs some initialization, executes
-the user's profile if necessary, and calls cmdloop.  Cmdloop is
-repeatedly parses and executes commands.
-
-OPTIONS.C:  This file contains the option processing code.  It is
-called from main to parse the shell arguments when the shell is
-invoked, and it also contains the set builtin.  The -i and -j op-
-tions (the latter turns on job control) require changes in signal
-handling.  The routines setjobctl (in jobs.c) and setinteractive
-(in trap.c) are called to handle changes to these options.
-
-PARSING:  The parser code is all in parser.c.  A recursive des-
-cent parser is used.  Syntax tables (generated by mksyntax) are
-used to classify characters during lexical analysis.  There are
-three tables:  one for normal use, one for use when inside single
-quotes, and one for use when inside double quotes.  The tables
-are machine dependent because they are indexed by character vari-
-ables and the range of a char varies from machine to machine.
-
-PARSE OUTPUT:  The output of the parser consists of a tree of
-nodes.  The various types of nodes are defined in the file node-
-types.
-
-Nodes of type NARG are used to represent both words and the con-
-tents of here documents.  An early version of ash kept the con-
-tents of here documents in temporary files, but keeping here do-
-cuments in memory typically results in significantly better per-
-formance.  It would have been nice to make it an option to use
-temporary files for here documents, for the benefit of small
-machines, but the code to keep track of when to delete the tem-
-porary files was complex and I never fixed all the bugs in it.
-(AT&T has been maintaining the Bourne shell for more than ten
-years, and to the best of my knowledge they still haven't gotten
-it to handle temporary files correctly in obscure cases.)
-
-The text field of a NARG structure points to the text of the
-word.  The text consists of ordinary characters and a number of
-special codes defined in parser.h.  The special codes are:
-
-        CTLVAR              Variable substitution
-        CTLENDVAR           End of variable substitution
-        CTLBACKQ            Command substitution
-        CTLBACKQ|CTLQUOTE   Command substitution inside double quotes
-        CTLESC              Escape next character
-
-A variable substitution contains the following elements:
-
-        CTLVAR type name '=' [ alternative-text CTLENDVAR ]
-
-The type field is a single character specifying the type of sub-
-stitution.  The possible types are:
-
-        VSNORMAL            $var
-        VSMINUS             ${var-text}
-        VSMINUS|VSNUL       ${var:-text}
-        VSPLUS              ${var+text}
-        VSPLUS|VSNUL        ${var:+text}
-        VSQUESTION          ${var?text}
-        VSQUESTION|VSNUL    ${var:?text}
-        VSASSIGN            ${var=text}
-        VSASSIGN|VSNUL      ${var=text}
-
-In addition, the type field will have the VSQUOTE flag set if the
-variable is enclosed in double quotes.  The name of the variable
-comes next, terminated by an equals sign.  If the type is not
-VSNORMAL, then the text field in the substitution follows, ter-
-minated by a CTLENDVAR byte.
-
-Commands in back quotes are parsed and stored in a linked list.
-The locations of these commands in the string are indicated by
-CTLBACKQ and CTLBACKQ+CTLQUOTE characters, depending upon whether
-the back quotes were enclosed in double quotes.
-
-The character CTLESC escapes the next character, so that in case
-any of the CTL characters mentioned above appear in the input,
-they can be passed through transparently.  CTLESC is also used to
-escape '*', '?', '[', and '!' characters which were quoted by the
-user and thus should not be used for file name generation.
-
-CTLESC characters have proved to be particularly tricky to get
-right.  In the case of here documents which are not subject to
-variable and command substitution, the parser doesn't insert any
-CTLESC characters to begin with (so the contents of the text
-field can be written without any processing).  Other here docu-
-ments, and words which are not subject to splitting and file name
-generation, have the CTLESC characters removed during the vari-
-able and command substitution phase.  Words which are subject
-splitting and file name generation have the CTLESC characters re-
-moved as part of the file name phase.
-
-EXECUTION:  Command execution is handled by the following files:
-        eval.c     The top level routines.
-        redir.c    Code to handle redirection of input and output.
-        jobs.c     Code to handle forking, waiting, and job control.
-        exec.c     Code to to path searches and the actual exec sys call.
-        expand.c   Code to evaluate arguments.
-        var.c      Maintains the variable symbol table.  Called from expand.c.
-
-EVAL.C:  Evaltree recursively executes a parse tree.  The exit
-status is returned in the global variable exitstatus.  The alter-
-native entry evalbackcmd is called to evaluate commands in back
-quotes.  It saves the result in memory if the command is a buil-
-tin; otherwise it forks off a child to execute the command and
-connects the standard output of the child to a pipe.
-
-JOBS.C:  To create a process, you call makejob to return a job
-structure, and then call forkshell (passing the job structure as
-an argument) to create the process.  Waitforjob waits for a job
-to complete.  These routines take care of process groups if job
-control is defined.
-
-REDIR.C:  Ash allows file descriptors to be redirected and then
-restored without forking off a child process.  This is accom-
-plished by duplicating the original file descriptors.  The redir-
-tab structure records where the file descriptors have be dupli-
-cated to.
-
-EXEC.C:  The routine find_command locates a command, and enters
-the command in the hash table if it is not already there.  The
-third argument specifies whether it is to print an error message
-if the command is not found.  (When a pipeline is set up,
-find_command is called for all the commands in the pipeline be-
-fore any forking is done, so to get the commands into the hash
-table of the parent process.  But to make command hashing as
-transparent as possible, we silently ignore errors at that point
-and only print error messages if the command cannot be found
-later.)
-
-The routine shellexec is the interface to the exec system call.
-
-EXPAND.C:  Arguments are processed in three passes.  The first
-(performed by the routine argstr) performs variable and command
-substitution.  The second (ifsbreakup) performs word splitting
-and the third (expandmeta) performs file name generation.  If the
-"/u" directory is simulated, then when "/u/username" is replaced
-by the user's home directory, the flag "didudir" is set.  This
-tells the cd command that it should print out the directory name,
-just as it would if the "/u" directory were implemented using
-symbolic links.
-
-VAR.C:  Variables are stored in a hash table.  Probably we should
-switch to extensible hashing.  The variable name is stored in the
-same string as the value (using the format "name=value") so that
-no string copying is needed to create the environment of a com-
-mand.  Variables which the shell references internally are preal-
-located so that the shell can reference the values of these vari-
-ables without doing a lookup.
-
-When a program is run, the code in eval.c sticks any environment
-variables which precede the command (as in "PATH=xxx command") in
-the variable table as the simplest way to strip duplicates, and
-then calls "environment" to get the value of the environment.
-There are two consequences of this.  First, if an assignment to
-PATH precedes the command, the value of PATH before the assign-
-ment must be remembered and passed to shellexec.  Second, if the
-program turns out to be a shell procedure, the strings from the
-environment variables which preceded the command must be pulled
-out of the table and replaced with strings obtained from malloc,
-since the former will automatically be freed when the stack (see
-the entry on memalloc.c) is emptied.
-
-BUILTIN COMMANDS:  The procedures for handling these are scat-
-tered throughout the code, depending on which location appears
-most appropriate.  They can be recognized because their names al-
-ways end in "cmd".  The mapping from names to procedures is
-specified in the file builtins, which is processed by the mkbuil-
-tins command.
-
-A builtin command is invoked with argc and argv set up like a
-normal program.  A builtin command is allowed to overwrite its
-arguments.  Builtin routines can call nextopt to do option pars-
-ing.  This is kind of like getopt, but you don't pass argc and
-argv to it.  Builtin routines can also call error.  This routine
-normally terminates the shell (or returns to the main command
-loop if the shell is interactive), but when called from a builtin
-command it causes the builtin command to terminate with an exit
-status of 2.
-
-The directory bltins contains commands which can be compiled in-
-dependently but can also be built into the shell for efficiency
-reasons.  The makefile in this directory compiles these programs
-in the normal fashion (so that they can be run regardless of
-whether the invoker is ash), but also creates a library named
-bltinlib.a which can be linked with ash.  The header file bltin.h
-takes care of most of the differences between the ash and the
-stand-alone environment.  The user should call the main routine
-"main", and #define main to be the name of the routine to use
-when the program is linked into ash.  This #define should appear
-before bltin.h is included; bltin.h will #undef main if the pro-
-gram is to be compiled stand-alone.
-
-CD.C:  This file defines the cd and pwd builtins.  The pwd com-
-mand runs /bin/pwd the first time it is invoked (unless the user
-has already done a cd to an absolute pathname), but then
-remembers the current directory and updates it when the cd com-
-mand is run, so subsequent pwd commands run very fast.  The main
-complication in the cd command is in the docd command, which
-resolves symbolic links into actual names and informs the user
-where the user ended up if he crossed a symbolic link.
-
-SIGNALS:  Trap.c implements the trap command.  The routine set-
-signal figures out what action should be taken when a signal is
-received and invokes the signal system call to set the signal ac-
-tion appropriately.  When a signal that a user has set a trap for
-is caught, the routine "onsig" sets a flag.  The routine dotrap
-is called at appropriate points to actually handle the signal.
-When an interrupt is caught and no trap has been set for that
-signal, the routine "onint" in error.c is called.
-
-OUTPUT:  Ash uses it's own output routines.  There are three out-
-put structures allocated.  "Output" represents the standard out-
-put, "errout" the standard error, and "memout" contains output
-which is to be stored in memory.  This last is used when a buil-
-tin command appears in backquotes, to allow its output to be col-
-lected without doing any I/O through the UNIX operating system.
-The variables out1 and out2 normally point to output and errout,
-respectively, but they are set to point to memout when appropri-
-ate inside backquotes.
-
-INPUT:  The basic input routine is pgetc, which reads from the
-current input file.  There is a stack of input files; the current
-input file is the top file on this stack.  The code allows the
-input to come from a string rather than a file.  (This is for the
--c option and the "." and eval builtin commands.)  The global
-variable plinno is saved and restored when files are pushed and
-popped from the stack.  The parser routines store the number of
-the current line in this variable.
-
-DEBUGGING:  If DEBUG is defined in shell.h, then the shell will
-write debugging information to the file $HOME/trace.  Most of
-this is done using the TRACE macro, which takes a set of printf
-arguments inside two sets of parenthesis.  Example:
-"TRACE(("n=%d0, n))".  The double parenthesis are necessary be-
-cause the preprocessor can't handle functions with a variable
-number of arguments.  Defining DEBUG also causes the shell to
-generate a core dump if it is sent a quit signal.  The tracing
-code is in show.c.
Index: trunk/minix/commands/ash/bltin/LICENSE
===================================================================
--- trunk/minix/commands/ash/bltin/LICENSE	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-		    ASH GENERAL PUBLIC LICENSE
-
-  1. You may copy and distribute ash code or code derived from it in
-source or object form, provided that you conspicuously and appropriately
-publish on each copy a valid copyright notice "Copyright 1989 by Kenneth
-Almquist." (or with whatever year is appropriate); keep intact the
-notices on all files that refer to this License Agreement and to the
-absence of any warranty; and give any other recipients of the ash program
-a copy of this License Agreement along with the program.
-
-  2. You may not copy, sublicense, distribute or transfer ash except as
-expressly provided under this License Agreement.  Any attempt otherwise
-to copy, sublicense, distribute or transfer ash is void and your rights
-to use ash under this License agreement shall be automatically terminated.
-However, parties who have received computer software programs from you
-with this License Agreement will not have their licenses terminated so
-long as such parties remain in full compliance.
-
-
-			   NO WARRANTY
-
-  Because ash is licensed free of charge, I provide absolutely no
-warranty, to the extent permitted by applicable state law.  Except
-when otherwise stated in writing, Kenneth Almquist and/or other
-parties provide ash "as is" without warranty of any kind, either
-expressed or implied, including, but not limited to, the implied
-warranties of merchantability and fitness for a particular purpose.
-The entire risk as to the quality and performance of the program is
-with you.  Should the ash program prove defective, you assume the cost
-of all necessary servicing, repair or correction.
-
- In no event unless required by applicable law will Kenneth Almquist
-and/or any other party who may modify and redistribute ash as permitted
-above, be liable to you for damages, including any lost profits, lost
-monies, or other special, incidental or consequential damages arising
-out of the use or inability to use (including but not limited to loss
-of data or data being rendered inaccurate or losses sustained by third
-parties or a failure of the program to operate with programs provided
-by other parties) the program, even if you have been advised of the
-possibility of such damages, or for any claim by any other party.
Index: trunk/minix/commands/ash/bltin/binary_op
===================================================================
--- trunk/minix/commands/ash/bltin/binary_op	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-# List of binary operators used by test/expr.
-#
-# Copyright 1989 by Kenneth Almquist.  All rights reserved.
-# This file is part of ash, which is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-OR1	 -o	1
-OR2	 |	1
-AND1	 -a	2
-AND2	 &	2
-STREQ	 =	4    OP_STRING
-STRNE	 !=	4    OP_STRING
-NEWER	 -newer	4    OP_STRING
-EQ	 -eq	4    OP_INT
-NE	 -ne	4    OP_INT
-GT	 -gt	4    OP_INT
-LT	 -lt	4    OP_INT
-LE	 -le	4    OP_INT
-GE	 -ge	4    OP_INT
-PLUS	 +	5    OP_INT
-MINUS	 -	5    OP_INT
-TIMES	 *	6    OP_INT
-DIVIDE	 /	6    OP_INT
-REM	 %	6    OP_INT
-MATCHPAT :	7    OP_STRING
Index: trunk/minix/commands/ash/bltin/bltin.h
===================================================================
--- trunk/minix/commands/ash/bltin/bltin.h	(revision 9)
+++ 	(revision )
@@ -1,40 +1,0 @@
-/*
- * This file is included by programs which are optionally built into the
- * shell.  If SHELL is defined, we try to map the standard UNIX library
- * routines to ash routines using defines.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include "../shell.h"
-#include "../mystring.h"
-#ifdef SHELL
-#include "../output.h"
-#define stdout out1
-#define stderr out2
-#define printf out1fmt
-#define putc(c, file)	outc(c, file)
-#define putchar(c)	out1c(c)
-#define fprintf outfmt
-#define fputs outstr
-#define fflush flushout
-#define INITARGS(argv)
-#else
-#undef NULL
-#include <stdio.h>
-#undef main
-#define INITARGS(argv)	if ((commandname = argv[0]) == NULL) {fputs("Argc is zero\n", stderr); exit(2);} else
-#endif
-
-#ifdef __STDC__
-pointer stalloc(int);
-void error(char *, ...);
-#else
-pointer stalloc();
-void error();
-#endif
-
-
-extern char *commandname;
Index: trunk/minix/commands/ash/bltin/catf.c
===================================================================
--- trunk/minix/commands/ash/bltin/catf.c	(revision 9)
+++ 	(revision )
@@ -1,88 +1,0 @@
-/*
- * Copy the files given as arguments to the standard output.  The file
- * name "-" refers to the standard input.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#define main catfcmd
-
-#include "bltin.h"
-#include "../error.h"
-#include <sys/param.h>
-#include <fcntl.h>
-
-
-#ifdef SBUFSIZE
-#define BUFSIZE() SBUFSIZE
-#else
-#ifdef MAXBSIZE
-#define BUFSIZE() MAXBSIZE
-#else
-#define BUFSIZE() BSIZE
-#endif
-#endif
-
-
-main(argc, argv)  char **argv; {
-      char *filename;
-      char *buf = stalloc(BUFSIZE());
-      int fd;
-      int i;
-#ifdef SHELL
-      volatile int input;
-      struct jmploc jmploc;
-      struct jmploc *volatile savehandler;
-#endif
-
-      INITARGS(argv);
-#ifdef SHELL
-      input = -1;
-      if (setjmp(jmploc.loc)) {
-	    close(input);
-	    handler = savehandler;
-	    longjmp(handler, 1);
-      }
-      savehandler = handler;
-      handler = &jmploc;
-#endif
-      while ((filename = *++argv) != NULL) {
-	    if (filename[0] == '-' && filename[1] == '\0') {
-		  fd = 0;
-	    } else {
-#ifdef SHELL
-		  INTOFF;
-		  if ((fd = open(filename, O_RDONLY)) < 0)
-			error("Can't open %s", filename);
-		  input = fd;
-		  INTON;
-#else
-		  if ((fd = open(filename, O_RDONLY)) < 0) {
-			fprintf(stderr, "catf: Can't open %s\n", filename);
-			exit(2);
-		  }
-#endif
-	    }
-	    while ((i = read(fd, buf, BUFSIZE())) > 0) {
-#ifdef SHELL
-		  if (out1 == &memout) {
-			register char *p;
-			for (p = buf ; --i >= 0 ; p++) {
-			      outc(*p, &memout);
-			}
-		  } else {
-			write(1, buf, i);
-		  }
-#else
-		  write(1, buf, i);
-#endif
-	    }
-	    if (fd != 0)
-		  close(fd);
-      }
-#ifdef SHELL
-      handler = savehandler;
-#endif
-}
Index: trunk/minix/commands/ash/bltin/echo.c
===================================================================
--- trunk/minix/commands/ash/bltin/echo.c	(revision 9)
+++ 	(revision )
@@ -1,74 +1,0 @@
-/*
- * Echo command.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#define main echocmd
-
-#include "bltin.h"
-
-#undef eflag
-
-
-main(argc, argv)  char **argv; {
-      register char **ap;
-      register char *p;
-      register char c;
-      int count;
-      int nflag = 0;
-#ifndef eflag
-      int eflag = 0;
-#endif
-
-      ap = argv;
-      if (argc)
-	    ap++;
-      if ((p = *ap) != NULL) {
-	    if (equal(p, "--")) {
-		  ap++;
-	    }
-	    if (equal(p, "-n")) {
-		  nflag++;
-		  ap++;
-	    } else if (equal(p, "-e")) {
-#ifndef eflag
-		  eflag++;
-#endif
-		  ap++;
-	    }
-      }
-      while ((p = *ap++) != NULL) {
-	    while ((c = *p++) != '\0') {
-		  if (c == '\\' && eflag) {
-			switch (*p++) {
-			case 'b':  c = '\b';  break;
-			case 'c':  return 0;		/* exit */
-			case 'f':  c = '\f';  break;
-			case 'n':  c = '\n';  break;
-			case 'r':  c = '\r';  break;
-			case 't':  c = '\t';  break;
-			case 'v':  c = '\v';  break;
-			case '\\':  break;		/* c = '\\' */
-			case '0':
-			      c = 0;
-			      count = 3;
-			      while (--count >= 0 && (unsigned)(*p - '0') < 8)
-				    c = (c << 3) + (*p++ - '0');
-			      break;
-			default:
-			      p--;
-			      break;
-			}
-		  }
-		  putchar(c);
-	    }
-	    if (*ap)
-		  putchar(' ');
-      }
-      if (! nflag)
-	    putchar('\n');
-      return 0;
-}
Index: trunk/minix/commands/ash/bltin/error.c
===================================================================
--- trunk/minix/commands/ash/bltin/error.c	(revision 9)
+++ 	(revision )
@@ -1,23 +1,0 @@
-/*
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include <stdio.h>
-
-char *commandname;
-
-
-void
-#ifdef __STDC__
-error(char *msg, ...) {
-#else
-error(msg)
-      char *msg;
-      {
-#endif
-
-      fprintf(stderr, "%s: %s\n", commandname, msg);
-      exit(2);
-}
Index: trunk/minix/commands/ash/bltin/expr.c
===================================================================
--- trunk/minix/commands/ash/bltin/expr.c	(revision 9)
+++ 	(revision )
@@ -1,481 +1,0 @@
-/*
- * The expr and test commands.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-
-#define main exprcmd
-
-#include "bltin.h"
-#include "operators.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#ifndef S_ISLNK
-#define lstat		stat
-#define S_ISLNK(mode)	(0)
-#endif
-
-#define STACKSIZE 12
-#define NESTINCR 16
-
-/* data types */
-#define STRING 0
-#define INTEGER 1
-#define BOOLEAN 2
-
-
-/*
- * This structure hold a value.  The type keyword specifies the type of
- * the value, and the union u holds the value.  The value of a boolean
- * is stored in u.num (1 = TRUE, 0 = FALSE).
- */
-
-struct value {
-      int type;
-      union {
-	    char *string;
-	    long num;
-      } u;
-};
-
-
-struct operator {
-      short op;			/* which operator */
-      short pri;		/* priority of operator */
-};
-
-
-struct filestat {
-      int op;			/* OP_FILE or OP_LFILE */
-      char *name;		/* name of file */
-      int rcode;		/* return code from stat */
-      struct stat stat;		/* status info on file */
-};
-
-
-extern char *match_begin[10];	/* matched string */
-extern short match_length[10];	/* defined in regexp.c */
-extern short number_parens;	/* number of \( \) pairs */
-
-
-#ifdef __STDC__
-int expr_is_false(struct value *);
-void expr_operator(int, struct value *, struct filestat *);
-int lookup_op(char *, char *const*);
-char *re_compile(char *);	/* defined in regexp.c */
-int re_match(char *, char *);	/* defined in regexp.c */
-long atol(const char *);
-#else
-int expr_is_false();
-void expr_operator();
-int lookup_op();
-char *re_compile();	/* defined in regexp.c */
-int re_match();	/* defined in regexp.c */
-long atol();
-#endif
-
-
-
-main(argc, argv)  char **argv; {
-      char **ap;
-      char *opname;
-      char c;
-      char *p;
-      int print;
-      int nest;		/* parenthises nesting */
-      int op;
-      int pri;
-      int skipping;
-      int binary;
-      struct operator opstack[STACKSIZE];
-      struct operator *opsp;
-      struct value valstack[STACKSIZE + 1];
-      struct value *valsp;
-      struct filestat fs;
-
-      INITARGS(argv);
-      c = **argv;
-      print = 1;
-      if (c == 't')
-	    print = 0;
-      else if (c == '[') {
-	    if (! equal(argv[argc - 1], "]"))
-		  error("missing ]");
-	    argv[argc - 1] = NULL;
-	    print = 0;
-      }
-      ap = argv + 1;
-      fs.name = NULL;
-
-      /*
-       * We use operator precedence parsing, evaluating the expression
-       * as we parse it.  Parentheses are handled by bumping up the
-       * priority of operators using the variable "nest."  We use the
-       * variable "skipping" to turn off evaluation temporarily for the
-       * short circuit boolean operators.  (It is important do the short
-       * circuit evaluation because under NFS a stat operation can take
-       * infinitely long.)
-       */
-
-      nest = 0;
-      skipping = 0;
-      opsp = opstack + STACKSIZE;
-      valsp = valstack;
-      if (*ap == NULL) {
-	    valstack[0].type = BOOLEAN;
-	    valstack[0].u.num = 0;
-	    goto done;
-      }
-      for (;;) {
-	    opname = *ap++;
-	    if (opname == NULL)
-syntax:		  error("syntax error");
-	    if (opname[0] == '(' && opname[1] == '\0') {
-		  nest += NESTINCR;
-		  continue;
-	    } else if (*ap && (op = lookup_op(opname, unary_op)) >= 0) {
-		  if (opsp == &opstack[0])
-overflow:		error("Expression too complex");
-		  --opsp;
-		  opsp->op = op;
-		  opsp->pri = op_priority[op] + nest;
-		  continue;
-
-	    } else {
-		  valsp->type = STRING;
-		  valsp->u.string = opname;
-		  valsp++;
-	    }
-	    for (;;) {
-		  opname = *ap++;
-		  if (opname == NULL) {
-			if (nest != 0)
-			      goto syntax;
-			pri = 0;
-			break;
-		  }
-		  if (opname[0] != ')' || opname[1] != '\0') {
-			if ((op = lookup_op(opname, binary_op)) < 0)
-			      goto syntax;
-			op += FIRST_BINARY_OP;
-			pri = op_priority[op] + nest;
-			break;
-		  }
-		  if ((nest -= NESTINCR) < 0)
-			goto syntax;
-	    }
-	    while (opsp < &opstack[STACKSIZE] && opsp->pri >= pri) {
-		  binary = opsp->op;
-		  for (;;) {
-			valsp--;
-			c = op_argflag[opsp->op];
-			if (c == OP_INT) {
-			      if (valsp->type == STRING)
-				    valsp->u.num = atol(valsp->u.string);
-			      valsp->type = INTEGER;
-			} else if (c >= OP_STRING) { /* OP_STRING or OP_FILE */
-			      if (valsp->type == INTEGER) {
-				    p = stalloc(32);
-#ifdef SHELL
-				    fmtstr(p, 32, "%d", valsp->u.num);
-#else
-				    sprintf(p, "%d", valsp->u.num);
-#endif
-				    valsp->u.string = p;
-			      } else if (valsp->type == BOOLEAN) {
-				    if (valsp->u.num)
-					  valsp->u.string = "true";
-				    else
-					  valsp->u.string = "";
-			      }
-			      valsp->type = STRING;
-			      if (c >= OP_FILE
-			       && (fs.op != c
-			           || fs.name == NULL
-			           || ! equal(fs.name, valsp->u.string))) {
-				    fs.op = c;
-				    fs.name = valsp->u.string;
-				    if (c == OP_FILE) {
-					fs.rcode = stat(valsp->u.string,
-								&fs.stat);
-				    } else {
-					fs.rcode = lstat(valsp->u.string,
-								&fs.stat);
-				    }
-			      }
-			}
-			if (binary < FIRST_BINARY_OP)
-			      break;
-			binary = 0;
-		  }
-		  if (! skipping)
-			expr_operator(opsp->op, valsp, &fs);
-		  else if (opsp->op == AND1 || opsp->op == OR1)
-			skipping--;
-		  valsp++;		/* push value */
-		  opsp++;		/* pop operator */
-	    }
-	    if (opname == NULL)
-		  break;
-	    if (opsp == &opstack[0])
-		  goto overflow;
-	    if (op == AND1 || op == AND2) {
-		  op = AND1;
-		  if (skipping || expr_is_false(valsp - 1))
-			skipping++;
-	    }
-	    if (op == OR1 || op == OR2) {
-		  op = OR1;
-		  if (skipping || ! expr_is_false(valsp - 1))
-			skipping++;
-	    }
-	    opsp--;
-	    opsp->op = op;
-	    opsp->pri = pri;
-      }
-done:
-      if (print) {
-	    if (valstack[0].type == STRING)
-		  printf("%s\n", valstack[0].u.string);
-	    else if (valstack[0].type == INTEGER)
-		  printf("%ld\n", valstack[0].u.num);
-	    else if (valstack[0].u.num != 0)
-		  printf("true\n");
-      }
-      return expr_is_false(&valstack[0]);
-}
-
-
-int
-expr_is_false(val)
-      struct value *val;
-      {
-      if (val->type == STRING) {
-	    if (val->u.string[0] == '\0')
-		  return 1;
-      } else {	/* INTEGER or BOOLEAN */
-	    if (val->u.num == 0)
-		  return 1;
-      }
-      return 0;
-}
-
-
-/*
- * Execute an operator.  Op is the operator.  Sp is the stack pointer;
- * sp[0] refers to the first operand, sp[1] refers to the second operand
- * (if any), and the result is placed in sp[0].  The operands are converted
- * to the type expected by the operator before expr_operator is called.
- * Fs is a pointer to a structure which holds the value of the last call
- * to stat, to avoid repeated stat calls on the same file.
- */
-
-void
-expr_operator(op, sp, fs)
-      int op;
-      struct value *sp;
-      struct filestat *fs;
-      {
-      int i;
-      struct stat st1, st2;
-
-      switch (op) {
-      case NOT:
-	    sp->u.num = expr_is_false(sp);
-	    sp->type = BOOLEAN;
-	    break;
-      case ISREAD:
-	    i = 04;
-	    goto permission;
-      case ISWRITE:
-	    i = 02;
-	    goto permission;
-      case ISEXEC:
-	    i = 01;
-permission:
-	    if (fs->stat.st_uid == geteuid())
-		  i <<= 6;
-	    else if (fs->stat.st_gid == getegid())
-		  i <<= 3;
-	    goto filebit;	/* true if (stat.st_mode & i) != 0 */
-      case ISFILE:
-	    i = S_IFREG;
-	    goto filetype;
-      case ISDIR:
-	    i = S_IFDIR;
-	    goto filetype;
-      case ISCHAR:
-	    i = S_IFCHR;
-	    goto filetype;
-      case ISBLOCK:
-	    i = S_IFBLK;
-	    goto filetype;
-      case ISFIFO:
-#ifdef S_IFIFO
-	    i = S_IFIFO;
-	    goto filetype;
-#else
-	    goto false;
-#endif
-filetype:
-	    if ((fs->stat.st_mode & S_IFMT) == i && fs->rcode >= 0) {
-true:
-		  sp->u.num = 1;
-	    } else {
-false:
-		  sp->u.num = 0;
-	    }
-	    sp->type = BOOLEAN;
-	    break;
-      case ISSETUID:
-	    i = S_ISUID;
-	    goto filebit;
-      case ISSETGID:
-	    i = S_ISGID;
-	    goto filebit;
-      case ISSTICKY:
-	    i = S_ISVTX;
-filebit:
-	    if (fs->stat.st_mode & i && fs->rcode >= 0)
-		  goto true;
-	    goto false;
-      case ISSIZE:
-	    sp->u.num = fs->rcode >= 0? fs->stat.st_size : 0L;
-	    sp->type = INTEGER;
-	    break;
-      case ISLINK1:
-      case ISLINK2:
-	    if (S_ISLNK(fs->stat.st_mode) && fs->rcode >= 0)
-		  goto true;
-	    fs->op = OP_FILE;	/* not a symlink, so expect a -d or so next */
-	    goto false;
-      case NEWER:
-	    if (stat(sp->u.string, &st1) != 0) {
-		  sp->u.num = 0;
-	    } else if (stat((sp + 1)->u.string, &st2) != 0) {
-		  sp->u.num = 1;
-	    } else {
-		  sp->u.num = st1.st_mtime >= st2.st_mtime;
-	    }
-	    sp->type = INTEGER;
-	    break;
-      case ISTTY:
-	    sp->u.num = isatty(sp->u.num);
-	    sp->type = BOOLEAN;
-	    break;
-      case NULSTR:
-	    if (sp->u.string[0] == '\0')
-		  goto true;
-	    goto false;
-      case STRLEN:
-	    sp->u.num = strlen(sp->u.string);
-	    sp->type = INTEGER;
-	    break;
-      case OR1:
-      case AND1:
-	    /*
-	     * These operators are mostly handled by the parser.  If we
-	     * get here it means that both operands were evaluated, so
-	     * the value is the value of the second operand.
-	     */
-	    *sp = *(sp + 1);
-	    break;
-      case STREQ:
-      case STRNE:
-	    i = 0;
-	    if (equal(sp->u.string, (sp + 1)->u.string))
-		  i++;
-	    if (op == STRNE)
-		  i = 1 - i;
-	    sp->u.num = i;
-	    sp->type = BOOLEAN;
-	    break;
-      case EQ:
-	    if (sp->u.num == (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case NE:
-	    if (sp->u.num != (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case GT:
-	    if (sp->u.num > (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case LT:
-	    if (sp->u.num < (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case LE:
-	    if (sp->u.num <= (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case GE:
-	    if (sp->u.num >= (sp + 1)->u.num)
-		  goto true;
-	    goto false;
-      case PLUS:
-	    sp->u.num += (sp + 1)->u.num;
-	    break;
-      case MINUS:
-	    sp->u.num -= (sp + 1)->u.num;
-	    break;
-      case TIMES:
-	    sp->u.num *= (sp + 1)->u.num;
-	    break;
-      case DIVIDE:
-	    if ((sp + 1)->u.num == 0)
-		  error("Division by zero");
-	    sp->u.num /= (sp + 1)->u.num;
-	    break;
-      case REM:
-	    if ((sp + 1)->u.num == 0)
-		  error("Division by zero");
-	    sp->u.num %= (sp + 1)->u.num;
-	    break;
-      case MATCHPAT:
-	    {
-		  char *pat;
-
-		  pat = re_compile((sp + 1)->u.string);
-		  if (re_match(pat, sp->u.string)) {
-			if (number_parens > 0) {
-			      sp->u.string = match_begin[1];
-			      sp->u.string[match_length[1]] = '\0';
-			} else {
-			      sp->u.num = match_length[0];
-			      sp->type = INTEGER;
-			}
-		  } else {
-			if (number_parens > 0) {
-			      sp->u.string[0] = '\0';
-			} else {
-			      sp->u.num = 0;
-			      sp->type = INTEGER;
-			}
-		  }
-	    }
-	    break;
-      }
-}
-
-
-int
-lookup_op(name, table)
-      char *name;
-      char *const*table;
-      {
-      register char *const*tp;
-      register char const *p;
-      char c = name[1];
-
-      for (tp = table ; (p = *tp) != NULL ; tp++) {
-	    if (p[1] == c && equal(p, name))
-		  return tp - table;
-      }
-      return -1;
-}
Index: trunk/minix/commands/ash/bltin/line.c
===================================================================
--- trunk/minix/commands/ash/bltin/line.c	(revision 9)
+++ 	(revision )
@@ -1,27 +1,0 @@
-/*
- * The line command.  Reads one line from the standard input and writes it
- * to the standard output.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#define main linecmd
-
-#include "bltin.h"
-
-
-main(argc, argv)  char **argv; {
-      char c;
-
-      for (;;) {
-	    if (read(0, &c, 1) != 1) {
-		  putchar('\n');
-		  return 1;
-	    }
-	    putchar(c);
-	    if (c == '\n')
-		  return 0;
-      }
-}
Index: trunk/minix/commands/ash/bltin/makefile.not
===================================================================
--- trunk/minix/commands/ash/bltin/makefile.not	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-# Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
-# This file is part of ash, which is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-LIBFILES=catfcmd.o echocmd.o exprcmd.o linecmd.o nlechocmd.o\
-	operators.o regexp.o
-DEBUG=-g
-CFLAGS=$(DEBUG)
-#CC=gcc
-
-all:$P bltinlib.a catf echo expr line nlecho true umask
-
-bltinlib.a:$P $(LIBFILES)
-	ar rc $@ $(LIBFILES)
-
-catf: catf.c bltin.h ../shell.h ../error.h error.o stalloc.o
-	$(CC) $(CFLAGS) -o $@ catf.c error.o stalloc.o
-
-catfcmd.o: catf.c bltin.h ../shell.h ../error.h
-	$(CC) -DSHELL $(CFLAGS) -c catf.c
-	mv catf.o $@
-
-expr: expr.c bltin.h ../shell.h operators.h operators.o regexp.o error.o stalloc.o
-	$(CC) $(CFLAGS) -o $@ expr.c operators.o regexp.o error.o stalloc.o
-	-rm -f test '['
-	ln expr test
-	ln expr '['
-
-exprcmd.o: expr.c bltin.h ../shell.h operators.h
-	$(CC) -DSHELL $(CFLAGS) -c expr.c
-	mv expr.o $@
-
-operators.c operators.h: unary_op binary_op mkexpr
-	./mkexpr
-
-operators.o: ../shell.h operators.h
-
-regexp.o: bltin.h ../shell.h
-
-echo: echo.c bltin.h ../shell.h
-	$(CC) $(CFLAGS) -o $@ echo.c
-
-echocmd.o: echo.c bltin.h ../shell.h
-	$(CC) -DSHELL $(CFLAGS) -c echo.c
-	mv echo.o $@
-
-line: line.c bltin.h ../shell.h
-	$(CC) $(CFLAGS) -o $@ line.c
-
-linecmd.o: line.c bltin.h ../shell.h
-	$(CC) -DSHELL $(CFLAGS) -c line.c
-	mv line.o $@
-
-nlecho: nlecho.c bltin.h ../shell.h
-	$(CC) $(CFLAGS) -o $@ nlecho.c
-
-nlechocmd.o: nlecho.c bltin.h ../shell.h
-	$(CC) -DSHELL $(CFLAGS) -c nlecho.c
-	mv nlecho.o $@
-
-umask: umask.c bltin.h
-	$(CC) $(CFLAGS) -o $@ umask.c
-
-true:
-	> :
-	chmod 755 :
-	rm -f true
-	ln : true
-
-stalloc.o: ../shell.h
-
Index: trunk/minix/commands/ash/bltin/mkexpr
===================================================================
--- trunk/minix/commands/ash/bltin/mkexpr	(revision 9)
+++ 	(revision )
@@ -1,66 +1,0 @@
-# Copyright 1989 by Kenneth Almquist.  All rights reserved.
-#
-# This file is part of ash.  Ash is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-# All calls to awk removed, because Minix bawk is deficient.  (kjb)
-
-exec > operators.h
-i=0
-sed -e '/^[^#]/!d' unary_op binary_op | while read line
-do
-	set -$- $line
-	echo "#define $1 $i"
-	i=`expr $i + 1`
-done
-echo
-echo "#define FIRST_BINARY_OP" `sed -e '/^[^#]/!d' unary_op | wc -l`
-echo '
-#define OP_INT 1		/* arguments to operator are integer */
-#define OP_STRING 2		/* arguments to operator are string */
-#define OP_FILE 3		/* argument is a file name */
-#define OP_LFILE 4		/* argument is a file name of a symlink? */
-
-extern char *const unary_op[];
-extern char *const binary_op[];
-extern const char op_priority[];
-extern const char op_argflag[];'
-
-exec > operators.c
-echo '/*
- * Operators used in the expr/test command.
- */
-
-#include "../shell.h"
-#include "operators.h"
-
-char *const unary_op[] = {'
-sed -e '/^[^#]/!d
-	s/[ 	][ 	]*/ /g
-	s/^[^ ][^ ]* \([^ ][^ ]*\).*/      "\1",/
-	' unary_op
-echo '      NULL
-};
-
-char *const binary_op[] = {'
-sed -e '/^[^#]/!d
-	s/[ 	][ 	]*/ /g
-	s/^[^ ][^ ]* \([^ ][^ ]*\).*/      "\1",/
-	' binary_op
-echo '      NULL
-};
-
-const char op_priority[] = {'
-sed -e '/^[^#]/!d
-	s/[ 	][ 	]*/ /g
-	s/^[^ ][^ ]* [^ ][^ ]* \([^ ][^ ]*\).*/      \1,/
-	' unary_op binary_op
-echo '};
-
-const char op_argflag[] = {'
-sed -e '/^[^#]/!d
-	s/[ 	][ 	]*/ /g
-	s/^[^ ][^ ]* [^ ][^ ]* [^ ][^ ]*$/& 0/
-	s/^[^ ][^ ]* [^ ][^ ]* [^ ][^ ]* \([^ ][^ ]*\)/      \1,/
-	' unary_op binary_op
-echo '};'
Index: trunk/minix/commands/ash/bltin/nlecho.c
===================================================================
--- trunk/minix/commands/ash/bltin/nlecho.c	(revision 9)
+++ 	(revision )
@@ -1,25 +1,0 @@
-/*
- * Echo the command argument to the standard output, one line at a time.
- * This command is useful for debugging th shell and whenever you what
- * to output strings literally.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-
-#define main nlechocmd
-
-#include "bltin.h"
-
-
-main(argc, argv)  char **argv; {
-      register char **ap;
-
-      for (ap = argv + 1 ; *ap ; ap++) {
-	    fputs(*ap, stdout);
-	    putchar('\n');
-      }
-      return 0;
-}
Index: trunk/minix/commands/ash/bltin/regexp.c
===================================================================
--- trunk/minix/commands/ash/bltin/regexp.c	(revision 9)
+++ 	(revision )
@@ -1,299 +1,0 @@
-/*
- * Regular expression matching for expr(1).  Bugs:  The upper bound of
- * a range specified by the \{ feature cannot be zero.
- *
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include "bltin.h"
-
-
-#define RE_END 0		/* end of regular expression */
-#define RE_LITERAL 1		/* normal character follows */
-#define RE_DOT 2		/* "." */
-#define RE_CCL 3		/* "[...]" */
-#define RE_NCCL 4		/* "[^...]" */
-#define RE_LP 5			/* "\(" */
-#define RE_RP 6			/* "\)" */
-#define RE_MATCHED 7		/* "\digit" */
-#define RE_EOS 8		/* "$" matches end of string */
-#define RE_STAR 9		/* "*" */
-#define RE_RANGE 10		/* "\{num,num\}" */
-
-
-
-char *match_begin[10];
-short match_length[10];
-short number_parens;
-static int match();
-
-
-
-char *
-re_compile(pattern)
-	char *pattern;
-	{
-	register char *p;
-	register char c;
-	char *comp;
-	register char *q;
-	char *begin;
-	char *endp;
-	register int len;
-	int first;
-	int type;
-	char *stackp;
-	char stack[10];
-	int paren_num;
-	int i;
-	char *malloc();
-
-	p = pattern;
-	if (*p == '^')
-		p++;
-	comp = q = malloc(2 * strlen(p) + 1);
-	begin = q;
-	stackp = stack;
-	paren_num = 0;
-	for (;;) {
-		switch (c = *p++) {
-		case '\0':
-			*q = '\0';
-			goto out;
-		case '.':
-			*q++ = RE_DOT;
-			len = 1;
-			break;
-		case '[':
-			begin = q;
-			*q = RE_CCL;
-			if (*p == '^') {
-				*q = RE_NCCL;
-				p++;
-			}
-			q++;
-			first = 1;
-			while (*p != ']' || first == 1) {
-				if (p[1] == '-' && p[2] != ']') {
-					*q++ = '-';
-					*q++ = p[0];
-					*q++ = p[2];
-					p += 3;
-				} else if (*p == '-') {
-					*q++ = '-';
-					*q++ = '-';
-					*q++ = '-';
-					p++;
-				} else {
-					*q++ = *p++;
-				}
-				first = 0;
-			}
-			p++;
-			*q++ = '\0';
-			len = q - begin;
-			break;
-		case '$':
-			if (*p != '\0')
-				goto dft;
-			*q++ = RE_EOS;
-			break;
-		case '*':
-			if (len == 0)
-				goto dft;
-			type = RE_STAR;
-range:
-			i = (type == RE_RANGE)? 3 : 1;
-			endp = q + i;
-			begin = q - len;
-			do {
-				--q;
-				*(q + i) = *q;
-			} while (--len > 0);
-			q = begin;
-			*q++ = type;
-			if (type == RE_RANGE) {
-				i = 0;
-				while ((unsigned)(*p - '0') <= 9)
-					i = 10 * i + (*p++ - '0');
-				*q++ = i;
-				if (*p != ',') {
-					*q++ = i;
-				} else {
-					p++;
-					i = 0;
-					while ((unsigned)(*p - '0') <= 9)
-						i = 10 * i + (*p++ - '0');
-					*q++ = i;
-				}
-				if (*p != '\\' || *++p != '}')
-					error("RE error");
-				p++;
-			}
-			q = endp;
-			break;
-		case '\\':
-			if ((c = *p++) == '(') {
-				if (++paren_num > 9)
-					error("RE error");
-				*q++ = RE_LP;
-				*q++ = paren_num;
-				*stackp++ = paren_num;
-				len = 0;
-			} else if (c == ')') {
-				if (stackp == stack)
-					error("RE error");
-				*q++ = RE_RP;
-				*q++ = *--stackp;
-				len = 0;
-			} else if (c == '{') {
-				type = RE_RANGE;
-				goto range;
-			} else if ((unsigned)(c - '1') < 9) {
-				/* should check validity here */
-				*q++ = RE_MATCHED;
-				*q++ = c - '0';
-				len = 2;
-			} else {
-				goto dft;
-			}
-			break;
-		default:
-dft:			*q++ = RE_LITERAL;
-			*q++ = c;
-			len = 2;
-			break;
-		}
-	}
-out:
-	if (stackp != stack)
-		error("RE error");
-	number_parens = paren_num;
-	return comp;
-}
-
-
-
-re_match(pattern, string)
-	char *pattern;
-	char *string;
-	{
-	char **pp;
-
-	match_begin[0] = string;
-	for (pp = &match_begin[1] ; pp <= &match_begin[9] ; pp++)
-		*pp = 0;
-	return match(pattern, string);
-}
-
-
-
-static
-match(pattern, string)
-	char *pattern;
-	char *string;
-	{
-	register char *p, *q;
-	int counting;
-	int low, high, count;
-	char *curpat;
-	char *start_count;
-	int negate;
-	int found;
-	char *r;
-	int len;
-	char c;
-
-	p = pattern;
-	q = string;
-	counting = 0;
-	for (;;) {
-		if (counting) {
-			if (++count > high)
-				goto bad;
-			p = curpat;
-		}
-		switch (*p++) {
-		case RE_END:
-			match_length[0] = q - match_begin[0];
-			return 1;
-		case RE_LITERAL:
-			if (*q++ != *p++)
-				goto bad;
-			break;
-		case RE_DOT:
-			if (*q++ == '\0')
-				goto bad;
-			break;
-		case RE_CCL:
-			negate = 0;
-			goto ccl;
-		case RE_NCCL:
-			negate = 1;
-ccl:
-			found = 0;
-			c = *q++;
-			while (*p) {
-				if (*p == '-') {
-					if (c >= *++p && c <= *++p)
-						found = 1;
-				} else {
-					if (c == *p)
-						found = 1;
-				}
-				p++;
-			}
-			p++;
-			if (found == negate || c == 0)
-				goto bad;
-			break;
-		case RE_LP:
-			match_begin[*p++] = q;
-			break;
-		case RE_RP:
-			match_length[*p] = q - match_begin[*p];
-			p++;
-			break;
-		case RE_MATCHED:
-			r = match_begin[*p];
-			len = match_length[*p++];
-			while (--len >= 0) {
-				if (*q++ != *r++)
-					goto bad;
-			}
-			break;
-		case RE_EOS:
-			if (*q != '\0')
-				goto bad;
-			break;
-		case RE_STAR:
-			low = 0;
-			high = 32767;
-			goto range;
-		case RE_RANGE:
-			low = *p++;
-			high = *p++;
-			if (high == 0)
-				high = 32767;
-range:
-			curpat = p;
-			start_count = q;
-			count = 0;
-			counting++;
-			break;
-		}
-	}
-bad:
-	if (! counting)
-		return 0;
-	len = 1;
-	if (*curpat == RE_MATCHED)
-		len = match_length[curpat[1]];
-	while (--count >= low) {
-		if (match(p, start_count + count * len))
-			return 1;
-	}
-	return 0;
-}
Index: trunk/minix/commands/ash/bltin/stalloc.c
===================================================================
--- trunk/minix/commands/ash/bltin/stalloc.c	(revision 9)
+++ 	(revision )
@@ -1,21 +1,0 @@
-/*
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include "../shell.h"
-
-
-void error();
-pointer malloc();
-
-
-pointer
-stalloc(nbytes) {
-      register pointer p;
-
-      if ((p = malloc(nbytes)) == NULL)
-	    error("Out of space");
-      return p;
-}
Index: trunk/minix/commands/ash/bltin/umask.c
===================================================================
--- trunk/minix/commands/ash/bltin/umask.c	(revision 9)
+++ 	(revision )
@@ -1,19 +1,0 @@
-/*
- * Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
- * This file is part of ash, which is distributed under the terms specified
- * by the Ash General Public License.  See the file named LICENSE.
- */
-
-#include <stdio.h>
-
-
-main(argc, argv)  char **argv; {
-      int mask;
-
-      if (argc > 1) {
-	    fprintf(stderr, "umask: only builtin version of umask can set value\n");
-	    exit(2);
-      }
-      printf("%.4o\n", umask(0));
-      return 0;
-}
Index: trunk/minix/commands/ash/bltin/unary_op
===================================================================
--- trunk/minix/commands/ash/bltin/unary_op	(revision 9)
+++ 	(revision )
@@ -1,24 +1,0 @@
-# List of unary operators used by test/expr.
-#
-# Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
-# This file is part of ash, which is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-NOT	 !	3
-ISREAD	 -r	12   OP_FILE
-ISWRITE  -w	12   OP_FILE
-ISEXEC	 -x	12   OP_FILE
-ISFILE	 -f	12   OP_FILE
-ISDIR	 -d	12   OP_FILE
-ISCHAR	 -c	12   OP_FILE
-ISBLOCK	 -b	12   OP_FILE
-ISFIFO	 -p	12   OP_FILE
-ISSETUID -u	12   OP_FILE
-ISSETGID -g	12   OP_FILE
-ISSTICKY -k	12   OP_FILE
-ISSIZE	 -s	12   OP_FILE
-ISLINK1  -h	12   OP_LFILE
-ISLINK2  -L	12   OP_LFILE
-ISTTY	 -t	12   OP_INT
-NULSTR	 -z	12   OP_STRING
-STRLEN	 -n	12   OP_STRING
Index: trunk/minix/commands/ash/build
===================================================================
--- trunk/minix/commands/ash/build	(revision 9)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#!/bin/sh
-make clean
-make && make install
Index: trunk/minix/commands/ash/builtins.table
===================================================================
--- trunk/minix/commands/ash/builtins.table	(revision 9)
+++ 	(revision )
@@ -1,83 +1,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)builtins	5.1 (Berkeley) 3/7/91
-
-#
-# This file lists all the builtin commands.  The first column is the name
-# of a C routine.  The -j flag, if present, specifies that this command
-# is to be excluded from systems without job control.  The rest of the line
-# specifies the command name or names used to run the command.  The entry
-# for nullcmd, which is run when the user does not specify a command, must
-# come first.
-#
-# Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
-# This file is part of ash, which is distributed under the terms specified
-# by the Ash General Public License.  See the file named LICENSE.
-
-bltincmd	command
-#alloccmd	alloc
-bgcmd -j	bg
-breakcmd	break continue
-#catfcmd	catf
-cdcmd		cd chdir
-dotcmd		.
-echocmd		echo
-evalcmd		eval
-execcmd		exec
-exitcmd		exit
-exportcmd	export readonly
-exprcmd		expr test [
-fgcmd -j	fg
-getoptscmd	getopts
-hashcmd		hash
-jobidcmd	jobid
-jobscmd		jobs
-#lccmd		lc
-#linecmd		line
-localcmd	local
-#nlechocmd	nlecho
-pwdcmd		pwd
-readcmd		read
-returncmd	return
-setcmd		set
-setvarcmd	setvar
-shiftcmd	shift
-trapcmd		trap
-truecmd		: true false
-umaskcmd	umask
-unsetcmd	unset
-waitcmd		wait
Index: trunk/minix/commands/ash/cd.c
===================================================================
--- trunk/minix/commands/ash/cd.c	(revision 9)
+++ 	(revision )
@@ -1,372 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)cd.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-/*
- * The cd and pwd commands.
- */
-
-#include "shell.h"
-#include "var.h"
-#include "nodes.h"	/* for jobs.h */
-#include "jobs.h"
-#include "options.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-
-
-#ifdef __STDC__
-STATIC int docd(char *, int, int);
-STATIC void updatepwd(char *);
-STATIC void getpwd(void);
-STATIC char *getcomponent(void);
-#else
-STATIC int docd();
-STATIC void updatepwd();
-STATIC void getpwd();
-STATIC char *getcomponent();
-#endif
-
-
-char *curdir;			/* current working directory */
-STATIC char *cdcomppath;
-
-#if UDIR || TILDE
-extern int didudir;		/* set if /u/logname or ~logname expanded */
-#endif
-
-
-int
-cdcmd(argc, argv)  char **argv; {
-	char *dest;
-	char *path;
-	char *p;
-	struct stat statb;
-	char *padvance();
-	int tohome= 0;
-
-	nextopt(nullstr);
-	if ((dest = *argptr) == NULL) {
-		if ((dest = bltinlookup("HOME", 1)) == NULL)
-			error("HOME not set");
-		tohome = 1;
-	}
-	if (*dest == '/' || (path = bltinlookup("CDPATH", 1)) == NULL)
-		path = nullstr;
-	while ((p = padvance(&path, dest)) != NULL) {
-		if (stat(p, &statb) >= 0
-		 && (statb.st_mode & S_IFMT) == S_IFDIR
-		 && docd(p, strcmp(p, dest), tohome) >= 0)
-			return 0;
-	}
-	error("can't cd to %s", dest);
-}
-
-
-/*
- * Actually do the chdir.  If the name refers to symbolic links, we
- * compute the actual directory name before doing the cd.  In an
- * interactive shell, print the directory name if "print" is nonzero
- * or if the name refers to a symbolic link.  We also print the name
- * if "/u/logname" was expanded in it, since this is similar to a
- * symbolic link.  (The check for this breaks if the user gives the
- * cd command some additional, unused arguments.)
- */
-
-#if SYMLINKS == 0
-STATIC int
-docd(dest, print, tohome)
-	char *dest;
-	{
-#if UDIR || TILDE
-	if (didudir)
-		print = 1;
-#endif
-	INTOFF;
-	if (chdir(dest) < 0) {
-		INTON;
-		return -1;
-	}
-	updatepwd(dest);
-	INTON;
-	if (print && iflag)
-		out1fmt("%s\n", stackblock());
-	return 0;
-}
-
-#else
-
-
-
-STATIC int
-docd(dest, print, tohome)
-	char *dest;
-	{
-	register char *p;
-	register char *q;
-	char *symlink;
-	char *component;
-	struct stat statb;
-	int first;
-	int i;
-
-	TRACE(("docd(\"%s\", %d, %d) called\n", dest, print, tohome));
-#if UDIR || TILDE
-	if (didudir)
-		print = 1;
-#endif
-
-top:
-	cdcomppath = dest;
-	STARTSTACKSTR(p);
-	if (*dest == '/') {
-		STPUTC('/', p);
-		cdcomppath++;
-	}
-	first = 1;
-	while ((q = getcomponent()) != NULL) {
-		if (q[0] == '\0' || q[0] == '.' && q[1] == '\0')
-			continue;
-		if (! first)
-			STPUTC('/', p);
-		first = 0;
-		component = q;
-		while (*q)
-			STPUTC(*q++, p);
-		if (equal(component, ".."))
-			continue;
-		STACKSTRNUL(p);
-		if (lstat(stackblock(), &statb) < 0)
-			error("lstat %s failed", stackblock());
-		if ((statb.st_mode & S_IFMT) != S_IFLNK)
-			continue;
-
-		/* Hit a symbolic link.  We have to start all over again. */
-		print = 1;
-		STPUTC('\0', p);
-		symlink = grabstackstr(p);
-		i = (int)statb.st_size + 2;		/* 2 for '/' and '\0' */
-		if (cdcomppath != NULL)
-			i += strlen(cdcomppath);
-		p = stalloc(i);
-		if (readlink(symlink, p, (int)statb.st_size) < 0) {
-			error("readlink %s failed", stackblock());
-		}
-		if (cdcomppath != NULL) {
-			p[(int)statb.st_size] = '/';
-			scopy(cdcomppath, p + (int)statb.st_size + 1);
-		} else {
-			p[(int)statb.st_size] = '\0';
-		}
-		if (p[0] != '/') {	/* relative path name */
-			char *r;
-			q = r = symlink;
-			while (*q) {
-				if (*q++ == '/')
-					r = q;
-			}
-			*r = '\0';
-			dest = stalloc(strlen(symlink) + strlen(p) + 1);
-			scopy(symlink, dest);
-			strcat(dest, p);
-		} else {
-			dest = p;
-		}
-		goto top;
-	}
-	STPUTC('\0', p);
-	p = grabstackstr(p);
-	INTOFF;
-	/* The empty string is not a legal argument to chdir on a POSIX 1003.1 
-	 * system. */
-	if (p[0] != '\0' && chdir(p) < 0) {
-		INTON;
-		return -1;
-	}
-	updatepwd(p);
-	INTON;
-	if (print && !tohome && iflag)
-		out1fmt("%s\n", p);
-	return 0;
-}
-#endif /* SYMLINKS */
-
-
-
-/*
- * Get the next component of the path name pointed to by cdcomppath.
- * This routine overwrites the string pointed to by cdcomppath.
- */
-
-STATIC char *
-getcomponent() {
-	register char *p;
-	char *start;
-
-	if ((p = cdcomppath) == NULL)
-		return NULL;
-	start = cdcomppath;
-	while (*p != '/' && *p != '\0')
-		p++;
-	if (*p == '\0') {
-		cdcomppath = NULL;
-	} else {
-		*p++ = '\0';
-		cdcomppath = p;
-	}
-	return start;
-}
-
-
-
-/*
- * Update curdir (the name of the current directory) in response to a
- * cd command.  We also call hashcd to let the routines in exec.c know
- * that the current directory has changed.
- */
-
-void hashcd();
-
-STATIC void
-updatepwd(dir)
-	char *dir;
-	{
-	char *new;
-	char *p;
-
-	hashcd();				/* update command hash table */
-	cdcomppath = stalloc(strlen(dir) + 1);
-	scopy(dir, cdcomppath);
-	STARTSTACKSTR(new);
-	if (*dir != '/') {
-		if (curdir == NULL)
-			return;
-		p = curdir;
-		while (*p)
-			STPUTC(*p++, new);
-		if (p[-1] == '/')
-			STUNPUTC(new);
-	}
-	while ((p = getcomponent()) != NULL) {
-		if (equal(p, "..")) {
-			while (new > stackblock() && (STUNPUTC(new), *new) != '/');
-		} else if (*p != '\0' && ! equal(p, ".")) {
-			STPUTC('/', new);
-			while (*p)
-				STPUTC(*p++, new);
-		}
-	}
-	if (new == stackblock())
-		STPUTC('/', new);
-	STACKSTRNUL(new);
-	if (curdir)
-		ckfree(curdir);
-	curdir = savestr(stackblock());
-}
-
-
-
-int
-pwdcmd(argc, argv)  char **argv; {
-	getpwd();
-	out1str(curdir);
-	out1c('\n');
-	return 0;
-}
-
-
-
-/*
- * Run /bin/pwd to find out what the current directory is.  We suppress
- * interrupts throughout most of this, but the user can still break out
- * of it by killing the pwd program.  If we already know the current
- * directory, this routine returns immediately.
- */
-
-#define MAXPWD 256
-
-STATIC void
-getpwd() {
-	char buf[MAXPWD];
-	char *p;
-	int i;
-	int status;
-	struct job *jp;
-	int pip[2];
-
-	if (curdir)
-		return;
-	INTOFF;
-	if (pipe(pip) < 0)
-		error("Pipe call failed");
-	jp = makejob((union node *)NULL, 1);
-	if (forkshell(jp, (union node *)NULL, FORK_NOJOB) == 0) {
-		close(pip[0]);
-		if (pip[1] != 1) {
-			close(1);
-			copyfd(pip[1], 1);
-			close(pip[1]);
-		}
-		execl("/bin/pwd", "pwd", (char *)0);
-		error("Cannot exec /bin/pwd");
-	}
-	close(pip[1]);
-	pip[1] = -1;
-	p = buf;
-	while ((i = read(pip[0], p, buf + MAXPWD - p)) > 0
-	     || i == -1 && errno == EINTR) {
-		if (i > 0)
-			p += i;
-	}
-	close(pip[0]);
-	pip[0] = -1;
-	status = waitforjob(jp);
-	if (status != 0)
-		error((char *)0);
-	if (i < 0 || p == buf || p[-1] != '\n')
-		error("pwd command failed");
-	p[-1] = '\0';
-	curdir = savestr(buf);
-	INTON;
-}
Index: trunk/minix/commands/ash/dirent.c
===================================================================
--- trunk/minix/commands/ash/dirent.c	(revision 9)
+++ 	(revision )
@@ -1,194 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)dirent.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-#include "shell.h"	/* definitions for pointer, NULL, DIRENT, and BSD */
-
-#if ! DIRENT
-
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-
-#ifndef S_ISDIR				/* macro to test for directory file */
-#define	S_ISDIR(mode)		(((mode) & S_IFMT) == S_IFDIR)
-#endif
-
-#ifdef BSD
-
-#ifdef __STDC__
-int stat(char *, struct stat *);
-#else
-int stat();
-#endif
-
-
-/*
- * The BSD opendir routine doesn't check that what is being opened is a
- * directory, so we have to include the check in a wrapper routine.
- */
-
-#undef opendir
-
-DIR *
-myopendir(dirname)
-	char *dirname;			/* name of directory */
-	{
-	struct stat statb;
-
-	if (stat(dirname, &statb) != 0 || ! S_ISDIR(statb.st_mode)) {
-		errno = ENOTDIR;
-		return NULL;		/* not a directory */
-	}
-	return opendir(dirname);
-}
-
-#else /* not BSD */
-
-/*
- * Dirent routines for old style file systems.
- */
-
-#ifdef __STDC__
-pointer malloc(unsigned);
-void free(pointer);
-int open(char *, int, ...);
-int close(int);
-int fstat(int, struct stat *);
-#else
-pointer malloc();
-void free();
-int open();
-int close();
-int fstat();
-#endif
-
-
-DIR *
-opendir(dirname)
-	char		*dirname;	/* name of directory */
-	{
-	register DIR	*dirp;		/* -> malloc'ed storage */
-	register int	fd;		/* file descriptor for read */
-	struct stat	statb;		/* result of fstat() */
-
-#ifdef O_NDELAY
-	fd = open(dirname, O_RDONLY|O_NDELAY);
-#else
-	fd = open(dirname, O_RDONLY);
-#endif
-	if (fd < 0)
-		return NULL;		/* errno set by open() */
-
-	if (fstat(fd, &statb) != 0 || !S_ISDIR(statb.st_mode)) {
-		(void)close(fd);
-		errno = ENOTDIR;
-		return NULL;		/* not a directory */
-	}
-
-	if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
-		(void)close(fd);
-		errno = ENOMEM;
-		return NULL;		/* not enough memory */
-	}
-
-	dirp->dd_fd = fd;
-	dirp->dd_nleft = 0;		/* refill needed */
-
-	return dirp;
-}
-
-
-
-int
-closedir(dirp)
-	register DIR *dirp;		/* stream from opendir() */
-	{
-	register int fd;
-
-	if (dirp == NULL) {
-		errno = EFAULT;
-		return -1;			/* invalid pointer */
-	}
-
-	fd = dirp->dd_fd;
-	free((pointer)dirp);
-	return close(fd);
-}
-
-
-
-struct dirent *
-readdir(dirp)
-	register DIR *dirp;		/* stream from opendir() */
-	{
-	register struct direct *dp;
-	register char *p, *q;
-	register int i;
-
-	do {
-		if ((dirp->dd_nleft -= sizeof (struct direct)) < 0) {
-			if ((i = read(dirp->dd_fd,
-					   (char *)dirp->dd_buf,
-					   DIRBUFENT*sizeof(struct direct))) <= 0) {
-				if (i == 0)
-					errno = 0;	/* unnecessary */
-				return NULL;		/* EOF or error */
-			}
-			dirp->dd_loc = dirp->dd_buf;
-			dirp->dd_nleft = i - sizeof (struct direct);
-		}
-		dp = dirp->dd_loc++;
-	} while (dp->d_ino == 0);
-	dirp->dd_entry.d_ino = dp->d_ino;
-
-	/* now copy the name, nul terminating it */
-	p = dp->d_name;
-	q = dirp->dd_entry.d_name;
-	i = DIRSIZ;
-	while (--i >= 0 && *p != '\0')
-		*q++ = *p++;
-	*q = '\0';
-	return &dirp->dd_entry;
-}
-
-#endif /* BSD */
-#endif /* DIRENT */
Index: trunk/minix/commands/ash/error.c
===================================================================
--- trunk/minix/commands/ash/error.c	(revision 9)
+++ 	(revision )
@@ -1,252 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)error.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * Errors and exceptions.
- */
-
-#include "shell.h"
-#include "main.h"
-#include "options.h"
-#include "output.h"
-#include "error.h"
-#include <sys/types.h>
-#include <signal.h>
-#ifdef __STDC__
-#include "stdarg.h"
-#else
-#include <varargs.h>	
-#endif
-#include <errno.h>
-
-
-/*
- * Code to handle exceptions in C.
- */
-
-struct jmploc *handler;
-int exception;
-volatile int suppressint;
-volatile int intpending;
-char *commandname;
-
-
-/*
- * Called to raise an exception.  Since C doesn't include exceptions, we
- * just do a longjmp to the exception handler.  The type of exception is
- * stored in the global variable "exception".
- */
-
-void
-exraise(e) {
-	if (handler == NULL)
-		abort();
-	exception = e;
-	longjmp(handler->loc, 1);
-}
-
-
-/*
- * Called from trap.c when a SIGINT is received.  (If the user specifies
- * that SIGINT is to be trapped or ignored using the trap builtin, then
- * this routine is not called.)  Suppressint is nonzero when interrupts
- * are held using the INTOFF macro.  The call to _exit is necessary because
- * there is a short period after a fork before the signal handlers are
- * set to the appropriate value for the child.  (The test for iflag is
- * just defensive programming.)
- */
-
-void
-onint() {
-	if (suppressint) {
-		intpending++;
-		return;
-	}
-	intpending = 0;
-#ifdef BSD
-	sigsetmask(0);
-#endif
-	if (rootshell && iflag)
-		exraise(EXINT);
-	else
-		_exit(128 + SIGINT);
-}
-
-
-
-void
-error2(a, b)
-	char *a, *b;
-	{
-	error("%s: %s", a, b);
-}
-
-
-/*
- * Error is called to raise the error exception.  If the first argument
- * is not NULL then error prints an error message using printf style
- * formatting.  It then raises the error exception.
- */
-
-#ifdef __STDC__
-void
-error(char *msg, ...) {
-#else
-void
-error(va_alist)
-	va_dcl
-	{
-	char *msg;
-#endif
-	va_list ap;
-
-	CLEAR_PENDING_INT;
-	INTOFF;
-#ifdef __STDC__
-	va_start(ap, msg);
-#else
-	va_start(ap);
-	msg = va_arg(ap, char *);
-#endif
-#if DEBUG
-	if (msg)
-		TRACE(("error(\"%s\") pid=%d\n", msg, getpid()));
-	else
-		TRACE(("error(NULL) pid=%d\n", getpid()));
-#endif
-	if (msg) {
-		if (commandname)
-			outfmt(&errout, "%s: ", commandname);
-		doformat(&errout, msg, ap);
-		out2c('\n');
-	}
-	va_end(ap);
-	flushall();
-	exraise(EXERROR);
-}
-
-
-#ifdef notdef	/* These strange error messages only confuse. -- kjb */
-/*
- * Table of error messages.
- */
-
-struct errname {
-	short errcode;		/* error number */
-	short action;		/* operation which encountered the error */
-	char *msg;		/* text describing the error */
-};
-
-
-#define ALL (E_OPEN|E_CREAT|E_EXEC)
-
-STATIC const struct errname errormsg[] = {
-	EINTR, ALL,	"interrupted",
-	EACCES, ALL,	"permission denied",
-	EIO, ALL,		"I/O error",
-	ENOENT, E_OPEN,	"no such file",
-	ENOENT, E_CREAT,	"directory nonexistent",
-	ENOENT, E_EXEC,	"not found",
-	ENOTDIR, E_OPEN,	"no such file",
-	ENOTDIR, E_CREAT,	"directory nonexistent",
-	ENOTDIR, E_EXEC,	"not found",
-	ENOEXEC, ALL,	"not an executable",
-	EISDIR, ALL,	"is a directory",
-/*    EMFILE, ALL,	"too many open files", */
-	ENFILE, ALL,	"file table overflow",
-	ENOSPC, ALL,	"file system full",
-#ifdef EDQUOT
-	EDQUOT, ALL,	"disk quota exceeded",
-#endif
-#ifdef ENOSR
-	ENOSR, ALL,	"no streams resources",
-#endif
-	ENXIO, ALL,	"no such device or address",
-	EROFS, ALL,	"read-only file system",
-	ETXTBSY, ALL,	"text busy",
-#ifdef SYSV
-	EAGAIN, E_EXEC,	"not enough memory",
-#endif
-	ENOMEM, ALL,	"not enough memory",
-#ifdef ENOLINK
-	ENOLINK, ALL,	"remote access failed",
-#endif
-#ifdef EMULTIHOP
-	EMULTIHOP, ALL,	"remote access failed",
-#endif
-#ifdef ECOMM
-	ECOMM, ALL,	"remote access failed",
-#endif
-#ifdef ESTALE
-	ESTALE, ALL,	"remote access failed",
-#endif
-#ifdef ETIMEDOUT
-	ETIMEDOUT, ALL,	"remote access failed",
-#endif
-#ifdef ELOOP
-	ELOOP, ALL,	"symbolic link loop",
-#endif
-	E2BIG, E_EXEC,	"argument list too long",
-#ifdef ELIBACC
-	ELIBACC, E_EXEC,	"shared library missing",
-#endif
-	0, 0,		NULL
-};
-
-
-/*
- * Return a string describing an error.  The returned string may be a
- * pointer to a static buffer that will be overwritten on the next call.
- * Action describes the operation that got the error.
- */
-
-char *
-errmsg(e, action) {
-	const struct errname *ep;
-	static char buf[12];
-
-	for (ep = errormsg ; ep->errcode ; ep++) {
-		if (ep->errcode == e && (ep->action & action) != 0)
-			return ep->msg;
-	}
-	fmtstr(buf, sizeof buf, "error %d", e);
-	return buf;
-}
-#endif
Index: trunk/minix/commands/ash/error.h
===================================================================
--- trunk/minix/commands/ash/error.h	(revision 9)
+++ 	(revision )
@@ -1,116 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)error.h	5.1 (Berkeley) 3/7/91
- */
-
-/*
- * Types of operations (passed to the errmsg routine).
- */
-
-#define E_OPEN 01	/* opening a file */
-#define E_CREAT 02	/* creating a file */
-#define E_EXEC 04	/* executing a program */
-
-
-/*
- * We enclose jmp_buf in a structure so that we can declare pointers to
- * jump locations.  The global variable handler contains the location to
- * jump to when an exception occurs, and the global variable exception
- * contains a code identifying the exeception.  To implement nested
- * exception handlers, the user should save the value of handler on entry
- * to an inner scope, set handler to point to a jmploc structure for the
- * inner scope, and restore handler on exit from the scope.
- */
-
-#include <setjmp.h>
-
-struct jmploc {
-	jmp_buf loc;
-};
-
-extern struct jmploc *handler;
-extern int exception;
-
-/* exceptions */
-#define EXINT 0		/* SIGINT received */
-#define EXERROR 1	/* a generic error */
-#define EXSHELLPROC 2	/* execute a shell procedure */
-
-
-/*
- * These macros allow the user to suspend the handling of interrupt signals
- * over a period of time.  This is similar to SIGHOLD to or sigblock, but
- * much more efficient and portable.  (But hacking the kernel is so much
- * more fun than worrying about efficiency and portability. :-))
- */
-
-extern volatile int suppressint;
-extern volatile int intpending;
-extern char *commandname;	/* name of command--printed on error */
-
-#define INTOFF suppressint++
-#define INTON if (--suppressint == 0 && intpending) onint(); else
-#define FORCEINTON {suppressint = 0; if (intpending) onint();}
-#define CLEAR_PENDING_INT intpending = 0
-#define int_pending() intpending
-
-#ifdef __STDC__
-void exraise(int);
-void onint(void);
-void error2(char *, char *);
-void error(char *, ...);
-char *errmsg(int, int);
-#else
-void exraise();
-void onint();
-void error2();
-void error();
-char *errmsg();
-#endif
-
-/* Errmsg uses confusingly different messages.  Prefer strerror().  -- kjb */
-#define errmsg(errno, action)	strerror(errno)
-
-
-/*
- * BSD setjmp saves the signal mask, which violates ANSI C and takes time,
- * so we use _setjmp instead.
- */
-
-#ifdef BSD
-#define setjmp(jmploc)	_setjmp(jmploc)
-#define longjmp(jmploc, val)	_longjmp(jmploc, val)
-#endif
Index: trunk/minix/commands/ash/eval.c
===================================================================
--- trunk/minix/commands/ash/eval.c	(revision 9)
+++ 	(revision )
@@ -1,939 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)eval.c	5.3 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-/*
- * Evaluate a command.
- */
-
-#include "shell.h"
-#include "nodes.h"
-#include "syntax.h"
-#include "expand.h"
-#include "parser.h"
-#include "jobs.h"
-#include "eval.h"
-#include "builtins.h"
-#include "options.h"
-#include "exec.h"
-#include "redir.h"
-#include "input.h"
-#include "output.h"
-#include "trap.h"
-#include "var.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-#include <sys/types.h>
-#include <signal.h>
-
-
-/* flags in argument to evaltree */
-#define EV_EXIT 01		/* exit after evaluating tree */
-#define EV_TESTED 02		/* exit status is checked; ignore -e flag */
-#define EV_BACKCMD 04		/* command executing within back quotes */
-
-
-/* reasons for skipping commands (see comment on breakcmd routine) */
-#define SKIPBREAK 1
-#define SKIPCONT 2
-#define SKIPFUNC 3
-
-MKINIT int evalskip;		/* set if we are skipping commands */
-STATIC int skipcount;		/* number of levels to skip */
-MKINIT int loopnest;		/* current loop nesting level */
-int funcnest;			/* depth of function calls */
-
-
-char *commandname;
-struct strlist *cmdenviron;
-int exitstatus;			/* exit status of last command */
-int oexitstatus;		/* saved exit status */
-
-
-#ifdef __STDC__
-STATIC void evalloop(union node *);
-STATIC void evalfor(union node *);
-STATIC void evalcase(union node *, int);
-STATIC void evalsubshell(union node *, int);
-STATIC void expredir(union node *);
-STATIC void evalpipe(union node *);
-STATIC void evalcommand(union node *, int, struct backcmd *);
-STATIC void prehash(union node *);
-#else
-STATIC void evalloop();
-STATIC void evalfor();
-STATIC void evalcase();
-STATIC void evalsubshell();
-STATIC void expredir();
-STATIC void evalpipe();
-STATIC void evalcommand();
-STATIC void prehash();
-#endif
-
-
-
-/*
- * Called to reset things after an exception.
- */
-
-#ifdef mkinit
-INCLUDE "eval.h"
-
-RESET {
-	evalskip = 0;
-	loopnest = 0;
-	funcnest = 0;
-}
-
-SHELLPROC {
-	exitstatus = 0;
-}
-#endif
-
-
-
-/*
- * The eval commmand.
- */
-
-evalcmd(argc, argv)  
-	char **argv; 
-{
-        char *p;
-        char *concat;
-        char **ap;
-
-        if (argc > 1) {
-                p = argv[1];
-                if (argc > 2) {
-                        STARTSTACKSTR(concat);
-                        ap = argv + 2;
-                        for (;;) {
-                                while (*p)
-                                        STPUTC(*p++, concat);
-                                if ((p = *ap++) == NULL)
-                                        break;
-                                STPUTC(' ', concat);
-                        }
-                        STPUTC('\0', concat);
-                        p = grabstackstr(concat);
-                }
-                evalstring(p);
-        }
-        return exitstatus;
-}
-
-
-/*
- * Execute a command or commands contained in a string.
- */
-
-void
-evalstring(s)
-	char *s;
-	{
-	union node *n;
-	struct stackmark smark;
-
-	setstackmark(&smark);
-	setinputstring(s, 1);
-	while ((n = parsecmd(0)) != NEOF) {
-		evaltree(n, 0);
-		popstackmark(&smark);
-	}
-	popfile();
-	popstackmark(&smark);
-}
-
-
-
-/*
- * Evaluate a parse tree.  The value is left in the global variable
- * exitstatus.
- */
-
-void
-evaltree(n, flags)
-	union node *n;
-	{
-	if (n == NULL) {
-		TRACE(("evaltree(NULL) called\n"));
-		return;
-	}
-	TRACE(("evaltree(0x%x: %d) called\n", (int)n, n->type));
-	switch (n->type) {
-	case NSEMI:
-		evaltree(n->nbinary.ch1, 0);
-		if (evalskip)
-			goto out;
-		evaltree(n->nbinary.ch2, flags);
-		break;
-	case NAND:
-		evaltree(n->nbinary.ch1, EV_TESTED);
-		if (evalskip || exitstatus != 0)
-			goto out;
-		evaltree(n->nbinary.ch2, flags);
-		break;
-	case NOR:
-		evaltree(n->nbinary.ch1, EV_TESTED);
-		if (evalskip || exitstatus == 0)
-			goto out;
-		evaltree(n->nbinary.ch2, flags);
-		break;
-	case NREDIR:
-		expredir(n->nredir.redirect);
-		redirect(n->nredir.redirect, REDIR_PUSH);
-		evaltree(n->nredir.n, flags);
-		popredir();
-		break;
-	case NSUBSHELL:
-		evalsubshell(n, flags);
-		break;
-	case NBACKGND:
-		evalsubshell(n, flags);
-		break;
-	case NIF: {
-		int status = 0; 
-
-		evaltree(n->nif.test, EV_TESTED);
-		if (evalskip)
-			goto out;
-		if (exitstatus == 0) {
-			evaltree(n->nif.ifpart, flags);
-			status = exitstatus;
-		} else if (n->nif.elsepart) {
-			evaltree(n->nif.elsepart, flags);
-			status = exitstatus;
-		}
-		exitstatus = status;
-		break;
-	}
-	case NWHILE:
-	case NUNTIL:
-		evalloop(n);
-		break;
-	case NFOR:
-		evalfor(n);
-		break;
-	case NCASE:
-		evalcase(n, flags);
-		break;
-	case NDEFUN:
-		defun(n->narg.text, n->narg.next);
-		exitstatus = 0;
-		break;
-	case NPIPE:
-		evalpipe(n);
-		break;
-	case NCMD:
-		evalcommand(n, flags, (struct backcmd *)NULL);
-		break;
-	default:
-		out1fmt("Node type = %d\n", n->type);
-		flushout(&output);
-		break;
-	}
-out:
-	if (pendingsigs)
-		dotrap();
-	if ((flags & EV_EXIT) || (eflag && exitstatus
-	  && !(flags & EV_TESTED) && (n->type == NCMD ||
-	  n->type == NSUBSHELL))) {
-		exitshell(exitstatus);
-	}
-}
-
-
-STATIC void
-evalloop(n)
-	union node *n;
-	{
-	int status;
-
-	loopnest++;
-	status = 0;
-	for (;;) {
-		evaltree(n->nbinary.ch1, EV_TESTED);
-		if (evalskip) {
-skipping:	  if (evalskip == SKIPCONT && --skipcount <= 0) {
-				evalskip = 0;
-				continue;
-			}
-			if (evalskip == SKIPBREAK && --skipcount <= 0)
-				evalskip = 0;
-			break;
-		}
-		if (n->type == NWHILE) {
-			if (exitstatus != 0)
-				break;
-		} else {
-			if (exitstatus == 0)
-				break;
-		}
-		evaltree(n->nbinary.ch2, 0);
-		status = exitstatus;
-		if (evalskip)
-			goto skipping;
-	}
-	loopnest--;
-	exitstatus = status;
-}
-
-
-
-STATIC void
-evalfor(n)
-	union node *n;
-	{
-	struct arglist arglist;
-	union node *argp;
-	struct strlist *sp;
-	struct stackmark smark;
-
-	setstackmark(&smark);
-	arglist.lastp = &arglist.list;
-	for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
-		oexitstatus = exitstatus;
-		expandarg(argp, &arglist, 1);
-		if (evalskip)
-			goto out;
-	}
-	*arglist.lastp = NULL;
-
-	exitstatus = 0;
-	loopnest++;
-	for (sp = arglist.list ; sp ; sp = sp->next) {
-		setvar(n->nfor.var, sp->text, 0);
-		evaltree(n->nfor.body, 0);
-		if (evalskip) {
-			if (evalskip == SKIPCONT && --skipcount <= 0) {
-				evalskip = 0;
-				continue;
-			}
-			if (evalskip == SKIPBREAK && --skipcount <= 0)
-				evalskip = 0;
-			break;
-		}
-	}
-	loopnest--;
-out:
-	popstackmark(&smark);
-}
-
-
-
-STATIC void
-evalcase(n, flags)
-	union node *n;
-	{
-	union node *cp;
-	union node *patp;
-	struct arglist arglist;
-	struct stackmark smark;
-
-	setstackmark(&smark);
-	arglist.lastp = &arglist.list;
-        oexitstatus = exitstatus;
-	expandarg(n->ncase.expr, &arglist, 0);
-	for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
-		for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
-			if (casematch(patp, arglist.list->text)) {
-				if (evalskip == 0) {
-					evaltree(cp->nclist.body, flags);
-				}
-				goto out;
-			}
-		}
-	}
-out:
-	popstackmark(&smark);
-}
-
-
-
-/*
- * Kick off a subshell to evaluate a tree.
- */
-
-STATIC void
-evalsubshell(n, flags)
-	union node *n;
-	{
-	struct job *jp;
-	int backgnd = (n->type == NBACKGND);
-
-	expredir(n->nredir.redirect);
-	jp = makejob(n, 1);
-	if (forkshell(jp, n, backgnd) == 0) {
-		if (backgnd)
-			flags &=~ EV_TESTED;
-		redirect(n->nredir.redirect, 0);
-		evaltree(n->nredir.n, flags | EV_EXIT);	/* never returns */
-	}
-	if (! backgnd) {
-		INTOFF;
-		exitstatus = waitforjob(jp);
-		INTON;
-	}
-}
-
-
-
-/*
- * Compute the names of the files in a redirection list.
- */
-
-STATIC void
-expredir(n)
-	union node *n;
-	{
-	register union node *redir;
-
-	for (redir = n ; redir ; redir = redir->nfile.next) {
-		oexitstatus = exitstatus;
-		if (redir->type == NFROM
-		 || redir->type == NTO
-		 || redir->type == NAPPEND) {
-			struct arglist fn;
-			fn.lastp = &fn.list;
-			expandarg(redir->nfile.fname, &fn, 0);
-			redir->nfile.expfname = fn.list->text;
-		}
-	}
-}
-
-
-
-/*
- * Evaluate a pipeline.  All the processes in the pipeline are children
- * of the process creating the pipeline.  (This differs from some versions
- * of the shell, which make the last process in a pipeline the parent
- * of all the rest.)
- */
-
-STATIC void
-evalpipe(n)
-	union node *n;
-	{
-	struct job *jp;
-	struct nodelist *lp;
-	int pipelen;
-	int prevfd;
-	int pip[2];
-
-	TRACE(("evalpipe(0x%x) called\n", (int)n));
-	pipelen = 0;
-	for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
-		pipelen++;
-	INTOFF;
-	jp = makejob(n, pipelen);
-	prevfd = -1;
-	for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
-		prehash(lp->n);
-		pip[1] = -1;
-		if (lp->next) {
-			if (pipe(pip) < 0) {
-				close(prevfd);
-				error("Pipe call failed");
-			}
-		}
-		if (forkshell(jp, lp->n, n->npipe.backgnd) == 0) {
-			INTON;
-			if (prevfd > 0) {
-				close(0);
-				copyfd(prevfd, 0);
-				close(prevfd);
-			}
-			if (pip[1] >= 0) {
-				close(pip[0]);
-				if (pip[1] != 1) {
-					close(1);
-					copyfd(pip[1], 1);
-					close(pip[1]);
-				}
-			}
-			evaltree(lp->n, EV_EXIT);
-		}
-		if (prevfd >= 0)
-			close(prevfd);
-		prevfd = pip[0];
-		close(pip[1]);
-	}
-	INTON;
-	if (n->npipe.backgnd == 0) {
-		INTOFF;
-		exitstatus = waitforjob(jp);
-		TRACE(("evalpipe:  job done exit status %d\n", exitstatus));
-		INTON;
-	}
-}
-
-
-
-/*
- * Execute a command inside back quotes.  If it's a builtin command, we
- * want to save its output in a block obtained from malloc.  Otherwise
- * we fork off a subprocess and get the output of the command via a pipe.
- * Should be called with interrupts off.
- */
-
-void
-evalbackcmd(n, result)
-	union node *n;
-	struct backcmd *result;
-	{
-	int pip[2];
-	struct job *jp;
-	struct stackmark smark;		/* unnecessary */
-
-	setstackmark(&smark);
-	result->fd = -1;
-	result->buf = NULL;
-	result->nleft = 0;
-	result->jp = NULL;
-	if (n == NULL) {
-		/* `` */
-	} else
-	if (n->type == NCMD) {
-                exitstatus = oexitstatus;
-		evalcommand(n, EV_BACKCMD, result);
-	} else {
-		if (pipe(pip) < 0)
-			error("Pipe call failed");
-		jp = makejob(n, 1);
-		if (forkshell(jp, n, FORK_NOJOB) == 0) {
-			FORCEINTON;
-			close(pip[0]);
-			if (pip[1] != 1) {
-				close(1);
-				copyfd(pip[1], 1);
-				close(pip[1]);
-			}
-			evaltree(n, EV_EXIT);
-		}
-		close(pip[1]);
-		result->fd = pip[0];
-		result->jp = jp;
-	}
-	popstackmark(&smark);
-	TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
-		result->fd, result->buf, result->nleft, result->jp));
-}
-
-
-
-/*
- * Execute a simple command.
- */
-
-STATIC void
-evalcommand(cmd, flags, backcmd)
-	union node *cmd;
-	struct backcmd *backcmd;
-	{
-	struct stackmark smark;
-	union node *argp;
-	struct arglist arglist;
-	struct arglist varlist;
-	char **argv;
-	int argc;
-	char **envp;
-	int varflag;
-	struct strlist *sp;
-	register char *p;
-	int mode;
-	int pip[2];
-	struct cmdentry cmdentry;
-	struct job *jp;
-	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-	char *volatile savecmdname;
-	volatile struct shparam saveparam;
-	struct localvar *volatile savelocalvars;
-	volatile int e;
-	char *lastarg;
-
-	/* First expand the arguments. */
-	TRACE(("evalcommand(0x%x, %d) called\n", (int)cmd, flags));
-	setstackmark(&smark);
-	arglist.lastp = &arglist.list;
-	varlist.lastp = &varlist.list;
-	varflag = 1;
-        oexitstatus = exitstatus;
-	exitstatus = 0;
-	for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
-		p = argp->narg.text;
-		if (varflag && is_name(*p)) {
-			do {
-				p++;
-			} while (is_in_name(*p));
-			if (*p == '=') {
-				expandarg(argp, &varlist, 0);
-				continue;
-			}
-		}
-		expandarg(argp, &arglist, 1);
-		varflag = 0;
-	}
-	*arglist.lastp = NULL;
-	*varlist.lastp = NULL;
-	expredir(cmd->ncmd.redirect);
-	argc = 0;
-	for (sp = arglist.list ; sp ; sp = sp->next)
-		argc++;
-	argv = stalloc(sizeof (char *) * (argc + 1));
-	for (sp = arglist.list ; sp ; sp = sp->next)
-		*argv++ = sp->text;
-	*argv = NULL;
-	lastarg = NULL;
-	if (iflag && funcnest == 0 && argc > 0)
-		lastarg = argv[-1];
-	argv -= argc;
-
-	/* Print the command if xflag is set. */
-	if (xflag == 1) {
-		outc('+', &errout);
-		for (sp = varlist.list ; sp ; sp = sp->next) {
-			outc(' ', &errout);
-			out2str(sp->text);
-		}
-		for (sp = arglist.list ; sp ; sp = sp->next) {
-			outc(' ', &errout);
-			out2str(sp->text);
-		}
-		outc('\n', &errout);
-		flushout(&errout);
-	}
-
-	/* Now locate the command. */
-	if (argc == 0) {
-		cmdentry.cmdtype = CMDBUILTIN;
-		cmdentry.u.index = BLTINCMD;
-	} else {
-		find_command(argv[0], &cmdentry, 1);
-		if (cmdentry.cmdtype == CMDUNKNOWN) {	/* command not found */
-			exitstatus = 2;
-			flushout(&errout);
-			popstackmark(&smark);
-			return;
-		}
-		/* implement the bltin builtin here */
-		if (cmdentry.cmdtype == CMDBUILTIN && cmdentry.u.index == BLTINCMD) {
-			for (;;) {
-				argv++;
-				if (--argc == 0)
-					break;
-				if ((cmdentry.u.index = find_builtin(*argv)) < 0) {
-					outfmt(&errout, "%s: not found\n", *argv);
-					exitstatus = 2;
-					flushout(&errout);
-					popstackmark(&smark);
-					return;
-				}
-				if (cmdentry.u.index != BLTINCMD)
-					break;
-			}
-		}
-	}
-
-	/* Fork off a child process if necessary. */
-	if (cmd->ncmd.backgnd
-	 || cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0
-	 || (flags & EV_BACKCMD) != 0
-	    && (cmdentry.cmdtype != CMDBUILTIN
-		 || cmdentry.u.index == DOTCMD
-		 || cmdentry.u.index == EVALCMD)) {
-		jp = makejob(cmd, 1);
-		mode = cmd->ncmd.backgnd;
-		if (flags & EV_BACKCMD) {
-			mode = FORK_NOJOB;
-			if (pipe(pip) < 0)
-				error("Pipe call failed");
-		}
-		if (forkshell(jp, cmd, mode) != 0)
-			goto parent;	/* at end of routine */
-		if (flags & EV_BACKCMD) {
-			FORCEINTON;
-			close(pip[0]);
-			if (pip[1] != 1) {
-				close(1);
-				copyfd(pip[1], 1);
-				close(pip[1]);
-			}
-		}
-		flags |= EV_EXIT;
-	}
-
-	/* This is the child process if a fork occurred. */
-	/* Execute the command. */
-	if (cmdentry.cmdtype == CMDFUNCTION) {
-		trputs("Shell function:  ");  trargs(argv);
-		redirect(cmd->ncmd.redirect, REDIR_PUSH);
-		saveparam = shellparam;
-		shellparam.malloc = 0;
-		shellparam.nparam = argc - 1;
-		shellparam.p = argv + 1;
-		shellparam.optnext = NULL;
-		INTOFF;
-		savelocalvars = localvars;
-		localvars = NULL;
-		INTON;
-		if (setjmp(jmploc.loc)) {
-			if (exception == EXSHELLPROC)
-				freeparam((struct shparam *)&saveparam);
-			else {
-				freeparam(&shellparam);
-				shellparam = saveparam;
-			}
-			poplocalvars();
-			localvars = savelocalvars;
-			handler = savehandler;
-			longjmp(handler->loc, 1);
-		}
-		savehandler = handler;
-		handler = &jmploc;
-		for (sp = varlist.list ; sp ; sp = sp->next)
-			mklocal(sp->text);
-		funcnest++;
-		if (flags & EV_TESTED)
-			evaltree(cmdentry.u.func, EV_TESTED);
-		else
-			evaltree(cmdentry.u.func, 0);
-		funcnest--;
-		INTOFF;
-		poplocalvars();
-		localvars = savelocalvars;
-		freeparam(&shellparam);
-		shellparam = saveparam;
-		handler = savehandler;
-		popredir();
-		INTON;
-		if (evalskip == SKIPFUNC) {
-			evalskip = 0;
-			skipcount = 0;
-		}
-		if (flags & EV_EXIT)
-			exitshell(exitstatus);
-	} else if (cmdentry.cmdtype == CMDBUILTIN) {
-		trputs("builtin command:  ");  trargs(argv);
-		mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
-		if (flags == EV_BACKCMD) {
-			memout.nleft = 0;
-			memout.nextc = memout.buf;
-			memout.bufsize = 64;
-			mode |= REDIR_BACKQ;
-		}
-		redirect(cmd->ncmd.redirect, mode);
-		savecmdname = commandname;
-		cmdenviron = varlist.list;
-		e = -1;
-		if (setjmp(jmploc.loc)) {
-			e = exception;
-			exitstatus = (e == EXINT)? SIGINT+128 : 2;
-			goto cmddone;
-		}
-		savehandler = handler;
-		handler = &jmploc;
-		commandname = argv[0];
-		argptr = argv + 1;
-		optptr = NULL;			/* initialize nextopt */
-		exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
-		flushall();
-cmddone:
-		out1 = &output;
-		out2 = &errout;
-		freestdout();
-		if (e != EXSHELLPROC) {
-			commandname = savecmdname;
-			if (flags & EV_EXIT) {
-				exitshell(exitstatus);
-			}
-		}
-		handler = savehandler;
-		if (e != -1) {
-			if (e != EXERROR || cmdentry.u.index == BLTINCMD
-					       || cmdentry.u.index == DOTCMD
-					       || cmdentry.u.index == EVALCMD
-					       || cmdentry.u.index == EXECCMD)
-				exraise(e);
-			FORCEINTON;
-		}
-		if (cmdentry.u.index != EXECCMD)
-			popredir();
-		if (flags == EV_BACKCMD) {
-			backcmd->buf = memout.buf;
-			backcmd->nleft = memout.nextc - memout.buf;
-			memout.buf = NULL;
-		}
-	} else {
-		trputs("normal command:  ");  trargs(argv);
-		clearredir();
-		redirect(cmd->ncmd.redirect, 0);
-		if (varlist.list) {
-			p = stalloc(strlen(pathval()) + 1);
-			scopy(pathval(), p);
-		} else {
-			p = pathval();
-		}
-		for (sp = varlist.list ; sp ; sp = sp->next)
-			setvareq(sp->text, VEXPORT|VSTACK);
-		envp = environment();
-		shellexec(argv, envp, p, cmdentry.u.index);
-		/*NOTREACHED*/
-	}
-	goto out;
-
-parent:	/* parent process gets here (if we forked) */
-	if (mode == 0) {	/* argument to fork */
-		INTOFF;
-		exitstatus = waitforjob(jp);
-		INTON;
-	} else if (mode == 2) {
-		backcmd->fd = pip[0];
-		close(pip[1]);
-		backcmd->jp = jp;
-	}
-
-out:
-	if (lastarg)
-		setvar("_", lastarg, 0);
-	popstackmark(&smark);
-}
-
-
-
-/*
- * Search for a command.  This is called before we fork so that the
- * location of the command will be available in the parent as well as
- * the child.  The check for "goodname" is an overly conservative
- * check that the name will not be subject to expansion.
- */
-
-STATIC void
-prehash(n)
-	union node *n;
-	{
-	struct cmdentry entry;
-
-	if (n->type == NCMD && goodname(n->ncmd.args->narg.text))
-		find_command(n->ncmd.args->narg.text, &entry, 0);
-}
-
-
-
-/*
- * Builtin commands.  Builtin commands whose functions are closely
- * tied to evaluation are implemented here.
- */
-
-/*
- * No command given, or a bltin command with no arguments.  Set the
- * specified variables.
- */
-
-bltincmd(argc, argv)  char **argv; {
-	listsetvar(cmdenviron);
-	return exitstatus;
-}
-
-
-/*
- * Handle break and continue commands.  Break, continue, and return are
- * all handled by setting the evalskip flag.  The evaluation routines
- * above all check this flag, and if it is set they start skipping
- * commands rather than executing them.  The variable skipcount is
- * the number of loops to break/continue, or the number of function
- * levels to return.  (The latter is always 1.)  It should probably
- * be an error to break out of more loops than exist, but it isn't
- * in the standard shell so we don't make it one here.
- */
-
-breakcmd(argc, argv)  char **argv; {
-	int n;
-
-	n = 1;
-	if (argc > 1)
-		n = number(argv[1]);
-	if (n > loopnest)
-		n = loopnest;
-	if (n > 0) {
-		evalskip = (**argv == 'c')? SKIPCONT : SKIPBREAK;
-		skipcount = n;
-	}
-	return 0;
-}
-
-
-/*
- * The return command.
- */
-
-returncmd(argc, argv)  char **argv; {
-	int ret;
-
-	ret = oexitstatus;
-	if (argc > 1)
-		ret = number(argv[1]);
-	if (funcnest) {
-		evalskip = SKIPFUNC;
-		skipcount = 1;
-	}
-	return ret;
-}
-
-
-truecmd(argc, argv)  char **argv; {
-	return strcmp(argv[0], "false") == 0 ? 1 : 0;
-}
-
-
-execcmd(argc, argv)  char **argv; {
-	if (argc > 1) {
-		iflag = 0;		/* exit on error */
-		setinteractive(0);
-#if JOBS
-		jflag = 0;
-		setjobctl(0);
-#endif
-		shellexec(argv + 1, environment(), pathval(), 0);
-
-	}
-	return 0;
-}
Index: trunk/minix/commands/ash/eval.h
===================================================================
--- trunk/minix/commands/ash/eval.h	(revision 9)
+++ 	(revision )
@@ -1,65 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)eval.h	5.2 (Berkeley) 4/12/91
- */
-
-extern char *commandname;	/* currently executing command */
-extern int exitstatus;		/* exit status of last command */
-extern struct strlist *cmdenviron;  /* environment for builtin command */
-
-
-struct backcmd {		/* result of evalbackcmd */
-	int fd;			/* file descriptor to read from */
-	char *buf;		/* buffer */
-	int nleft;		/* number of chars in buffer */
-	struct job *jp;		/* job structure for command */
-};
-
-
-#ifdef __STDC__
-void evalstring(char *);
-union node;	/* BLETCH for ansi C */
-void evaltree(union node *, int);
-void evalbackcmd(union node *, struct backcmd *);
-#else
-void evalstring();
-void evaltree();
-void evalbackcmd();
-#endif
-
-/* in_function returns nonzero if we are currently evaluating a function */
-#define in_function()	funcnest
-extern int funcnest;
Index: trunk/minix/commands/ash/exec.c
===================================================================
--- trunk/minix/commands/ash/exec.c	(revision 9)
+++ 	(revision )
@@ -1,824 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)exec.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-/*
- * When commands are first encountered, they are entered in a hash table.
- * This ensures that a full path search will not have to be done for them
- * on each invocation.
- *
- * We should investigate converting to a linear search, even though that
- * would make the command name "hash" a misnomer.
- */
-
-#include "shell.h"
-#include "main.h"
-#include "nodes.h"
-#include "parser.h"
-#include "redir.h"
-#include "eval.h"
-#include "exec.h"
-#include "builtins.h"
-#include "var.h"
-#include "options.h"
-#include "input.h"
-#include "output.h"
-#include "syntax.h"
-#include "memalloc.h"
-#include "error.h"
-#include "init.h"
-#include "mystring.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-
-
-#define CMDTABLESIZE 31		/* should be prime */
-#define ARB 1			/* actual size determined at run time */
-
-
-
-struct tblentry {
-	struct tblentry *next;	/* next entry in hash chain */
-	union param param;	/* definition of builtin function */
-	short cmdtype;		/* index identifying command */
-	char rehash;		/* if set, cd done since entry created */
-	char cmdname[ARB];	/* name of command */
-};
-
-
-STATIC struct tblentry *cmdtable[CMDTABLESIZE];
-STATIC int builtinloc = -1;		/* index in path of %builtin, or -1 */
-
-
-#ifdef __STDC__
-STATIC void tryexec(char *, char **, char **);
-STATIC void execinterp(char **, char **);
-STATIC void printentry(struct tblentry *);
-STATIC void clearcmdentry(int);
-STATIC struct tblentry *cmdlookup(char *, int);
-STATIC void delete_cmd_entry(void);
-#else
-STATIC void tryexec();
-STATIC void execinterp();
-STATIC void printentry();
-STATIC void clearcmdentry();
-STATIC struct tblentry *cmdlookup();
-STATIC void delete_cmd_entry();
-#endif
-
-
-
-/*
- * Exec a program.  Never returns.  If you change this routine, you may
- * have to change the find_command routine as well.
- */
-
-void
-shellexec(argv, envp, path, index)
-	char **argv, **envp;
-	char *path;
-	{
-	char *cmdname;
-	int e;
-
-	if (strchr(argv[0], '/') != NULL) {
-		tryexec(argv[0], argv, envp);
-		e = errno;
-	} else {
-		e = ENOENT;
-		while ((cmdname = padvance(&path, argv[0])) != NULL) {
-			if (--index < 0 && pathopt == NULL) {
-				tryexec(cmdname, argv, envp);
-				if (errno != ENOENT && errno != ENOTDIR)
-					e = errno;
-			}
-			stunalloc(cmdname);
-		}
-	}
-	error2(argv[0], errmsg(e, E_EXEC));
-}
-
-
-STATIC void
-tryexec(cmd, argv, envp)
-	char *cmd;
-	char **argv;
-	char **envp;
-	{
-	int e;
-	char *p;
-
-#ifdef SYSV
-	do {
-		execve(cmd, argv, envp);
-	} while (errno == EINTR);
-#else
-	execve(cmd, argv, envp);
-#endif
-#if HASHBANG
-	e = errno;
-	if (e == ENOEXEC) {
-		initshellproc();
-		setinputfile(cmd, 0);
-		commandname = arg0 = savestr(argv[0]);
-#ifndef BSD
-		pgetc(); pungetc();		/* fill up input buffer */
-		p = parsenextc;
-		if (parsenleft > 2 && p[0] == '#' && p[1] == '!') {
-			argv[0] = cmd;
-			execinterp(argv, envp);
-		}
-#endif
-		setparam(argv + 1);
-		exraise(EXSHELLPROC);
-		/*NOTREACHED*/
-	}
-	errno = e;
-#endif
-}
-
-
-#if !defined(BSD) && HASHBANG
-/*
- * Execute an interpreter introduced by "#!", for systems where this
- * feature has not been built into the kernel.  If the interpreter is
- * the shell, return (effectively ignoring the "#!").  If the execution
- * of the interpreter fails, exit.
- *
- * This code peeks inside the input buffer in order to avoid actually
- * reading any input.  It would benefit from a rewrite.
- */
-
-#define NEWARGS 5
-
-STATIC void
-execinterp(argv, envp)
-	char **argv, **envp;
-	{
-	int n;
-	char *inp;
-	char *outp;
-	char c;
-	char *p;
-	char **ap;
-	char *newargs[NEWARGS];
-	int i;
-	char **ap2;
-	char **new;
-
-	n = parsenleft - 2;
-	inp = parsenextc + 2;
-	ap = newargs;
-	for (;;) {
-		while (--n >= 0 && (*inp == ' ' || *inp == '\t'))
-			inp++;
-		if (n < 0)
-			goto bad;
-		if ((c = *inp++) == '\n')
-			break;
-		if (ap == &newargs[NEWARGS])
-bad:		  error("Bad #! line");
-		STARTSTACKSTR(outp);
-		do {
-			STPUTC(c, outp);
-		} while (--n >= 0 && (c = *inp++) != ' ' && c != '\t' && c != '\n');
-		STPUTC('\0', outp);
-		n++, inp--;
-		*ap++ = grabstackstr(outp);
-	}
-#if !__minix
-	if (ap == newargs + 1) {	/* if no args, maybe no exec is needed */
-		p = newargs[0];
-		for (;;) {
-			if (equal(p, "sh") || equal(p, "ash")) {
-				return;
-			}
-			while (*p != '/') {
-				if (*p == '\0')
-					goto break2;
-				p++;
-			}
-			p++;
-		}
-break2:;
-	}
-#endif
-	i = (char *)ap - (char *)newargs;		/* size in bytes */
-	if (i == 0)
-		error("Bad #! line");
-	for (ap2 = argv ; *ap2++ != NULL ; );
-	new = ckmalloc(i + ((char *)ap2 - (char *)argv));
-	ap = newargs, ap2 = new;
-	while ((i -= sizeof (char **)) >= 0)
-		*ap2++ = *ap++;
-	ap = argv;
-	while (*ap2++ = *ap++);
-	shellexec(new, envp, pathval(), 0);
-}
-#endif
-
-
-
-/*
- * Do a path search.  The variable path (passed by reference) should be
- * set to the start of the path before the first call; padvance will update
- * this value as it proceeds.  Successive calls to padvance will return
- * the possible path expansions in sequence.  If an option (indicated by
- * a percent sign) appears in the path entry then the global variable
- * pathopt will be set to point to it; otherwise pathopt will be set to
- * NULL.
- */
-
-char *pathopt;
-
-char *
-padvance(path, name)
-	char **path;
-	char *name;
-	{
-	register char *p, *q;
-	char *start;
-	int len;
-
-	if (*path == NULL)
-		return NULL;
-	start = *path;
-	for (p = start ; *p && *p != ':' && *p != '%' ; p++);
-	len = p - start + strlen(name) + 2;	/* "2" is for '/' and '\0' */
-	while (stackblocksize() < len)
-		growstackblock();
-	q = stackblock();
-	if (p != start) {
-		bcopy(start, q, p - start);
-		q += p - start;
-		*q++ = '/';
-	}
-	strcpy(q, name);
-	pathopt = NULL;
-	if (*p == '%') {
-		pathopt = ++p;
-		while (*p && *p != ':')  p++;
-	}
-	if (*p == ':')
-		*path = p + 1;
-	else
-		*path = NULL;
-	return stalloc(len);
-}
-
-
-
-/*** Command hashing code ***/
-
-
-hashcmd(argc, argv)  char **argv; {
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-	int c;
-	int verbose;
-	struct cmdentry entry;
-	char *name;
-
-	if (argc <= 1) {
-		for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
-			for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-				printentry(cmdp);
-			}
-		}
-		return 0;
-	}
-	verbose = 0;
-	while ((c = nextopt("rv")) != '\0') {
-		if (c == 'r') {
-			clearcmdentry(0);
-		} else if (c == 'v') {
-			verbose++;
-		}
-	}
-	while ((name = *argptr) != NULL) {
-		if ((cmdp = cmdlookup(name, 0)) != NULL
-		 && (cmdp->cmdtype == CMDNORMAL
-		     || cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0))
-			delete_cmd_entry();
-		find_command(name, &entry, 1);
-		if (verbose) {
-			if (entry.cmdtype != CMDUNKNOWN) {	/* if no error msg */
-				cmdp = cmdlookup(name, 0);
-				printentry(cmdp);
-			}
-			flushall();
-		}
-		argptr++;
-	}
-	return 0;
-}
-
-
-STATIC void
-printentry(cmdp)
-	struct tblentry *cmdp;
-	{
-	int index;
-	char *path;
-	char *name;
-
-	if (cmdp->cmdtype == CMDNORMAL) {
-		index = cmdp->param.index;
-		path = pathval();
-		do {
-			name = padvance(&path, cmdp->cmdname);
-			stunalloc(name);
-		} while (--index >= 0);
-		out1str(name);
-	} else if (cmdp->cmdtype == CMDBUILTIN) {
-		out1fmt("builtin %s", cmdp->cmdname);
-	} else if (cmdp->cmdtype == CMDFUNCTION) {
-		out1fmt("function %s", cmdp->cmdname);
-#if DEBUG
-	} else {
-		error("internal error: cmdtype %d", cmdp->cmdtype);
-#endif
-	}
-	if (cmdp->rehash)
-		out1c('*');
-	out1c('\n');
-}
-
-
-
-/*
- * Resolve a command name.  If you change this routine, you may have to
- * change the shellexec routine as well.
- */
-
-void
-find_command(name, entry, printerr)
-	char *name;
-	struct cmdentry *entry;
-	{
-	struct tblentry *cmdp;
-	int index;
-	int prev;
-	char *path;
-	char *fullname;
-	struct stat statb;
-	int e;
-	int i;
-
-	/* If name contains a slash, don't use the hash table */
-	if (strchr(name, '/') != NULL) {
-		entry->cmdtype = CMDNORMAL;
-		entry->u.index = 0;
-		return;
-	}
-
-	/* If name is in the table, and not invalidated by cd, we're done */
-	if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->rehash == 0)
-		goto success;
-
-	/* If %builtin not in path, check for builtin next */
-	if (builtinloc < 0 && (i = find_builtin(name)) >= 0) {
-		INTOFF;
-		cmdp = cmdlookup(name, 1);
-		cmdp->cmdtype = CMDBUILTIN;
-		cmdp->param.index = i;
-		INTON;
-		goto success;
-	}
-
-	/* We have to search path. */
-	prev = -1;		/* where to start */
-	if (cmdp) {		/* doing a rehash */
-		if (cmdp->cmdtype == CMDBUILTIN)
-			prev = builtinloc;
-		else
-			prev = cmdp->param.index;
-	}
-
-	path = pathval();
-	e = ENOENT;
-	index = -1;
-loop:
-	while ((fullname = padvance(&path, name)) != NULL) {
-		stunalloc(fullname);
-		index++;
-		if (pathopt) {
-			if (prefix("builtin", pathopt)) {
-				if ((i = find_builtin(name)) < 0)
-					goto loop;
-				INTOFF;
-				cmdp = cmdlookup(name, 1);
-				cmdp->cmdtype = CMDBUILTIN;
-				cmdp->param.index = i;
-				INTON;
-				goto success;
-			} else if (prefix("func", pathopt)) {
-				/* handled below */
-			} else {
-				goto loop;	/* ignore unimplemented options */
-			}
-		}
-		/* if rehash, don't redo absolute path names */
-		if (fullname[0] == '/' && index <= prev) {
-			if (index < prev)
-				goto loop;
-			TRACE(("searchexec \"%s\": no change\n", name));
-			goto success;
-		}
-		while (stat(fullname, &statb) < 0) {
-#ifdef SYSV
-			if (errno == EINTR)
-				continue;
-#endif
-			if (errno != ENOENT && errno != ENOTDIR)
-				e = errno;
-			goto loop;
-		}
-		e = EACCES;	/* if we fail, this will be the error */
-		if ((statb.st_mode & S_IFMT) != S_IFREG)
-			goto loop;
-		if (pathopt) {		/* this is a %func directory */
-			stalloc(strlen(fullname) + 1);
-			readcmdfile(fullname);
-			if ((cmdp = cmdlookup(name, 0)) == NULL || cmdp->cmdtype != CMDFUNCTION)
-				error("%s not defined in %s", name, fullname);
-			stunalloc(fullname);
-			goto success;
-		}
-		if (statb.st_uid == geteuid()) {
-			if ((statb.st_mode & 0100) == 0)
-				goto loop;
-		} else if (statb.st_gid == getegid()) {
-			if ((statb.st_mode & 010) == 0)
-				goto loop;
-		} else {
-#if __minix_vmd || defined(BSD)
-			gid_t group_list[NGROUPS_MAX];
-			int ngroups, i;
-
-			ngroups = getgroups(NGROUPS_MAX, group_list);
-
-			for (i = 0; i < ngroups; i++) {
-				if (statb.st_gid == group_list[i]) break;
-			}
-			if (i < ngroups) {
-				if ((statb.st_mode & 010) == 0)
-					goto loop;
-			} else
-#endif
-			if ((statb.st_mode & 01) == 0)
-				goto loop;
-		}
-		TRACE(("searchexec \"%s\" returns \"%s\"\n", name, fullname));
-		INTOFF;
-		cmdp = cmdlookup(name, 1);
-		cmdp->cmdtype = CMDNORMAL;
-		cmdp->param.index = index;
-		INTON;
-		goto success;
-	}
-
-	/* We failed.  If there was an entry for this command, delete it */
-	if (cmdp)
-		delete_cmd_entry();
-	if (printerr)
-		outfmt(out2, "%s: %s\n", name, errmsg(e, E_EXEC));
-	entry->cmdtype = CMDUNKNOWN;
-	return;
-
-success:
-	cmdp->rehash = 0;
-	entry->cmdtype = cmdp->cmdtype;
-	entry->u = cmdp->param;
-}
-
-
-
-/*
- * Search the table of builtin commands.
- */
-
-int
-find_builtin(name)
-	char *name;
-	{
-	const register struct builtincmd *bp;
-
-	for (bp = builtincmd ; bp->name ; bp++) {
-		if (*bp->name == *name && equal(bp->name, name))
-			return bp->code;
-	}
-	return -1;
-}
-
-
-
-/*
- * Called when a cd is done.  Marks all commands so the next time they
- * are executed they will be rehashed.
- */
-
-void
-hashcd() {
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-
-	for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
-		for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-			if (cmdp->cmdtype == CMDNORMAL
-			 || cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)
-				cmdp->rehash = 1;
-		}
-	}
-}
-
-
-
-/*
- * Called before PATH is changed.  The argument is the new value of PATH;
- * pathval() still returns the old value at this point.  Called with
- * interrupts off.
- */
-
-void
-changepath(newval)
-	char *newval;
-	{
-	char *old, *new;
-	int index;
-	int firstchange;
-	int bltin;
-
-	old = pathval();
-	new = newval;
-	firstchange = 9999;	/* assume no change */
-	index = 0;
-	bltin = -1;
-	for (;;) {
-		if (*old != *new) {
-			firstchange = index;
-			if (*old == '\0' && *new == ':'
-			 || *old == ':' && *new == '\0')
-				firstchange++;
-			old = new;	/* ignore subsequent differences */
-		}
-		if (*new == '\0')
-			break;
-		if (*new == '%' && bltin < 0 && prefix("builtin", new + 1))
-			bltin = index;
-		if (*new == ':') {
-			index++;
-		}
-		new++, old++;
-	}
-	if (builtinloc < 0 && bltin >= 0)
-		builtinloc = bltin;		/* zap builtins */
-	if (builtinloc >= 0 && bltin < 0)
-		firstchange = 0;
-	clearcmdentry(firstchange);
-	builtinloc = bltin;
-}
-
-
-/*
- * Clear out command entries.  The argument specifies the first entry in
- * PATH which has changed.
- */
-
-STATIC void
-clearcmdentry(firstchange) {
-	struct tblentry **tblp;
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-
-	INTOFF;
-	for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
-		pp = tblp;
-		while ((cmdp = *pp) != NULL) {
-			if (cmdp->cmdtype == CMDNORMAL && cmdp->param.index >= firstchange
-			 || cmdp->cmdtype == CMDBUILTIN && builtinloc >= firstchange) {
-				*pp = cmdp->next;
-				ckfree(cmdp);
-			} else {
-				pp = &cmdp->next;
-			}
-		}
-	}
-	INTON;
-}
-
-
-/*
- * Delete all functions.
- */
-
-#ifdef mkinit
-MKINIT void deletefuncs();
-
-SHELLPROC {
-	deletefuncs();
-}
-#endif
-
-void
-deletefuncs() {
-	struct tblentry **tblp;
-	struct tblentry **pp;
-	struct tblentry *cmdp;
-
-	INTOFF;
-	for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
-		pp = tblp;
-		while ((cmdp = *pp) != NULL) {
-			if (cmdp->cmdtype == CMDFUNCTION) {
-				*pp = cmdp->next;
-				freefunc(cmdp->param.func);
-				ckfree(cmdp);
-			} else {
-				pp = &cmdp->next;
-			}
-		}
-	}
-	INTON;
-}
-
-
-
-/*
- * Locate a command in the command hash table.  If "add" is nonzero,
- * add the command to the table if it is not already present.  The
- * variable "lastcmdentry" is set to point to the address of the link
- * pointing to the entry, so that delete_cmd_entry can delete the
- * entry.
- */
-
-struct tblentry **lastcmdentry;
-
-
-STATIC struct tblentry *
-cmdlookup(name, add)
-	char *name;
-	{
-	int hashval;
-	register char *p;
-	struct tblentry *cmdp;
-	struct tblentry **pp;
-
-	p = name;
-	hashval = *p << 4;
-	while (*p)
-		hashval += *p++;
-	hashval &= 0x7FFF;
-	pp = &cmdtable[hashval % CMDTABLESIZE];
-	for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
-		if (equal(cmdp->cmdname, name))
-			break;
-		pp = &cmdp->next;
-	}
-	if (add && cmdp == NULL) {
-		INTOFF;
-		cmdp = *pp = ckmalloc(sizeof (struct tblentry) - ARB
-					+ strlen(name) + 1);
-		cmdp->next = NULL;
-		cmdp->cmdtype = CMDUNKNOWN;
-		cmdp->rehash = 0;
-		strcpy(cmdp->cmdname, name);
-		INTON;
-	}
-	lastcmdentry = pp;
-	return cmdp;
-}
-
-
-/*
- * Delete the command entry returned on the last lookup.
- */
-
-STATIC void
-delete_cmd_entry() {
-	struct tblentry *cmdp;
-
-	INTOFF;
-	cmdp = *lastcmdentry;
-	*lastcmdentry = cmdp->next;
-	ckfree(cmdp);
-	INTON;
-}
-
-
-
-#ifdef notdef
-void
-getcmdentry(name, entry)
-	char *name;
-	struct cmdentry *entry; 
-	{
-	struct tblentry *cmdp = cmdlookup(name, 0);
-
-	if (cmdp) {
-		entry->u = cmdp->param;
-		entry->cmdtype = cmdp->cmdtype;
-	} else {
-		entry->cmdtype = CMDUNKNOWN;
-		entry->u.index = 0;
-	}
-}
-#endif
-
-
-/*
- * Add a new command entry, replacing any existing command entry for
- * the same name.
- */
-
-void
-addcmdentry(name, entry)
-	char *name;
-	struct cmdentry *entry;
-	{
-	struct tblentry *cmdp;
-
-	INTOFF;
-	cmdp = cmdlookup(name, 1);
-	if (cmdp->cmdtype == CMDFUNCTION) {
-		freefunc(cmdp->param.func);
-	}
-	cmdp->cmdtype = entry->cmdtype;
-	cmdp->param = entry->u;
-	INTON;
-}
-
-
-/*
- * Define a shell function.
- */
-
-void
-defun(name, func)
-	char *name;
-	union node *func;
-	{
-	struct cmdentry entry;
-
-	INTOFF;
-	entry.cmdtype = CMDFUNCTION;
-	entry.u.func = copyfunc(func);
-	addcmdentry(name, &entry);
-	INTON;
-}
-
-
-/*
- * Delete a function if it exists.
- */
-
-void
-unsetfunc(name)
-	char *name;
-	{
-	struct tblentry *cmdp;
-
-	if ((cmdp = cmdlookup(name, 0)) != NULL && cmdp->cmdtype == CMDFUNCTION) {
-		freefunc(cmdp->param.func);
-		delete_cmd_entry();
-	}
-}
Index: trunk/minix/commands/ash/exec.h
===================================================================
--- trunk/minix/commands/ash/exec.h	(revision 9)
+++ 	(revision )
@@ -1,75 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)exec.h	5.1 (Berkeley) 3/7/91
- */
-
-/* values of cmdtype */
-#define CMDUNKNOWN -1		/* no entry in table for command */
-#define CMDNORMAL 0		/* command is an executable program */
-#define CMDBUILTIN 1		/* command is a shell builtin */
-#define CMDFUNCTION 2		/* command is a shell function */
-
-
-struct cmdentry {
-	int cmdtype;
-	union param {
-		int index;
-		union node *func;
-	} u;
-};
-
-
-extern char *pathopt;		/* set by padvance */
-
-#ifdef __STDC__
-void shellexec(char **, char **, char *, int);
-char *padvance(char **, char *);
-void find_command(char *, struct cmdentry *, int);
-int find_builtin(char *);
-void hashcd(void);
-void changepath(char *);
-void defun(char *, union node *);
-void unsetfunc(char *);
-#else
-void shellexec();
-char *padvance();
-void find_command();
-int find_builtin();
-void hashcd();
-void changepath();
-void defun();
-void unsetfunc();
-#endif
Index: trunk/minix/commands/ash/expand.c
===================================================================
--- trunk/minix/commands/ash/expand.c	(revision 9)
+++ 	(revision )
@@ -1,1159 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)expand.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * Routines to expand arguments to commands.  We have to deal with
- * backquotes, shell variables, and file metacharacters.
- */
-
-#include "shell.h"
-#include "main.h"
-#include "nodes.h"
-#include "eval.h"
-#include "expand.h"
-#include "syntax.h"
-#include "parser.h"
-#include "jobs.h"
-#include "options.h"
-#include "var.h"
-#include "input.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <dirent.h>
-#if USEGETPW
-#include <pwd.h>
-#endif
-
-/*
- * Structure specifying which parts of the string should be searched
- * for IFS characters.
- */
-
-struct ifsregion {
-	struct ifsregion *next;	/* next region in list */
-	int begoff;		/* offset of start of region */
-	int endoff;		/* offset of end of region */
-	int nulonly;		/* search for nul bytes only */
-};
-
-
-char *expdest;			/* output of current string */
-struct nodelist *argbackq;	/* list of back quote expressions */
-struct ifsregion ifsfirst;	/* first struct in list of ifs regions */
-struct ifsregion *ifslastp;	/* last struct in list */
-struct arglist exparg;		/* holds expanded arg list */
-#if UDIR || TILDE
-/*
- * Set if the last argument processed had /u/logname or ~logname expanded.
- * This variable is read by the cd command.
- */
-int didudir;
-#endif
-
-#ifdef __STDC__
-STATIC void argstr(char *, int);
-STATIC void expbackq(union node *, int, int);
-STATIC char *evalvar(char *, int);
-STATIC int varisset(int);
-STATIC void varvalue(int, int, int);
-STATIC void recordregion(int, int, int);
-STATIC void ifsbreakup(char *, struct arglist *);
-STATIC void expandmeta(struct strlist *);
-STATIC void expmeta(char *, char *);
-STATIC void addfname(char *);
-STATIC struct strlist *expsort(struct strlist *);
-STATIC struct strlist *msort(struct strlist *, int);
-STATIC int pmatch(char *, char *);
-#else
-STATIC void argstr();
-STATIC void expbackq();
-STATIC char *evalvar();
-STATIC int varisset();
-STATIC void varvalue();
-STATIC void recordregion();
-STATIC void ifsbreakup();
-STATIC void expandmeta();
-STATIC void expmeta();
-STATIC void addfname();
-STATIC struct strlist *expsort();
-STATIC struct strlist *msort();
-STATIC int pmatch();
-#endif
-#if UDIR || TILDE
-#ifdef __STDC__
-STATIC char *expudir(char *);
-#else
-STATIC char *expudir();
-#endif
-#endif /* UDIR || TILDE */
-
-
-
-/*
- * Expand shell variables and backquotes inside a here document.
- */
-
-void
-expandhere(arg, fd)
-	union node *arg;	/* the document */
-	int fd;			/* where to write the expanded version */
-	{
-	herefd = fd;
-	expandarg(arg, (struct arglist *)NULL, 0);
-	xwrite(fd, stackblock(), expdest - stackblock());
-}
-
-
-/*
- * Perform variable substitution and command substitution on an argument,
- * placing the resulting list of arguments in arglist.  If full is true,
- * perform splitting and file name expansion.  When arglist is NULL, perform
- * here document expansion.
- */
-
-void
-expandarg(arg, arglist, full)
-	union node *arg;
-	struct arglist *arglist;
-	{
-	struct strlist *sp;
-	char *p;
-
-#if UDIR || TILDE
-	didudir = 0;
-#endif
-	argbackq = arg->narg.backquote;
-	STARTSTACKSTR(expdest);
-	ifsfirst.next = NULL;
-	ifslastp = NULL;
-	argstr(arg->narg.text, full);
-	if (arglist == NULL)
-		return;			/* here document expanded */
-	STPUTC('\0', expdest);
-	p = grabstackstr(expdest);
-	exparg.lastp = &exparg.list;
-	if (full) {
-		ifsbreakup(p, &exparg);
-		*exparg.lastp = NULL;
-		exparg.lastp = &exparg.list;
-		expandmeta(exparg.list);
-	} else {
-		sp = (struct strlist *)stalloc(sizeof (struct strlist));
-		sp->text = p;
-		*exparg.lastp = sp;
-		exparg.lastp = &sp->next;
-	}
-	while (ifsfirst.next != NULL) {
-		struct ifsregion *ifsp;
-		INTOFF;
-		ifsp = ifsfirst.next->next;
-		ckfree(ifsfirst.next);
-		ifsfirst.next = ifsp;
-		INTON;
-	}
-	*exparg.lastp = NULL;
-	if (exparg.list) {
-		*arglist->lastp = exparg.list;
-		arglist->lastp = exparg.lastp;
-	}
-}
-
-
-
-/*
- * Perform variable and command substitution.  If full is set, output CTLESC
- * characters to allow for further processing.  If full is not set, treat
- * $@ like $* since no splitting will be performed.
- */
-
-STATIC void
-argstr(p, full)
-	register char *p;
-	{
-	char c;
-
-	for (;;) {
-		switch (c = *p++) {
-		case '\0':
-		case CTLENDVAR:
-			goto breakloop;
-		case CTLESC:
-			if (full)
-				STPUTC(c, expdest);
-			c = *p++;
-			STPUTC(c, expdest);
-			break;
-		case CTLVAR:
-			p = evalvar(p, full);
-			break;
-		case CTLBACKQ:
-		case CTLBACKQ|CTLQUOTE:
-			expbackq(argbackq->n, c & CTLQUOTE, full);
-			argbackq = argbackq->next;
-			break;
-		default:
-			STPUTC(c, expdest);
-		}
-	}
-breakloop:;
-}
-
-
-/*
- * Expand stuff in backwards quotes.
- */
-
-STATIC void
-expbackq(cmd, quoted, full)
-	union node *cmd;
-	{
-	struct backcmd in;
-	int i;
-	char buf[128];
-	char *p;
-	char *dest = expdest;
-	struct ifsregion saveifs, *savelastp;
-	struct nodelist *saveargbackq;
-	char lastc;
-	int startloc = dest - stackblock();
-	char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
-	int saveherefd;
-
-	INTOFF;
-	saveifs = ifsfirst;
-	savelastp = ifslastp;
-	saveargbackq = argbackq;
-	saveherefd = herefd;      
-	herefd = -1;
-	p = grabstackstr(dest);
-	evalbackcmd(cmd, &in);
-	ungrabstackstr(p, dest);
-	ifsfirst = saveifs;
-	ifslastp = savelastp;
-	argbackq = saveargbackq;
-	herefd = saveherefd;
-
-	p = in.buf;
-	lastc = '\0';
-	for (;;) {
-		if (--in.nleft < 0) {
-			if (in.fd < 0)
-				break;
-			while ((i = read(in.fd, buf, sizeof buf)) < 0 && errno == EINTR);
-			TRACE(("expbackq: read returns %d\n", i));
-			if (i <= 0)
-				break;
-			p = buf;
-			in.nleft = i - 1;
-		}
-		lastc = *p++;
-		if (lastc != '\0') {
-			if (full && syntax[lastc] == CCTL)
-				STPUTC(CTLESC, dest);
-			STPUTC(lastc, dest);
-		}
-	}
-	if (lastc == '\n') {
-		STUNPUTC(dest);
-	}
-	if (in.fd >= 0)
-		close(in.fd);
-	if (in.buf)
-		ckfree(in.buf);
-	if (in.jp)
-		exitstatus = waitforjob(in.jp);
-	if (quoted == 0)
-		recordregion(startloc, dest - stackblock(), 0);
-	TRACE(("evalbackq: size=%d: \"%.*s\"\n",
-		(dest - stackblock()) - startloc,
-		(dest - stackblock()) - startloc,
-		stackblock() + startloc));
-	expdest = dest;
-	INTON;
-}
-
-
-
-/*
- * Expand a variable, and return a pointer to the next character in the
- * input string.
- */
-
-STATIC char *
-evalvar(p, full)
-	char *p;
-	{
-	int subtype;
-	int flags;
-	char *var;
-	char *val;
-	int c;
-	int set;
-	int special;
-	int startloc;
-
-	flags = *p++;
-	subtype = flags & VSTYPE;
-	var = p;
-	special = 0;
-	if (! is_name(*p))
-		special = 1;
-	p = strchr(p, '=') + 1;
-again: /* jump here after setting a variable with ${var=text} */
-	if (special) {
-		set = varisset(*var);
-		val = NULL;
-	} else {
-		val = lookupvar(var);
-		if (val == NULL || (flags & VSNUL) && val[0] == '\0') {
-			val = NULL;
-			set = 0;
-		} else
-			set = 1;
-	}
-	startloc = expdest - stackblock();
-	if (set && subtype != VSPLUS) {
-		/* insert the value of the variable */
-		if (special) {
-			varvalue(*var, flags & VSQUOTE, full);
-		} else {
-			char const *syntax = (flags & VSQUOTE)? DQSYNTAX : BASESYNTAX;
-
-			while (*val) {
-				if (full && syntax[*val] == CCTL)
-					STPUTC(CTLESC, expdest);
-				STPUTC(*val++, expdest);
-			}
-		}
-	}
-	if (subtype == VSPLUS)
-		set = ! set;
-	if (((flags & VSQUOTE) == 0 || (*var == '@' && shellparam.nparam != 1))
-	 && (set || subtype == VSNORMAL))
-		recordregion(startloc, expdest - stackblock(), flags & VSQUOTE);
-	if (! set && subtype != VSNORMAL) {
-		if (subtype == VSPLUS || subtype == VSMINUS) {
-			argstr(p, full);
-		} else {
-			char *startp;
-			int saveherefd = herefd;
-			herefd = -1;
-			argstr(p, 0);
-			STACKSTRNUL(expdest);
-			herefd = saveherefd;
-			startp = stackblock() + startloc;
-			if (subtype == VSASSIGN) {
-				setvar(var, startp, 0);
-				STADJUST(startp - expdest, expdest);
-				flags &=~ VSNUL;
-				goto again;
-			}
-			/* subtype == VSQUESTION */
-			if (*p != CTLENDVAR) {
-				outfmt(&errout, "%s\n", startp);
-				error((char *)NULL);
-			}
-			error("%.*s: parameter %snot set", p - var - 1,
-				var, (flags & VSNUL)? "null or " : nullstr);
-		}
-	}
-	if (subtype != VSNORMAL) {	/* skip to end of alternative */
-		int nesting = 1;
-		for (;;) {
-			if ((c = *p++) == CTLESC)
-				p++;
-			else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) {
-				if (set) {
-					if (argbackq != NULL)
-						argbackq = argbackq->next;
-				}
-			} else if (c == CTLVAR) {
-				if ((*p++ & VSTYPE) != VSNORMAL)
-					nesting++;
-			} else if (c == CTLENDVAR) {
-				if (--nesting == 0)
-					break;
-			}
-		}
-	}
-	return p;
-}
-
-
-
-/*
- * Test whether a specialized variable is set.
- */
-
-STATIC int
-varisset(name)
-	char name;
-	{
-	char **ap;
-
-	if (name == '!') {
-		if (backgndpid == -1)
-			return 0;
-	} else if (name == '@' || name == '*') {
-		if (*shellparam.p == NULL)
-			return 0;
-	} else if ((unsigned)(name -= '1') <= '9' - '1') {
-		ap = shellparam.p;
-		do {
-			if (*ap++ == NULL)
-				return 0;
-		} while (--name >= 0);
-	}
-	return 1;
-}
-
-
-
-/*
- * Add the value of a specialized variable to the stack string.
- */
-
-STATIC void
-varvalue(name, quoted, allow_split)
-	char name;
-	{
-	int num;
-	char temp[32];
-	char *p;
-	int i;
-	extern int oexitstatus;
-	char sep;
-	char **ap;
-	char const *syntax;
-
-	switch (name) {
-	case '$':
-		num = rootpid;
-		goto numvar;
-	case '?':
-		num = oexitstatus;
-		goto numvar;
-	case '#':
-		num = shellparam.nparam;
-		goto numvar;
-	case '!':
-		num = backgndpid;
-numvar:
-		p = temp + 31;
-		temp[31] = '\0';
-		do {
-			*--p = num % 10 + '0';
-		} while ((num /= 10) != 0);
-		while (*p)
-			STPUTC(*p++, expdest);
-		break;
-	case '-':
-		for (i = 0 ; optchar[i] ; i++) {
-			if (optval[i])
-				STPUTC(optchar[i], expdest);
-		}
-		break;
-	case '@':
-		if (allow_split) {
-			sep = '\0';
-			goto allargs;
-		}
-		/* fall through */			
-	case '*':
-		sep = ' ';
-allargs:
-		/* Only emit CTLESC if we will do further processing,
-		   i.e. if allow_split is set.  */
-		syntax = quoted && allow_split ? DQSYNTAX : BASESYNTAX;
-		for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
-			/* should insert CTLESC characters */
-			while (*p) {
-				if (syntax[*p] == CCTL)
-					STPUTC(CTLESC, expdest);
-				STPUTC(*p++, expdest);
-			}
-			if (*ap)
-				STPUTC(sep, expdest);
-		}
-		break;
-	case '0':
-		p = arg0;
-string:
-		/* Only emit CTLESC if we will do further processing,
-		   i.e. if allow_split is set.  */
-		syntax = quoted && allow_split ? DQSYNTAX : BASESYNTAX;
-		while (*p) {
-			if (syntax[*p] == CCTL)
-				STPUTC(CTLESC, expdest);
-			STPUTC(*p++, expdest);
-		}
-		break;
-	default:
-		if ((unsigned)(name -= '1') <= '9' - '1') {
-			p = shellparam.p[name];
-			goto string;
-		}
-		break;
-	}
-}
-
-
-
-/*
- * Record the the fact that we have to scan this region of the
- * string for IFS characters.
- */
-
-STATIC void
-recordregion(start, end, nulonly) {
-	register struct ifsregion *ifsp;
-
-	if (ifslastp == NULL) {
-		ifsp = &ifsfirst;
-	} else {
-		ifsp = (struct ifsregion *)ckmalloc(sizeof (struct ifsregion));
-		ifslastp->next = ifsp;
-	}
-	ifslastp = ifsp;
-	ifslastp->next = NULL;
-	ifslastp->begoff = start;
-	ifslastp->endoff = end;
-	ifslastp->nulonly = nulonly;
-}
-
-
-
-/*
- * Break the argument string into pieces based upon IFS and add the
- * strings to the argument list.  The regions of the string to be
- * searched for IFS characters have been stored by recordregion.
- */
-
-STATIC void
-ifsbreakup(string, arglist)
-	char *string;
-	struct arglist *arglist;
-	{
-	struct ifsregion *ifsp;
-	struct strlist *sp;
-	char *start;
-	register char *p;
-	char *q;
-	char *ifs;
-
-	start = string;
-	if (ifslastp != NULL) {
-		ifsp = &ifsfirst;
-		do {
-			p = string + ifsp->begoff;
-			ifs = ifsp->nulonly? nullstr : ifsval();
-			while (p < string + ifsp->endoff) {
-				q = p;
-				if (*p == CTLESC)
-					p++;
-				if (strchr(ifs, *p++)) {
-					if (q > start || *ifs != ' ') {
-						*q = '\0';
-						sp = (struct strlist *)stalloc(sizeof *sp);
-						sp->text = start;
-						*arglist->lastp = sp;
-						arglist->lastp = &sp->next;
-					}
-					if (*ifs == ' ') {
-						for (;;) {
-							if (p >= string + ifsp->endoff)
-								break;
-							q = p;
-							if (*p == CTLESC)
-								p++;
-							if (strchr(ifs, *p++) == NULL) {
-								p = q;
-								break;
-							}
-						}
-					}
-					start = p;
-				}
-			}
-		} while ((ifsp = ifsp->next) != NULL);
-		if (*start || (*ifs != ' ' && start > string)) {
-			sp = (struct strlist *)stalloc(sizeof *sp);
-			sp->text = start;
-			*arglist->lastp = sp;
-			arglist->lastp = &sp->next;
-		}
-	} else {
-		sp = (struct strlist *)stalloc(sizeof *sp);
-		sp->text = start;
-		*arglist->lastp = sp;
-		arglist->lastp = &sp->next;
-	}
-}
-
-
-
-/*
- * Expand shell metacharacters.  At this point, the only control characters
- * should be escapes.  The results are stored in the list exparg.
- */
-
-char *expdir;
-
-
-STATIC void
-expandmeta(str)
-	struct strlist *str;
-	{
-	char *p;
-	struct strlist **savelastp;
-	struct strlist *sp;
-	char c;
-
-	while (str) {
-		if (fflag)
-			goto nometa;
-		p = str->text;
-#if UDIR
-		if (p[0] == '/' && p[1] == 'u' && p[2] == '/')
-			str->text = p = expudir(p);
-#endif
-#if TILDE
-		if (p[0] == '~')
-			str->text = p = expudir(p);
-#endif
-		for (;;) {			/* fast check for meta chars */
-			if ((c = *p++) == '\0')
-				goto nometa;
-			if (c == '*' || c == '?' || c == '[' || c == '!')
-				break;
-		}
-		savelastp = exparg.lastp;
-		INTOFF;
-		if (expdir == NULL)
-		{
-			int i = strlen(str->text);
-			expdir = ckmalloc(i < 2048 ? 2048 : i); /* XXX */
-		}
-		expmeta(expdir, str->text);
-		ckfree(expdir);
-		expdir = NULL;
-		INTON;
-		if (exparg.lastp == savelastp) {
-			if (! zflag) {
-nometa:
-				*exparg.lastp = str;
-				rmescapes(str->text);
-				exparg.lastp = &str->next;
-			}
-		} else {
-			*exparg.lastp = NULL;
-			*savelastp = sp = expsort(*savelastp);
-			while (sp->next != NULL)
-				sp = sp->next;
-			exparg.lastp = &sp->next;
-		}
-		str = str->next;
-	}
-}
-
-
-#if UDIR || TILDE
-/*
- * UDIR: Expand /u/username into the home directory for the specified user.
- * TILDE: Expand ~username into the home directory for the specified user.
- * We hope not to use the getpw stuff here, because then we would have to load
- * in stdio and who knows what else.  With networked password files there is
- * no choice alas.
- */
-
-#define MAXLOGNAME 32
-#define MAXPWLINE 128
-
-char *pfgets();
-
-
-STATIC char *
-expudir(path)
-	char *path;
-	{
-	register char *p, *q, *r;
-	char name[MAXLOGNAME];
-	char line[MAXPWLINE];
-	int i;
-#if USEGETPW
-	struct passwd *pw;
-#endif
-
-	r = path;				/* result on failure */
-	p = r + (*r == '~' ? 1 : 3);	/* the 1 skips "~", 3 skips "/u/" */
-	q = name;
-	while (*p && *p != '/') {
-		if (q >= name + MAXLOGNAME - 1)
-			return r;		/* fail, name too long */
-		*q++ = *p++;
-	}
-	*q = '\0';
-
-#if TILDE
-	if (*name == 0 && *r == '~') {
-		/* null name, use $HOME */
-		if ((q = lookupvar("HOME")) == NULL)
-			return r;		/* fail, home not set */
-		i = strlen(q);
-		r = stalloc(i + strlen(p) + 1);
-		scopy(q, r);
-		scopy(p, r + i);
-		TRACE(("expudir converts %s to %s\n", path, r));
-		didudir = 1;
-		path = r;
-		return r;
-	}
-#endif
-#if !USEGETPW	/* can do without the bloat */
-	setinputfile("/etc/passwd", 1);
-	q = line + strlen(name);
-	while (pfgets(line, MAXPWLINE) != NULL) {
-		if (line[0] == name[0] && prefix(name, line) && *q == ':') {
-			/* skip to start of home directory */
-			i = 4;
-			do {
-				while (*++q && *q != ':');
-			} while (--i > 0);
-			if (*q == '\0')
-				break;		/* fail, corrupted /etc/passwd */
-			q++;
-			for (r = q ; *r && *r != '\n' && *r != ':' ; r++);
-			*r = '\0';		/* nul terminate home directory */
-			i = r - q;		/* i = strlen(q) */
-			r = stalloc(i + strlen(p) + 1);
-			scopy(q, r);
-			scopy(p, r + i);
-			TRACE(("expudir converts %s to %s\n", path, r));
-			didudir = 1;
-			path = r;		/* succeed */
-			break;
-		}
-	}
-	popfile();
-#else
-	if ((pw = getpwnam(name)) != NULL) {
-		/* user exists */
-		q = pw->pw_dir;
-		i = strlen(q);
-		r = stalloc(i + strlen(p) + 1);
-		scopy(q, r);
-		scopy(p, r + i);
-		TRACE(("expudir converts %s to %s\n", path, r));
-		didudir = 1;
-		path = r;
-	}
-	endpwent();
-#endif /* USEGETPW */
-
-	return r;
-}
-#endif
-
-
-/*
- * Do metacharacter (i.e. *, ?, [...]) expansion.
- */
-
-STATIC void
-expmeta(enddir, name)
-	char *enddir;
-	char *name;
-	{
-	register char *p;
-	char *q;
-	char *start;
-	char *endname;
-	int metaflag;
-	struct stat statb;
-	DIR *dirp;
-	struct dirent *dp;
-	int atend;
-	int matchdot;
-
-	metaflag = 0;
-	start = name;
-	for (p = name ; ; p++) {
-		if (*p == '*' || *p == '?')
-			metaflag = 1;
-		else if (*p == '[') {
-			q = p + 1;
-			if (*q == '!')
-				q++;
-			for (;;) {
-				if (*q == CTLESC)
-					q++;
-				if (*q == '/' || *q == '\0')
-					break;
-				if (*++q == ']') {
-					metaflag = 1;
-					break;
-				}
-			}
-		} else if (*p == '!' && p[1] == '!'	&& (p == name || p[-1] == '/')) {
-			metaflag = 1;
-		} else if (*p == '\0')
-			break;
-		else if (*p == CTLESC)
-			p++;
-		if (*p == '/') {
-			if (metaflag)
-				break;
-			start = p + 1;
-		}
-	}
-	if (metaflag == 0) {	/* we've reached the end of the file name */
-		if (enddir != expdir)
-			metaflag++;
-		for (p = name ; ; p++) {
-			if (*p == CTLESC)
-				p++;
-			*enddir++ = *p;
-			if (*p == '\0')
-				break;
-		}
-		if (metaflag == 0 || stat(expdir, &statb) >= 0)
-			addfname(expdir);
-		return;
-	}
-	endname = p;
-	if (start != name) {
-		p = name;
-		while (p < start) {
-			if (*p == CTLESC)
-				p++;
-			*enddir++ = *p++;
-		}
-	}
-	if (enddir == expdir) {
-		p = ".";
-	} else if (enddir == expdir + 1 && *expdir == '/') {
-		p = "/";
-	} else {
-		p = expdir;
-		enddir[-1] = '\0';
-	}
-	if ((dirp = opendir(p)) == NULL)
-		return;
-	if (enddir != expdir)
-		enddir[-1] = '/';
-	if (*endname == 0) {
-		atend = 1;
-	} else {
-		atend = 0;
-		*endname++ = '\0';
-	}
-	matchdot = 0;
-	if (start[0] == '.' || start[0] == CTLESC && start[1] == '.')
-		matchdot++;
-	while (! int_pending() && (dp = readdir(dirp)) != NULL) {
-		if (dp->d_name[0] == '.' && ! matchdot)
-			continue;
-		if (patmatch(start, dp->d_name)) {
-			if (atend) {
-				scopy(dp->d_name, enddir);
-				addfname(expdir);
-			} else {
-				char *q;
-				for (p = enddir, q = dp->d_name ; *p++ = *q++ ;);
-				p[-1] = '/';
-				expmeta(p, endname);
-			}
-		}
-	}
-	closedir(dirp);
-	if (! atend)
-		endname[-1] = '/';
-}
-
-
-/*
- * Add a file name to the list.
- */
-
-STATIC void
-addfname(name)
-	char *name;
-	{
-	char *p;
-	struct strlist *sp;
-
-	p = stalloc(strlen(name) + 1);
-	scopy(name, p);
-	sp = (struct strlist *)stalloc(sizeof *sp);
-	sp->text = p;
-	*exparg.lastp = sp;
-	exparg.lastp = &sp->next;
-}
-
-
-/*
- * Sort the results of file name expansion.  It calculates the number of
- * strings to sort and then calls msort (short for merge sort) to do the
- * work.
- */
-
-STATIC struct strlist *
-expsort(str)
-	struct strlist *str;
-	{
-	int len;
-	struct strlist *sp;
-
-	len = 0;
-	for (sp = str ; sp ; sp = sp->next)
-		len++;
-	return msort(str, len);
-}
-
-
-STATIC struct strlist *
-msort(list, len)
-	struct strlist *list;
-	{
-	struct strlist *p, *q;
-	struct strlist **lpp;
-	int half;
-	int n;
-
-	if (len <= 1)
-		return list;
-	half = len >> 1;      
-	p = list;
-	for (n = half ; --n >= 0 ; ) {
-		q = p;
-		p = p->next;
-	}
-	q->next = NULL;			/* terminate first half of list */
-	q = msort(list, half);		/* sort first half of list */
-	p = msort(p, len - half);		/* sort second half */
-	lpp = &list;
-	for (;;) {
-		if (strcmp(p->text, q->text) < 0) {
-			*lpp = p;
-			lpp = &p->next;
-			if ((p = *lpp) == NULL) {
-				*lpp = q;
-				break;
-			}
-		} else {
-			*lpp = q;
-			lpp = &q->next;
-			if ((q = *lpp) == NULL) {
-				*lpp = p;
-				break;
-			}
-		}
-	}
-	return list;
-}
-
-
-
-/*
- * Returns true if the pattern matches the string.
- */
-
-int
-patmatch(pattern, string)
-	char *pattern;
-	char *string;
-	{
-	if (pattern[0] == '!' && pattern[1] == '!')
-		return 1 - pmatch(pattern + 2, string);
-	else
-		return pmatch(pattern, string);
-}
-
-
-STATIC int
-pmatch(pattern, string)
-	char *pattern;
-	char *string;
-	{
-	register char *p, *q;
-	register char c;
-
-	p = pattern;
-	q = string;
-	for (;;) {
-		switch (c = *p++) {
-		case '\0':
-			goto breakloop;
-		case CTLESC:
-			if (*q++ != *p++)
-				return 0;
-			break;
-		case '?':
-			if (*q++ == '\0')
-				return 0;
-			break;
-		case '*':
-			c = *p;
-			if (c != CTLESC && c != '?' && c != '*' && c != '[') {
-				while (*q != c) {
-					if (*q == '\0')
-						return 0;
-					q++;
-				}
-			}
-			do {
-				if (pmatch(p, q))
-					return 1;
-			} while (*q++ != '\0');
-			return 0;
-		case '[': {
-			char *endp;
-			int invert, found;
-			char chr;
-
-			endp = p;
-			if (*endp == '!')
-				endp++;
-			for (;;) {
-				if (*endp == '\0')
-					goto dft;		/* no matching ] */
-				if (*endp == CTLESC)
-					endp++;
-				if (*++endp == ']')
-					break;
-			}
-			invert = 0;
-			if (*p == '!') {
-				invert++;
-				p++;
-			}
-			found = 0;
-			chr = *q++;
-			c = *p++;
-			do {
-				if (c == CTLESC)
-					c = *p++;
-				if (*p == '-' && p[1] != ']') {
-					p++;
-					if (*p == CTLESC)
-						p++;
-					if (chr >= c && chr <= *p)
-						found = 1;
-					p++;
-				} else {
-					if (chr == c)
-						found = 1;
-				}
-			} while ((c = *p++) != ']');
-			if (found == invert)
-				return 0;
-			break;
-		}
-dft:	    default:
-			if (*q++ != c)
-				return 0;
-			break;
-		}
-	}
-breakloop:
-	if (*q != '\0')
-		return 0;
-	return 1;
-}
-
-
-
-/*
- * Remove any CTLESC characters from a string.
- */
-
-void
-rmescapes(str)
-	char *str;
-	{
-	register char *p, *q;
-
-	p = str;
-	while (*p != CTLESC) {
-		if (*p++ == '\0')
-			return;
-	}
-	q = p;
-	while (*p) {
-		if (*p == CTLESC)
-			p++;
-		*q++ = *p++;
-	}
-	*q = '\0';
-}
-
-
-
-/*
- * See if a pattern matches in a case statement.
- */
-
-int
-casematch(pattern, val)
-	union node *pattern;
-	char *val;
-	{
-	struct stackmark smark;
-	int result;
-	char *p;
-
-	setstackmark(&smark);
-	argbackq = pattern->narg.backquote;
-	STARTSTACKSTR(expdest);
-	ifslastp = NULL;
-	/* Preserve any CTLESC characters inserted previously, so that
-	   we won't expand reg exps which are inside strings.  */
-	argstr(pattern->narg.text, 1);
-	STPUTC('\0', expdest);
-	p = grabstackstr(expdest);
-	result = patmatch(p, val);
-	popstackmark(&smark);
-	return result;
-}
Index: trunk/minix/commands/ash/expand.h
===================================================================
--- trunk/minix/commands/ash/expand.h	(revision 9)
+++ 	(revision )
@@ -1,63 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)expand.h	5.1 (Berkeley) 3/7/91
- */
-
-struct strlist {
-	struct strlist *next;
-	char *text;
-};
-
-
-struct arglist {
-	struct strlist *list;
-	struct strlist **lastp;
-};
-
-#ifdef __STDC__
-union node;
-void expandarg(union node *, struct arglist *, int);
-void expandhere(union node *, int);
-int patmatch(char *, char *);
-void rmescapes(char *);
-int casematch(union node *, char *);
-#else
-void expandarg();
-void expandhere();
-int patmatch();
-void rmescapes();
-int casematch();
-#endif
Index: trunk/minix/commands/ash/funcs/cmv
===================================================================
--- trunk/minix/commands/ash/funcs/cmv	(revision 9)
+++ 	(revision )
@@ -1,49 +1,0 @@
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)cmv	5.1 (Berkeley) 3/7/91
-
-# Conditional move--don't replace an existing file.
-
-cmv() {
-	if test $# != 2
-	then	echo "cmv: arg count"
-		return 2
-	fi
-	if test -f "$2" -o -w "$2"
-	then	echo "$2 exists"
-		return 2
-	fi
-	/bin/mv "$1" "$2"
-}
Index: trunk/minix/commands/ash/funcs/dirs
===================================================================
--- trunk/minix/commands/ash/funcs/dirs	(revision 9)
+++ 	(revision )
@@ -1,73 +1,0 @@
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)dirs	5.1 (Berkeley) 3/7/91
-
-# pushd, popd, and dirs --- written by Chris Bertin
-# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
-# as modified by Patrick Elam of GTRI and Kenneth Almquist at UW
-
-pushd () {
-	SAVE=`pwd`
-	if [ "$1" = "" ] 
-	then	if [ "$DSTACK" = "" ]
-		then	echo "pushd: directory stack empty."
-			return 1
-		fi
-		set $DSTACK
-		cd $1 || return
-		shift 1
-		DSTACK="$*"
-	else	cd $1 > /dev/null || return
-	fi
-	DSTACK="$SAVE $DSTACK"
-	dirs
-}
-
-popd () {
-	if [ "$DSTACK" = "" ] 
-	then	echo "popd: directory stack empty."
-		return 1
-	fi
-	set $DSTACK
-	cd $1
-	shift
-	DSTACK=$*
-	dirs
-}
-
-dirs () {
-	echo "`pwd` $DSTACK"
-	return 0
-}
Index: trunk/minix/commands/ash/funcs/kill
===================================================================
--- trunk/minix/commands/ash/funcs/kill	(revision 9)
+++ 	(revision )
@@ -1,49 +1,0 @@
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)kill	5.1 (Berkeley) 3/7/91
-
-# Convert job names to process ids and then run /bin/kill.
-
-kill() {
-	local args x
-	args=
-	for x in "$@"
-	do	case $x in
-		%*)	x=`jobid "$x"` ;;
-		esac
-		args="$args $x"
-	done
-	/bin/kill $args
-}
Index: trunk/minix/commands/ash/funcs/login
===================================================================
--- trunk/minix/commands/ash/funcs/login	(revision 9)
+++ 	(revision )
@@ -1,38 +1,0 @@
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)login	5.1 (Berkeley) 3/7/91
-
-# replaces the login builtin in the BSD shell
-login () exec login "$@"
Index: trunk/minix/commands/ash/funcs/newgrp
===================================================================
--- trunk/minix/commands/ash/funcs/newgrp	(revision 9)
+++ 	(revision )
@@ -1,37 +1,0 @@
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)newgrp	5.1 (Berkeley) 3/7/91
-
-newgrp() exec newgrp "$@"
Index: trunk/minix/commands/ash/funcs/popd
===================================================================
--- trunk/minix/commands/ash/funcs/popd	(revision 9)
+++ 	(revision )
@@ -1,73 +1,0 @@
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)popd	5.1 (Berkeley) 3/7/91
-
-# pushd, popd, and dirs --- written by Chris Bertin
-# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
-# as modified by Patrick Elam of GTRI and Kenneth Almquist at UW
-
-pushd () {
-	SAVE=`pwd`
-	if [ "$1" = "" ] 
-	then	if [ "$DSTACK" = "" ]
-		then	echo "pushd: directory stack empty."
-			return 1
-		fi
-		set $DSTACK
-		cd $1 || return
-		shift 1
-		DSTACK="$*"
-	else	cd $1 > /dev/null || return
-	fi
-	DSTACK="$SAVE $DSTACK"
-	dirs
-}
-
-popd () {
-	if [ "$DSTACK" = "" ] 
-	then	echo "popd: directory stack empty."
-		return 1
-	fi
-	set $DSTACK
-	cd $1
-	shift
-	DSTACK=$*
-	dirs
-}
-
-dirs () {
-	echo "`pwd` $DSTACK"
-	return 0
-}
Index: trunk/minix/commands/ash/funcs/pushd
===================================================================
--- trunk/minix/commands/ash/funcs/pushd	(revision 9)
+++ 	(revision )
@@ -1,73 +1,0 @@
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)pushd	5.1 (Berkeley) 3/7/91
-
-# pushd, popd, and dirs --- written by Chris Bertin
-# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
-# as modified by Patrick Elam of GTRI and Kenneth Almquist at UW
-
-pushd () {
-	SAVE=`pwd`
-	if [ "$1" = "" ] 
-	then	if [ "$DSTACK" = "" ]
-		then	echo "pushd: directory stack empty."
-			return 1
-		fi
-		set $DSTACK
-		cd $1 || return
-		shift 1
-		DSTACK="$*"
-	else	cd $1 > /dev/null || return
-	fi
-	DSTACK="$SAVE $DSTACK"
-	dirs
-}
-
-popd () {
-	if [ "$DSTACK" = "" ] 
-	then	echo "popd: directory stack empty."
-		return 1
-	fi
-	set $DSTACK
-	cd $1
-	shift
-	DSTACK=$*
-	dirs
-}
-
-dirs () {
-	echo "`pwd` $DSTACK"
-	return 0
-}
Index: trunk/minix/commands/ash/funcs/suspend
===================================================================
--- trunk/minix/commands/ash/funcs/suspend	(revision 9)
+++ 	(revision )
@@ -1,41 +1,0 @@
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)suspend	5.1 (Berkeley) 3/7/91
-
-suspend() {
-	local -
-	set +j
-	kill -TSTP 0
-}
Index: trunk/minix/commands/ash/init.h
===================================================================
--- trunk/minix/commands/ash/init.h	(revision 9)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)init.h	5.1 (Berkeley) 3/7/91
- */
-
-#ifdef __STDC__
-void init(void);
-void reset(void);
-void initshellproc(void);
-#else
-void init();
-void reset();
-void initshellproc();
-#endif
Index: trunk/minix/commands/ash/input.c
===================================================================
--- trunk/minix/commands/ash/input.c	(revision 9)
+++ 	(revision )
@@ -1,414 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)input.c	5.4 (Berkeley) 7/1/91";
-#endif /* not lint */
-
-/*
- * This file implements the input routines used by the parser.
- */
-
-#include <sys/types.h>
-#include <stdio.h>	/* defines BUFSIZ */
-#include "shell.h"
-#include <fcntl.h>
-#include <errno.h>
-#include "syntax.h"
-#include "input.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-
-#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
-
-
-/*
- * The parsefile structure pointed to by the global variable parsefile
- * contains information about the current file being read.
- */
-
-MKINIT
-struct parsefile {
-	int linno;		/* current line */
-	int fd;			/* file descriptor (or -1 if string) */
-	int nleft;		/* number of chars left in buffer */
-	char *nextc;		/* next char in buffer */
-	struct parsefile *prev;	/* preceding file on stack */
-	char *buf;		/* input buffer */
-};
-
-
-int plinno = 1;			/* input line number */
-MKINIT int parsenleft;		/* copy of parsefile->nleft */
-char *parsenextc;		/* copy of parsefile->nextc */
-MKINIT struct parsefile basepf;	/* top level input file */
-char basebuf[BUFSIZ];		/* buffer for top level input file */
-struct parsefile *parsefile = &basepf;	/* current input file */
-char *pushedstring;		/* copy of parsenextc when text pushed back */
-int pushednleft;		/* copy of parsenleft when text pushed back */
-
-#if READLINE
-char *readline __P((const char *prompt));
-char *r_use_prompt = NULL;	/* the prompt to use with readline */
-#endif
-
-#ifdef __STDC__
-STATIC void pushfile(void);
-#else
-STATIC void pushfile();
-#endif
-
-
-
-#ifdef mkinit
-INCLUDE "input.h"
-INCLUDE "error.h"
-
-INIT {
-	extern char basebuf[];
-
-	basepf.nextc = basepf.buf = basebuf;
-}
-
-RESET {
-	if (exception != EXSHELLPROC)
-		parsenleft = 0;            /* clear input buffer */
-	popallfiles();
-}
-
-SHELLPROC {
-	popallfiles();
-}
-#endif
-
-
-/*
- * Read a line from the script.
- */
-
-char *
-pfgets(line, len)
-	char *line;
-	{
-	register char *p = line;
-	int nleft = len;
-	int c;
-
-	while (--nleft > 0) {
-		c = pgetc_macro();
-		if (c == PEOF) {
-			if (p == line)
-				return NULL;
-			break;
-		}
-		*p++ = c;
-		if (c == '\n')
-			break;
-	}
-	*p = '\0';
-	return line;
-}
-
-
-
-/*
- * Read a character from the script, returning PEOF on end of file.
- * Nul characters in the input are silently discarded.
- */
-
-int
-pgetc() {
-	return pgetc_macro();
-}
-
-
-/*
- * Refill the input buffer and return the next input character:
- *
- * 1) If a string was pushed back on the input, switch back to the regular
- *    buffer.
- * 2) If an EOF was pushed back (parsenleft == EOF_NLEFT) or we are reading
- *    from a string so we can't refill the buffer, return EOF.
- * 3) Call read to read in the characters.
- * 4) Delete all nul characters from the buffer.
- */
-
-int
-preadbuffer() {
-	register char *p, *q;
-	register int i;
-
-	if (pushedstring) {
-		parsenextc = pushedstring;
-		pushedstring = NULL;
-		parsenleft = pushednleft;
-		if (--parsenleft >= 0)
-			return *parsenextc++;
-	}
-	if (parsenleft == EOF_NLEFT || parsefile->buf == NULL)
-		return PEOF;
-	flushout(&output);
-	flushout(&errout);
-#if READLINE
-    /* Use the readline() call if a prompt is to be printed (interactive). */
-    if (r_use_prompt != NULL) {
-	char *prompt;
-	char *line;
-
-	p = parsenextc = parsefile->buf;
-
-	prompt = r_use_prompt;
-	r_use_prompt = NULL;
-
-	if ((line = readline(prompt)) == NULL) {
-                parsenleft = EOF_NLEFT;
-                return PEOF;
-	}
-	strcpy(p, line);
-	free(line);
-	i = strlen(p);
-	p[i++] = '\n';
-    } else {
-#endif
-retry:
-	p = parsenextc = parsefile->buf;
-	i = read(parsefile->fd, p, BUFSIZ);
-	if (i <= 0) {
-                if (i < 0) {
-                        if (errno == EINTR)
-                                goto retry;
-#ifdef EWOULDBLOCK
-                        if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
-                                int flags = fcntl(0, F_GETFL, 0);
-                                if (flags >= 0 && flags & O_NONBLOCK) {
-                                        flags &=~ O_NONBLOCK;
-                                        if (fcntl(0, F_SETFL, flags) >= 0) {
-						out2str("sh: turning off NDELAY mode\n");
-                                                goto retry;
-                                        }
-                                }
-                        }
-#endif
-                }
-                parsenleft = EOF_NLEFT;
-                return PEOF;
-	}
-#if READLINE
-    }
-#endif
-	parsenleft = i - 1;
-
-	/* delete nul characters */
-	for (;;) {
-		if (*p++ == '\0')
-			break;
-		if (--i <= 0)
-			return *parsenextc++;		/* no nul characters */
-	}
-	q = p - 1;
-	while (--i > 0) {
-		if (*p != '\0')
-			*q++ = *p;
-		p++;
-	}
-	if (q == parsefile->buf)
-		goto retry;			/* buffer contained nothing but nuls */
-	parsenleft = q - parsefile->buf - 1;
-	return *parsenextc++;
-}
-
-
-/*
- * Undo the last call to pgetc.  Only one character may be pushed back.
- * PEOF may be pushed back.
- */
-
-void
-pungetc() {
-	parsenleft++;
-	parsenextc--;
-}
-
-
-/*
- * Push a string back onto the input.  This code doesn't work if the user
- * tries to push back more than one string at once.
- */
-
-void
-ppushback(string, length)
-	char *string;
-	{
-	pushedstring = parsenextc;
-	pushednleft = parsenleft;
-	parsenextc = string;
-	parsenleft = length;
-}
-
-
-
-/*
- * Set the input to take input from a file.  If push is set, push the
- * old input onto the stack first.
- */
-
-void
-setinputfile(fname, push)
-	char *fname;
-	{
-	int fd;
-	int fd2;
-
-	INTOFF;
-	if ((fd = open(fname, O_RDONLY)) < 0)
-		error("Can't open %s", fname);
-	if (fd < 10) {
-		fd2 = copyfd(fd, 10);
-		close(fd);
-		if (fd2 < 0)
-			error("Out of file descriptors");
-		fd = fd2;
-	}
-	setinputfd(fd, push);
-	INTON;
-}
-
-
-/*
- * Like setinputfile, but takes an open file descriptor.  Call this with
- * interrupts off.
- */
-
-void
-setinputfd(fd, push) {
-	(void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
-	if (push) {
-		pushfile();
-		parsefile->buf = ckmalloc(BUFSIZ);
-	}
-	if (parsefile->fd > 0)
-		close(parsefile->fd);
-	parsefile->fd = fd;
-	if (parsefile->buf == NULL)
-		parsefile->buf = ckmalloc(BUFSIZ);
-	parsenleft = 0;
-	plinno = 1;
-}
-
-
-/*
- * Like setinputfile, but takes input from a string.
- */
-
-void
-setinputstring(string, push)
-	char *string;
-	{
-	INTOFF;
-	if (push)
-		pushfile();
-	parsenextc = string;
-	parsenleft = strlen(string);
-	parsefile->buf = NULL;
-	plinno = 1;
-	INTON;
-}
-
-
-
-/*
- * To handle the "." command, a stack of input files is used.  Pushfile
- * adds a new entry to the stack and popfile restores the previous level.
- */
-
-STATIC void
-pushfile() {
-	struct parsefile *pf;
-
-	parsefile->nleft = parsenleft;
-	parsefile->nextc = parsenextc;
-	parsefile->linno = plinno;
-	pf = (struct parsefile *)ckmalloc(sizeof (struct parsefile));
-	pf->prev = parsefile;
-	pf->fd = -1;
-	parsefile = pf;
-}
-
-
-void
-popfile() {
-	struct parsefile *pf = parsefile;
-
-	INTOFF;
-	if (pf->fd >= 0)
-		close(pf->fd);
-	if (pf->buf)
-		ckfree(pf->buf);
-	parsefile = pf->prev;
-	ckfree(pf);
-	parsenleft = parsefile->nleft;
-	parsenextc = parsefile->nextc;
-	plinno = parsefile->linno;
-	INTON;
-}
-
-
-/*
- * Return to top level.
- */
-
-void
-popallfiles() {
-	while (parsefile != &basepf)
-		popfile();
-}
-
-
-
-/*
- * Close the file(s) that the shell is reading commands from.  Called
- * after a fork is done.
- */
-
-void
-closescript() {
-	popallfiles();
-	if (parsefile->fd > 0) {
-		close(parsefile->fd);
-		parsefile->fd = 0;
-	}
-}
Index: trunk/minix/commands/ash/input.h
===================================================================
--- trunk/minix/commands/ash/input.h	(revision 9)
+++ 	(revision )
@@ -1,84 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)input.h	5.1 (Berkeley) 3/7/91
- */
-
-/* PEOF (the end of file marker) is defined in syntax.h */
-
-/*
- * The input line number.  Input.c just defines this variable, and saves
- * and restores it when files are pushed and popped.  The user of this
- * package must set its value.
- */
-extern int plinno;
-extern int parsenleft;		/* number of characters left in input buffer */
-extern char *parsenextc;	/* next character in input buffer */
-
-
-#ifdef __STDC__
-char *pfgets(char *, int);
-int pgetc(void);
-int preadbuffer(void);
-void pungetc(void);
-void ppushback(char *, int);
-void setinputfile(char *, int);
-void setinputfd(int, int);
-void setinputstring(char *, int);
-void popfile(void);
-void popallfiles(void);
-void closescript(void);
-#else
-char *pfgets();
-int pgetc();
-int preadbuffer();
-void pungetc();
-void ppushback();
-void setinputfile();
-void setinputfd();
-void setinputstring();
-void popfile();
-void popallfiles();
-void closescript();
-#endif
-
-#define pgetc_macro()	(--parsenleft >= 0? *parsenextc++ : preadbuffer())
-
-#if READLINE
-/* The variable "r_use_prompt" indicates the prompt to use with readline,
- * *and* that readline may only be used if non-NULL.
- */
-extern char *r_use_prompt;
-#endif
Index: trunk/minix/commands/ash/jobs.c
===================================================================
--- trunk/minix/commands/ash/jobs.c	(revision 9)
+++ 	(revision )
@@ -1,1035 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)jobs.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-#include "shell.h"
-#if JOBS
-#include "sgtty.h"
-#undef CEOF			/* syntax.h redefines this */
-#endif
-#include "main.h"
-#include "parser.h"
-#include "nodes.h"
-#include "jobs.h"
-#include "options.h"
-#include "trap.h"
-#include "signames.h"
-#include "syntax.h"
-#include "input.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-#include "redir.h"
-#include <sys/types.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <errno.h>
-#ifdef BSD
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif
-#if POSIX
-#include <sys/wait.h>
-#endif
-
-
-
-struct job *jobtab;		/* array of jobs */
-int njobs;			/* size of array */
-MKINIT pid_t backgndpid = -1;	/* pid of last background process */
-#if JOBS
-int initialpgrp;		/* pgrp of shell on invocation */
-pid_t curjob;			/* current job */
-#endif
-
-#ifdef __STDC__
-STATIC void restartjob(struct job *);
-STATIC struct job *getjob(char *);
-STATIC void freejob(struct job *);
-STATIC int procrunning(int);
-STATIC int dowait(int, struct job *);
-STATIC int waitproc(int, int *);
-STATIC char *commandtext(union node *);
-#else
-STATIC void restartjob();
-STATIC struct job *getjob();
-STATIC void freejob();
-STATIC int procrunning();
-STATIC int dowait();
-STATIC int waitproc();
-STATIC char *commandtext();
-#endif
-
-
- 
-#if JOBS
-/*
- * Turn job control on and off.
- *
- * Note:  This code assumes that the third arg to ioctl is a character
- * pointer, which is true on Berkeley systems but not System V.  Since
- * System V doesn't have job control yet, this isn't a problem now.
- */
-
-MKINIT int jobctl;
-
-void
-setjobctl(on) {
-	int ldisc;
-
-	if (on == jobctl || rootshell == 0)
-		return;
-	if (on) {
-		do { /* while we are in the background */
-			if (ioctl(2, TIOCGPGRP, (char *)&initialpgrp) < 0) {
-				out2str("ash: can't access tty; job control turned off\n");
-				jflag = 0;
-				return;
-			}
-			if (initialpgrp == -1)
-				initialpgrp = getpgrp(0);
-			else if (initialpgrp != getpgrp(0)) {
-				killpg(initialpgrp, SIGTTIN);
-				continue;
-			}
-		} while (0);
-		if (ioctl(2, TIOCGETD, (char *)&ldisc) < 0 || ldisc != NTTYDISC) {
-			out2str("ash: need new tty driver to run job control; job control turned off\n");
-			jflag = 0;
-			return;
-		}
-		setsignal(SIGTSTP);
-		setsignal(SIGTTOU);
-		setpgrp(0, rootpid);
-		ioctl(2, TIOCSPGRP, (char *)&rootpid);
-	} else { /* turning job control off */
-		setpgrp(0, initialpgrp);
-		ioctl(2, TIOCSPGRP, (char *)&initialpgrp);
-		setsignal(SIGTSTP);
-		setsignal(SIGTTOU);
-	}
-	jobctl = on;
-}
-#endif
-
-
-#ifdef mkinit
-
-SHELLPROC {
-	backgndpid = -1;
-#if JOBS
-	jobctl = 0;
-#endif
-}
-
-#endif
-
-
-
-#if JOBS
-fgcmd(argc, argv)  char **argv; {
-	struct job *jp;
-	int pgrp;
-	int status;
-
-	jp = getjob(argv[1]);
-	if (jp->jobctl == 0)
-		error("job not created under job control");
-	pgrp = jp->ps[0].pid;
-	ioctl(2, TIOCSPGRP, (char *)&pgrp);
-	restartjob(jp);
-	INTOFF;
-	status = waitforjob(jp);
-	INTON;
-	return status;
-}
-
-
-bgcmd(argc, argv)  char **argv; {
-	struct job *jp;
-
-	do {
-		jp = getjob(*++argv);
-		if (jp->jobctl == 0)
-			error("job not created under job control");
-		restartjob(jp);
-	} while (--argc > 1);
-	return 0;
-}
-
-
-STATIC void
-restartjob(jp)
-	struct job *jp;
-	{
-	struct procstat *ps;
-	int i;
-
-	if (jp->state == JOBDONE)
-		return;
-	INTOFF;
-	killpg(jp->ps[0].pid, SIGCONT);
-	for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) {
-		if ((ps->status & 0377) == 0177) {
-			ps->status = -1;
-			jp->state = 0;
-		}
-	}
-	INTON;
-}
-#endif
-
-
-int
-jobscmd(argc, argv)  char **argv; {
-	showjobs(0);
-	return 0;
-}
-
-
-/*
- * Print a list of jobs.  If "change" is nonzero, only print jobs whose
- * statuses have changed since the last call to showjobs.
- *
- * If the shell is interrupted in the process of creating a job, the
- * result may be a job structure containing zero processes.  Such structures
- * will be freed here.
- */
-
-void
-showjobs(change) {
-	int jobno;
-	int procno;
-	int i;
-	struct job *jp;
-	struct procstat *ps;
-	int col;
-	char s[64];
-
-	TRACE(("showjobs(%d) called\n", change));
-	while (dowait(0, (struct job *)NULL) > 0);
-	for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) {
-		if (! jp->used)
-			continue;
-		if (jp->nprocs == 0) {
-			freejob(jp);
-			continue;
-		}
-		if (change && ! jp->changed)
-			continue;
-		procno = jp->nprocs;
-		for (ps = jp->ps ; ; ps++) {	/* for each process */
-			if (ps == jp->ps)
-				fmtstr(s, 64, "[%d] %d ", jobno, ps->pid);
-			else
-				fmtstr(s, 64, "    %d ", ps->pid);
-			out1str(s);
-			col = strlen(s);
-			s[0] = '\0';
-			if (ps->status == -1) {
-				/* don't print anything */
-			} else if ((ps->status & 0xFF) == 0) {
-				fmtstr(s, 64, "Exit %d", ps->status >> 8);
-			} else {
-				i = ps->status;
-#if JOBS
-				if ((i & 0xFF) == 0177)
-					i >>= 8;
-#endif
-				if ((i & 0x7F) <= MAXSIG && sigmesg[i & 0x7F])
-					scopy(sigmesg[i & 0x7F], s);
-				else
-					fmtstr(s, 64, "Signal %d", i & 0x7F);
-				if (i & 0x80)
-					strcat(s, " (core dumped)");
-			}
-			out1str(s);
-			col += strlen(s);
-			do {
-				out1c(' ');
-				col++;
-			} while (col < 30);
-			out1str(ps->cmd);
-			out1c('\n');
-			if (--procno <= 0)
-				break;
-		}
-		jp->changed = 0;
-		if (jp->state == JOBDONE) {
-			freejob(jp);
-		}
-	}
-}
-
-
-/*
- * Mark a job structure as unused.
- */
-
-STATIC void
-freejob(jp)
-	struct job *jp;
-	{
-	struct procstat *ps;
-	int i;
-
-	INTOFF;
-	for (i = jp->nprocs, ps = jp->ps ; --i >= 0 ; ps++) {
-		if (ps->cmd != nullstr)
-			ckfree(ps->cmd);
-	}
-	if (jp->ps != &jp->ps0)
-		ckfree(jp->ps);
-	jp->used = 0;
-#if JOBS
-	if (curjob == jp - jobtab + 1)
-		curjob = 0;
-#endif
-	INTON;
-}
-
-
-
-int
-waitcmd(argc, argv)  char **argv; {
-	struct job *job;
-	int status;
-	struct job *jp;
-
-	if (argc > 1) {
-		job = getjob(argv[1]);
-	} else {
-		job = NULL;
-	}
-	for (;;) {	/* loop until process terminated or stopped */
-		if (job != NULL) {
-			if (job->state) {
-				status = job->ps[job->nprocs - 1].status;
-				if ((status & 0xFF) == 0)
-					status = status >> 8 & 0xFF;
-#if JOBS
-				else if ((status & 0xFF) == 0177)
-					status = (status >> 8 & 0x7F) + 128;
-#endif
-				else
-					status = (status & 0x7F) + 128;
-				if (! iflag)
-					freejob(job);
-				return status;
-			}
-		} else {
-			for (jp = jobtab ; ; jp++) {
-				if (jp >= jobtab + njobs) {	/* no running procs */
-					return 0;
-				}
-				if (jp->used && jp->state == 0)
-					break;
-			}
-		}
-		dowait(1, (struct job *)NULL);
-	}
-}
-
-
-
-jobidcmd(argc, argv)  char **argv; {
-	struct job *jp;
-	int i;
-
-	jp = getjob(argv[1]);
-	for (i = 0 ; i < jp->nprocs ; ) {
-		out1fmt("%d", jp->ps[i].pid);
-		out1c(++i < jp->nprocs? ' ' : '\n');
-	}
-	return 0;
-}
-
-
-
-/*
- * Convert a job name to a job structure.
- */
-
-STATIC struct job *
-getjob(name)
-	char *name;
-	{
-	int jobno;
-	register struct job *jp;
-	int pid;
-	int i;
-
-	if (name == NULL) {
-#if JOBS
-currentjob:
-		if ((jobno = curjob) == 0 || jobtab[jobno - 1].used == 0)
-			error("No current job");
-		return &jobtab[jobno - 1];
-#else
-		error("No current job");
-#endif
-	} else if (name[0] == '%') {
-		if (is_digit(name[1])) {
-			jobno = number(name + 1);
-			if (jobno > 0 && jobno <= njobs
-			 && jobtab[jobno - 1].used != 0)
-				return &jobtab[jobno - 1];
-#if JOBS
-		} else if (name[1] == '%' && name[2] == '\0') {
-			goto currentjob;
-#endif
-		} else {
-			register struct job *found = NULL;
-			for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
-				if (jp->used && jp->nprocs > 0
-				 && prefix(name + 1, jp->ps[0].cmd)) {
-					if (found)
-						error("%s: ambiguous", name);
-					found = jp;
-				}
-			}
-			if (found)
-				return found;
-		}
-	} else if (is_number(name)) {
-		pid = number(name);
-		for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
-			if (jp->used && jp->nprocs > 0
-			 && jp->ps[jp->nprocs - 1].pid == pid)
-				return jp;
-		}
-	}
-	error("No such job: %s", name);
-}
-
-
-
-/*
- * Return a new job structure,
- */
-
-struct job *
-makejob(node, nprocs)
-	union node *node;
-	{
-	int i;
-	struct job *jp;
-
-	for (i = njobs, jp = jobtab ; ; jp++) {
-		if (--i < 0) {
-			INTOFF;
-			if (njobs == 0) {
-				jobtab = ckmalloc(4 * sizeof jobtab[0]);
-			} else {
-				jp = ckmalloc((njobs + 4) * sizeof jobtab[0]);
-				bcopy(jobtab, jp, njobs * sizeof jp[0]);
-				for (i= 0; i<njobs; i++)
-				{
-					if (jobtab[i].ps == &jobtab[i].ps0)
-						jp[i].ps= &jp[i].ps0;
-				}
-				ckfree(jobtab);
-				jobtab = jp;
-			}
-			jp = jobtab + njobs;
-			for (i = 4 ; --i >= 0 ; jobtab[njobs++].used = 0);
-			INTON;
-			break;
-		}
-		if (jp->used == 0)
-			break;
-	}
-	INTOFF;
-	jp->state = 0;
-	jp->used = 1;
-	jp->changed = 0;
-	jp->nprocs = 0;
-#if JOBS
-	jp->jobctl = jobctl;
-#endif
-	if (nprocs > 1) {
-		jp->ps = ckmalloc(nprocs * sizeof (struct procstat));
-	} else {
-		jp->ps = &jp->ps0;
-	}
-	INTON;
-	TRACE(("makejob(0x%x, %d) returns %%%d\n", (int)node, nprocs, jp - jobtab + 1));
-	return jp;
-}	
-
-
-/*
- * Fork of a subshell.  If we are doing job control, give the subshell its
- * own process group.  Jp is a job structure that the job is to be added to.
- * N is the command that will be evaluated by the child.  Both jp and n may
- * be NULL.  The mode parameter can be one of the following:
- *	FORK_FG - Fork off a foreground process.
- *	FORK_BG - Fork off a background process.
- *	FORK_NOJOB - Like FORK_FG, but don't give the process its own
- *		     process group even if job control is on.
- *
- * When job control is turned off, background processes have their standard
- * input redirected to /dev/null (except for the second and later processes
- * in a pipeline).
- */
-
-int
-forkshell(jp, n, mode)
-	union node *n;
-	struct job *jp;
-	{
-	int pid;
-	int pgrp;
-
-	TRACE(("forkshell(%%%d, 0x%x, %d) called\n", jp - jobtab, (int)n, mode));
-	INTOFF;
-	pid = fork();
-	if (pid == -1) {
-		TRACE(("Fork failed, errno=%d\n", errno));
-		INTON;
-		error("Cannot fork");
-	}
-	if (pid == 0) {
-		struct job *p;
-		int wasroot;
-		int i;
-
-		TRACE(("Child shell %d\n", getpid()));
-		wasroot = rootshell;
-		rootshell = 0;
-		for (i = njobs, p = jobtab ; --i >= 0 ; p++)
-			if (p->used)
-				freejob(p);
-		closescript();
-		INTON;
-		clear_traps();
-#if JOBS
-		jobctl = 0;		/* do job control only in root shell */
-		if (wasroot && mode != FORK_NOJOB && jflag) {
-			if (jp == NULL || jp->nprocs == 0)
-				pgrp = getpid();
-			else
-				pgrp = jp->ps[0].pid;
-			setpgrp(0, pgrp);
-			if (mode == FORK_FG) {
-				/*** this causes superfluous TIOCSPGRPS ***/
-				if (ioctl(2, TIOCSPGRP, (char *)&pgrp) < 0)
-					error("TIOCSPGRP failed, errno=%d\n", errno);
-			}
-			setsignal(SIGTSTP);
-			setsignal(SIGTTOU);
-		} else if (mode == FORK_BG) {
-			ignoresig(SIGINT);
-			ignoresig(SIGQUIT);
-			if ((jp == NULL || jp->nprocs == 0)
-			    && ! fd0_redirected_p ()) {
-				close(0);
-				if (open("/dev/null", O_RDONLY) != 0)
-					error("Can't open /dev/null");
-			}
-		}
-#else
-		if (mode == FORK_BG) {
-			ignoresig(SIGINT);
-			ignoresig(SIGQUIT);
-			if ((jp == NULL || jp->nprocs == 0)
-			    && ! fd0_redirected_p ()) {
-				close(0);
-				if (open("/dev/null", O_RDONLY) != 0)
-					error("Can't open /dev/null");
-			}
-		}
-#endif
-		if (wasroot && iflag) {
-			setsignal(SIGINT);
-			setsignal(SIGQUIT);
-			setsignal(SIGTERM);
-		}
-		return pid;
-	}
-	if (rootshell && mode != FORK_NOJOB && jflag) {
-		if (jp == NULL || jp->nprocs == 0)
-			pgrp = pid;
-		else
-			pgrp = jp->ps[0].pid;
-#if JOBS
-		setpgrp(pid, pgrp);
-#endif
-	}
-	if (mode == FORK_BG)
-		backgndpid = pid;		/* set $! */
-	if (jp) {
-		struct procstat *ps = &jp->ps[jp->nprocs++];
-		ps->pid = pid;
-		ps->status = -1;
-		ps->cmd = nullstr;
-		if (iflag && rootshell && n)
-			ps->cmd = commandtext(n);
-	}
-	INTON;
-	TRACE(("In parent shell:  child = %d\n", pid));
-	return pid;
-}
-
-
-
-/*
- * Wait for job to finish.
- *
- * Under job control we have the problem that while a child process is
- * running interrupts generated by the user are sent to the child but not
- * to the shell.  This means that an infinite loop started by an inter-
- * active user may be hard to kill.  With job control turned off, an
- * interactive user may place an interactive program inside a loop.  If
- * the interactive program catches interrupts, the user doesn't want
- * these interrupts to also abort the loop.  The approach we take here
- * is to have the shell ignore interrupt signals while waiting for a
- * forground process to terminate, and then send itself an interrupt
- * signal if the child process was terminated by an interrupt signal.
- * Unfortunately, some programs want to do a bit of cleanup and then
- * exit on interrupt; unless these processes terminate themselves by
- * sending a signal to themselves (instead of calling exit) they will
- * confuse this approach.
- */
-
-int
-waitforjob(jp)
-	register struct job *jp;
-	{
-#if JOBS
-	int mypgrp = getpgrp(0);
-#endif
-	int status;
-	int st;
-
-	INTOFF;
-	TRACE(("waitforjob(%%%d) called\n", jp - jobtab + 1));
-	while (jp->state == 0 && dowait(1, jp) != -1) ;
-#if JOBS
-	if (jp->jobctl) {
-		if (ioctl(2, TIOCSPGRP, (char *)&mypgrp) < 0)
-			error("TIOCSPGRP failed, errno=%d\n", errno);
-	}
-	if (jp->state == JOBSTOPPED)
-		curjob = jp - jobtab + 1;
-#endif
-	status = jp->ps[jp->nprocs - 1].status;
-	/* convert to 8 bits */
-	if ((status & 0xFF) == 0)
-		st = status >> 8 & 0xFF;
-#if JOBS
-	else if ((status & 0xFF) == 0177)
-		st = (status >> 8 & 0x7F) + 128;
-#endif
-	else
-		st = (status & 0x7F) + 128;
-	if (! JOBS || jp->state == JOBDONE)
-		freejob(jp);
-	CLEAR_PENDING_INT;
-	if ((status & 0x7F) == SIGINT)
-		kill(getpid(), SIGINT);
-	INTON;
-	return st;
-}
-
-
-
-/*
- * Wait for a process to terminate.
- */
-
-STATIC int
-dowait(block, job)
-	struct job *job;
-	{
-	int pid;
-	int status;
-	struct procstat *sp;
-	struct job *jp;
-	struct job *thisjob;
-	int done;
-	int stopped;
-	int core;
-
-	TRACE(("dowait(%d) called\n", block));
-	do {
-		pid = waitproc(block, &status);
-		TRACE(("wait returns %d, status=%d, errno=%d\n",
-				pid, status, errno));
-	} while (pid == -1 && errno == EINTR);
-	if (pid <= 0)
-		return pid;
-	INTOFF;
-	thisjob = NULL;
-	for (jp = jobtab ; jp < jobtab + njobs ; jp++) {
-		if (jp->used) {
-			done = 1;
-			stopped = 1;
-			for (sp = jp->ps ; sp < jp->ps + jp->nprocs ; sp++) {
-				if (sp->pid == -1)
-					continue;
-				if (sp->pid == pid) {
-					TRACE(("Changin status of proc %d from 0x%x to 0x%x\n", pid, sp->status, status));
-					sp->status = status;
-					thisjob = jp;
-				}
-				if (sp->status == -1)
-					stopped = 0;
-				else if ((sp->status & 0377) == 0177)
-					done = 0;
-			}
-			if (stopped) {		/* stopped or done */
-				int state = done? JOBDONE : JOBSTOPPED;
-				if (jp->state != state) {
-					TRACE(("Job %d: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state));
-					jp->state = state;
-#if JOBS
-					if (done && curjob == jp - jobtab + 1)
-						curjob = 0;		/* no current job */
-#endif
-				}
-			}
-		}
-	}
-	INTON;
-	if (! rootshell || ! iflag || (job && thisjob == job)) {
-#if JOBS
-		if ((status & 0xFF) == 0177)
-			status >>= 8;
-#endif
-		core = status & 0x80;
-		status &= 0x7F;
-		if (status != 0 && status != SIGINT && status != SIGPIPE) {
-			if (thisjob != job)
-				outfmt(out2, "%d: ", pid);
-#if JOBS
-			if (status == SIGTSTP && rootshell && iflag)
-				outfmt(out2, "%%%d ", job - jobtab + 1);
-#endif
-			if (status <= MAXSIG && sigmesg[status])
-				out2str(sigmesg[status]);
-			else
-				outfmt(out2, "Signal %d", status);
-			if (core)
-				out2str(" - core dumped");
-			out2c('\n');
-			flushout(&errout);
-		} else {
-			TRACE(("Not printing status: status=%d\n", status));
-		}
-	} else {
-		TRACE(("Not printing status, rootshell=%d, job=0x%x\n", rootshell, job));
-		if (thisjob)
-			thisjob->changed = 1;
-	}
-	return pid;
-}
-
-
-
-/*
- * Do a wait system call.  If job control is compiled in, we accept
- * stopped processes.  If block is zero, we return a value of zero
- * rather than blocking.
- *
- * System V doesn't have a non-blocking wait system call.  It does
- * have a SIGCLD signal that is sent to a process when one of it's
- * children dies.  The obvious way to use SIGCLD would be to install
- * a handler for SIGCLD which simply bumped a counter when a SIGCLD
- * was received, and have waitproc bump another counter when it got
- * the status of a process.  Waitproc would then know that a wait
- * system call would not block if the two counters were different.
- * This approach doesn't work because if a process has children that
- * have not been waited for, System V will send it a SIGCLD when it
- * installs a signal handler for SIGCLD.  What this means is that when
- * a child exits, the shell will be sent SIGCLD signals continuously
- * until is runs out of stack space, unless it does a wait call before
- * restoring the signal handler.  The code below takes advantage of
- * this (mis)feature by installing a signal handler for SIGCLD and
- * then checking to see whether it was called.  If there are any
- * children to be waited for, it will be.
- *
- * If neither SYSV nor BSD is defined, we don't implement nonblocking
- * waits at all.  In this case, the user will not be informed when
- * a background process until the next time she runs a real program
- * (as opposed to running a builtin command or just typing return),
- * and the jobs command may give out of date information.
- */
-
-#ifdef SYSV
-STATIC int gotsigchild;
-
-STATIC int onsigchild() {
-	gotsigchild = 1;
-}
-#endif
-
-
-STATIC int
-waitproc(block, status)
-	int *status;
-	{
-#ifdef BSD
-	int flags;
-
-#if JOBS
-	flags = WUNTRACED;
-#else
-	flags = 0;
-#endif
-	if (block == 0)
-		flags |= WNOHANG;
-	return wait3((union wait *)status, flags, (struct rusage *)NULL);
-#else
-#ifdef SYSV
-	int (*save)();
-
-	if (block == 0) {
-		gotsigchild = 0;
-		save = signal(SIGCLD, onsigchild);
-		signal(SIGCLD, save);
-		if (gotsigchild == 0)
-			return 0;
-	}
-	return wait(status);
-#else
-#if POSIX
-	return waitpid(-1, status, block == 0 ? WNOHANG : 0);
-#else
-	if (block == 0)
-		return 0;
-	return wait(status);
-#endif
-#endif
-#endif
-}
-
-
-
-/*
- * Return a string identifying a command (to be printed by the
- * jobs command.
- */
-
-STATIC char *cmdnextc;
-STATIC int cmdnleft;
-STATIC void cmdtxt(), cmdputs();
-
-STATIC char *
-commandtext(n)
-	union node *n;
-	{
-	char *name;
-
-	cmdnextc = name = ckmalloc(50);
-	cmdnleft = 50 - 4;
-	cmdtxt(n);
-	*cmdnextc = '\0';
-	return name;
-}
-
-
-STATIC void
-cmdtxt(n)
-	union node *n;
-	{
-	union node *np;
-	struct nodelist *lp;
-	char *p;
-	int i;
-	char s[2];
-
-	if (n == NULL) return;
-
-	switch (n->type) {
-	case NSEMI:
-		cmdtxt(n->nbinary.ch1);
-		cmdputs("; ");
-		cmdtxt(n->nbinary.ch2);
-		break;
-	case NAND:
-		cmdtxt(n->nbinary.ch1);
-		cmdputs(" && ");
-		cmdtxt(n->nbinary.ch2);
-		break;
-	case NOR:
-		cmdtxt(n->nbinary.ch1);
-		cmdputs(" || ");
-		cmdtxt(n->nbinary.ch2);
-		break;
-	case NPIPE:
-		for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
-			cmdtxt(lp->n);
-			if (lp->next)
-				cmdputs(" | ");
-		}
-		break;
-	case NSUBSHELL:
-		cmdputs("(");
-		cmdtxt(n->nredir.n);
-		cmdputs(")");
-		break;
-	case NREDIR:
-	case NBACKGND:
-		cmdtxt(n->nredir.n);
-		break;
-	case NIF:
-		cmdputs("if ");
-		cmdtxt(n->nif.test);
-		cmdputs("; then ");
-		cmdtxt(n->nif.ifpart);
-		cmdputs("...");
-		break;
-	case NWHILE:
-		cmdputs("while ");
-		goto until;
-	case NUNTIL:
-		cmdputs("until ");
-until:
-		cmdtxt(n->nbinary.ch1);
-		cmdputs("; do ");
-		cmdtxt(n->nbinary.ch2);
-		cmdputs("; done");
-		break;
-	case NFOR:
-		cmdputs("for ");
-		cmdputs(n->nfor.var);
-		cmdputs(" in ...");
-		break;
-	case NCASE:
-		cmdputs("case ");
-		cmdputs(n->ncase.expr->narg.text);
-		cmdputs(" in ...");
-		break;
-	case NDEFUN:
-		cmdputs(n->narg.text);
-		cmdputs("() ...");
-		break;
-	case NCMD:
-		for (np = n->ncmd.args ; np ; np = np->narg.next) {
-			cmdtxt(np);
-			if (np->narg.next)
-				cmdputs(" ");
-		}
-		for (np = n->ncmd.redirect ; np ; np = np->nfile.next) {
-			cmdputs(" ");
-			cmdtxt(np);
-		}
-		break;
-	case NARG:
-		cmdputs(n->narg.text);
-		break;
-	case NTO:
-		p = ">";  i = 1;  goto redir;
-	case NAPPEND:
-		p = ">>";  i = 1;  goto redir;
-	case NTOFD:
-		p = ">&";  i = 1;  goto redir;
-	case NFROM:
-		p = "<";  i = 0;  goto redir;
-	case NFROMFD:
-		p = "<&";  i = 0;  goto redir;
-redir:
-		if (n->nfile.fd != i) {
-			s[0] = n->nfile.fd + '0';
-			s[1] = '\0';
-			cmdputs(s);
-		}
-		cmdputs(p);
-		if (n->type == NTOFD || n->type == NFROMFD) {
-			s[0] = n->ndup.dupfd + '0';
-			s[1] = '\0';
-			cmdputs(s);
-		} else {
-			cmdtxt(n->nfile.fname);
-		}
-		break;
-	case NHERE:
-	case NXHERE:
-		cmdputs("<<...");
-		break;
-	default:
-		cmdputs("???");
-		break;
-	}
-}
-
-
-
-STATIC void
-cmdputs(s)
-	char *s;
-	{
-	register char *p, *q;
-	register char c;
-	int subtype = 0;
-
-	if (cmdnleft <= 0)
-		return;
-	p = s;
-	q = cmdnextc;
-	while ((c = *p++) != '\0') {
-		if (c == CTLESC)
-			*q++ = *p++;
-		else if (c == CTLVAR) {
-			*q++ = '$';
-			if (--cmdnleft > 0)
-				*q++ = '{';
-			subtype = *p++;
-		} else if (c == '=' && subtype != 0) {
-			*q++ = "}-+?="[(subtype & VSTYPE) - VSNORMAL];
-			subtype = 0;
-		} else if (c == CTLENDVAR) {
-			*q++ = '}';
-		} else if (c == CTLBACKQ | c == CTLBACKQ+CTLQUOTE)
-			cmdnleft++;		/* ignore it */
-		else
-			*q++ = c;
-		if (--cmdnleft <= 0) {
-			*q++ = '.';
-			*q++ = '.';
-			*q++ = '.';
-			break;
-		}
-	}
-	cmdnextc = q;
-}
Index: trunk/minix/commands/ash/jobs.h
===================================================================
--- trunk/minix/commands/ash/jobs.h	(revision 9)
+++ 	(revision )
@@ -1,96 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)jobs.h	5.1 (Berkeley) 3/7/91
- */
-
-/* Mode argument to forkshell.  Don't change FORK_FG or FORK_BG. */
-#define FORK_FG 0
-#define FORK_BG 1
-#define FORK_NOJOB 2
-
-
-/*
- * A job structure contains information about a job.  A job is either a
- * single process or a set of processes contained in a pipeline.  In the
- * latter case, pidlist will be non-NULL, and will point to a -1 terminated
- * array of pids.
- */
-
-struct procstat {
-	pid_t pid;		/* process id */
-	short status;		/* status flags (defined above) */
-	char *cmd;		/* text of command being run */
-};
-
-
-/* states */
-#define JOBSTOPPED 1		/* all procs are stopped */
-#define JOBDONE 2		/* all procs are completed */
-
-
-struct job {
-	struct procstat ps0;	/* status of process */
-	struct procstat *ps;	/* status or processes when more than one */
-	pid_t nprocs;		/* number of processes */
-	pid_t pgrp;		/* process group of this job */
-	char state;		/* true if job is finished */
-	char used;		/* true if this entry is in used */
-	char changed;		/* true if status has changed */
-#if JOBS
-	char jobctl;		/* job running under job control */
-#endif
-};
-
-extern pid_t backgndpid;	/* pid of last background process */
-
-
-#ifdef __STDC__
-void setjobctl(int);
-void showjobs(int);
-struct job *makejob(union node *, int);
-int forkshell(struct job *, union node *, int);
-int waitforjob(struct job *);
-#else
-void setjobctl();
-void showjobs();
-struct job *makejob();
-int forkshell();
-int waitforjob();
-#endif
-
-#if ! JOBS
-#define setjobctl(on)	/* do nothing */
-#endif
Index: trunk/minix/commands/ash/machdep.h
===================================================================
--- trunk/minix/commands/ash/machdep.h	(revision 9)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)machdep.h	5.1 (Berkeley) 3/7/91
- */
-
-/*
- * Most machines require the value returned from malloc to be aligned
- * in some way.  The following macro will get this right on many machines.
- */
-
-#ifndef ALIGN
-union align {
-	int i;
-	char *cp;
-};
-
-#define ALIGN(nbytes)	((nbytes) + sizeof(union align) - 1 &~ (sizeof(union align) - 1))
-#endif
Index: trunk/minix/commands/ash/mail.c
===================================================================
--- trunk/minix/commands/ash/mail.c	(revision 9)
+++ 	(revision )
@@ -1,108 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)mail.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * Routines to check for mail.  (Perhaps make part of main.c?)
- */
-
-#include "shell.h"
-#include "exec.h"	/* defines padvance() */
-#include "var.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-
-
-#define MAXMBOXES 10
-
-
-STATIC int nmboxes;			/* number of mailboxes */
-STATIC time_t mailtime[MAXMBOXES];	/* times of mailboxes */
-
-
-
-/*
- * Print appropriate message(s) if mail has arrived.  If the argument is
- * nozero, then the value of MAIL has changed, so we just update the
- * values.
- */
-
-void
-chkmail(silent) {
-	register int i;
-	char *mpath;
-	char *p;
-	register char *q;
-	struct stackmark smark;
-	struct stat statb;
-
-	if (silent)
-		nmboxes = 10;
-	if (nmboxes == 0)
-		return;
-	setstackmark(&smark);
-	mpath = mpathset()? mpathval() : mailval();
-	for (i = 0 ; i < nmboxes ; i++) {
-		p = padvance(&mpath, nullstr);
-		if (p == NULL)
-			break;
-		if (*p == '\0')
-			continue;
-		for (q = p ; *q ; q++);
-		if (q[-1] != '/')
-			abort();
-		q[-1] = '\0';			/* delete trailing '/' */
-		if (stat(p, &statb) < 0)
-			statb.st_mtime = 0;
-		if (!silent
-			&& statb.st_size > 0
-			&& statb.st_mtime > mailtime[i]
-			&& statb.st_mtime > statb.st_atime
-		) {
-			out2str(pathopt? pathopt : "You have mail");
-			out2c('\n');
-		}
-		mailtime[i] = statb.st_mtime;
-	}
-	nmboxes = i;
-	popstackmark(&smark);
-}
Index: trunk/minix/commands/ash/mail.h
===================================================================
--- trunk/minix/commands/ash/mail.h	(revision 9)
+++ 	(revision )
@@ -1,43 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)mail.h	5.1 (Berkeley) 3/7/91
- */
-
-#ifdef __STDC__
-void chkmail(int);
-#else
-void chkmail();
-#endif
Index: trunk/minix/commands/ash/main.c
===================================================================
--- trunk/minix/commands/ash/main.c	(revision 9)
+++ 	(revision )
@@ -1,359 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)main.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <signal.h>
-#include <fcntl.h>
-#include "shell.h"
-#include "main.h"
-#include "mail.h"
-#include "options.h"
-#include "output.h"
-#include "parser.h"
-#include "nodes.h"
-#include "eval.h"
-#include "jobs.h"
-#include "input.h"
-#include "trap.h"
-#if ATTY
-#include "var.h"
-#endif
-#include "memalloc.h"
-#include "error.h"
-#include "init.h"
-#include "mystring.h"
-
-#define PROFILE 0
-
-int rootpid;
-int rootshell;
-STATIC union node *curcmd;
-STATIC union node *prevcmd;
-extern int errno;
-#if PROFILE
-short profile_buf[16384];
-extern int etext();
-#endif
-
-#ifdef __STDC__
-STATIC void read_profile(char *);
-char *getenv(char *);
-#else
-STATIC void read_profile();
-char *getenv();
-#endif
-
-
-/*
- * Main routine.  We initialize things, parse the arguments, execute
- * profiles if we're a login shell, and then call cmdloop to execute
- * commands.  The setjmp call sets up the location to jump to when an
- * exception occurs.  When an exception occurs the variable "state"
- * is used to figure out how far we had gotten.
- */
-
-main(argc, argv)  char **argv; {
-	struct jmploc jmploc;
-	struct stackmark smark;
-	volatile int state;
-	char *shinit, *home;
-	char *profile = NULL, *ashrc = NULL;
-
-#if PROFILE
-	monitor(4, etext, profile_buf, sizeof profile_buf, 50);
-#endif
-	state = 0;
-	if (setjmp(jmploc.loc)) {
-		/*
-		 * When a shell procedure is executed, we raise the
-		 * exception EXSHELLPROC to clean up before executing
-		 * the shell procedure.
-		 */
-		if (exception == EXSHELLPROC) {
-			rootpid = getpid();
-			rootshell = 1;
-			minusc = NULL;
-			state = 3;
-		} else if (state == 0 || iflag == 0 || ! rootshell)
-			exitshell(2);
-		reset();
-#if ATTY
-		if (exception == EXINT
-		 && (! attyset() || equal(termval(), "emacs"))) {
-#else
-		if (exception == EXINT) {
-#endif
-			out2c('\n');
-			flushout(&errout);
-		}
-		popstackmark(&smark);
-		FORCEINTON;				/* enable interrupts */
-		if (state == 1)
-			goto state1;
-		else if (state == 2)
-			goto state2;
-		else if (state == 3)
-			goto state3;
-		else
-			goto state4;
-	}
-	handler = &jmploc;
-#if DEBUG
-	opentrace();
-	trputs("Shell args:  ");  trargs(argv);
-#endif
-	rootpid = getpid();
-	rootshell = 1;
-	init();
-	setstackmark(&smark);
-	procargs(argc, argv);
-	if (eflag) eflag = 2;	/* Truly enable [ex]flag after init. */
-	if (xflag) xflag = 2;
-	if (argv[0] && argv[0][0] == '-') {
-		state = 1;
-		read_profile("/etc/profile");
-state1:
-		state = 2;
-		if ((home = getenv("HOME")) != NULL
-		    && (profile = (char *) malloc(strlen(home) + 10)) != NULL)
-		{
-			strcpy(profile, home);
-			strcat(profile, "/.profile");
-			read_profile(profile);
-		} else {
-			read_profile(".profile");
-		}
-	} else if ((sflag || minusc) && (shinit = getenv("SHINIT")) != NULL) {
-		state = 2;
-		evalstring(shinit);
-	}
-state2:
-	if (profile != NULL) free(profile);
-
-	state = 3;
-	if (!argv[0] || argv[0][0] != '-') {
-		if ((home = getenv("HOME")) != NULL
-			&& (ashrc = (char *) malloc(strlen(home) + 8)) != NULL)
-		{
-			strcpy(ashrc, home);
-			strcat(ashrc, "/.ashrc");
-			read_profile(ashrc);
-		}
-	}
-state3:
-	if (ashrc != NULL) free(ashrc);
-	if (eflag) eflag = 1;	/* Init done, enable [ex]flag */
-	if (xflag) xflag = 1;
-	exitstatus = 0;		/* Init shouldn't influence initial $? */
-
-	state = 4;
-	if (minusc) {
-		evalstring(minusc);
-	}
-	if (sflag || minusc == NULL) {
-state4:
-		cmdloop(1);
-	}
-#if PROFILE
-	monitor(0);
-#endif
-	exitshell(exitstatus);
-}
-
-
-/*
- * Read and execute commands.  "Top" is nonzero for the top level command
- * loop; it turns on prompting if the shell is interactive.
- */
-
-void
-cmdloop(top) {
-	union node *n;
-	struct stackmark smark;
-	int inter;
-	int numeof;
-
-	TRACE(("cmdloop(%d) called\n", top));
-	setstackmark(&smark);
-	numeof = 0;
-	for (;;) {
-		if (pendingsigs)
-			dotrap();
-		inter = 0;
-		if (iflag && top) {
-			inter++;
-			showjobs(1);
-			chkmail(0);
-			flushout(&output);
-		}
-		n = parsecmd(inter);
-#if DEBUG
-		/* showtree(n); */
-#endif
-		if (n == NEOF) {
-			if (Iflag == 0 || numeof >= 50)
-				break;
-			out2str("\nUse \"exit\" to leave shell.\n");
-			numeof++;
-		} else if (n != NULL && nflag == 0) {
-			if (inter) {
-				INTOFF;
-				if (prevcmd)
-					freefunc(prevcmd);
-				prevcmd = curcmd;
-				curcmd = copyfunc(n);
-				INTON;
-			}
-			evaltree(n, 0);
-#ifdef notdef
-			if (exitstatus)				      /*DEBUG*/
-				outfmt(&errout, "Exit status 0x%X\n", exitstatus);
-#endif
-		}
-		popstackmark(&smark);
-	}
-	popstackmark(&smark);		/* unnecessary */
-}
-
-
-
-/*
- * Read /etc/profile or .profile.  Return on error.
- */
-
-STATIC void
-read_profile(name)
-	char *name;
-	{
-	int fd;
-
-	INTOFF;
-	if ((fd = open(name, O_RDONLY)) >= 0)
-		setinputfd(fd, 1);
-	INTON;
-	if (fd < 0)
-		return;
-	cmdloop(0);
-	popfile();
-}
-
-
-
-/*
- * Read a file containing shell functions.
- */
-
-void
-readcmdfile(name)
-	char *name;
-	{
-	int fd;
-
-	INTOFF;
-	if ((fd = open(name, O_RDONLY)) >= 0)
-		setinputfd(fd, 1);
-	else
-		error("Can't open %s", name);
-	INTON;
-	cmdloop(0);
-	popfile();
-}
-
-
-/*
- * Take commands from a file.  To be compatable we should do a path
- * search for the file, but a path search doesn't make any sense.
- */
-
-dotcmd(argc, argv)  char **argv; {
-	exitstatus = 0;
-	if (argc >= 2) {		/* That's what SVR2 does */
-		setinputfile(argv[1], 1);
-		commandname = argv[1];
-		cmdloop(0);
-		popfile();
-	}
-	return exitstatus;
-}
-
-
-exitcmd(argc, argv)  char **argv; {
-	extern int oexitstatus;
-	if (argc > 1)
-		exitstatus = number(argv[1]);
-	else
-		exitstatus = oexitstatus;
-	exitshell(exitstatus);
-}
-
-
-lccmd(argc, argv)  char **argv; {
-	if (argc > 1) {
-		defun(argv[1], prevcmd);
-		return 0;
-	} else {
-		INTOFF;
-		freefunc(curcmd);
-		curcmd = prevcmd;
-		prevcmd = NULL;
-		INTON;
-		evaltree(curcmd, 0);
-		return exitstatus;
-	}
-}
-
-
-
-#ifdef notdef
-/*
- * Should never be called.
- */
-
-void
-exit(exitstatus) {
-	_exit(exitstatus);
-}
-#endif
Index: trunk/minix/commands/ash/main.h
===================================================================
--- trunk/minix/commands/ash/main.h	(revision 9)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)main.h	5.1 (Berkeley) 3/7/91
- */
-
-extern int rootpid;	/* pid of main shell */
-extern int rootshell;	/* true if we aren't a child of the main shell */
-
-#ifdef __STDC__
-void readcmdfile(char *);
-void cmdloop(int);
-#else
-void readcmdfile();
-void cmdloop();
-#endif
Index: trunk/minix/commands/ash/memalloc.c
===================================================================
--- trunk/minix/commands/ash/memalloc.c	(revision 9)
+++ 	(revision )
@@ -1,292 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)memalloc.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-#include "shell.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "machdep.h"
-#include "mystring.h"
-
-/*
- * Like malloc, but returns an error when out of space.
- */
-
-pointer
-ckmalloc(nbytes) {
-	register pointer p;
-	pointer malloc();
-
-	if ((p = malloc(nbytes)) == NULL)
-		error("Out of space");
-	return p;
-}
-
-
-/*
- * Same for realloc.
- */
-
-pointer
-ckrealloc(p, nbytes)
-	register pointer p;
-	{
-	pointer realloc();
-
-	if ((p = realloc(p, nbytes)) == NULL)
-		error("Out of space");
-	return p;
-}
-
-
-/*
- * Make a copy of a string in safe storage.
- */
-
-char *
-savestr(s)
-	char *s;
-	{
-	register char *p;
-
-	p = ckmalloc(strlen(s) + 1);
-	scopy(s, p);
-	return p;
-}
-
-
-/*
- * Parse trees for commands are allocated in lifo order, so we use a stack
- * to make this more efficient, and also to avoid all sorts of exception
- * handling code to handle interrupts in the middle of a parse.
- *
- * The size 504 was chosen because the Ultrix malloc handles that size
- * well.
- */
-
-#define MINSIZE 504		/* minimum size of a block */
-
-
-struct stack_block {
-	struct stack_block *prev;
-	char space[MINSIZE];
-};
-
-struct stack_block stackbase;
-struct stack_block *stackp = &stackbase;
-char *stacknxt = stackbase.space;
-int stacknleft = MINSIZE;
-int sstrnleft;
-int herefd = -1;
-
-
-
-pointer
-stalloc(nbytes) {
-	register char *p;
-
-	nbytes = ALIGN(nbytes);
-	if (nbytes > stacknleft) {
-		int blocksize;
-		struct stack_block *sp;
-
-		blocksize = nbytes;
-		if (blocksize < MINSIZE)
-			blocksize = MINSIZE;
-		INTOFF;
-		sp = ckmalloc(sizeof(struct stack_block) - MINSIZE + blocksize);
-		sp->prev = stackp;
-		stacknxt = sp->space;
-		stacknleft = blocksize;
-		stackp = sp;
-		INTON;
-	}
-	p = stacknxt;
-	stacknxt += nbytes;
-	stacknleft -= nbytes;
-	return p;
-}
-
-
-void
-stunalloc(p)
-	pointer p;
-	{
-	if (p == NULL) {		/*DEBUG */
-		write(2, "stunalloc\n", 10);
-		abort();
-	}
-	stacknleft += stacknxt - (char *)p;
-	stacknxt = p;
-}
-
-
-
-void
-setstackmark(mark)
-	struct stackmark *mark;
-	{
-	mark->stackp = stackp;
-	mark->stacknxt = stacknxt;
-	mark->stacknleft = stacknleft;
-}
-
-
-void
-popstackmark(mark)
-	struct stackmark *mark;
-	{
-	struct stack_block *sp;
-
-	INTOFF;
-	while (stackp != mark->stackp) {
-		sp = stackp;
-		stackp = sp->prev;
-		ckfree(sp);
-	}
-	stacknxt = mark->stacknxt;
-	stacknleft = mark->stacknleft;
-	INTON;
-}
-
-
-/*
- * When the parser reads in a string, it wants to stick the string on the
- * stack and only adjust the stack pointer when it knows how big the
- * string is.  Stackblock (defined in stack.h) returns a pointer to a block
- * of space on top of the stack and stackblocklen returns the length of
- * this block.  Growstackblock will grow this space by at least one byte,
- * possibly moving it (like realloc).  Grabstackblock actually allocates the
- * part of the block that has been used.
- */
-
-void
-growstackblock() {
-	char *p;
-	int newlen = stacknleft * 2 + 100;
-	char *oldspace = stacknxt;
-	int oldlen = stacknleft;
-	struct stack_block *sp;
-
-	if (stacknxt == stackp->space && stackp != &stackbase) {
-		INTOFF;
-		sp = stackp;
-		stackp = sp->prev;
-		sp = ckrealloc((pointer)sp, sizeof(struct stack_block) - MINSIZE + newlen);
-		sp->prev = stackp;
-		stackp = sp;
-		stacknxt = sp->space;
-		stacknleft = newlen;
-		INTON;
-	} else {
-		p = stalloc(newlen);
-		bcopy(oldspace, p, oldlen);
-		stacknxt = p;			/* free the space */
-		stacknleft += newlen;		/* we just allocated */
-	}
-}
-
-
-
-void
-grabstackblock(len) {
-	len = ALIGN(len);
-	stacknxt += len;
-	stacknleft -= len;
-}
-
-
-
-/*
- * The following routines are somewhat easier to use that the above.
- * The user declares a variable of type STACKSTR, which may be declared
- * to be a register.  The macro STARTSTACKSTR initializes things.  Then
- * the user uses the macro STPUTC to add characters to the string.  In
- * effect, STPUTC(c, p) is the same as *p++ = c except that the stack is
- * grown as necessary.  When the user is done, she can just leave the
- * string there and refer to it using stackblock().  Or she can allocate
- * the space for it using grabstackstr().  If it is necessary to allow
- * someone else to use the stack temporarily and then continue to grow
- * the string, the user should use grabstack to allocate the space, and
- * then call ungrabstr(p) to return to the previous mode of operation.
- *
- * USTPUTC is like STPUTC except that it doesn't check for overflow.
- * CHECKSTACKSPACE can be called before USTPUTC to ensure that there
- * is space for at least one character.
- */
-
-
-char *
-growstackstr() {
-	int len = stackblocksize();
-	if (herefd >= 0 && len >= 1024) {
-		xwrite(herefd, stackblock(), len);
-		sstrnleft = len - 1;
-		return stackblock();
-	}
-	growstackblock();
-	sstrnleft = stackblocksize() - len - 1;
-	return stackblock() + len;
-}
-
-
-/*
- * Called from CHECKSTRSPACE.
- */
-
-char *
-makestrspace() {
-	int len = stackblocksize() - sstrnleft;
-	growstackblock();
-	sstrnleft = stackblocksize() - len;
-	return stackblock() + len;
-}
-
-
-
-void
-ungrabstackstr(s, p)
-	char *s;
-	char *p;
-	{
-	stacknleft += stacknxt - s;
-	stacknxt = s;
-	sstrnleft = stacknleft - (p - s);
-}
Index: trunk/minix/commands/ash/memalloc.h
===================================================================
--- trunk/minix/commands/ash/memalloc.h	(revision 9)
+++ 	(revision )
@@ -1,95 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)memalloc.h	5.1 (Berkeley) 3/7/91
- */
-
-struct stackmark {
-	struct stack_block *stackp;
-	char *stacknxt;
-	int stacknleft;
-};
-
-
-extern char *stacknxt;
-extern int stacknleft;
-extern int sstrnleft;
-extern int herefd;
-
-#ifdef __STDC__
-pointer ckmalloc(int);
-pointer ckrealloc(pointer, int);
-void free(pointer);		/* defined in C library */
-char *savestr(char *);
-pointer stalloc(int);
-void stunalloc(pointer);
-void setstackmark(struct stackmark *);
-void popstackmark(struct stackmark *);
-void growstackblock(void);
-void grabstackblock(int);
-char *growstackstr(void);
-char *makestrspace(void);
-void ungrabstackstr(char *, char *);
-#else
-pointer ckmalloc();
-pointer ckrealloc();
-void free();		/* defined in C library */
-char *savestr();
-pointer stalloc();
-void stunalloc();
-void setstackmark();
-void popstackmark();
-void growstackblock();
-void grabstackblock();
-char *growstackstr();
-char *makestrspace();
-void ungrabstackstr();
-#endif
-
-
-
-#define stackblock() stacknxt
-#define stackblocksize() stacknleft
-#define STARTSTACKSTR(p)	p = stackblock(), sstrnleft = stackblocksize()
-#define STPUTC(c, p)	(--sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(), *p++ = (c)))
-#define CHECKSTRSPACE(n, p)	if (sstrnleft < n) p = makestrspace(); else
-#define USTPUTC(c, p)	(--sstrnleft, *p++ = (c))
-#define STACKSTRNUL(p)	(sstrnleft == 0? (p = growstackstr(), *p = '\0') : (*p = '\0'))
-#define STUNPUTC(p)	(++sstrnleft, --p)
-#define STTOPC(p)	p[-1]
-#define STADJUST(amount, p)	(p += (amount), sstrnleft -= (amount))
-#define grabstackstr(p)	stalloc(stackblocksize() - sstrnleft)
-
-#define ckfree(p)	free((pointer)(p))
Index: trunk/minix/commands/ash/miscbltin.c
===================================================================
--- trunk/minix/commands/ash/miscbltin.c	(revision 9)
+++ 	(revision )
@@ -1,166 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)miscbltin.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-/*
- * Miscelaneous builtins.
- */
-
-#include "shell.h"
-#include "options.h"
-#include "var.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-
-#undef eflag
-
-extern char **argptr;		/* argument list for builtin command */
-
-
-/*
- * The read builtin.  The -e option causes backslashes to escape the
- * following character.
- *
- * This uses unbuffered input, which may be avoidable in some cases.
- */
-
-readcmd(argc, argv)  char **argv; {
-	char **ap;
-	int backslash;
-	char c;
-	int eflag;
-	char *prompt;
-	char *ifs;
-	char *p;
-	int startword;
-	int status;
-	int i;
-
-	eflag = 0;
-	prompt = NULL;
-	while ((i = nextopt("ep:")) != '\0') {
-		if (i == 'p')
-			prompt = optarg;
-		else
-			eflag = 1;
-	}
-	if (prompt && isatty(0)) {
-		out2str(prompt);
-		flushall();
-	}
-	if (*(ap = argptr) == NULL)
-		error("arg count");
-	if ((ifs = bltinlookup("IFS", 1)) == NULL)
-		ifs = nullstr;
-	status = 0;
-	startword = 1;
-	backslash = 0;
-	STARTSTACKSTR(p);
-	for (;;) {
-		if (read(0, &c, 1) != 1) {
-			status = 1;
-			break;
-		}
-		if (c == '\0')
-			continue;
-		if (backslash) {
-			backslash = 0;
-			if (c != '\n')
-				STPUTC(c, p);
-			continue;
-		}
-		if (eflag && c == '\\') {
-			backslash++;
-			continue;
-		}
-		if (c == '\n')
-			break;
-		if (startword && *ifs == ' ' && strchr(ifs, c)) {
-			continue;
-		}
-		startword = 0;
-		if (backslash && c == '\\') {
-			if (read(0, &c, 1) != 1) {
-				status = 1;
-				break;
-			}
-			STPUTC(c, p);
-		} else if (ap[1] != NULL && strchr(ifs, c) != NULL) {
-			STACKSTRNUL(p);
-			setvar(*ap, stackblock(), 0);
-			ap++;
-			startword = 1;
-			STARTSTACKSTR(p);
-		} else {
-			STPUTC(c, p);
-		}
-	}
-	STACKSTRNUL(p);
-	setvar(*ap, stackblock(), 0);
-	while (*++ap != NULL)
-		setvar(*ap, nullstr, 0);
-	return status;
-}
-
-
-
-umaskcmd(argc, argv)  char **argv; {
-	int mask;
-	char *p;
-	int i;
-
-	if ((p = argv[1]) == NULL) {
-		INTOFF;
-		mask = umask(0);
-		umask(mask);
-		INTON;
-		out1fmt("%.4o\n", mask);	/* %#o might be better */
-	} else {
-		mask = 0;
-		do {
-			if ((unsigned)(i = *p - '0') >= 8)
-				error("Illegal number: %s", argv[1]);
-			mask = (mask << 3) + i;
-		} while (*++p != '\0');
-		umask(mask);
-	}
-	return 0;
-}
Index: trunk/minix/commands/ash/mkbuiltins
===================================================================
--- trunk/minix/commands/ash/mkbuiltins	(revision 9)
+++ 	(revision )
@@ -1,123 +1,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)mkbuiltins	5.2 (Berkeley) 3/8/91
-
-# All calls to awk removed, because Minix bawk is deficient.  (kjb)
-
-if [ $# != 2 ]
-then
-	echo "USAGE: $0 shell.h builtins"
-	exit 1
-fi
-SHL=$1
-BLTINS=$2
-
-temp=/tmp/ka$$
-exec > builtins.c
-cat <<\!
-/*
- * This file was generated by the mkbuiltins program.
- */
-
-#include "shell.h"
-#include "builtins.h"
-
-!
-if grep '^#define JOBS[	 ]*1' $SHL > /dev/null
-then
-	# Job control.
-	sed -e '/^#/d
-		s/	/ /g
-		s/ #.*//
-		/^ *$/d
-		s/-j//' $BLTINS > $temp
-else
-	# No job control.
-	sed -e '/^#/d
-		s/	/ /g
-		s/ #.*//
-		/^ *$/d
-		/-j/d' $BLTINS > $temp
-fi
-sed -e 's/ .*//
-	s/\(.*\)/int \1();/' $temp
-echo '
-int (*const builtinfunc[])() = {'
-sed -e 's/ .*//
-	s/\(.*\)/	\1,/' $temp
-echo '};
-
-const struct builtincmd builtincmd[] = {'
-i=0
-while read line
-do
-	set -$- $line
-	shift
-	for fun
-	do
-		echo "	\"$fun\", $i,"
-	done
-	i=`expr $i + 1`
-done < $temp
-echo '	NULL, 0
-};'
-
-exec > builtins.h
-cat <<\!
-/*
- * This file was generated by the mkbuiltins program.
- */
-
-#include <sys/cdefs.h>
-!
-i=0
-tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ < $temp |
-	while read line
-	do
-		set -$- $line
-		echo "#define $1 $i"
-		i=`expr $i + 1`
-	done
-echo '
-struct builtincmd {
-      char *name;
-      int code;
-};
-
-extern int (*const builtinfunc[])();
-extern const struct builtincmd builtincmd[];'
-rm -f $temp
Index: trunk/minix/commands/ash/mkinit.c
===================================================================
--- trunk/minix/commands/ash/mkinit.c	(revision 9)
+++ 	(revision )
@@ -1,547 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mkinit.c	5.3 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-/*
- * This program scans all the source files for code to handle various
- * special events and combines this code into one file.  This (allegedly)
- * improves the structure of the program since there is no need for
- * anyone outside of a module to know that that module performs special
- * operations on particular events.  The command is executed iff init.c
- * is actually changed.
- *
- * Usage:  mkinit command sourcefile...
- */
-
-
-#include <sys/cdefs.h>
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <fcntl.h>
-
-
-/*
- * OUTFILE is the name of the output file.  Output is initially written
- * to the file OUTTEMP, which is then moved to OUTFILE if OUTTEMP and
- * OUTFILE are different.
- */
-
-#define OUTFILE "init.c"
-#define OUTTEMP "init.c.new"
-#define OUTOBJ "init.o"
-
-
-/*
- * A text structure is basicly just a string that grows as more characters
- * are added onto the end of it.  It is implemented as a linked list of
- * blocks of characters.  The routines addstr and addchar append a string
- * or a single character, respectively, to a text structure.  Writetext
- * writes the contents of a text structure to a file.
- */
-
-#define BLOCKSIZE 512
-
-struct text {
-	char *nextc;
-	int nleft;
-	struct block *start;
-	struct block *last;
-};      
-
-struct block {
-	struct block *next;
-	char text[BLOCKSIZE];
-};
-
-
-/*
- * There is one event structure for each event that mkinit handles.
- */
-
-struct event {
-	char *name;		/* name of event (e.g. INIT) */
-	char *routine;		/* name of routine called on event */
-	char *comment;		/* comment describing routine */
-	struct text code;		/* code for handling event */
-};
-
-
-char writer[] = "\
-/*\n\
- * This file was generated by the mkinit program.\n\
- */\n\
-\n";
-
-char init[] = "\
-/*\n\
- * Initialization code.\n\
- */\n";
-
-char reset[] = "\
-/*\n\
- * This routine is called when an error or an interrupt occurs in an\n\
- * interactive shell and control is returned to the main command loop.\n\
- */\n";
-
-char shellproc[] = "\
-/*\n\
- * This routine is called to initialize the shell to run a shell procedure.\n\
- */\n";
-
-
-struct event event[] = {
-	{"INIT", "init", init},
-	{"RESET", "reset", reset},
-	{"SHELLPROC", "initshellproc", shellproc},
-	{NULL, NULL}
-};
-
-
-char *curfile;				/* current file */
-int linno;				/* current line */
-char *header_files[200];		/* list of header files */
-struct text defines;			/* #define statements */
-struct text decls;			/* declarations */
-int amiddecls;				/* for formatting */
-
-
-void readfile(), doevent(), doinclude(), dodecl(), output();
-void addstr(), addchar(), writetext();
-
-#define equal(s1, s2)	(strcmp(s1, s2) == 0)
-
-FILE *ckfopen();
-char *savestr();
-void *ckmalloc __P((int));
-void error();
-
-main(argc, argv)
-	char **argv;
-	{
-	char **ap;
-	int fd;
-	char c;
-
-	if (argc < 2)
-		error("Usage:  mkinit command file...");
-	header_files[0] = "\"shell.h\"";
-	header_files[1] = "\"mystring.h\"";
-	for (ap = argv + 2 ; *ap ; ap++)
-		readfile(*ap);
-	output();
-	if (file_changed()) {
-		unlink(OUTFILE);
-		link(OUTTEMP, OUTFILE);
-		unlink(OUTTEMP);
-	} else {
-		unlink(OUTTEMP);
-		if (touch(OUTOBJ))
-			exit(0);		/* no compilation necessary */
-	}
-	printf("%s\n", argv[1]);
-	execl("/bin/sh", "sh", "-c", argv[1], (char *)0);
-	error("Can't exec shell");
-}
-
-
-/*
- * Parse an input file.
- */
-
-void
-readfile(fname)
-	char *fname;
-	{
-	FILE *fp;
-	char line[1024];
-	struct event *ep;
-
-	fp = ckfopen(fname, "r");
-	curfile = fname;
-	linno = 0;
-	amiddecls = 0;
-	while (fgets(line, sizeof line, fp) != NULL) {
-		linno++;
-		for (ep = event ; ep->name ; ep++) {
-			if (line[0] == ep->name[0] && match(ep->name, line)) {
-				doevent(ep, fp, fname);
-				break;
-			}
-		}
-		if (line[0] == 'I' && match("INCLUDE", line))
-			doinclude(line);
-		if (line[0] == 'M' && match("MKINIT", line))
-			dodecl(line, fp);
-		if (line[0] == '#' && gooddefine(line))
-			addstr(line, &defines);
-	}
-	fclose(fp);
-}
-
-
-int
-match(name, line)
-	char *name;
-	char *line;
-	{
-	register char *p, *q;
-
-	p = name, q = line;
-	while (*p) {
-		if (*p++ != *q++)
-			return 0;
-	}
-	if (*q != '{' && *q != ' ' && *q != '\t' && *q != '\n')
-		return 0;
-	return 1;
-}
-
-
-int
-gooddefine(line)
-	char *line;
-	{
-	register char *p;
-
-	if (! match("#define", line))
-		return 0;			/* not a define */
-	p = line + 7;
-	while (*p == ' ' || *p == '\t')
-		p++;
-	while (*p != ' ' && *p != '\t') {
-		if (*p == '(')
-			return 0;		/* macro definition */
-		p++;
-	}
-	while (*p != '\n' && *p != '\0')
-		p++;
-	if (p[-1] == '\\')
-		return 0;			/* multi-line definition */
-	return 1;
-}
-
-
-void
-doevent(ep, fp, fname)
-	register struct event *ep;
-	FILE *fp;
-	char *fname;
-	{
-	char line[1024];
-	int indent;
-	char *p;
-
-	sprintf(line, "\n      /* from %s: */\n", fname);
-	addstr(line, &ep->code);
-	addstr("      {\n", &ep->code);
-	for (;;) {
-		linno++;
-		if (fgets(line, sizeof line, fp) == NULL)
-			error("Unexpected EOF");
-		if (equal(line, "}\n"))
-			break;
-		indent = 6;
-		for (p = line ; *p == '\t' ; p++)
-			indent += 8;
-		for ( ; *p == ' ' ; p++)
-			indent++;
-		if (*p == '\n' || *p == '#')
-			indent = 0;
-		while (indent >= 8) {
-			addchar('\t', &ep->code);
-			indent -= 8;
-		}
-		while (indent > 0) {
-			addchar(' ', &ep->code);
-			indent--;
-		}
-		addstr(p, &ep->code);
-	}
-	addstr("      }\n", &ep->code);
-}
-
-
-void
-doinclude(line)
-	char *line;
-	{
-	register char *p;
-	char *name;
-	register char **pp;
-
-	for (p = line ; *p != '"' && *p != '<' && *p != '\0' ; p++);
-	if (*p == '\0')
-		error("Expecting '\"' or '<'");
-	name = p;
-	while (*p != ' ' && *p != '\t' && *p != '\n')
-		p++;
-	if (p[-1] != '"' && p[-1] != '>')
-		error("Missing terminator");
-	*p = '\0';
-
-	/* name now contains the name of the include file */
-	for (pp = header_files ; *pp && ! equal(*pp, name) ; pp++);
-	if (*pp == NULL)
-		*pp = savestr(name);
-}
-
-
-void
-dodecl(line1, fp)
-	char *line1;
-	FILE *fp;
-	{
-	char line[1024];
-	register char *p, *q;
-
-	if (strcmp(line1, "MKINIT\n") == 0) { /* start of struct/union decl */
-		addchar('\n', &decls);
-		do {
-			linno++;
-			if (fgets(line, sizeof line, fp) == NULL)
-				error("Unterminated structure declaration");
-			addstr(line, &decls);
-		} while (line[0] != '}');
-		amiddecls = 0;
-	} else {
-		if (! amiddecls)
-			addchar('\n', &decls);
-		q = NULL;
-		for (p = line1 + 6 ; *p != '=' && *p != '/' ; p++);
-		if (*p == '=') {		/* eliminate initialization */
-			for (q = p ; *q && *q != ';' ; q++);
-			if (*q == '\0')
-				q = NULL;
-			else {
-				while (p[-1] == ' ')
-					p--;
-				*p = '\0';
-			}
-		}
-		addstr("extern", &decls);
-		addstr(line1 + 6, &decls);
-		if (q != NULL)
-			addstr(q, &decls);
-		amiddecls = 1;
-	}
-}
-
-
-
-/*
- * Write the output to the file OUTTEMP.
- */
-
-void
-output() {
-	FILE *fp;
-	char **pp;
-	struct event *ep;
-
-	fp = ckfopen(OUTTEMP, "w");
-	fputs(writer, fp);
-	for (pp = header_files ; *pp ; pp++)
-		fprintf(fp, "#include %s\n", *pp);
-	fputs("\n\n\n", fp);
-	writetext(&defines, fp);
-	fputs("\n\n", fp);
-	writetext(&decls, fp);
-	for (ep = event ; ep->name ; ep++) {
-		fputs("\n\n\n", fp);
-		fputs(ep->comment, fp);
-		fprintf(fp, "\nvoid\n%s() {\n", ep->routine);
-		writetext(&ep->code, fp);
-		fprintf(fp, "}\n");
-	}
-	fclose(fp);
-}
-
-
-/*
- * Return true if the new output file is different from the old one.
- */
-
-int
-file_changed() {
-	register FILE *f1, *f2;
-	register int c;
-
-	if ((f1 = fopen(OUTFILE, "r")) == NULL
-	 || (f2 = fopen(OUTTEMP, "r")) == NULL)
-		return 1;
-	while ((c = getc(f1)) == getc(f2)) {
-		if (c == EOF)
-			return 0;
-	}
-	return 1;
-}
-
-
-/*
- * Touch a file.  Returns 0 on failure, 1 on success.
- */
-
-int
-touch(file)
-	char *file;
-	{
-	int fd;
-	char c;
-
-	if ((fd = open(file, O_RDWR)) < 0)
-		return 0;
-	if (read(fd, &c, 1) != 1) {
-		close(fd);
-		return 0;
-	}
-	lseek(fd, 0L, 0);
-	write(fd, &c, 1);
-	close(fd);
-	return 1;
-}
-
-
-
-/*
- * A text structure is simply a block of text that is kept in memory.
- * Addstr appends a string to the text struct, and addchar appends a single
- * character.
- */
-
-void
-addstr(s, text)
-	register char *s;
-	register struct text *text;
-	{
-	while (*s) {
-		if (--text->nleft < 0)
-			addchar(*s++, text);
-		else
-			*text->nextc++ = *s++;
-	}
-}
-
-
-void
-addchar(c, text)
-	register struct text *text;
-	{
-	struct block *bp;
-
-	if (--text->nleft < 0) {
-		bp = ckmalloc(sizeof *bp);
-		if (text->start == NULL)
-			text->start = bp;
-		else
-			text->last->next = bp;
-		text->last = bp;
-		text->nextc = bp->text;
-		text->nleft = BLOCKSIZE - 1;
-	}
-	*text->nextc++ = c;
-}
-
-/*
- * Write the contents of a text structure to a file.
- */
-void
-writetext(text, fp)
-	struct text *text;
-	FILE *fp;
-	{
-	struct block *bp;
-
-	if (text->start != NULL) {
-		for (bp = text->start ; bp != text->last ; bp = bp->next)
-			fwrite(bp->text, sizeof (char), BLOCKSIZE, fp);
-		fwrite(bp->text, sizeof (char), BLOCKSIZE - text->nleft, fp);
-	}
-}
-
-FILE *
-ckfopen(file, mode)
-	char *file;
-	char *mode;
-	{
-	FILE *fp;
-
-	if ((fp = fopen(file, mode)) == NULL) {
-		fprintf(stderr, "Can't open %s\n", file);
-		exit(2);
-	}
-	return fp;
-}
-
-void *
-ckmalloc(nbytes) {
-	register char *p;
-	char *malloc();
-
-	if ((p = malloc(nbytes)) == NULL)
-		error("Out of space");
-	return p;
-}
-
-char *
-savestr(s)
-	char *s;
-	{
-	register char *p;
-
-	p = ckmalloc(strlen(s) + 1);
-	strcpy(p, s);
-	return p;
-}
-
-void
-error(msg)
-	char *msg;
-	{
-	if (curfile != NULL)
-		fprintf(stderr, "%s:%d: ", curfile, linno);
-	fprintf(stderr, "%s\n", msg);
-	exit(2);
-}
Index: trunk/minix/commands/ash/mknodes.c
===================================================================
--- trunk/minix/commands/ash/mknodes.c	(revision 9)
+++ 	(revision )
@@ -1,432 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mknodes.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * This program reads the nodetypes file and nodes.c.pat file.  It generates
- * the files nodes.h and nodes.c.
- */
-
-#include <stdio.h>
-
-
-#define MAXTYPES 50		/* max number of node types */
-#define MAXFIELDS 20		/* max fields in a structure */
-#define BUFLEN 100		/* size of character buffers */
-
-/* field types */
-#define T_NODE 1		/* union node *field */
-#define T_NODELIST 2		/* struct nodelist *field */
-#define T_STRING 3
-#define T_INT 4			/* int field */
-#define T_OTHER 5		/* other */
-#define T_TEMP 6		/* don't copy this field */
-
-
-struct field {			/* a structure field */
-	char *name;		/* name of field */
-	int type;			/* type of field */
-	char *decl;		/* declaration of field */
-};
-
-
-struct str {			/* struct representing a node structure */
-	char *tag;		/* structure tag */
-	int nfields;		/* number of fields in the structure */
-	struct field field[MAXFIELDS];	/* the fields of the structure */
-	int done;			/* set if fully parsed */
-};
-
-
-int ntypes;			/* number of node types */
-char *nodename[MAXTYPES];	/* names of the nodes */
-struct str *nodestr[MAXTYPES];	/* type of structure used by the node */
-int nstr;			/* number of structures */
-struct str str[MAXTYPES];	/* the structures */
-struct str *curstr;		/* current structure */
-
-
-FILE *infp = stdin;
-char line[1024];
-int linno;
-char *linep;
-
-
-char *savestr();
-#define equal(s1, s2)	(strcmp(s1, s2) == 0)
-
-
-main(argc, argv)
-	char **argv;
-	{
-	if (argc != 3)
-		error("usage: mknodes file\n");
-	if ((infp = fopen(argv[1], "r")) == NULL)
-		error("Can't open %s", argv[1]);
-	while (readline()) {
-		if (line[0] == ' ' || line[0] == '\t')
-			parsefield();
-		else if (line[0] != '\0')
-			parsenode();
-	}
-	output(argv[2]);
-	return 0;
-}
-
-
-
-parsenode() {
-	char name[BUFLEN];
-	char tag[BUFLEN];
-	struct str *sp;
-
-	if (curstr && curstr->nfields > 0)
-		curstr->done = 1;
-	nextfield(name);
-	if (! nextfield(tag))
-		error("Tag expected");
-	if (*linep != '\0')
-		error("Garbage at end of line");
-	nodename[ntypes] = savestr(name);
-	for (sp = str ; sp < str + nstr ; sp++) {
-		if (equal(sp->tag, tag))
-			break;
-	}
-	if (sp >= str + nstr) {
-		sp->tag = savestr(tag);
-		sp->nfields = 0;
-		curstr = sp;
-		nstr++;
-	}
-	nodestr[ntypes] = sp;
-	ntypes++;
-}
-
-
-parsefield() {
-	char name[BUFLEN];
-	char type[BUFLEN];
-	char decl[2 * BUFLEN];
-	struct field *fp;
-
-	if (curstr == NULL || curstr->done)
-		error("No current structure to add field to");
-	if (! nextfield(name))
-		error("No field name");
-	if (! nextfield(type))
-		error("No field type");
-	fp = &curstr->field[curstr->nfields];
-	fp->name = savestr(name);
-	if (equal(type, "nodeptr")) {
-		fp->type = T_NODE;
-		sprintf(decl, "union node *%s", name);
-	} else if (equal(type, "nodelist")) {
-		fp->type = T_NODELIST;
-		sprintf(decl, "struct nodelist *%s", name);
-	} else if (equal(type, "string")) {
-		fp->type = T_STRING;
-		sprintf(decl, "char *%s", name);
-	} else if (equal(type, "int")) {
-		fp->type = T_INT;
-		sprintf(decl, "int %s", name);
-	} else if (equal(type, "other")) {
-		fp->type = T_OTHER;
-	} else if (equal(type, "temp")) {
-		fp->type = T_TEMP;
-	} else {
-		error("Unknown type %s", type);
-	}
-	if (fp->type == T_OTHER || fp->type == T_TEMP) {
-		skipbl();
-		fp->decl = savestr(linep);
-	} else {
-		if (*linep)
-			error("Garbage at end of line");
-		fp->decl = savestr(decl);
-	}
-	curstr->nfields++;
-}
-
-
-char writer[] = "\
-/*\n\
- * This file was generated by the mknodes program.\n\
- */\n\
-\n";
-
-output(file)
-	char *file;
-	{
-	FILE *hfile;
-	FILE *cfile;
-	FILE *patfile;
-	int i;
-	struct str *sp;
-	struct field *fp;
-	char *p;
-
-	if ((patfile = fopen(file, "r")) == NULL)
-		error("Can't open %s", file);
-	if ((hfile = fopen("nodes.h", "w")) == NULL)
-		error("Can't create nodes.h");
-	if ((cfile = fopen("nodes.c", "w")) == NULL)
-		error("Can't create nodes.c");
-	fputs(writer, hfile);
-	for (i = 0 ; i < ntypes ; i++)
-		fprintf(hfile, "#define %s %d\n", nodename[i], i);
-	fputs("\n\n\n", hfile);
-	for (sp = str ; sp < &str[nstr] ; sp++) {
-		fprintf(hfile, "struct %s {\n", sp->tag);
-		for (i = sp->nfields, fp = sp->field ; --i >= 0 ; fp++) {
-			fprintf(hfile, "      %s;\n", fp->decl);
-		}
-		fputs("};\n\n\n", hfile);
-	}
-	fputs("union node {\n", hfile);
-	fprintf(hfile, "      int type;\n");
-	for (sp = str ; sp < &str[nstr] ; sp++) {
-		fprintf(hfile, "      struct %s %s;\n", sp->tag, sp->tag);
-	}
-	fputs("};\n\n\n", hfile);
-	fputs("struct nodelist {\n", hfile);
-	fputs("\tstruct nodelist *next;\n", hfile);
-	fputs("\tunion node *n;\n", hfile);
-	fputs("};\n\n\n", hfile);
-	fputs("#ifdef __STDC__\n", hfile);
-	fputs("union node *copyfunc(union node *);\n", hfile);
-	fputs("void freefunc(union node *);\n", hfile);
-	fputs("#else\n", hfile);
-	fputs("union node *copyfunc();\n", hfile);
-	fputs("void freefunc();\n", hfile);
-	fputs("#endif\n", hfile);
-
-	fputs(writer, cfile);
-	while (fgets(line, sizeof line, patfile) != NULL) {
-		for (p = line ; *p == ' ' || *p == '\t' ; p++);
-		if (equal(p, "%SIZES\n"))
-			outsizes(cfile);
-		else if (equal(p, "%CALCSIZE\n"))
-			outfunc(cfile, 1);
-		else if (equal(p, "%COPY\n"))
-			outfunc(cfile, 0);
-		else
-			fputs(line, cfile);
-	}
-}
-
-
-
-outsizes(cfile)
-	FILE *cfile;
-	{
-	int i;
-
-	fprintf(cfile, "static const short nodesize[%d] = {\n", ntypes);
-	for (i = 0 ; i < ntypes ; i++) {
-		fprintf(cfile, "      ALIGN(sizeof (struct %s)),\n", nodestr[i]->tag);
-	}
-	fprintf(cfile, "};\n");
-}
-
-
-outfunc(cfile, calcsize)
-	FILE *cfile;
-	{
-	struct str *sp;
-	struct field *fp;
-	int i;
-
-	fputs("      if (n == NULL)\n", cfile);
-	if (calcsize)
-		fputs("	    return;\n", cfile);
-	else
-		fputs("	    return NULL;\n", cfile);
-	if (calcsize)
-		fputs("      funcblocksize += nodesize[n->type];\n", cfile);
-	else {
-		fputs("      new = funcblock;\n", cfile);
-		fputs("      *(char **)&funcblock += nodesize[n->type];\n", 
-									cfile);
-	}
-	fputs("      switch (n->type) {\n", cfile);
-	for (sp = str ; sp < &str[nstr] ; sp++) {
-		for (i = 0 ; i < ntypes ; i++) {
-			if (nodestr[i] == sp)
-				fprintf(cfile, "      case %s:\n", nodename[i]);
-		}
-		for (i = sp->nfields ; --i >= 1 ; ) {
-			fp = &sp->field[i];
-			switch (fp->type) {
-			case T_NODE:
-				if (calcsize) {
-					indent(12, cfile);
-					fprintf(cfile, "calcsize(n->%s.%s);\n",
-						sp->tag, fp->name);
-				} else {
-					indent(12, cfile);
-					fprintf(cfile, "new->%s.%s = copynode(n->%s.%s);\n",
-						sp->tag, fp->name, sp->tag, fp->name);
-				}
-				break;
-			case T_NODELIST:
-				if (calcsize) {
-					indent(12, cfile);
-					fprintf(cfile, "sizenodelist(n->%s.%s);\n",
-						sp->tag, fp->name);
-				} else {
-					indent(12, cfile);
-					fprintf(cfile, "new->%s.%s = copynodelist(n->%s.%s);\n",
-						sp->tag, fp->name, sp->tag, fp->name);
-				}
-				break;
-			case T_STRING:
-				if (calcsize) {
-					indent(12, cfile);
-					fprintf(cfile, "funcstringsize += strlen(n->%s.%s) + 1;\n",
-						sp->tag, fp->name);
-				} else {
-					indent(12, cfile);
-					fprintf(cfile, "new->%s.%s = nodesavestr(n->%s.%s);\n",
-						sp->tag, fp->name, sp->tag, fp->name);
-				}
-				break;
-			case T_INT:
-			case T_OTHER:
-				if (! calcsize) {
-					indent(12, cfile);
-					fprintf(cfile, "new->%s.%s = n->%s.%s;\n",
-						sp->tag, fp->name, sp->tag, fp->name);
-				}
-				break;
-			}
-		}
-		indent(12, cfile);
-		fputs("break;\n", cfile);
-	}
-	fputs("      };\n", cfile);
-	if (! calcsize)
-		fputs("      new->type = n->type;\n", cfile);
-}
-
-
-indent(amount, fp)
-	FILE *fp;
-	{
-	while (amount >= 8) {
-		putc('\t', fp);
-		amount -= 8;
-	}
-	while (--amount >= 0) {
-		putc(' ', fp);
-	}
-}
-
-
-int
-nextfield(buf)
-	char *buf;
-	{
-	register char *p, *q;
-
-	p = linep;
-	while (*p == ' ' || *p == '\t')
-		p++;
-	q = buf;
-	while (*p != ' ' && *p != '\t' && *p != '\0')
-		*q++ = *p++;
-	*q = '\0';
-	linep = p;
-	return (q > buf);
-}
-
-
-skipbl() {
-	while (*linep == ' ' || *linep == '\t')
-		linep++;
-}
-
-
-int
-readline() {
-	register char *p;
-
-	if (fgets(line, 1024, infp) == NULL)
-		return 0;
-	for (p = line ; *p != '#' && *p != '\n' && *p != '\0' ; p++);
-	while (p > line && (p[-1] == ' ' || p[-1] == '\t'))
-		p--;
-	*p = '\0';
-	linep = line;
-	linno++;
-	if (p - line > BUFLEN)
-		error("Line too long");
-	return 1;
-}
-
-
-
-error(msg, a1, a2, a3, a4, a5, a6)
-	char *msg;
-	{
-	fprintf(stderr, "line %d: ", linno);
-	fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
-	putc('\n', stderr);
-	exit(2);
-}
-
-
-
-char *
-savestr(s)
-	char *s;
-	{
-	register char *p;
-	char *malloc();
-
-	if ((p = malloc(strlen(s) + 1)) == NULL)
-		error("Out of space");
-	strcpy(p, s);
-	return p;
-}
Index: trunk/minix/commands/ash/mksignames.c
===================================================================
--- trunk/minix/commands/ash/mksignames.c	(revision 9)
+++ 	(revision )
@@ -1,200 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mksignames.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * This program generates the signames.h and signames.c files.
- */
-#include <sys/types.h>
-#include <stdio.h>
-#include <signal.h>
-
-
-
-struct sig {
-	int signo;		/* signal number */
-	char *name;		/* signal name (without leading "SIG") */
-	char *mesg;		/* description */
-};
-
-
-struct sig sigtab[] = {
-	SIGHUP, "HUP", "Hangup",
-	SIGINT, "INT", "Interrupt",	/* normally don't print message */
-	SIGQUIT, "QUIT", "Quit",
-	SIGILL, "ILL", "Illegal instruction",
-	SIGTRAP, "TRAP", "Trace/BPT trap",
-#ifdef SIGABRT
-	SIGABRT, "ABRT", "abort",
-#endif
-#if defined(SIGIOT) && (! defined(SIGABRT) || SIGABRT != SIGIOT)
-	SIGIOT, "IOT", "abort",
-#endif
-#ifdef SIGEMT
-	SIGEMT, "EMT", "EMT trap",
-#endif
-	SIGFPE, "FPE", "Floating exception",
-	SIGKILL, "KILL", "Killed",
-	SIGBUS, "BUS", "Bus error",
-	SIGSEGV, "SEGV", "Memory fault",
-#ifdef SIGSYS
-	SIGSYS, "SYS", "Bad system call",
-#endif
-	SIGPIPE, "PIPE", "Broken pipe",	/* normally don't print message */
-	SIGALRM, "ALRM", "Alarm call",
-	SIGTERM, "TERM", "Terminated",
-#ifdef SIGUSR1
-	SIGUSR1, "USR1", "User signal 1",
-#endif
-#ifdef SIGUSR2
-	SIGUSR2, "USR2", "User signal 2",
-#endif
-#ifdef SIGCLD
-	SIGCLD, "CLD", NULL,
-#endif
-#if defined(SIGCHLD) && ! defined(SIGCLD)
-	SIGCHLD, "CLD", NULL,
-#endif
-#ifdef SIGPWR
-	SIGPWR, "PWR", "Power fail",
-#endif
-#ifdef SIGPOLL
-	SIGPOLL, "POLL", "Poll",
-#endif
-	/* Now for the BSD signals */
-#ifdef SIGURG
-	SIGURG, "URG", NULL,
-#endif
-#ifdef SIGSTOP
-	SIGSTOP, "STOP", "Stopped",
-#endif
-#ifdef SIGTSTP
-	SIGTSTP, "TSTP", "Stopped",
-#endif
-#ifdef SIGCONT
-	SIGCONT, "CONT", NULL,
-#endif
-#ifdef SIGTTIN
-	SIGTTIN, "TTIN", "Stopped (input)",
-#endif
-#ifdef SIGTTOU
-	SIGTTOU, "TTOU", "Stopped (output)",
-#endif
-#ifdef SIGIO
-	SIGIO, "IO", NULL,
-#endif
-#ifdef SIGXCPU
-	SIGXCPU, "XCPU", "Time limit exceeded",
-#endif
-#ifdef SIGXFSZ
-	SIGXFSZ, "XFSZ", NULL,
-#endif
-#ifdef SIGVTALARM
-	SIGVTALARM, "VTALARM", "Virtual alarm",
-#endif
-#ifdef SIGPROF
-	SIGPROF, "PROF", "Profiling alarm",
-#endif
-#ifdef SIGWINCH
-	SIGWINCH, "WINCH", NULL,
-#endif
-	0, NULL, NULL
-};
-
-
-#define MAXSIG 64
-
-
-char *sigmesg[MAXSIG + 1];
-
-
-char writer[] = "\
-/*\n\
- * This file was generated by the mksignames program.\n\
- */\n\
-\n";
-
-
-
-main(argc, argv)  char **argv; {
-	FILE *cfile, *hfile;	
-	struct sig *sigp;
-	int maxsig;
-	int i;
-
-	if ((cfile = fopen("signames.c", "w")) == NULL) {
-		fputs("Can't create signames.c\n", stderr);
-		exit(2);
-	}
-	if ((hfile = fopen("signames.h", "w")) == NULL) {
-		fputs("Can't create signames.h\n", stderr);
-		exit(2);
-	}
-	maxsig = 0;
-	for (sigp = sigtab ; sigp->signo != 0 ; sigp++) {
-		if (sigp->signo < 0 || sigp->signo > MAXSIG)
-			continue;
-		sigmesg[sigp->signo] = sigp->mesg;
-		if (maxsig < sigp->signo)
-			maxsig = sigp->signo;
-	}
-
-	fputs(writer, hfile);
-	fprintf(hfile, "#define MAXSIG %d\n\n", maxsig);
-	fprintf(hfile, "extern char *const sigmesg[MAXSIG+1];\n");
-
-	fputs(writer, cfile);
-	fprintf(cfile, "#include \"shell.h\"\n\n");
-	fprintf(cfile, "char *const sigmesg[%d] = {\n", maxsig + 1);
-	for (i = 0 ; i <= maxsig ; i++) {
-		if (sigmesg[i] == NULL) {
-			fprintf(cfile, "      0,\n");
-		} else {
-			fprintf(cfile, "      \"%s\",\n", sigmesg[i]);
-		}
-	}
-	fprintf(cfile, "};\n");
-	exit(0);
-}
Index: trunk/minix/commands/ash/mksyntax.c
===================================================================
--- trunk/minix/commands/ash/mksyntax.c	(revision 9)
+++ 	(revision )
@@ -1,356 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mksyntax.c	5.2 (Berkeley) 3/8/91";
-#endif /* not lint */
-
-/*
- * This program creates syntax.h and syntax.c.
- */
-
-#include <stdio.h>
-#include "parser.h"
-
-
-struct synclass {
-	char *name;
-	char *comment;
-};
-
-/* Syntax classes */
-struct synclass synclass[] = {
-	"CWORD",		"character is nothing special",
-	"CNL",		"newline character",
-	"CBACK",		"a backslash character",
-	"CSQUOTE",	"single quote",
-	"CDQUOTE",	"double quote",
-	"CENDQUOTE",	"a terminating quote",
-	"CBQUOTE",	"backwards single quote",
-	"CVAR",		"a dollar sign",
-	"CENDVAR",	"a '}' character",
-	"CEOF",		"end of file",
-	"CCTL",		"like CWORD, except it must be escaped",
-	"CSPCL",		"these terminate a word",
-	NULL, NULL
-};
-
-
-/*
- * Syntax classes for is_ functions.  Warning:  if you add new classes
- * you may have to change the definition of the is_in_name macro.
- */
-struct synclass is_entry[] = {
-	"ISDIGIT",	"a digit",
-	"ISUPPER",	"an upper case letter",
-	"ISLOWER",	"a lower case letter",
-	"ISUNDER",	"an underscore",
-	"ISSPECL",	"the name of a special parameter",
-	NULL, NULL,
-};
-
-char writer[] = "\
-/*\n\
- * This file was generated by the mksyntax program.\n\
- */\n\
-\n";
-
-
-FILE *cfile;
-FILE *hfile;
-char *syntax[513];
-int base;
-int size;		/* number of values which a char variable can have */
-int nbits;		/* number of bits in a character */
-int digit_contig;	/* true if digits are contiguous */
-
-
-main() {
-	char c;
-	char d;
-	int sign;
-	int i;
-	char buf[80];
-	int pos;
-	static char digit[] = "0123456789";
-
-	/* Create output files */
-	if ((cfile = fopen("syntax.c", "w")) == NULL) {
-		perror("syntax.c");
-		exit(2);
-	}
-	if ((hfile = fopen("syntax.h", "w")) == NULL) {
-		perror("syntax.h");
-		exit(2);
-	}
-	fputs(writer, hfile);
-	fputs(writer, cfile);
-
-	/* Determine the characteristics of chars. */
-	c = -1;
-	if (c < 0)
-		sign = 1;
-	else
-		sign = 0;
-	for (nbits = 1 ; ; nbits++) {
-		d = (1 << nbits) - 1;
-		if (d == c)
-			break;
-	}
-	printf("%s %d bit chars\n", sign? "signed" : "unsigned", nbits);
-	if (nbits > 9) {
-		fputs("Characters can't have more than 9 bits\n", stderr);
-		exit(2);
-	}
-	size = (1 << nbits) + 1;
-	base = 1;
-	if (sign)
-		base += 1 << (nbits - 1);
-	digit_contig = 1;
-	for (i = 0 ; i < 10 ; i++) {
-		if (digit[i] != '0' + i)
-			digit_contig = 0;
-	}
-
-	fputs("#include <sys/cdefs.h>\n", hfile);
-
-	/* Generate the #define statements in the header file */
-	fputs("/* Syntax classes */\n", hfile);
-	for (i = 0 ; synclass[i].name ; i++) {
-		sprintf(buf, "#define %s %d", synclass[i].name, i);
-		fputs(buf, hfile);
-		for (pos = strlen(buf) ; pos < 32 ; pos = pos + 8 &~ 07)
-			putc('\t', hfile);
-		fprintf(hfile, "/* %s */\n", synclass[i].comment);
-	}
-	putc('\n', hfile);
-	fputs("/* Syntax classes for is_ functions */\n", hfile);
-	for (i = 0 ; is_entry[i].name ; i++) {
-		sprintf(buf, "#define %s %#o", is_entry[i].name, 1 << i);
-		fputs(buf, hfile);
-		for (pos = strlen(buf) ; pos < 32 ; pos = pos + 8 &~ 07)
-			putc('\t', hfile);
-		fprintf(hfile, "/* %s */\n", is_entry[i].comment);
-	}
-	putc('\n', hfile);
-	fprintf(hfile, "#define SYNBASE %d\n", base);
-	fprintf(hfile, "#define PEOF %d\n\n", -base);
-	putc('\n', hfile);
-	fputs("#define BASESYNTAX (basesyntax + SYNBASE)\n", hfile);
-	fputs("#define DQSYNTAX (dqsyntax + SYNBASE)\n", hfile);
-	fputs("#define SQSYNTAX (sqsyntax + SYNBASE)\n", hfile);
-	putc('\n', hfile);
-	output_type_macros();		/* is_digit, etc. */
-	putc('\n', hfile);
-
-	/* Generate the syntax tables. */
-	fputs("#include \"shell.h\"\n", cfile);
-	fputs("#include \"syntax.h\"\n\n", cfile);
-	init();
-	fputs("/* syntax table used when not in quotes */\n", cfile);
-	add("\n", "CNL");
-	add("\\", "CBACK");
-	add("'", "CSQUOTE");
-	add("\"", "CDQUOTE");
-	add("`", "CBQUOTE");
-	add("$", "CVAR");
-	add("}", "CENDVAR");
-	add("<>();&| \t", "CSPCL");
-	print("basesyntax");
-	init();
-	fputs("\n/* syntax table used when in double quotes */\n", cfile);
-	add("\n", "CNL");
-	add("\\", "CBACK");
-	add("\"", "CENDQUOTE");
-	add("`", "CBQUOTE");
-	add("$", "CVAR");
-	add("}", "CENDVAR");
-	add("!*?[=", "CCTL");
-	print("dqsyntax");
-	init();
-	fputs("\n/* syntax table used when in single quotes */\n", cfile);
-	add("\n", "CNL");
-	add("'", "CENDQUOTE");
-	add("!*?[=", "CCTL");
-	print("sqsyntax");
-	filltable("0");
-	fputs("\n/* character classification table */\n", cfile);
-	add("0123456789", "ISDIGIT");
-	add("abcdefghijklmnopqrstucvwxyz", "ISLOWER");
-	add("ABCDEFGHIJKLMNOPQRSTUCVWXYZ", "ISUPPER");
-	add("_", "ISUNDER");
-	add("#?$!-*@", "ISSPECL");
-	print("is_type");
-	if (! digit_contig)
-		digit_convert();
-	exit(0);
-}
-
-
-
-/*
- * Clear the syntax table.
- */
-
-filltable(dftval)
-	char *dftval;
-	{
-	int i;
-
-	for (i = 0 ; i < size ; i++)
-		syntax[i] = dftval;
-}
-
-
-/*
- * Initialize the syntax table with default values.
- */
-
-init() {
-	filltable("CWORD");
-	syntax[0] = "CEOF";
-	syntax[base + CTLESC] = "CCTL";
-	syntax[base + CTLVAR] = "CCTL";
-	syntax[base + CTLENDVAR] = "CCTL";
-	syntax[base + CTLBACKQ] = "CCTL";
-	syntax[base + CTLBACKQ + CTLQUOTE] = "CCTL";
-}
-
-
-/*
- * Add entries to the syntax table.
- */
-
-add(p, type)
-	char *p, *type;
-	{
-	while (*p)
-		syntax[*p++ + base] = type;
-}
-
-
-
-/*
- * Output the syntax table.
- */
-
-print(name)
-	char *name;
-	{
-	int i;
-	int col;
-
-	fprintf(hfile, "extern const char %s[];\n", name);
-	fprintf(cfile, "const char %s[%d] = {\n", name, size);
-	col = 0;
-	for (i = 0 ; i < size ; i++) {
-		if (i == 0) {
-			fputs("      ", cfile);
-		} else if ((i & 03) == 0) {
-			fputs(",\n      ", cfile);
-			col = 0;
-		} else {
-			putc(',', cfile);
-			while (++col < 9 * (i & 03))
-				putc(' ', cfile);
-		}
-		fputs(syntax[i], cfile);
-		col += strlen(syntax[i]);
-	}
-	fputs("\n};\n", cfile);
-}
-
-
-
-/*
- * Output character classification macros (e.g. is_digit).  If digits are
- * contiguous, we can test for them quickly.
- */
-
-char *macro[] = {
-	"#define is_digit(c)\t((is_type+SYNBASE)[c] & ISDIGIT)",
-	"#define is_alpha(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER))",
-	"#define is_name(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER|ISUNDER))",
-	"#define is_in_name(c)\t((is_type+SYNBASE)[c] & (ISUPPER|ISLOWER|ISUNDER|ISDIGIT))",
-	"#define is_special(c)\t((is_type+SYNBASE)[c] & (ISSPECL|ISDIGIT))",
-	NULL
-};
-
-output_type_macros() {
-	char **pp;
-
-	if (digit_contig)
-		macro[0] = "#define is_digit(c)\t((unsigned)((c) - '0') <= 9)";
-	for (pp = macro ; *pp ; pp++)
-		fprintf(hfile, "%s\n", *pp);
-	if (digit_contig)
-		fputs("#define digit_val(c)\t((c) - '0')\n", hfile);
-	else
-		fputs("#define digit_val(c)\t(digit_value[c])\n", hfile);
-}
-
-
-
-/*
- * Output digit conversion table (if digits are not contiguous).
- */
-
-digit_convert() {
-	int maxdigit;
-	static char digit[] = "0123456789";
-	char *p;
-	int i;
-
-	maxdigit = 0;
-	for (p = digit ; *p ; p++)
-		if (*p > maxdigit)
-			maxdigit = *p;
-	fputs("extern const char digit_value[];\n", hfile);
-	fputs("\n\nconst char digit_value[] = {\n", cfile);
-	for (i = 0 ; i <= maxdigit ; i++) {
-		for (p = digit ; *p && *p != i ; p++);
-		if (*p == '\0')
-			p = digit;
-		fprintf(cfile, "      %d,\n", p - digit);
-	}
-	fputs("};\n", cfile);
-}
Index: trunk/minix/commands/ash/mktokens
===================================================================
--- trunk/minix/commands/ash/mktokens	(revision 9)
+++ 	(revision )
@@ -1,121 +1,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)mktokens	5.1 (Berkeley) 3/7/91
-
-# All calls to awk removed, because Minix bawk is deficient.  (kjb)
-
-# The following is a list of tokens.  The second column is nonzero if the
-# token marks the end of a list.  The third column is the name to print in
-# error messages.
-
-cat > /tmp/ka$$ <<\!
-TEOF	1	end of file
-TNL	0	newline
-TSEMI	0	";"
-TBACKGND 0	"&"
-TAND	0	"&&"
-TOR	0	"||"
-TPIPE	0	"|"
-TLP	0	"("
-TRP	1	")"
-TENDCASE 1	";;"
-TENDBQUOTE 1	"`"
-TREDIR	0	redirection
-TWORD	0	word
-TIF	0	"if"
-TTHEN	1	"then"
-TELSE	1	"else"
-TELIF	1	"elif"
-TFI	1	"fi"
-TWHILE	0	"while"
-TUNTIL	0	"until"
-TFOR	0	"for"
-TDO	1	"do"
-TDONE	1	"done"
-TBEGIN	0	"{"
-TEND	1	"}"
-TCASE	0	"case"
-TESAC	1	"esac"
-!
-nl=`wc -l /tmp/ka$$`
-exec > token.def
-i=0
-while read line
-do
-	set -$- $line
-	echo "#define $1 $i"
-	i=`expr $i + 1`
-done </tmp/ka$$
-echo '
-/* Array indicating which tokens mark the end of a list */
-const char tokendlist[] = {'
-while read line
-do
-	set -$- $line
-	echo "	$2,"
-done </tmp/ka$$
-echo '};
-
-char *const tokname[] = {'
-sed -e 's/"/\\"/g' \
-    -e 's/[^	 ]*[	 ][	 ]*[^	 ]*[	 ][	 ]*\(.*\)/	"\1",/' \
-    /tmp/ka$$
-echo '};
-'
-i=0
-go=
-sed 's/"//g' /tmp/ka$$ |
-	while read line
-	do
-		set -$- $line
-		if [ "$1" = TIF ]
-		then
-			echo "#define KWDOFFSET $i"
-			echo
-			echo "char *const parsekwd[] = {"
-			go=true
-		fi
-		if [ "$go" ]
-		then
-			echo "	\"$3\","
-		fi
-		i=`expr $i + 1`
-	done
-echo '	0
-};'
-
-rm /tmp/ka$$
Index: trunk/minix/commands/ash/mystring.c
===================================================================
--- trunk/minix/commands/ash/mystring.c	(revision 9)
+++ 	(revision )
@@ -1,174 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)mystring.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * String functions.
- *
- *	equal(s1, s2)		Return true if strings are equal.
- *	scopy(from, to)		Copy a string.
- *	scopyn(from, to, n)	Like scopy, but checks for overflow.
- *	strchr(s, c)		Find first occurance of c in s.
- *	bcopy(from, to, n)	Copy a block of memory.
- *	number(s)		Convert a string of digits to an integer.
- *	is_number(s)		Return true if s is a string of digits.
- */
-
-#include "shell.h"
-#include "syntax.h"
-#include "error.h"
-#include "mystring.h"
-
-
-char nullstr[1];		/* zero length string */
-
-
-/*
- * scopyn - copy a string from "from" to "to", truncating the string
- *		if necessary.  "To" is always nul terminated, even if
- *		truncation is performed.  "Size" is the size of "to".
- */
-
-void
-scopyn(from, to, size)
-	register char const *from;
-	register char *to;
-	register int size;
-	{
-
-	while (--size > 0) {
-		if ((*to++ = *from++) == '\0')
-			return;
-	}
-	*to = '\0';
-}
-
-
-/*
- * strchr - find first occurrence of a character in a string.
- */
-
-#ifndef SYS5
-char *
-mystrchr(s, charwanted)
-	char const *s;
-	register char charwanted;
-	{
-	register char const *scan;
-
-	/*
-	 * The odd placement of the two tests is so NUL is findable.
-	 */
-	for (scan = s ; *scan != charwanted ; )	/* ++ moved down for opt. */
-		if (*scan++ == '\0')
-			return NULL;
-	return (char *)scan;
-}
-#endif
-
-
-
-/*
- * bcopy - copy bytes
- *
- * This routine was derived from code by Henry Spencer.
- */
-
-void
-mybcopy(src, dst, length)
-	pointer dst;
-	const pointer src;
-	register int length;
-	{
-	register char *d = dst;
-	register char *s = src;
-
-	while (--length >= 0)
-		*d++ = *s++;
-}
-
-
-/*
- * prefix -- see if pfx is a prefix of string.
- */
-
-int
-prefix(pfx, string)
-	register char const *pfx;
-	register char const *string;
-	{
-	while (*pfx) {
-		if (*pfx++ != *string++)
-			return 0;
-	}
-	return 1;
-}
-
-
-/*
- * Convert a string of digits to an integer, printing an error message on
- * failure.
- */
-
-int
-number(s)
-	const char *s;
-	{
-
-	if (! is_number(s))
-		error2("Illegal number", (char *)s);
-	return atoi(s);
-}
-
-
-
-/*
- * Check for a valid number.  This should be elsewhere.
- */
-
-int
-is_number(p)
-	register const char *p;
-	{
-	do {
-		if (! is_digit(*p))
-			return 0;
-	} while (*++p != '\0');
-	return 1;
-}
Index: trunk/minix/commands/ash/mystring.h
===================================================================
--- trunk/minix/commands/ash/mystring.h	(revision 9)
+++ 	(revision )
@@ -1,71 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)mystring.h	5.1 (Berkeley) 3/7/91
- */
-
-#ifndef SYSV
-#define strchr mystrchr
-#endif
-
-#ifdef __STDC__
-void scopyn(const char *, char *, int);
-char *strchr(const char *, int);
-void mybcopy(const pointer, pointer, int);
-int prefix(const char *, const char *);
-int number(const char *);
-int is_number(const char *);
-int strcmp(const char *, const char *);	/* from C library */
-char *strcpy(char *, const char *);	/* from C library */
-int strlen(const char *);		/* from C library */
-char *strcat(char *, const char *);	/* from C library */
-char *strerror(int);			/* from C library */
-#else
-void scopyn();
-char *strchr();
-void mybcopy();
-int prefix();
-int number();
-int is_number();
-int strcmp();
-char *strcpy();
-int strlen();
-char *strcat();
-char *strerror();
-#endif
-
-#define equal(s1, s2)	(strcmp(s1, s2) == 0)
-#define scopy(s1, s2)	((void)strcpy(s2, s1))
-#define bcopy(src, dst, n)	mybcopy((pointer)(src), (pointer)(dst), n)
Index: trunk/minix/commands/ash/nodes.c.pat
===================================================================
--- trunk/minix/commands/ash/nodes.c.pat	(revision 9)
+++ 	(revision )
@@ -1,177 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)nodes.c.pat	5.2 (Berkeley) 3/8/91
- */
-
-/*
- * Routine for dealing with parsed shell commands.
- */
-
-#include "shell.h"
-#include "nodes.h"
-#include "memalloc.h"
-#include "machdep.h"
-#include "mystring.h"
-
-
-int funcblocksize;		/* size of structures in function */
-int funcstringsize;		/* size of strings in node */
-#ifdef __STDC__
-pointer funcblock;		/* block to allocate function from */
-#else
-char *funcblock;		/* block to allocate function from */
-#endif
-char *funcstring;		/* block to allocate strings from */
-
-%SIZES
-
-
-#ifdef __STDC__
-STATIC void calcsize(union node *);
-STATIC void sizenodelist(struct nodelist *);
-STATIC union node *copynode(union node *);
-STATIC struct nodelist *copynodelist(struct nodelist *);
-STATIC char *nodesavestr(char *);
-#else
-STATIC void calcsize();
-STATIC void sizenodelist();
-STATIC union node *copynode();
-STATIC struct nodelist *copynodelist();
-STATIC char *nodesavestr();
-#endif
-
-
-
-/*
- * Make a copy of a parse tree.
- */
-
-union node *
-copyfunc(n)
-      union node *n;
-      {
-      if (n == NULL)
-	    return NULL;
-      funcblocksize = 0;
-      funcstringsize = 0;
-      calcsize(n);
-      funcblock = ckmalloc(funcblocksize + funcstringsize);
-      funcstring = (char *)funcblock + funcblocksize;
-      return copynode(n);
-}
-
-
-
-STATIC void
-calcsize(n)
-      union node *n;
-      {
-      %CALCSIZE
-}
-
-
-
-STATIC void
-sizenodelist(lp)
-      struct nodelist *lp;
-      {
-      while (lp) {
-	    funcblocksize += ALIGN(sizeof (struct nodelist));
-	    calcsize(lp->n);
-	    lp = lp->next;
-      }
-}
-
-
-
-STATIC union node *
-copynode(n)
-      union node *n;
-      {
-      union node *new;
-
-      %COPY
-      return new;
-}
-
-
-STATIC struct nodelist *
-copynodelist(lp)
-      struct nodelist *lp;
-      {
-      struct nodelist *start;
-      struct nodelist **lpp;
-
-      lpp = &start;
-      while (lp) {
-	    *lpp = funcblock;
-	    *(char **)&funcblock += ALIGN(sizeof (struct nodelist));
-	    (*lpp)->n = copynode(lp->n);
-	    lp = lp->next;
-	    lpp = &(*lpp)->next;
-      }
-      *lpp = NULL;
-      return start;
-}
-
-
-
-STATIC char *
-nodesavestr(s)
-      char *s;
-      {
-      register char *p = s;
-      register char *q = funcstring;
-      char *rtn = funcstring;
-
-      while (*q++ = *p++);
-      funcstring = q;
-      return rtn;
-}
-
-
-
-/*
- * Free a parse tree.
- */
-
-void
-freefunc(n)
-      union node *n;
-      {
-      if (n)
-	    ckfree(n);
-}
Index: trunk/minix/commands/ash/nodetypes
===================================================================
--- trunk/minix/commands/ash/nodetypes	(revision 9)
+++ 	(revision )
@@ -1,140 +1,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-#    must display the following acknowledgement:
-#	This product includes software developed by the University of
-#	California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-#	@(#)nodetypes	5.1 (Berkeley) 3/7/91
-
-# This file describes the nodes used in parse trees.  Unindented lines
-# contain a node type followed by a structure tag.  Subsequent indented
-# lines specify the fields of the structure.  Several node types can share
-# the same structure, in which case the fields of the structure should be
-# specified only once.
-#
-# A field of a structure is described by the name of the field followed
-# by a type.  The currently implemented types are:
-#	nodeptr - a pointer to a node
-#	nodelist - a pointer to a list of nodes
-#	string - a pointer to a nul terminated string
-#	int - an integer
-#	other - any type that can be copied by assignment
-#	temp - a field that doesn't have to be copied when the node is copied
-# The last two types should be followed by the text of a C declaration for
-# the field.
-
-NSEMI nbinary			# two commands separated by a semicolon
-	type	  int
-	ch1	  nodeptr		# the first child
-	ch2	  nodeptr		# the second child
-
-NCMD ncmd			# a simple command
-	type	  int
-	backgnd	  int			# set to run command in background
-	args	  nodeptr		# the arguments
-	redirect  nodeptr		# list of file redirections
-
-NPIPE npipe			# a pipeline
-	type	  int
-	backgnd	  int			# set to run pipeline in background
-	cmdlist	  nodelist		# the commands in the pipeline
-
-NREDIR nredir			# redirection (of a compex command)
-	type	  int
-	n	  nodeptr		# the command
-	redirect  nodeptr		# list of file redirections
-
-NBACKGND nredir			# run command in background
-NSUBSHELL nredir		# run command in a subshell
-
-NAND nbinary			# the && operator
-NOR nbinary			# the || operator
-
-NIF nif				# the if statement.  Elif clauses are handled
-	type	  int		    # using multiple if nodes.
-	test	  nodeptr		# if test
-	ifpart	  nodeptr		# then ifpart
-	elsepart  nodeptr		# else elsepart
-
-NWHILE nbinary			# the while statement.  First child is the test
-NUNTIL nbinary			# the until statement
-
-NFOR nfor			# the for statement
-	type	  int
-	args	  nodeptr		# for var in args
-	body	  nodeptr		# do body; done
-	var	  string		# the for variable
-
-NCASE ncase			# a case statement
-	type	  int
-	expr	  nodeptr		# the word to switch on
-	cases	  nodeptr		# the list of cases (NCLIST nodes)
-
-NCLIST nclist			# a case
-	type	  int
-	next	  nodeptr		# the next case in list
-	pattern	  nodeptr		# list of patterns for this case
-	body	  nodeptr		# code to execute for this case
-
-
-NDEFUN narg			# define a function.  The "next" field contains
-				# the body of the function.
-
-NARG narg			# represents a word
-	type	  int
-	next	  nodeptr		# next word in list
-	text	  string		# the text of the word
-	backquote nodelist		# list of commands in back quotes
-
-NTO nfile			# fd> fname
-NFROM nfile			# fd< fname
-NAPPEND nfile			# fd>> fname
-	type	  int
-	next	  nodeptr		# next redirection in list
-	fd	  int			# file descriptor being redirected
-	fname	  nodeptr		# file name, in a NARG node
-	expfname  temp	char *expfname	# actual file name
-
-NTOFD ndup			# fd<&dupfd
-NFROMFD ndup			# fd>&dupfd
-	type	  int
-	next	  nodeptr		# next redirection in list
-	fd	  int			# file descriptor being redirected
-	dupfd	  int			# file descriptor to duplicate
-
-NHERE nhere			# fd<<\!
-NXHERE nhere			# fd<<!
-	type	  int
-	next	  nodeptr		# next redirection in list
-	fd	  int			# file descriptor being redirected
-	doc	  nodeptr		# input to command (NARG node)
Index: trunk/minix/commands/ash/options.c
===================================================================
--- trunk/minix/commands/ash/options.c	(revision 9)
+++ 	(revision )
@@ -1,397 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)options.c	5.2 (Berkeley) 3/13/91";
-#endif /* not lint */
-
-#include "shell.h"
-#define DEFINE_OPTIONS
-#include "options.h"
-#undef DEFINE_OPTIONS
-#include "nodes.h"	/* for other header files */
-#include "eval.h"
-#include "jobs.h"
-#include "input.h"
-#include "output.h"
-#include "trap.h"
-#include "var.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-
-char *arg0;			/* value of $0 */
-struct shparam shellparam;	/* current positional parameters */
-char **argptr;			/* argument list for builtin commands */
-char *optarg;			/* set by nextopt (like getopt) */
-char *optptr;			/* used by nextopt */
-int editable;			/* isatty(0) && isatty(1) */
-
-char *minusc;			/* argument to -c option */
-
-
-#ifdef __STDC__
-STATIC void options(int);
-STATIC void setoption(int, int);
-#else
-STATIC void options();
-STATIC void setoption();
-#endif
-
-
-
-/*
- * Process the shell command line arguments.
- */
-
-void
-procargs(argc, argv)
-	char **argv;
-	{
-	char *p;
-
-	argptr = argv;
-	if (argc > 0)
-		argptr++;
-	for (p = optval ; p < optval + sizeof optval - 1 ; p++)
-		*p = 2;
-	options(1);
-	if (*argptr == NULL && minusc == NULL)
-		sflag = 1;
-	editable = (isatty(0) && isatty(1));
-	if (iflag == 2 && sflag == 1 && editable)
-		iflag = 1;
-	if (jflag == 2)
-		jflag = iflag;
-	for (p = optval ; p < optval + sizeof optval - 1 ; p++)
-		if (*p == 2)
-			*p = 0;
-	arg0 = argv[0];
-	if (sflag == 0) {
-		arg0 = *argptr++;
-		if (minusc == NULL) {
-			commandname = arg0;
-			setinputfile(commandname, 0);
-		}
-	}
-	shellparam.p = argptr;
-	/* assert(shellparam.malloc == 0 && shellparam.nparam == 0); */
-	while (*argptr) {
-		shellparam.nparam++;
-		argptr++;
-	}
-	setinteractive(iflag);
-	setjobctl(jflag);
-}
-
-
-
-/*
- * Process shell options.  The global variable argptr contains a pointer
- * to the argument list; we advance it past the options.
- */
-
-STATIC void
-options(cmdline) {
-	register char *p;
-	int val;
-	int c;
-
-	if (cmdline)
-		minusc = NULL;
-	while ((p = *argptr) != NULL) {
-		argptr++;
-		if ((c = *p++) == '-') {
-			val = 1;
-                        if (p[0] == '\0' || p[0] == '-' && p[1] == '\0') {
-                                if (!cmdline) {
-                                        /* "-" means turn off -x and -v */
-                                        if (p[0] == '\0')
-                                                xflag = vflag = 0;
-                                        /* "--" means reset params */
-                                        else if (*argptr == NULL)
-                                                setparam(argptr);
-                                }
-				break;	  /* "-" or  "--" terminates options */
-			}
-		} else if (c == '+') {
-			val = 0;
-		} else {
-			argptr--;
-			break;
-		}
-		while ((c = *p++) != '\0') {
-			if (c == 'c' && cmdline) {
-				char *q;
-#ifdef NOHACK	/* removing this code allows sh -ce 'foo' for compat */
-				if (*p == '\0')
-#endif
-					q = *argptr++;
-				if (q == NULL || minusc != NULL)
-					error("Bad -c option");
-				minusc = q;
-#ifdef NOHACK
-				break;
-#endif
-			} else {
-				setoption(c, val);
-			}
-		}
-		if (! cmdline)
-			break;
-	}
-}
-
-
-STATIC void
-setoption(flag, val)
-	char flag;
-	int val;
-	{
-	register char *p;
-
-	if ((p = strchr(optchar, flag)) == NULL)
-		error("Illegal option -%c", flag);
-	optval[p - optchar] = val;
-}
-
-
-
-#ifdef mkinit
-INCLUDE "options.h"
-
-SHELLPROC {
-	char *p;
-
-	for (p = optval ; p < optval + sizeof optval ; p++)
-		*p = 0;
-}
-#endif
-
-
-/*
- * Set the shell parameters.
- */
-
-void
-setparam(argv)
-	char **argv;
-	{
-	char **newparam;
-	char **ap;
-	int nparam;
-
-	for (nparam = 0 ; argv[nparam] ; nparam++);
-	ap = newparam = ckmalloc((nparam + 1) * sizeof *ap);
-	while (*argv) {
-		*ap++ = savestr(*argv++);
-	}
-	*ap = NULL;
-	freeparam(&shellparam);
-	shellparam.malloc = 1;
-	shellparam.nparam = nparam;
-	shellparam.p = newparam;
-	shellparam.optnext = NULL;
-}
-
-
-/*
- * Free the list of positional parameters.
- */
-
-void
-freeparam(param)
-	struct shparam *param;
-	{
-	char **ap;
-
-	if (param->malloc) {
-		for (ap = param->p ; *ap ; ap++)
-			ckfree(*ap);
-		ckfree(param->p);
-	}
-}
-
-
-
-/*
- * The shift builtin command.
- */
-
-shiftcmd(argc, argv)  char **argv; {
-	int n;
-	char **ap1, **ap2;
-
-	n = 1;
-	if (argc > 1)
-		n = number(argv[1]);
-	if (n > shellparam.nparam)
-		n = shellparam.nparam;
-	INTOFF;
-	shellparam.nparam -= n;
-	for (ap1 = shellparam.p ; --n >= 0 ; ap1++) {
-		if (shellparam.malloc)
-			ckfree(*ap1);
-	}
-	ap2 = shellparam.p;
-	while ((*ap2++ = *ap1++) != NULL);
-	shellparam.optnext = NULL;
-	INTON;
-	return 0;
-}
-
-
-
-/*
- * The set command builtin.
- */
-
-setcmd(argc, argv)  char **argv; {
-	if (argc == 1)
-		return showvarscmd(argc, argv);
-	INTOFF;
-	options(0);
-	setinteractive(iflag);
-	setjobctl(jflag);
-	if (*argptr != NULL) {
-		setparam(argptr);
-	}
-	INTON;
-	return 0;
-}
-
-
-/*
- * The getopts builtin.  Shellparam.optnext points to the next argument
- * to be processed.  Shellparam.optptr points to the next character to
- * be processed in the current argument.  If shellparam.optnext is NULL,
- * then it's the first time getopts has been called.
- */
-
-getoptscmd(argc, argv)  char **argv; {
-	register char *p, *q;
-	char c;
-	char s[10];
-
-	if (argc != 3)
-		error("Usage: getopts optstring var");
-	if (shellparam.optnext == NULL) {
-		shellparam.optnext = shellparam.p;
-		shellparam.optptr = NULL;
-	}
-	if ((p = shellparam.optptr) == NULL || *p == '\0') {
-		p = *shellparam.optnext;
-		if (p == NULL || *p != '-' || *++p == '\0') {
-atend:
-			fmtstr(s, 10, "%d", shellparam.optnext - shellparam.p + 1);
-			setvar("OPTIND", s, 0);
-			shellparam.optnext = NULL;
-			return 1;
-		}
-		shellparam.optnext++;
-		if (p[0] == '-' && p[1] == '\0')	/* check for "--" */
-			goto atend;
-	}
-	c = *p++;
-	for (q = argv[1] ; *q != c ; ) {
-		if (*q == '\0') {
-			out1fmt("Illegal option -%c\n", c);
-			c = '?';
-			goto out;
-		}
-		if (*++q == ':')
-			q++;
-	}
-	if (*++q == ':') {
-		if (*p == '\0') {
-			if ((p = *shellparam.optnext) == NULL) {
-				out1fmt("No arg for -%c option\n", c);
-				c = '?';
-				goto out;
-			}
-			shellparam.optnext++;
-		}
-		setvar("OPTARG", p, 0);
-		p = "";
-	}
-out:
-	shellparam.optptr = p;
-	s[0] = c;
-	s[1] = '\0';
-	setvar(argv[2], s, 0);
-	fmtstr(s, 10, "%d", shellparam.optnext - shellparam.p + 1);
-	setvar("OPTIND", s, 0);
-	return 0;
-}
-
-/*
- * Standard option processing (a la getopt) for builtin routines.  The
- * only argument that is passed to nextopt is the option string; the
- * other arguments are unnecessary.  It return the character, or '\0' on
- * end of input.
- */
-
-int
-nextopt(optstring)
-	char *optstring;
-	{
-	register char *p, *q;
-	char c;
-
-	if ((p = optptr) == NULL || *p == '\0') {
-		p = *argptr;
-		if (p == NULL || *p != '-' || *++p == '\0')
-			return '\0';
-		argptr++;
-		if (p[0] == '-' && p[1] == '\0')	/* check for "--" */
-			return '\0';
-	}
-	c = *p++;
-	for (q = optstring ; *q != c ; ) {
-		if (*q == '\0')
-			error("Illegal option -%c", c);
-		if (*++q == ':')
-			q++;
-	}
-	if (*++q == ':') {
-		if (*p == '\0' && (p = *argptr++) == NULL)
-			error("No arg for -%c option", c);
-		optarg = p;
-		p = NULL;
-	}
-	optptr = p;
-	return c;
-}
Index: trunk/minix/commands/ash/options.h
===================================================================
--- trunk/minix/commands/ash/options.h	(revision 9)
+++ 	(revision )
@@ -1,90 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)options.h	5.1 (Berkeley) 3/7/91
- */
-
-struct shparam {
-	int nparam;	/* number of positional parameters (without $0) */
-	char malloc;	/* true if parameter list dynamicly allocated */
-	char **p;		/* parameter list */
-	char **optnext;	/* next parameter to be processed by getopts */
-	char *optptr;	/* used by getopts */
-};
-
-
-
-#define eflag optval[0]
-#define fflag optval[1]
-#define Iflag optval[2]
-#define iflag optval[3]
-#define jflag optval[4]
-#define nflag optval[5]
-#define sflag optval[6]
-#define xflag optval[7]
-#define zflag optval[8]
-#define vflag optval[9]
-
-#define NOPTS	10
-
-#ifdef DEFINE_OPTIONS
-const char optchar[NOPTS+1] = "efIijnsxzv";       /* shell flags */
-char optval[NOPTS+1];           /* values of option flags */
-#else
-extern const char optchar[NOPTS+1];
-extern char optval[NOPTS+1];
-#endif
-
-
-extern char *minusc;		/* argument to -c option */
-extern char *arg0;		/* $0 */
-extern struct shparam shellparam;  /* $@ */
-extern char **argptr;		/* argument list for builtin commands */
-extern char *optarg;		/* set by nextopt */
-extern char *optptr;		/* used by nextopt */
-extern int editable;		/* isatty(0) && isatty(1) */
-
-
-#ifdef __STDC__
-void procargs(int, char **);
-void setparam(char **);
-void freeparam(struct shparam *);
-int nextopt(char *);
-#else
-void procargs();
-void setparam();
-void freeparam();
-int nextopt();
-#endif
Index: trunk/minix/commands/ash/output.c
===================================================================
--- trunk/minix/commands/ash/output.c	(revision 9)
+++ 	(revision )
@@ -1,531 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)output.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * Shell output routines.  We use our own output routines because:
- *	When a builtin command is interrupted we have to discard
- *		any pending output.
- *	When a builtin command appears in back quotes, we want to
- *		save the output of the command in a region obtained
- *		via malloc, rather than doing a fork and reading the
- *		output of the command via a pipe.
- *	Our output routines may be smaller than the stdio routines.
- */
-
-#include <stdio.h>	/* defines BUFSIZ */
-#include "shell.h"
-#include "syntax.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#ifdef __STDC__
-#include "stdarg.h"
-#else
-#include <varargs.h>
-#endif
-#include <errno.h>
-
-
-#define OUTBUFSIZ BUFSIZ
-#define BLOCK_OUT -2		/* output to a fixed block of memory */
-#define MEM_OUT -3		/* output to dynamically allocated memory */
-#define OUTPUT_ERR 01		/* error occurred on output */
-
-
-struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};
-struct output errout = {NULL, 0, NULL, 100, 2, 0};
-struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};
-struct output *out1 = &output;
-struct output *out2 = &errout;
-
-
-
-#ifdef mkinit
-
-INCLUDE "output.h"
-INCLUDE "memalloc.h"
-
-RESET {
-	out1 = &output;
-	out2 = &errout;
-	if (memout.buf != NULL) {
-		ckfree(memout.buf);
-		memout.buf = NULL;
-	}
-}
-
-#endif
-
-
-#ifdef notdef	/* no longer used */
-/*
- * Set up an output file to write to memory rather than a file.
- */
-
-void
-open_mem(block, length, file)
-	char *block;
-	int length;
-	struct output *file;
-	{
-	file->nextc = block;
-	file->nleft = --length;
-	file->fd = BLOCK_OUT;
-	file->flags = 0;
-}
-#endif
-
-
-void
-out1str(p)
-	char *p;
-	{
-	outstr(p, out1);
-}
-
-
-void
-out2str(p)
-	char *p;
-	{
-	outstr(p, out2);
-}
-
-
-void
-outstr(p, file)
-	register char *p;
-	register struct output *file;
-	{
-	while (*p)
-		outc(*p++, file);
-}
-
-
-char out_junk[16];
-
-
-void
-emptyoutbuf(dest)
-	struct output *dest;
-	{
-	int offset;
-
-	if (dest->fd == BLOCK_OUT) {
-		dest->nextc = out_junk;
-		dest->nleft = sizeof out_junk;
-		dest->flags |= OUTPUT_ERR;
-	} else if (dest->buf == NULL) {
-		INTOFF;
-		dest->buf = ckmalloc(dest->bufsize);
-		dest->nextc = dest->buf;
-		dest->nleft = dest->bufsize;
-		INTON;
-	} else if (dest->fd == MEM_OUT) {
-		offset = dest->bufsize;
-		INTOFF;
-		dest->bufsize <<= 1;
-		dest->buf = ckrealloc(dest->buf, dest->bufsize);
-		dest->nleft = dest->bufsize - offset;
-		dest->nextc = dest->buf + offset;
-		INTON;
-	} else {
-		flushout(dest);
-	}
-	dest->nleft--;
-}
-
-
-void
-flushall() {
-	flushout(&output);
-	flushout(&errout);
-}
-
-
-void
-flushout(dest)
-	struct output *dest;
-	{
-
-	if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0)
-		return;
-	if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0)
-		dest->flags |= OUTPUT_ERR;
-	dest->nextc = dest->buf;
-	dest->nleft = dest->bufsize;
-}
-
-
-void
-freestdout() {
-	INTOFF;
-	if (output.buf) {
-		ckfree(output.buf);
-		output.buf = NULL;
-		output.nleft = 0;
-	}
-	INTON;
-}
-
-
-#ifdef __STDC__
-void
-outfmt(struct output *file, char *fmt, ...) {
-	va_list ap;
-
-	va_start(ap, fmt);
-	doformat(file, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-out1fmt(char *fmt, ...) {
-	va_list ap;
-
-	va_start(ap, fmt);
-	doformat(out1, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-fmtstr(char *outbuf, int length, char *fmt, ...) {
-	va_list ap;
-	struct output strout;
-
-	va_start(ap, fmt);
-	strout.nextc = outbuf;
-	strout.nleft = length;
-	strout.fd = BLOCK_OUT;
-	strout.flags = 0;
-	doformat(&strout, fmt, ap);
-	outc('\0', &strout);
-	if (strout.flags & OUTPUT_ERR)
-		outbuf[length - 1] = '\0';
-	va_end(ap);
-}
-
-#else /* not __STDC__ */
-
-void
-outfmt(va_alist)
-	va_dcl
-	{
-	va_list ap;
-	struct output *file;
-	char *fmt;
-
-	va_start(ap);
-	file = va_arg(ap, struct output *);
-	fmt = va_arg(ap, char *);
-	doformat(file, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-out1fmt(va_alist)
-	va_dcl
-	{
-	va_list ap;
-	char *fmt;
-
-	va_start(ap);
-	fmt = va_arg(ap, char *);
-	doformat(out1, fmt, ap);
-	va_end(ap);
-}
-
-
-void
-fmtstr(va_alist)
-	va_dcl
-	{
-	va_list ap;
-	struct output strout;
-	char *outbuf;
-	int length;
-	char *fmt;
-
-	va_start(ap);
-	outbuf = va_arg(ap, char *);
-	length = va_arg(ap, int);
-	fmt = va_arg(ap, char *);
-	strout.nextc = outbuf;
-	strout.nleft = length;
-	strout.fd = BLOCK_OUT;
-	strout.flags = 0;
-	doformat(&strout, fmt, ap);
-	outc('\0', &strout);
-	if (strout.flags & OUTPUT_ERR)
-		outbuf[length - 1] = '\0';
-}
-#endif /* __STDC__ */
-
-
-/*
- * Formatted output.  This routine handles a subset of the printf formats:
- * - Formats supported: d, u, o, X, s, and c.
- * - The x format is also accepted but is treated like X.
- * - The l modifier is accepted.
- * - The - and # flags are accepted; # only works with the o format.
- * - Width and precision may be specified with any format except c.
- * - An * may be given for the width or precision.
- * - The obsolete practice of preceding the width with a zero to get
- *   zero padding is not supported; use the precision field.
- * - A % may be printed by writing %% in the format string.
- */
-
-#define TEMPSIZE 24
-
-#ifdef __STDC__
-static const char digit[16] = "0123456789ABCDEF";
-#else
-static const char digit[17] = "0123456789ABCDEF";
-#endif
-
-
-void
-doformat(dest, f, ap)
-	register struct output *dest;
-	register char *f;		/* format string */
-	va_list ap;
-	{
-	register char c;
-	char temp[TEMPSIZE];
-	int flushleft;
-	int sharp;
-	int width;
-	int prec;
-	int islong;
-	char *p;
-	int sign;
-	long l;
-	unsigned long num;
-	unsigned base;
-	int len;
-	int size;
-	int pad;
-
-	while ((c = *f++) != '\0') {
-		if (c != '%') {
-			outc(c, dest);
-			continue;
-		}
-		flushleft = 0;
-		sharp = 0;
-		width = 0;
-		prec = -1;
-		islong = 0;
-		for (;;) {
-			if (*f == '-')
-				flushleft++;
-			else if (*f == '#')
-				sharp++;
-			else
-				break;
-			f++;
-		}
-		if (*f == '*') {
-			width = va_arg(ap, int);
-			f++;
-		} else {
-			while (is_digit(*f)) {
-				width = 10 * width + digit_val(*f++);
-			}
-		}
-		if (*f == '.') {
-			if (*++f == '*') {
-				prec = va_arg(ap, int);
-				f++;
-			} else {
-				prec = 0;
-				while (is_digit(*f)) {
-					prec = 10 * prec + digit_val(*f++);
-				}
-			}
-		}
-		if (*f == 'l') {
-			islong++;
-			f++;
-		}
-		switch (*f) {
-		case 'd':
-			if (islong)
-				l = va_arg(ap, long);
-			else
-				l = va_arg(ap, int);
-			sign = 0;
-			num = l;
-			if (l < 0) {
-				num = -l;
-				sign = 1;
-			}
-			base = 10;
-			goto number;
-		case 'u':
-			base = 10;
-			goto uns_number;
-		case 'o':
-			base = 8;
-			goto uns_number;
-		case 'x':
-			/* we don't implement 'x'; treat like 'X' */
-		case 'X':
-			base = 16;
-uns_number:	  /* an unsigned number */
-			sign = 0;
-			if (islong)
-				num = va_arg(ap, unsigned long);
-			else
-				num = va_arg(ap, unsigned int);
-number:		  /* process a number */
-			p = temp + TEMPSIZE - 1;
-			*p = '\0';
-			while (num) {
-				*--p = digit[num % base];
-				num /= base;
-			}
-			len = (temp + TEMPSIZE - 1) - p;
-			if (prec < 0)
-				prec = 1;
-			if (sharp && *f == 'o' && prec <= len)
-				prec = len + 1;
-			pad = 0;
-			if (width) {
-				size = len;
-				if (size < prec)
-					size = prec;
-				size += sign;
-				pad = width - size;
-				if (flushleft == 0) {
-					while (--pad >= 0)
-						outc(' ', dest);
-				}
-			}
-			if (sign)
-				outc('-', dest);
-			prec -= len;
-			while (--prec >= 0)
-				outc('0', dest);
-			while (*p)
-				outc(*p++, dest);
-			while (--pad >= 0)
-				outc(' ', dest);
-			break;
-		case 's':
-			p = va_arg(ap, char *);
-			pad = 0;
-			if (width) {
-				len = strlen(p);
-				if (prec >= 0 && len > prec)
-					len = prec;
-				pad = width - len;
-				if (flushleft == 0) {
-					while (--pad >= 0)
-						outc(' ', dest);
-				}
-			}
-			prec++;
-			while (--prec != 0 && *p)
-				outc(*p++, dest);
-			while (--pad >= 0)
-				outc(' ', dest);
-			break;
-		case 'c':
-			c = va_arg(ap, int);
-			outc(c, dest);
-			break;
-		default:
-			outc(*f, dest);
-			break;
-		}
-		f++;
-	}
-}
-
-
-
-/*
- * Version of write which resumes after a signal is caught.
- */
-
-int
-xwrite(fd, buf, nbytes)
-	int fd;
-	char *buf;
-	int nbytes;
-	{
-	int ntry;
-	int i;
-	int n;
-
-	n = nbytes;
-	ntry = 0;
-	for (;;) {
-		i = write(fd, buf, n);
-		if (i > 0) {
-			if ((n -= i) <= 0)
-				return nbytes;
-			buf += i;
-			ntry = 0;
-		} else if (i == 0) {
-			if (++ntry > 10)
-				return nbytes - n;
-		} else if (errno != EINTR) {
-			return -1;
-		}
-	}
-}
-
-
-/*
- * Version of ioctl that retries after a signal is caught.
- */
-
-int
-xioctl(fd, request, arg) {
-	int i;
-
-	while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR);
-	return i;
-}
Index: trunk/minix/commands/ash/output.h
===================================================================
--- trunk/minix/commands/ash/output.h	(revision 9)
+++ 	(revision )
@@ -1,94 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)output.h	5.1 (Berkeley) 3/7/91
- */
-
-#ifndef OUTPUT_INCL
-
-struct output {
-	char *nextc;
-	int nleft;
-	char *buf;
-	int bufsize;
-	short fd;
-	short flags;
-};
-
-extern struct output output;
-extern struct output errout;
-extern struct output memout;
-extern struct output *out1;
-extern struct output *out2;
-
-
-#ifdef __STDC__
-void outstr(char *, struct output *);
-void out1str(char *);
-void out2str(char *);
-void outfmt(struct output *, char *, ...);
-void out1fmt(char *, ...);
-void fmtstr(char *, int, char *, ...);
-/* void doformat(struct output *, char *, va_list); */
-void doformat();
-void emptyoutbuf(struct output *);
-void flushall(void);
-void flushout(struct output *);
-void freestdout(void);
-int xwrite(int, char *, int);
-int xioctl(int, int, int);
-#else
-void outstr();
-void out1str();
-void out2str();
-void outfmt();
-void out1fmt();
-void fmtstr();
-/* void doformat(); */
-void doformat();
-void emptyoutbuf();
-void flushall();
-void flushout();
-void freestdout();
-int xwrite();
-int xioctl();
-#endif
-
-#define outc(c, file)	(--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
-#define out1c(c)	outc(c, out1);
-#define out2c(c)	outc(c, out2);
-
-#define OUTPUT_INCL
-#endif
Index: trunk/minix/commands/ash/parser.c
===================================================================
--- trunk/minix/commands/ash/parser.c	(revision 9)
+++ 	(revision )
@@ -1,1329 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)parser.c	5.3 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-#include "shell.h"
-#include "parser.h"
-#include "nodes.h"
-#include "expand.h"	/* defines rmescapes() */
-#include "redir.h"	/* defines copyfd() */
-#include "syntax.h"
-#include "options.h"
-#include "input.h"
-#include "output.h"
-#include "var.h"
-#include "error.h"
-#include "memalloc.h"
-#include "mystring.h"
-
-
-/*
- * Shell command parser.
- */
-
-#define EOFMARKLEN 79
-
-/* values returned by readtoken */
-#include "token.def"
-
-
-
-struct heredoc {
-	struct heredoc *next;	/* next here document in list */
-	union node *here;		/* redirection node */
-	char *eofmark;		/* string indicating end of input */
-	int striptabs;		/* if set, strip leading tabs */
-};
-
-
-
-struct heredoc *heredoclist;	/* list of here documents to read */
-int parsebackquote;		/* nonzero if we are inside backquotes */
-int doprompt;			/* if set, prompt the user */
-int needprompt;			/* true if interactive and at start of line */
-int lasttoken;			/* last token read */
-MKINIT int tokpushback;		/* last token pushed back */
-char *wordtext;			/* text of last word returned by readtoken */
-int checkkwd;               /* 1 == check for kwds, 2 == also eat newlines */
-struct nodelist *backquotelist;
-union node *redirnode;
-struct heredoc *heredoc;
-int quoteflag;			/* set if (part of) last token was quoted */
-int startlinno;			/* line # where last token started */
-
-
-#define GDB_HACK 1 /* avoid local declarations which gdb can't handle */
-#ifdef GDB_HACK
-static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0'};
-static const char types[] = "}-+?=";
-#endif
-
-
-STATIC union node *list __P((int));
-STATIC union node *andor __P((void));
-STATIC union node *pipeline __P((void));
-STATIC union node *command __P((void));
-STATIC union node *simplecmd __P((union node **, union node *));
-STATIC void parsefname __P((void));
-STATIC void parseheredoc __P((void));
-STATIC int readtoken __P((void));
-STATIC int readtoken1 __P((int, char const *, char *, int));
-STATIC void attyline __P((void));
-STATIC int noexpand __P((char *));
-STATIC void synexpect __P((int));
-STATIC void synerror __P((char *));
-
-#if ATTY || READLINE
-STATIC void putprompt __P((char *));
-#else /* not ATTY */
-#define putprompt(s)	out2str(s)
-#endif
-
-
-
-
-/*
- * Read and parse a command.  Returns NEOF on end of file.  (NULL is a
- * valid parse tree indicating a blank line.)
- */
-
-union node *
-parsecmd(interact) {
-	int t;
-	extern int exitstatus;
-
-	doprompt = interact;
-	if (doprompt)
-		putprompt(exitstatus == 0 ? ps1val() : pseval());
-	needprompt = 0;
-	if ((t = readtoken()) == TEOF)
-		return NEOF;
-	if (t == TNL)
-		return NULL;
-	tokpushback++;
-	return list(1);
-}
-
-
-STATIC union node *
-list(nlflag) {
-	union node *n1, *n2, *n3, **pn;
-	int first;
-
-	checkkwd = 2;
-	if (nlflag == 0 && tokendlist[peektoken()])
-		return NULL;
-	n1 = andor();
-	for (first = 1; ; first = 0) {
-		switch (readtoken()) {
-		case TBACKGND:
-			pn = &n1;
-			if (!first && n1->type == NSEMI) pn = &n1->nbinary.ch2;
-			if ((*pn)->type == NCMD || (*pn)->type == NPIPE) {
-				(*pn)->ncmd.backgnd = 1;
-			} else if ((*pn)->type == NREDIR) {
-				(*pn)->type = NBACKGND;
-			} else {
-				n3 = (union node *)stalloc(sizeof (struct nredir));
-				n3->type = NBACKGND;
-				n3->nredir.n = *pn;
-				n3->nredir.redirect = NULL;
-				*pn = n3;
-			}
-			goto tsemi;
-		case TNL:
-			tokpushback++;
-			/* fall through */
-tsemi:		case TSEMI:
-			if (readtoken() == TNL) {
-				parseheredoc();
-				if (nlflag)
-					return n1;
-			} else {
-				tokpushback++;
-			}
-			checkkwd = 2;
-			if (tokendlist[peektoken()])
-				return n1;
-			n2 = andor();
-			n3 = (union node *)stalloc(sizeof (struct nbinary));
-			n3->type = NSEMI;
-			n3->nbinary.ch1 = n1;
-			n3->nbinary.ch2 = n2;
-			n1 = n3;
-			break;
-		case TEOF:
-			if (heredoclist)
-				parseheredoc();
-			else
-				pungetc();		/* push back EOF on input */
-			return n1;
-		default:
-			if (nlflag)
-				synexpect(-1);
-			tokpushback++;
-			return n1;
-		}
-	}
-}
-
-
-
-STATIC union node *
-andor() {
-	union node *n1, *n2, *n3;
-	int t;
-
-	n1 = pipeline();
-	for (;;) {
-		if ((t = readtoken()) == TAND) {
-			t = NAND;
-		} else if (t == TOR) {
-			t = NOR;
-		} else {
-			tokpushback++;
-			return n1;
-		}
-		n2 = pipeline();
-		n3 = (union node *)stalloc(sizeof (struct nbinary));
-		n3->type = t;
-		n3->nbinary.ch1 = n1;
-		n3->nbinary.ch2 = n2;
-		n1 = n3;
-	}
-}
-
-
-
-STATIC union node *
-pipeline() {
-	union node *n1, *pipenode;
-	struct nodelist *lp, *prev;
-
-	n1 = command();
-	if (readtoken() == TPIPE) {
-		pipenode = (union node *)stalloc(sizeof (struct npipe));
-		pipenode->type = NPIPE;
-		pipenode->npipe.backgnd = 0;
-		lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
-		pipenode->npipe.cmdlist = lp;
-		lp->n = n1;
-		do {
-			prev = lp;
-			lp = (struct nodelist *)stalloc(sizeof (struct nodelist));
-			lp->n = command();
-			prev->next = lp;
-		} while (readtoken() == TPIPE);
-		lp->next = NULL;
-		n1 = pipenode;
-	}
-	tokpushback++;
-	return n1;
-}
-
-
-
-STATIC union node *
-command() {
-	union node *n1, *n2;
-	union node *ap, **app;
-	union node *cp, **cpp;
-	union node *redir, **rpp;
-	int t;
-
-	checkkwd = 2;
-	redir = 0;
-	rpp = &redir;
-	/* Check for redirection which may precede command */
-	while (readtoken() == TREDIR) {
-		*rpp = n2 = redirnode;
-		rpp = &n2->nfile.next;
-		parsefname();
-	}
-	tokpushback++;
-
-	switch (readtoken()) {
-	case TIF:
-		n1 = (union node *)stalloc(sizeof (struct nif));
-		n1->type = NIF;
-		n1->nif.test = list(0);
-		if (readtoken() != TTHEN)
-			synexpect(TTHEN);
-		n1->nif.ifpart = list(0);
-		n2 = n1;
-		while (readtoken() == TELIF) {
-			n2->nif.elsepart = (union node *)stalloc(sizeof (struct nif));
-			n2 = n2->nif.elsepart;
-			n2->type = NIF;
-			n2->nif.test = list(0);
-			if (readtoken() != TTHEN)
-				synexpect(TTHEN);
-			n2->nif.ifpart = list(0);
-		}
-		if (lasttoken == TELSE)
-			n2->nif.elsepart = list(0);
-		else {
-			n2->nif.elsepart = NULL;
-			tokpushback++;
-		}
-		if (readtoken() != TFI)
-			synexpect(TFI);
-		checkkwd = 1;
-		break;
-	case TWHILE:
-	case TUNTIL: {
-		int got;
-		n1 = (union node *)stalloc(sizeof (struct nbinary));
-		n1->type = (lasttoken == TWHILE)? NWHILE : NUNTIL;
-		n1->nbinary.ch1 = list(0);
-		if ((got=readtoken()) != TDO) {
-TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
-			synexpect(TDO);
-		}
-		n1->nbinary.ch2 = list(0);
-		if (readtoken() != TDONE)
-			synexpect(TDONE);
-		checkkwd = 1;
-		break;
-	}
-	case TFOR:
-		if (readtoken() != TWORD || quoteflag || ! goodname(wordtext))
-			synerror("Bad for loop variable");
-		n1 = (union node *)stalloc(sizeof (struct nfor));
-		n1->type = NFOR;
-		n1->nfor.var = wordtext;
-		if (readtoken() == TWORD && ! quoteflag && equal(wordtext, "in")) {
-			app = &ap;
-			while (readtoken() == TWORD) {
-				n2 = (union node *)stalloc(sizeof (struct narg));
-				n2->type = NARG;
-				n2->narg.text = wordtext;
-				n2->narg.backquote = backquotelist;
-				*app = n2;
-				app = &n2->narg.next;
-			}
-			*app = NULL;
-			n1->nfor.args = ap;
-			/* A newline or semicolon is required here to end
-			   the list.  */
-			if (lasttoken != TNL && lasttoken != TSEMI)
-				synexpect(-1);
-		} else {
-#ifndef GDB_HACK
-			static const char argvars[5] = {CTLVAR, VSNORMAL|VSQUOTE,
-								   '@', '=', '\0'};
-#endif
-			n2 = (union node *)stalloc(sizeof (struct narg));
-			n2->type = NARG;
-			n2->narg.text = (char *)argvars;
-			n2->narg.backquote = NULL;
-			n2->narg.next = NULL;
-			n1->nfor.args = n2;
-			/* A newline or semicolon is optional here. Anything
-			   else gets pushed back so we can read it again.  */
-			if (lasttoken != TNL && lasttoken != TSEMI)
-				tokpushback++;
-		}
-		checkkwd = 2;
-		if ((t = readtoken()) == TDO)
-			t = TDONE;
-		else if (t == TBEGIN)
-			t = TEND;
-		else
-			synexpect(-1);
-		n1->nfor.body = list(0);
-		if (readtoken() != t)
-			synexpect(t);
-		checkkwd = 1;
-		break;
-	case TCASE:
-		n1 = (union node *)stalloc(sizeof (struct ncase));
-		n1->type = NCASE;
-		if (readtoken() != TWORD)
-			synexpect(TWORD);
-		n1->ncase.expr = n2 = (union node *)stalloc(sizeof (struct narg));
-		n2->type = NARG;
-		n2->narg.text = wordtext;
-		n2->narg.backquote = backquotelist;
-		n2->narg.next = NULL;
-		while (readtoken() == TNL);
-		if (lasttoken != TWORD || ! equal(wordtext, "in"))
-			synerror("expecting \"in\"");
-		cpp = &n1->ncase.cases;
-		while (checkkwd = 2, readtoken() == TWORD) {
-			*cpp = cp = (union node *)stalloc(sizeof (struct nclist));
-			cp->type = NCLIST;
-			app = &cp->nclist.pattern;
-			for (;;) {
-				*app = ap = (union node *)stalloc(sizeof (struct narg));
-				ap->type = NARG;
-				ap->narg.text = wordtext;
-				ap->narg.backquote = backquotelist;
-				if (readtoken() != TPIPE)
-					break;
-				app = &ap->narg.next;
-				if (readtoken() != TWORD)
-					synexpect(TWORD);
-			}
-			ap->narg.next = NULL;
-			if (lasttoken != TRP)
-				synexpect(TRP);
-			cp->nclist.body = list(0);
-			if ((t = readtoken()) == TESAC)
-				tokpushback++;
-			else if (t != TENDCASE)
-				synexpect(TENDCASE);
-			cpp = &cp->nclist.next;
-		}
-		*cpp = NULL;
-		if (lasttoken != TESAC)
-			synexpect(TESAC);
-		checkkwd = 1;
-		break;
-	case TLP:
-		n1 = (union node *)stalloc(sizeof (struct nredir));
-		n1->type = NSUBSHELL;
-		n1->nredir.n = list(0);
-		n1->nredir.redirect = NULL;
-		if (readtoken() != TRP)
-			synexpect(TRP);
-		checkkwd = 1;
-		break;
-	case TBEGIN:
-		n1 = list(0);
-		if (readtoken() != TEND)
-			synexpect(TEND);
-		checkkwd = 1;
-		break;
-	/* Handle an empty command like other simple commands.  */
-	case TNL:
-	case TSEMI:
-	case TEND:
-	case TRP:
-	case TEOF:
-	case TWORD:
-		tokpushback++;
-		return simplecmd(rpp, redir);
-	default:
-		synexpect(-1);
-	}
-
-	/* Now check for redirection which may follow command */
-	while (readtoken() == TREDIR) {
-		*rpp = n2 = redirnode;
-		rpp = &n2->nfile.next;
-		parsefname();
-	}
-	tokpushback++;
-	*rpp = NULL;
-	if (redir) {
-		if (n1->type != NSUBSHELL) {
-			n2 = (union node *)stalloc(sizeof (struct nredir));
-			n2->type = NREDIR;
-			n2->nredir.n = n1;
-			n1 = n2;
-		}
-		n1->nredir.redirect = redir;
-	}
-	return n1;
-}
-
-
-STATIC union node *
-simplecmd(rpp, redir)
-	union node **rpp, *redir;
-	{
-	union node *args, **app;
-	union node **orig_rpp = rpp;
-	union node *n;
-
-	/* If we don't have any redirections already, then we must reset
-	   rpp to be the address of the local redir variable.  */
-	if (redir == 0)
-		rpp = &redir;
-
-	args = NULL;
-	app = &args;
-	/* We save the incoming value, because we need this for shell
-	   functions.  There can not be a redirect or an argument between
-	   the function name and the open parenthesis.  */
-	orig_rpp = rpp;
-	for (;;) {
-		if (readtoken() == TWORD) {
-			n = (union node *)stalloc(sizeof (struct narg));
-			n->type = NARG;
-			n->narg.text = wordtext;
-			n->narg.backquote = backquotelist;
-			*app = n;
-			app = &n->narg.next;
-		} else if (lasttoken == TREDIR) {
-			*rpp = n = redirnode;
-			rpp = &n->nfile.next;
-			parsefname();	/* read name of redirection file */
-		} else if (lasttoken == TLP && app == &args->narg.next
-					    && rpp == orig_rpp) {
-			/* We have a function */
-			if (readtoken() != TRP)
-				synexpect(TRP);
-#ifdef notdef
-			if (! goodname(n->narg.text))
-				synerror("Bad function name");
-#endif
-			n->type = NDEFUN;
-			n->narg.next = command();
-			return n;
-		} else {
-			tokpushback++;
-			break;
-		}
-	}
-	*app = NULL;
-	*rpp = NULL;
-	n = (union node *)stalloc(sizeof (struct ncmd));
-	n->type = NCMD;
-	n->ncmd.backgnd = 0;
-	n->ncmd.args = args;
-	n->ncmd.redirect = redir;
-	return n;
-}
-
-
-STATIC void
-parsefname() {
-	union node *n = redirnode;
-
-	if (readtoken() != TWORD)
-		synexpect(-1);
-	if (n->type == NHERE) {
-		struct heredoc *here = heredoc;
-		struct heredoc *p;
-		int i;
-
-		if (quoteflag == 0)
-			n->type = NXHERE;
-		TRACE(("Here document %d\n", n->type));
-		if (here->striptabs) {
-			while (*wordtext == '\t')
-				wordtext++;
-		}
-		if (! noexpand(wordtext) || (i = strlen(wordtext)) == 0 || i > EOFMARKLEN)
-			synerror("Illegal eof marker for << redirection");
-		rmescapes(wordtext);
-		here->eofmark = wordtext;
-		here->next = NULL;
-		if (heredoclist == NULL)
-			heredoclist = here;
-		else {
-			for (p = heredoclist ; p->next ; p = p->next);
-			p->next = here;
-		}
-	} else if (n->type == NTOFD || n->type == NFROMFD) {
-		if (is_digit(wordtext[0]))
-			n->ndup.dupfd = digit_val(wordtext[0]);
-		else if (wordtext[0] == '-')
-			n->ndup.dupfd = -1;
-		else
-			goto bad;
-		if (wordtext[1] != '\0') {
-bad:
-			synerror("Bad fd number");
-		}
-	} else {
-		n->nfile.fname = (union node *)stalloc(sizeof (struct narg));
-		n = n->nfile.fname;
-		n->type = NARG;
-		n->narg.next = NULL;
-		n->narg.text = wordtext;
-		n->narg.backquote = backquotelist;
-	}
-}
-
-
-/*
- * Input any here documents.
- */
-
-STATIC void
-parseheredoc() {
-	struct heredoc *here;
-	union node *n;
-
-	while (heredoclist) {
-		here = heredoclist;
-		heredoclist = here->next;
-		if (needprompt) {
-			putprompt(ps2val());
-			needprompt = 0;
-		}
-		readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
-				here->eofmark, here->striptabs);
-		n = (union node *)stalloc(sizeof (struct narg));
-		n->narg.type = NARG;
-		n->narg.next = NULL;
-		n->narg.text = wordtext;
-		n->narg.backquote = backquotelist;
-		here->here->nhere.doc = n;
-	}
-}
-
-STATIC int
-peektoken() {
-	int t;
-
-	t = readtoken();
-	tokpushback++;
-	return (t);
-}
-
-STATIC int xxreadtoken();
-
-STATIC int
-readtoken() {
-	int t;
-#if DEBUG
-	int alreadyseen = tokpushback;
-#endif
-	
-	t = xxreadtoken();
-
-	if (checkkwd) {
-		/*
-		 * eat newlines
-		 */
-		if (checkkwd == 2) {
-			checkkwd = 0;
-			while (t == TNL) {
-				parseheredoc();
-				t = xxreadtoken();
-			}
-		} else
-			checkkwd = 0;
-		/*
-		 * check for keywords
-		 */
-		if (t == TWORD && !quoteflag) {
-			register char *const *pp;
-
-			for (pp = parsekwd; *pp; pp++) {
-				if (**pp == *wordtext && equal(*pp, wordtext)) {
-					lasttoken = t = pp - parsekwd + KWDOFFSET;
-					TRACE(("keyword %s recognized\n", tokname[t]));
-					break;
-				}
-			}
-		}
-	}
-#if DEBUG
-	if (!alreadyseen)
-	    TRACE(("token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
-	else
-	    TRACE(("reread token %s %s\n", tokname[t], t == TWORD ? wordtext : ""));
-#endif
-	return (t);
-}
-
-
-/*
- * Read the next input token.
- * If the token is a word, we set backquotelist to the list of cmds in
- *	backquotes.  We set quoteflag to true if any part of the word was
- *	quoted.
- * If the token is TREDIR, then we set redirnode to a structure containing
- *	the redirection.
- * In all cases, the variable startlinno is set to the number of the line
- *	on which the token starts.
- *
- * [Change comment:  here documents and internal procedures]
- * [Readtoken shouldn't have any arguments.  Perhaps we should make the
- *  word parsing code into a separate routine.  In this case, readtoken
- *  doesn't need to have any internal procedures, but parseword does.
- *  We could also make parseoperator in essence the main routine, and
- *  have parseword (readtoken1?) handle both words and redirection.]
- */
-
-#define RETURN(token)	return lasttoken = token
-
-STATIC int
-xxreadtoken() {
-	register c;
-
-	if (tokpushback) {
-		tokpushback = 0;
-		return lasttoken;
-	}
-	if (needprompt) {
-		putprompt(ps2val());
-		needprompt = 0;
-	}
-	startlinno = plinno;
-	for (;;) {	/* until token or start of word found */
-		c = pgetc_macro();
-		if (c == ' ' || c == '\t')
-			continue;		/* quick check for white space first */
-		switch (c) {
-		case ' ': case '\t':
-			continue;
-		case '#':
-			while ((c = pgetc()) != '\n' && c != PEOF);
-			pungetc();
-			continue;
-		case '\\':
-			if (pgetc() == '\n') {
-				startlinno = ++plinno;
-				if (doprompt)
-					putprompt(ps2val());
-				continue;
-			}
-			pungetc();
-			goto breakloop;
-		case '\n':
-			plinno++;
-			needprompt = doprompt;
-			RETURN(TNL);
-		case PEOF:
-			RETURN(TEOF);
-		case '&':
-			if (pgetc() == '&')
-				RETURN(TAND);
-			pungetc();
-			RETURN(TBACKGND);
-		case '|':
-			if (pgetc() == '|')
-				RETURN(TOR);
-			pungetc();
-			RETURN(TPIPE);
-		case ';':
-			if (pgetc() == ';')
-				RETURN(TENDCASE);
-			pungetc();
-			RETURN(TSEMI);
-		case '(':
-			RETURN(TLP);
-		case ')':
-			RETURN(TRP);
-		default:
-			goto breakloop;
-		}
-	}
-breakloop:
-	return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
-#undef RETURN
-}
-
-
-
-/*
- * If eofmark is NULL, read a word or a redirection symbol.  If eofmark
- * is not NULL, read a here document.  In the latter case, eofmark is the
- * word which marks the end of the document and striptabs is true if
- * leading tabs should be stripped from the document.  The argument firstc
- * is the first character of the input token or document.
- *
- * Because C does not have internal subroutines, I have simulated them
- * using goto's to implement the subroutine linkage.  The following macros
- * will run code that appears at the end of readtoken1.
- */
-
-#define CHECKEND()	{goto checkend; checkend_return:;}
-#define PARSEREDIR()	{goto parseredir; parseredir_return:;}
-#define PARSESUB()	{goto parsesub; parsesub_return:;}
-#define PARSEBACKQOLD()	{oldstyle = 1; goto parsebackq; parsebackq_oldreturn:;}
-#define PARSEBACKQNEW()	{oldstyle = 0; goto parsebackq; parsebackq_newreturn:;}
-
-STATIC int
-readtoken1(firstc, syntax, eofmark, striptabs)
-	int firstc;
-	char const *syntax;
-	char *eofmark;
-	int striptabs;
-	{
-	register c = firstc;
-	register char *out;
-	int len;
-	char line[EOFMARKLEN + 1];
-	struct nodelist *bqlist;
-	int quotef;
-	int dblquote;
-	int varnest;
-	int oldstyle;
-
-	startlinno = plinno;
-	dblquote = 0;
-	if (syntax == DQSYNTAX)
-		dblquote = 1;
-	quotef = 0;
-	bqlist = NULL;
-	varnest = 0;
-	STARTSTACKSTR(out);
-	loop: {	/* for each line, until end of word */
-#if ATTY
-		if (c == '\034' && doprompt
-		 && attyset() && ! equal(termval(), "emacs")) {
-			attyline();
-			if (syntax == BASESYNTAX)
-				return readtoken();
-			c = pgetc();
-			goto loop;
-		}
-#endif
-		CHECKEND();	/* set c to PEOF if at end of here document */
-		for (;;) {	/* until end of line or end of word */
-			CHECKSTRSPACE(3, out);	/* permit 3 calls to USTPUTC */
-			switch(syntax[c]) {
-			case CNL:	/* '\n' */
-				if (syntax == BASESYNTAX)
-					goto endword;	/* exit outer loop */
-				USTPUTC(c, out);
-				plinno++;
-				if (doprompt) {
-					putprompt(ps2val());
-				}
-				c = pgetc();
-				goto loop;		/* continue outer loop */
-			case CWORD:
-				USTPUTC(c, out);
-				break;
-			case CCTL:
-				if (eofmark == NULL || dblquote)
-					USTPUTC(CTLESC, out);
-				USTPUTC(c, out);
-				break;
-			case CBACK:	/* backslash */
-				c = pgetc();
-				if (c == PEOF) {
-					USTPUTC('\\', out);
-					pungetc();
-				} else if (c == '\n') {
-					if (doprompt)
-						putprompt(ps2val());
-				} else {
-					if (dblquote && c != '\\' && c != '`' && c != '$'
-							 && (c != '"' || eofmark != NULL))
-						USTPUTC('\\', out);
-					if (SQSYNTAX[c] == CCTL)
-						USTPUTC(CTLESC, out);
-					USTPUTC(c, out);
-					quotef++;
-				}
-				break;
-			case CSQUOTE:
-				syntax = SQSYNTAX;
-				break;
-			case CDQUOTE:
-				syntax = DQSYNTAX;
-				dblquote = 1;
-				break;
-			case CENDQUOTE:
-				if (eofmark) {
-					USTPUTC(c, out);
-				} else {
-					syntax = BASESYNTAX;
-					quotef++;
-					dblquote = 0;
-				}
-				break;
-			case CVAR:	/* '$' */
-				PARSESUB();		/* parse substitution */
-				break;
-			case CENDVAR:	/* '}' */
-				if (varnest > 0) {
-					varnest--;
-					USTPUTC(CTLENDVAR, out);
-				} else {
-					USTPUTC(c, out);
-				}
-				break;
-			case CBQUOTE:	/* '`' */
-				PARSEBACKQOLD();
-				break;
-			case CEOF:
-				goto endword;		/* exit outer loop */
-			default:
-				if (varnest == 0)
-					goto endword;	/* exit outer loop */
-				USTPUTC(c, out);
-			}
-			c = pgetc_macro();
-		}
-	}
-endword:
-	if (syntax != BASESYNTAX && ! parsebackquote && eofmark == NULL)
-		synerror("Unterminated quoted string");
-	if (varnest != 0) {
-		startlinno = plinno;
-		synerror("Missing '}'");
-	}
-	USTPUTC('\0', out);
-	len = out - stackblock();
-	out = stackblock();
-	if (eofmark == NULL) {
-		if ((c == '>' || c == '<')
-		 && quotef == 0
-		 && len <= 2
-		 && (*out == '\0' || is_digit(*out))) {
-			PARSEREDIR();
-			return lasttoken = TREDIR;
-		} else {
-			pungetc();
-		}
-	}
-	quoteflag = quotef;
-	backquotelist = bqlist;
-	grabstackblock(len);
-	wordtext = out;
-	return lasttoken = TWORD;
-/* end of readtoken routine */
-
-
-
-/*
- * Check to see whether we are at the end of the here document.  When this
- * is called, c is set to the first character of the next input line.  If
- * we are at the end of the here document, this routine sets the c to PEOF.
- */
-
-checkend: {
-	if (eofmark) {
-		if (striptabs) {
-			while (c == '\t')
-				c = pgetc();
-		}
-		if (c == *eofmark) {
-			if (pfgets(line, sizeof line) != NULL) {
-				register char *p, *q;
-
-				p = line;
-				for (q = eofmark + 1 ; *q && *p == *q ; p++, q++);
-				if (*p == '\n' && *q == '\0') {
-					c = PEOF;
-					plinno++;
-					needprompt = doprompt;
-				} else {
-					ppushback(line, strlen(line));
-				}
-			}
-		}
-	}
-	goto checkend_return;
-}
-
-
-/*
- * Parse a redirection operator.  The variable "out" points to a string
- * specifying the fd to be redirected.  The variable "c" contains the
- * first character of the redirection operator.
- */
-
-parseredir: {
-	char fd = *out;
-	union node *np;
-
-	np = (union node *)stalloc(sizeof (struct nfile));
-	if (c == '>') {
-		np->nfile.fd = 1;
-		c = pgetc();
-		if (c == '>')
-			np->type = NAPPEND;
-		else if (c == '&')
-			np->type = NTOFD;
-		else {
-			np->type = NTO;
-			pungetc();
-		}
-	} else {	/* c == '<' */
-		np->nfile.fd = 0;
-		c = pgetc();
-		if (c == '<') {
-			if (sizeof (struct nfile) != sizeof (struct nhere)) {
-				np = (union node *)stalloc(sizeof (struct nhere));
-				np->nfile.fd = 0;
-			}
-			np->type = NHERE;
-			heredoc = (struct heredoc *)stalloc(sizeof (struct heredoc));
-			heredoc->here = np;
-			if ((c = pgetc()) == '-') {
-				heredoc->striptabs = 1;
-			} else {
-				heredoc->striptabs = 0;
-				pungetc();
-			}
-		} else if (c == '&')
-			np->type = NFROMFD;
-		else {
-			np->type = NFROM;
-			pungetc();
-		}
-	}
-	if (fd != '\0')
-		np->nfile.fd = digit_val(fd);
-	redirnode = np;
-	goto parseredir_return;
-}
-
-
-/*
- * Parse a substitution.  At this point, we have read the dollar sign
- * and nothing else.
- */
-
-parsesub: {
-	int subtype;
-	int typeloc;
-	int flags;
-	char *p;
-#ifndef GDB_HACK
-	static const char types[] = "}-+?=";
-#endif
-
-	c = pgetc();
-	if (c != '(' && c != '{' && !is_name(c) && !is_special(c)) {
-		USTPUTC('$', out);
-		pungetc();
-	} else if (c == '(') {	/* $(command) */
-		PARSEBACKQNEW();
-	} else {
-		USTPUTC(CTLVAR, out);
-		typeloc = out - stackblock();
-		USTPUTC(VSNORMAL, out);
-		subtype = VSNORMAL;
-		if (c == '{') {
-			c = pgetc();
-			subtype = 0;
-		}
-		if (is_name(c)) {
-			do {
-				STPUTC(c, out);
-				c = pgetc();
-			} while (is_in_name(c));
-		} else {
-			if (! is_special(c))
-badsub:				synerror("Bad substitution");
-			USTPUTC(c, out);
-			c = pgetc();
-		}
-		STPUTC('=', out);
-		flags = 0;
-		if (subtype == 0) {
-			if (c == ':') {
-				flags = VSNUL;
-				c = pgetc();
-			}
-			p = strchr(types, c);
-			if (p == NULL)
-				goto badsub;
-			subtype = p - types + VSNORMAL;
-		} else {
-			pungetc();
-		}
-		if (dblquote)
-			flags |= VSQUOTE;
-		*(stackblock() + typeloc) = subtype | flags;
-		if (subtype != VSNORMAL)
-			varnest++;
-	}
-	goto parsesub_return;
-}
-
-
-/*
- * Called to parse command substitutions.  Newstyle is set if the command
- * is enclosed inside $(...); nlpp is a pointer to the head of the linked
- * list of commands (passed by reference), and savelen is the number of
- * characters on the top of the stack which must be preserved.
- */
-
-parsebackq: {
-	struct nodelist **nlpp;
-	int savepbq;
-	union node *n;
-	char *volatile str;
-	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-	int savelen;
-	int savedoprompt;
-
-	savepbq = parsebackquote;
-	if (setjmp(jmploc.loc)) {
-		if (str)
-			ckfree(str);
-		parsebackquote = 0;
-		handler = savehandler;
-		longjmp(handler->loc, 1);
-	}
-	INTOFF;
-	str = NULL;
-	savelen = out - stackblock();
-	if (savelen > 0) {
-		str = ckmalloc(savelen);
-		bcopy(stackblock(), str, savelen);
-	}
-	savehandler = handler;
-	handler = &jmploc;
-	INTON;
-	if (oldstyle) {
-		/* We must read until the closing backquote, giving special
-		   treatment to some slashes, and then push the string and
-		   reread it as input, interpreting it normally.  */
-		register char *out;
-		register c;
-		int savelen;
-		char *str;
-
-		STARTSTACKSTR(out);
-		while ((c = pgetc ()) != '`') {
-			if (c == '\\') {
-				c = pgetc ();
-				if (c != '\\' && c != '`' && c != '$'
-				    && (!dblquote || c != '"'))
-					STPUTC('\\', out);
-			}
-			if (c == '\n') {
-				plinno++;
-				if (doprompt)
-					putprompt(ps2val());
-			}
-			STPUTC(c, out);
-		}
-		STPUTC('\0', out);
-		savelen = out - stackblock();
-		if (savelen > 0) {
-			str = ckmalloc(savelen);
-			bcopy(stackblock(), str, savelen);
-		}
-		setinputstring(str, 1);
-		savedoprompt = doprompt;
-		doprompt = 0;	/* no prompts while rereading string */
-	}
-	nlpp = &bqlist;
-	while (*nlpp)
-		nlpp = &(*nlpp)->next;
-	*nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist));
-	(*nlpp)->next = NULL;
-	parsebackquote = oldstyle;
-	n = list(0);
-	if (!oldstyle && (readtoken() != TRP))
-		synexpect(TRP);
-	(*nlpp)->n = n;
-	/* Start reading from old file again.  */
-	if (oldstyle) {
-		popfile();
-		doprompt = savedoprompt;
-	}
-	while (stackblocksize() <= savelen)
-		growstackblock();
-	STARTSTACKSTR(out);
-	if (str) {
-		bcopy(str, out, savelen);
-		STADJUST(savelen, out);
-		INTOFF;
-		ckfree(str);
-		str = NULL;
-		INTON;
-	}
-	parsebackquote = savepbq;
-	handler = savehandler;
-	USTPUTC(CTLBACKQ + dblquote, out);
-	if (oldstyle)
-		goto parsebackq_oldreturn;
-	else
-		goto parsebackq_newreturn;
-}
-
-} /* end of readtoken */
-
-
-
-#ifdef mkinit
-RESET {
-	tokpushback = 0;
-}
-#endif
-
-
-#if READLINE
-/*
- * Remember a prompt for use with readline if input and output is a terminal.
- */
-
-STATIC void
-putprompt(s)
-	char *s;
-	{
-	if (editable) {
-		r_use_prompt = s;
-	} else {
-		out2str(s);
-	}
-}
-#endif
-
-#if ATTY
-/*
- * Called to process a command generated by atty.  We execute the line,
- * and catch any errors that occur so they don't propagate outside of
- * this routine.
- */
-
-STATIC void
-attyline() {
-	char line[256];
-	struct stackmark smark;
-	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-
-	if (pfgets(line, sizeof line) == NULL)
-		return;				/* "can't happen" */
-	if (setjmp(jmploc.loc)) {
-		if (exception == EXERROR)
-			out2str("\033]D\n");
-		handler = savehandler;
-		longjmp(handler->loc, 1);
-	}
-	savehandler = handler;
-	handler = &jmploc;
-	setstackmark(&smark);
-	evalstring(line);
-	popstackmark(&smark);
-	handler = savehandler;
-	doprompt = 1;
-}
-
-
-/*
- * Output a prompt for atty.  We output the prompt as part of the
- * appropriate escape sequence.  
- */
-
-STATIC void
-putprompt(s)
-	char *s;
-	{
-	register char *p;
-
-	if (attyset() && ! equal(termval(), "emacs")) {
-		if (strchr(s, '\7'))
-			out2c('\7');
-		out2str("\033]P1;");
-		for (p = s ; *p ; p++) {
-			if ((unsigned)(*p - ' ') <= '~' - ' ')
-				out2c(*p);
-		}
-		out2c('\n');
-	} else {
-		out2str(s);
-	}
-}
-#endif
-
-
-
-/*
- * Returns true if the text contains nothing to expand (no dollar signs
- * or backquotes).
- */
-
-STATIC int
-noexpand(text)
-	char *text;
-	{
-	register char *p;
-	register char c;
-
-	p = text;
-	while ((c = *p++) != '\0') {
-		if (c == CTLESC)
-			p++;
-		else if (BASESYNTAX[c] == CCTL)
-			return 0;
-	}
-	return 1;
-}
-
-
-/*
- * Return true if the argument is a legal variable name (a letter or
- * underscore followed by zero or more letters, underscores, and digits).
- */
-
-int
-goodname(name)
-	char *name;
-	{
-	register char *p;
-
-	p = name;
-	if (! is_name(*p))
-		return 0;
-	while (*++p) {
-		if (! is_in_name(*p))
-			return 0;
-	}
-	return 1;
-}
-
-
-/*
- * Called when an unexpected token is read during the parse.  The argument
- * is the token that is expected, or -1 if more than one type of token can
- * occur at this point.
- */
-
-STATIC void
-synexpect(token) {
-	char msg[64];
-
-	if (token >= 0) {
-		fmtstr(msg, 64, "%s unexpected (expecting %s)",
-			tokname[lasttoken], tokname[token]);
-	} else {
-		fmtstr(msg, 64, "%s unexpected", tokname[lasttoken]);
-	}
-	synerror(msg);
-}
-
-
-STATIC void
-synerror(msg)
-	char *msg;
-	{
-	if (commandname)
-		outfmt(&errout, "%s: %d: ", commandname, startlinno);
-	outfmt(&errout, "Syntax error: %s\n", msg);
-	error((char *)NULL);
-}
Index: trunk/minix/commands/ash/parser.h
===================================================================
--- trunk/minix/commands/ash/parser.h	(revision 9)
+++ 	(revision )
@@ -1,74 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)parser.h	5.1 (Berkeley) 3/7/91
- */
-
-/* control characters in argument strings */
-#define CTLESC '\201'
-#define CTLVAR '\202'
-#define CTLENDVAR '\203'
-#define CTLBACKQ '\204'
-#define CTLQUOTE 01		/* ored with CTLBACKQ code if in quotes */
-
-/* variable substitution byte (follows CTLVAR) */
-#define VSTYPE 07		/* type of variable substitution */
-#define VSNUL 040		/* colon--treat the empty string as unset */
-#define VSQUOTE 0100		/* inside double quotes--suppress splitting */
-
-/* values of VSTYPE field */
-#define VSNORMAL 1		/* normal variable:  $var or ${var} */
-#define VSMINUS 2		/* ${var-text} */
-#define VSPLUS 3		/* ${var+text} */
-#define VSQUESTION 4		/* ${var?message} */
-#define VSASSIGN 5		/* ${var=text} */
-
-
-/*
- * NEOF is returned by parsecmd when it encounters an end of file.  It
- * must be distinct from NULL, so we use the address of a variable that
- * happens to be handy.
- */
-extern int tokpushback;
-#define NEOF ((union node *)&tokpushback)
-
-
-#ifdef __STDC__
-union node *parsecmd(int);
-int goodname(char *);
-#else
-union node *parsecmd();
-int goodname();
-#endif
Index: trunk/minix/commands/ash/redir.c
===================================================================
--- trunk/minix/commands/ash/redir.c	(revision 9)
+++ 	(revision )
@@ -1,370 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)redir.c	5.1 (Berkeley) 3/7/91";
-#endif /* not lint */
-
-/*
- * Code for dealing with input/output redirection.
- */
-
-#include "shell.h"
-#include "nodes.h"
-#include "jobs.h"
-#include "expand.h"
-#include "redir.h"
-#include "eval.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include <sys/types.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-
-
-#define EMPTY -2		/* marks an unused slot in redirtab */
-#define PIPESIZE 4096		/* amount of buffering in a pipe */
-
-
-MKINIT
-struct redirtab {
-	struct redirtab *next;
-	short renamed[10];
-};
-
-
-MKINIT struct redirtab *redirlist;
-
-/* We keep track of whether or not fd0 has been redirected.  This is for
-   background commands, where we want to redirect fd0 to /dev/null only
-   if it hasn't already been redirected.  */
-int fd0_redirected = 0;
-
-#ifdef __STDC__
-STATIC void openredirect(union node *, char *);
-STATIC int openhere(union node *);
-#else
-STATIC void openredirect();
-STATIC int openhere();
-#endif
-
-
-
-/*
- * Process a list of redirection commands.  If the REDIR_PUSH flag is set,
- * old file descriptors are stashed away so that the redirection can be
- * undone by calling popredir.  If the REDIR_BACKQ flag is set, then the
- * standard output, and the standard error if it becomes a duplicate of
- * stdout, is saved in memory.
- */
-
-void
-redirect(redir, flags)
-	union node *redir;
-	int flags;
-	{
-	union node *n;
-	struct redirtab *sv;
-	int i;
-	int fd;
-	char memory[10];		/* file descriptors to write to memory */
-
-	for (i = 10 ; --i >= 0 ; )
-		memory[i] = 0;
-	memory[1] = flags & REDIR_BACKQ;
-	if (flags & REDIR_PUSH) {
-		sv = ckmalloc(sizeof (struct redirtab));
-		for (i = 0 ; i < 10 ; i++)
-			sv->renamed[i] = EMPTY;
-		sv->next = redirlist;
-		redirlist = sv;
-	}
-	for (n = redir ; n ; n = n->nfile.next) {
-		fd = n->nfile.fd;
-		if ((flags & REDIR_PUSH) && sv->renamed[fd] == EMPTY) {
-			INTOFF;
-			if ((i = copyfd(fd, 10)) != EMPTY) {
-				sv->renamed[fd] = i;
-				close(fd);
-			}
-			INTON;
-			if (i == EMPTY)
-				error("Out of file descriptors");
-		} else {
-			close(fd);
-		}
-		if (fd == 0)
-			fd0_redirected++;
-		openredirect(n, memory);
-	}
-	if (memory[1])
-		out1 = &memout;
-	if (memory[2])
-		out2 = &memout;
-}
-
-
-STATIC void
-openredirect(redir, memory)
-	union node *redir;
-	char memory[10];
-	{
-	int fd = redir->nfile.fd;
-	char *fname;
-	int f;
-
-	/* Assume redirection succeeds. */
-	exitstatus = 0;
-
-	/*
-	 * We suppress interrupts so that we won't leave open file
-	 * descriptors around.  This may not be such a good idea because
-	 * an open of a device or a fifo can block indefinitely.
-	 */
-	INTOFF;
-	memory[fd] = 0;
-	switch (redir->nfile.type) {
-	case NFROM:
-		fname = redir->nfile.expfname;
-		if ((f = open(fname, O_RDONLY)) < 0)
-			error("cannot open %s: %s", fname, errmsg(errno, E_OPEN));
-movefd:
-		if (f != fd) {
-			copyfd(f, fd);
-			close(f);
-		}
-		break;
-	case NTO:
-		fname = redir->nfile.expfname;
-#ifdef O_CREAT
-		if ((f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
-			error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-#else
-		if ((f = creat(fname, 0666)) < 0)
-			error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-#endif
-		goto movefd;
-	case NAPPEND:
-		fname = redir->nfile.expfname;
-#ifdef O_APPEND
-		if ((f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0)
-			error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-#else
-		if ((f = open(fname, O_WRONLY)) < 0
-		 && (f = creat(fname, 0666)) < 0)
-			error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
-		lseek(f, 0L, 2);
-#endif
-		goto movefd;
-	case NTOFD:
-	case NFROMFD:
-		if (redir->ndup.dupfd >= 0) {	/* if not ">&-" */
-			if (memory[redir->ndup.dupfd])
-				memory[fd] = 1;
-			else
-				copyfd(redir->ndup.dupfd, fd);
-		}
-		break;
-	case NHERE:
-	case NXHERE:
-		f = openhere(redir);
-		goto movefd;
-	default:
-		abort();
-	}
-	INTON;
-}
-
-
-/*
- * Handle here documents.  Normally we fork off a process to write the
- * data to a pipe.  If the document is short, we can stuff the data in
- * the pipe without forking.
- */
-
-STATIC int
-openhere(redir)
-	union node *redir;
-	{
-	int pip[2];
-	int len;
-
-	if (pipe(pip) < 0)
-		error("Pipe call failed");
-	if (redir->type == NHERE) {
-		len = strlen(redir->nhere.doc->narg.text);
-		if (len <= PIPESIZE) {
-			xwrite(pip[1], redir->nhere.doc->narg.text, len);
-			goto out;
-		}
-	}
-	if (forkshell((struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) {
-		close(pip[0]);
-		signal(SIGINT, SIG_IGN);
-		signal(SIGQUIT, SIG_IGN);
-		signal(SIGHUP, SIG_IGN);
-#ifdef SIGTSTP
-		signal(SIGTSTP, SIG_IGN);
-#endif
-		signal(SIGPIPE, SIG_DFL);
-		if (redir->type == NHERE)
-			xwrite(pip[1], redir->nhere.doc->narg.text, len);
-		else
-			expandhere(redir->nhere.doc, pip[1]);
-		_exit(0);
-	}
-out:
-	close(pip[1]);
-	return pip[0];
-}
-
-
-
-/*
- * Undo the effects of the last redirection.
- */
-
-void
-popredir() {
-	register struct redirtab *rp = redirlist;
-	int i;
-
-	for (i = 0 ; i < 10 ; i++) {
-		if (rp->renamed[i] != EMPTY) {
-			if (i == 0)
-				fd0_redirected--;
-			close(i);
-			if (rp->renamed[i] >= 0) {
-				copyfd(rp->renamed[i], i);
-				close(rp->renamed[i]);
-			}
-		}
-	}
-	INTOFF;
-	redirlist = rp->next;
-	ckfree(rp);
-	INTON;
-}
-
-
-
-/*
- * Undo all redirections.  Called on error or interrupt.
- */
-
-#ifdef mkinit
-
-INCLUDE "redir.h"
-
-RESET {
-	while (redirlist)
-		popredir();
-}
-
-SHELLPROC {
-	clearredir();
-}
-
-#endif
-
-
-/*
- * Discard all saved file descriptors.
- */
-
-void
-clearredir() {
-	register struct redirtab *rp;
-	int i;
-
-	for (rp = redirlist ; rp ; rp = rp->next) {
-		for (i = 0 ; i < 10 ; i++) {
-			if (rp->renamed[i] >= 0) {
-				close(rp->renamed[i]);
-			}
-			rp->renamed[i] = EMPTY;
-		}
-	}
-}
-
-
-
-/*
- * Copy a file descriptor, like the F_DUPFD option of fcntl.  Returns -1
- * if the source file descriptor is closed, EMPTY if there are no unused
- * file descriptors left.
- */
-
-int
-copyfd(from, to) {
-#ifdef F_DUPFD
-	int newfd;
-
-	newfd = fcntl(from, F_DUPFD, to);
-	if (newfd < 0 && errno == EMFILE)
-		return EMPTY;
-	return newfd;
-#else
-	char toclose[32];
-	int i;
-	int newfd;
-	int e;
-
-	for (i = 0 ; i < to ; i++)
-		toclose[i] = 0;
-	INTOFF;
-	while ((newfd = dup(from)) >= 0 && newfd < to)
-		toclose[newfd] = 1;
-	e = errno;
-	for (i = 0 ; i < to ; i++) {
-		if (toclose[i])
-			close(i);
-	}
-	INTON;
-	if (newfd < 0 && e == EMFILE)
-		return EMPTY;
-	return newfd;
-#endif
-}
-
-/* Return true if fd 0 has already been redirected at least once.  */
-int
-fd0_redirected_p () {
-	return fd0_redirected != 0;
-}
Index: trunk/minix/commands/ash/redir.h
===================================================================
--- trunk/minix/commands/ash/redir.h	(revision 9)
+++ 	(revision )
@@ -1,56 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)redir.h	5.1 (Berkeley) 3/7/91
- */
-
-/* flags passed to redirect */
-#define REDIR_PUSH 01		/* save previous values of file descriptors */
-#define REDIR_BACKQ 02		/* save the command output in memory */
-
-#ifdef __STDC__
-union node;
-void redirect(union node *, int);
-void popredir(void);
-void clearredir(void);
-int copyfd(int, int);
-int fd0_redirected_p(void);
-#else
-void redirect();
-void popredir();
-void clearredir();
-int copyfd();
-int fd0_redirected_p();
-#endif
Index: trunk/minix/commands/ash/shell.h
===================================================================
--- trunk/minix/commands/ash/shell.h	(revision 9)
+++ 	(revision )
@@ -1,107 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)shell.h	5.4 (Berkeley) 4/12/91
- */
-
-/*
- * The follow should be set to reflect the type of system you have:
- *	JOBS -> 1 if you have Berkeley job control, 0 otherwise.
- *	SYMLINKS -> 1 if your system includes symbolic links, 0 otherwise.
- *	DIRENT -> 1 if your system has the SVR3 directory(3X) routines.
- *	UDIR -> 1 if you want the shell to simulate the /u directory.
- *	TILDE -> 1 if you want the shell to expand ~logname.
- *	USEGETPW -> 1 if getpwnam() must be used to look up a name.
- *	ATTY -> 1 to include code for atty(1).
- *	SHORTNAMES -> 1 if your linker cannot handle long names.
- *	READLINE -> 1 if line editing by readline() should be enabled.
- *	define BSD if you are running 4.2 BSD or later.
- *	define SYSV if you are running under System V.
- *	define DEBUG=1 to compile in debugging (set global "debug" to turn on)
- *	define DEBUG=2 to compile in and turn on debugging.
- *
- * When debugging is on, debugging info will be written to $HOME/trace and
- * a quit signal will generate a core dump.
- */
-
-
-#define JOBS	  0
-
-/* Set SYMLINKS to 0 by request of Giovanni Falzoni, who wrote the
- * symlink patches for Minix; email to minix-devel-l of thu 3 nov.
- */
-
-#if 0
-#define SYMLINKS  defined(S_ISLNK)
-#else
-#define SYMLINKS  0
-#endif
-
-#define DIRENT	  1
-#define UDIR	  0
-#define TILDE	  1
-#define USEGETPW  0
-#define ATTY	  0
-#define READLINE  1
-#define HASHBANG  0
-/* #define BSD */
-#define POSIX	  1
-#define DEBUG	  0
-
-#ifdef __STDC__
-typedef void *pointer;
-#ifndef NULL
-#define NULL (void *)0
-#endif
-#else /* not __STDC__ */
-typedef char *pointer;
-#ifndef NULL
-#define NULL 0
-#endif
-#endif /*  not __STDC__ */
-#define STATIC	/* empty */
-#define MKINIT	/* empty */
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-extern char nullstr[1];		/* null string */
-
-
-#if DEBUG
-#define TRACE(param)	trace param
-#else
-#define TRACE(param)
-#endif
Index: trunk/minix/commands/ash/show.c
===================================================================
--- trunk/minix/commands/ash/show.c	(revision 9)
+++ 	(revision )
@@ -1,377 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)show.c	5.2 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-#include <stdio.h>
-#include <errno.h>
-#include "shell.h"
-#include "parser.h"
-#include "nodes.h"
-#include "mystring.h"
-
-
-#if DEBUG
-static shtree(), shcmd(), sharg(), indent();
-
-
-showtree(n)
-	union node *n;
-	{
-	trputs("showtree called\n");
-	shtree(n, 1, NULL, stdout);
-}
-
-
-static
-shtree(n, ind, pfx, fp)
-	union node *n;
-	char *pfx;
-	FILE *fp;
-	{
-	struct nodelist *lp;
-	char *s;
-
-	indent(ind, pfx, fp);
-	switch(n->type) {
-	case NSEMI:
-		s = "; ";
-		goto binop;
-	case NAND:
-		s = " && ";
-		goto binop;
-	case NOR:
-		s = " || ";
-binop:
-		shtree(n->nbinary.ch1, ind, NULL, fp);
-	   /*    if (ind < 0) */
-			fputs(s, fp);
-		shtree(n->nbinary.ch2, ind, NULL, fp);
-		break;
-	case NCMD:
-		shcmd(n, fp);
-		if (ind >= 0)
-			putc('\n', fp);
-		break;
-	case NPIPE:
-		for (lp = n->npipe.cmdlist ; lp ; lp = lp->next) {
-			shcmd(lp->n, fp);
-			if (lp->next)
-				fputs(" | ", fp);
-		}
-		if (n->npipe.backgnd)
-			fputs(" &", fp);
-		if (ind >= 0)
-			putc('\n', fp);
-		break;
-	default:
-		fprintf(fp, "<node type %d>", n->type);
-		if (ind >= 0)
-			putc('\n', fp);
-		break;
-	}
-}
-
-
-
-static
-shcmd(cmd, fp)
-	union node *cmd;
-	FILE *fp;
-	{
-	union node *np;
-	int first;
-	char *s;
-	int dftfd;
-
-	first = 1;
-	for (np = cmd->ncmd.args ; np ; np = np->narg.next) {
-		if (! first)
-			putchar(' ');
-		sharg(np, fp);
-		first = 0;
-	}
-	for (np = cmd->ncmd.redirect ; np ; np = np->nfile.next) {
-		if (! first)
-			putchar(' ');
-		switch (np->nfile.type) {
-			case NTO:	s = ">";  dftfd = 1; break;
-			case NAPPEND:	s = ">>"; dftfd = 1; break;
-			case NTOFD:	s = ">&"; dftfd = 1; break;
-			case NFROM:	s = "<";  dftfd = 0; break;
-			case NFROMFD:	s = "<&"; dftfd = 0; break;
-		}
-		if (np->nfile.fd != dftfd)
-			fprintf(fp, "%d", np->nfile.fd);
-		fputs(s, fp);
-		if (np->nfile.type == NTOFD || np->nfile.type == NFROMFD) {
-			fprintf(fp, "%d", np->ndup.dupfd);
-		} else {
-			sharg(np->nfile.fname, fp);
-		}
-		first = 0;
-	}
-}
-
-
-
-static
-sharg(arg, fp)
-	union node *arg;
-	FILE *fp;
-	{
-	char *p;
-	struct nodelist *bqlist;
-	int subtype;
-
-	if (arg->type != NARG) {
-		printf("<node type %d>\n", arg->type);
-		fflush(stdout);
-		abort();
-	}
-	bqlist = arg->narg.backquote;
-	for (p = arg->narg.text ; *p ; p++) {
-		switch (*p) {
-		case CTLESC:
-			putc(*++p, fp);
-			break;
-		case CTLVAR:
-			putc('$', fp);
-			putc('{', fp);
-			subtype = *++p;
-			while (*p != '=')
-				putc(*p++, fp);
-			if (subtype & VSNUL)
-				putc(':', fp);
-			switch (subtype & VSTYPE) {
-			case VSNORMAL:
-				putc('}', fp);
-				break;
-			case VSMINUS:
-				putc('-', fp);
-				break;
-			case VSPLUS:
-				putc('+', fp);
-				break;
-			case VSQUESTION:
-				putc('?', fp);
-				break;
-			case VSASSIGN:
-				putc('=', fp);
-				break;
-			default:
-				printf("<subtype %d>", subtype);
-			}
-			break;
-		case CTLENDVAR:
-		     putc('}', fp);
-		     break;
-		case CTLBACKQ:
-		case CTLBACKQ|CTLQUOTE:
-			putc('$', fp);
-			putc('(', fp);
-			shtree(bqlist->n, -1, NULL, fp);
-			putc(')', fp);
-			break;
-		default:
-			putc(*p, fp);
-			break;
-		}
-	}
-}
-
-
-static
-indent(amount, pfx, fp)
-	char *pfx;
-	FILE *fp;
-	{
-	int i;
-
-	for (i = 0 ; i < amount ; i++) {
-		if (pfx && i == amount - 1)
-			fputs(pfx, fp);
-		putc('\t', fp);
-	}
-}
-#endif
-
-
-
-/*
- * Debugging stuff.
- */
-
-
-FILE *tracefile;
-
-#if DEBUG == 2
-int debug = 1;
-#else
-int debug = 0;
-#endif
-
-
-trputc(c) {
-#if DEBUG
-	if (tracefile == NULL)
-		return;
-	putc(c, tracefile);
-	if (c == '\n')
-		fflush(tracefile);
-#endif
-}
-
-
-trace(fmt, a1, a2, a3, a4, a5, a6, a7, a8)
-	char *fmt;
-	{
-#if DEBUG
-	int e = errno;
-	if (tracefile == NULL)
-		return;
-	fprintf(tracefile, fmt, a1, a2, a3, a4, a5, a6, a7, a8);
-	if (strchr(fmt, '\n'))
-		fflush(tracefile);
-	errno = e;
-#endif
-}
-
-
-trputs(s)
-	char *s;
-	{
-#if DEBUG
-	if (tracefile == NULL)
-		return;
-	fputs(s, tracefile);
-	if (strchr(s, '\n'))
-		fflush(tracefile);
-#endif
-}
-
-
-trstring(s)
-	char *s;
-	{
-	register char *p;
-	char c;
-
-#if DEBUG
-	if (tracefile == NULL)
-		return;
-	putc('"', tracefile);
-	for (p = s ; *p ; p++) {
-		switch (*p) {
-		case '\n':  c = 'n';  goto backslash;
-		case '\t':  c = 't';  goto backslash;
-		case '\r':  c = 'r';  goto backslash;
-		case '"':  c = '"';  goto backslash;
-		case '\\':  c = '\\';  goto backslash;
-		case CTLESC:  c = 'e';  goto backslash;
-		case CTLVAR:  c = 'v';  goto backslash;
-		case CTLVAR+CTLQUOTE:  c = 'V';  goto backslash;
-		case CTLBACKQ:  c = 'q';  goto backslash;
-		case CTLBACKQ+CTLQUOTE:  c = 'Q';  goto backslash;
-backslash:	  putc('\\', tracefile);
-			putc(c, tracefile);
-			break;
-		default:
-			if (*p >= ' ' && *p <= '~')
-				putc(*p, tracefile);
-			else {
-				putc('\\', tracefile);
-				putc(*p >> 6 & 03, tracefile);
-				putc(*p >> 3 & 07, tracefile);
-				putc(*p & 07, tracefile);
-			}
-			break;
-		}
-	}
-	putc('"', tracefile);
-#endif
-}
-
-
-trargs(ap)
-	char **ap;
-	{
-#if DEBUG
-	if (tracefile == NULL)
-		return;
-	while (*ap) {
-		trstring(*ap++);
-		if (*ap)
-			putc(' ', tracefile);
-		else
-			putc('\n', tracefile);
-	}
-	fflush(tracefile);
-#endif
-}
-
-
-opentrace() {
-	char s[100];
-	char *p;
-	char *getenv();
-	int flags;
-
-#if DEBUG
-	if (!debug)
-		return;
-	if ((p = getenv("HOME")) == NULL) {
-		if (getuid() == 0)
-			p = "/";
-		else
-			p = "/tmp";
-	}
-	scopy(p, s);
-	strcat(s, "/trace");
-	if ((tracefile = fopen(s, "a")) == NULL) {
-		fprintf(stderr, "Can't open %s\n", s);
-		return;
-	}
-#ifdef O_APPEND
-	if ((flags = fcntl(fileno(tracefile), F_GETFL, 0)) >= 0)
-		fcntl(fileno(tracefile), F_SETFL, flags | O_APPEND);
-#endif
-	fputs("\nTracing started.\n", tracefile);
-	fflush(tracefile);
-#endif
-}
Index: trunk/minix/commands/ash/sys/cdefs.h
===================================================================
--- trunk/minix/commands/ash/sys/cdefs.h	(revision 9)
+++ 	(revision )
@@ -1,15 +1,0 @@
-/*	Replacement for something BSD has in sys/cdefs.h. */
-
-#ifndef _ASH_SYS_CDEFS
-#define _ASH_SYS_CDEFS
-
-#if __STDC__
-#define	__P(params)			params
-#else
-#define	__P(params)			()
-#endif
-
-/*	Probably in sys/types.h. */
-typedef void (*sig_t) __P(( int ));
-
-#endif /* _ASH_SYS_CDEFS */
Index: trunk/minix/commands/ash/test/malloc.c
===================================================================
--- trunk/minix/commands/ash/test/malloc.c	(revision 9)
+++ 	(revision )
@@ -1,1298 +1,0 @@
-
-/**********************************************************/
-/*
-/*		 This was file READ_ME
-/*
-/**********************************************************/
-
-/*
-	PROGRAM
-		malloc(), free(), realloc()
-	AUTHOR
-		Dick Grune, Free University, Amsterdam
-		Modified by Ceriel Jacobs, Free University, Amsterdam,
-		to make it faster
-	VERSION
-		$Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $
-	DESCRIPTION
-	This is an independent rewrite of the malloc/free package; it is
-	fast and efficient.  Free blocks are kept in doubly linked lists,
-	list N holding blocks with sizes between 2**N and 2**(N+1)-1.
-	Consequently neither malloc nor free have to do any searching:
-	the cost of a call of malloc() (or free()) is constant, however
-	many blocks you have got.
-	
-	If you switch on the NON_STANDARD macro (see param.h) every block
-	costs 2 pointers overhead (otherwise it's 4).
-*/
-/*
-	There is an organisational problem here: during devellopment
-	I want the package divided into modules, which implies external
-	names for the communication.  The only external names I want in
-	the finished product are malloc, realloc and free.  This requires
-	some hanky-panky.
-*/
-
-
-/**********************************************************/
-/*
-/*		 This was file size_type.h
-/*
-/**********************************************************/
-
-#if	_EM_WSIZE == _EM_PSIZE
-typedef unsigned int size_type;
-#elif	_EM_LSIZE == _EM_PSIZE
-typedef unsigned long size_type;
-#else
-#error funny pointer size
-#endif
-#include	<stdlib.h>
-#include	<stdio.h>
-
-
-/**********************************************************/
-/*
-/*		 This was file param.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-
-#	undef	NON_STANDARD	/*	If defined, the contents of a block
-					will NOT be left undisturbed after it
-					is freed, as opposed to what it says
-					in the manual (malloc(2)).
-					Setting this option reduces the memory
-					overhead considerably.  I personally
-					consider the specified behaviour an
-					artefact of the original
-					implementation.
-				*/
-
-#	define	ASSERT		/*	If defined, some inexpensive tests
-					will be made to ensure the
-					correctness of some sensitive data.
-					It often turns an uncontrolled crash
-					into a controlled one.
-				*/
-
-#	define	CHECK		/*	If defined, extensive and expensive
-					tests will be done, inculding a
-					checksum on the mallinks (chunk
-					information blocks).  The resulting
-					information will be printed on a file
-					called mal.out .
-					Additionally a function
-						maldump(n) int n;
-					will be defined, which will dump
-					pertinent info in pseudo-readable
-					form; it aborts afterwards if n != 0.
-				*/
-
-#	undef	EXTERN		/*	If defined, all static names will
-					become extern, which is a help in
-					using adb(1) or prof(1)
-				*/
-
-#	define	STORE		/*	If defined, separate free lists will
-					be kept of chunks with small sizes,
-					to speed things up a little.
-				*/
-
-#	undef SYSTEM		/*	If defined, the system module is used.
-					Otherwise, "sbrk" is called directly.
-				*/
-
-#define	ALIGNMENT	8	
-				/* alignment common to all types */
-#define	LOG_MIN_SIZE	3
-#define	LOG_MAX_SIZE	24
-
-
-/**********************************************************/
-/*
-/*		 This was file impl.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/*	This file essentially describes how the mallink info block
-	is implemented.
-*/
-
-#define	MIN_SIZE	(1<<LOG_MIN_SIZE)
-#define	MAX_FLIST	(LOG_MAX_SIZE - LOG_MIN_SIZE)
-#if ALIGNMENT != 4 && ALIGNMENT != 8 && ALIGNMENT != 16
-#error ALIGNMENT must be 4, 8 or 16
-#elif ALIGNMENT % _EM_LSIZE
-/* since calloc() does it's initialization in longs */
-#error ALIGNMENT must be a multiple of the long size
-#endif
-#define align(n)	(((n) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1))
-
-union _inf {
-	union _inf *ptr;
-	size_type ui;
-};
-
-typedef union _inf mallink;
-#define	MAL_NULL	((mallink *)0)
-
-/*	Access macros; only these macros know where to find values.
-	They are also lvalues.
-*/
-#ifndef	NON_STANDARD
-#define	OFF_SET	0
-#else	/* def NON_STANDARD */
-#define	OFF_SET	2
-#endif	/* NON_STANDARD */
-
-#define	_log_prev_of(ml)	((ml)[-1+OFF_SET]).ptr
-#define	_log_next_of(ml)	((ml)[-2+OFF_SET]).ptr
-#define	_phys_prev_of(ml)	((ml)[-3+OFF_SET]).ptr
-#define	_this_size_of(ml)	((ml)[-4+OFF_SET]).ui
-#ifndef	CHECK
-#define	N_WORDS			4
-#else	/* ifdef	CHECK */
-#define	_checksum_of(ml)	((ml)[-5+OFF_SET]).ui
-#define	_print_of(ml)		((ml)[-6+OFF_SET]).ui
-#define	_mark_of(ml)		((ml)[-7+OFF_SET]).ui
-#define	N_WORDS			7
-#endif	/* CHECK */
-
-#define	mallink_size()		(size_t) \
-	align((N_WORDS - OFF_SET) * sizeof (mallink))
-
-#ifdef	CHECK
-#define	set_mark(ml,e)		(_mark_of(ml) = (e))
-#define	mark_of(ml)		(_mark_of(ml))
-
-#define	set_checksum(ml,e)	(_checksum_of(ml) = (e))
-#define	checksum_of(ml)		(_checksum_of(ml))
-#endif	/* CHECK */
-
-#define new_mallink(ml)		( _log_prev_of(ml) = 0, \
-				  _log_next_of(ml) = 0, \
-				  _phys_prev_of(ml) = 0, \
-				  _this_size_of(ml) = 0 )
-
-#define	block_of_mallink(ml)	((void *)ml)
-#define	mallink_of_block(addr)	((mallink *)addr)
-
-#define	public	extern
-#define	publicdata	extern
-#ifndef	EXTERN
-#define	private	static
-#define	privatedata	static
-#else	/* def	EXTERN */
-#define	private	extern
-#define	privatedata
-#endif	/* EXTERN */
-
-#ifdef	ASSERT
-private m_assert(const char *fn, int ln);
-#define	assert(b)		(!(b) ? m_assert(__FILE__, __LINE__) : 0)
-#else	/* ndef	ASSERT */
-#define	assert(b)		0
-#endif	/* ASSERT */
-
-
-/**********************************************************/
-/*
-/*		 This was file check.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#ifdef	CHECK
-
-private check_mallinks(const char *s), calc_checksum(mallink *ml);
-private check_work_empty(const char *s);
-private started_working_on(mallink *ml), stopped_working_on(mallink *ml);
-
-#else	/* ifndef	CHECK */
-
-#define	maldump(n)		abort()
-#define	check_mallinks(s)	0
-#define	calc_checksum(ml)	0
-#define	started_working_on(ml)	0
-#define	stopped_working_on(ml)	0
-#define	check_work_empty(s)	0
-
-#endif	/* CHECK */
-
-
-/**********************************************************/
-/*
-/*		 This was file log.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/*	Algorithms to manipulate the doubly-linked lists of free
-	chunks.
-*/
-
-private link_free_chunk(mallink *ml), unlink_free_chunk(mallink *ml);
-private mallink *first_present(int class);
-private mallink *search_free_list(int class, size_t n);
-
-#ifdef STORE
-#define in_store(ml)		((size_type)_phys_prev_of(ml) & STORE_BIT)
-#define set_store(ml, e) \
-	(_phys_prev_of(ml) = (mallink *) \
-		((e) ? (size_type) _phys_prev_of(ml) | STORE_BIT : \
-		       (size_type) _phys_prev_of(ml) & ~STORE_BIT))
-#endif
-#define	set_log_prev(ml,e)	(_log_prev_of(ml) = (e))
-#define	log_prev_of(ml)		(mallink *) (_log_prev_of(ml))
-
-#define	set_log_next(ml,e)	(_log_next_of(ml) = (e))
-#define	log_next_of(ml)		(mallink *) (_log_next_of(ml))
-
-
-
-/**********************************************************/
-/*
-/*		 This was file phys.h
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-/*	Algorithms to manipulate the doubly-linked list of physical
-	chunks.
-*/
-privatedata mallink *ml_last;
-
-#define FREE_BIT		01
-#ifdef STORE
-#define STORE_BIT		02
-#define BITS			(FREE_BIT|STORE_BIT)
-#else
-#define BITS			(FREE_BIT)
-#endif
-
-#define __bits(ml)		((int)((size_type)_phys_prev_of(ml) & BITS))
-#define	__free_of(ml)		((int)((size_type)_phys_prev_of(ml) & FREE_BIT))
-#define __phys_prev_of(ml)	((mallink *)((size_type)_phys_prev_of(ml) & ~BITS))
-#define prev_size_of(ml)	((char *)(ml) - \
-				 (char *)__phys_prev_of(ml) - \
-				 mallink_size() \
-				)
-#define	set_phys_prev(ml,e) \
-	(_phys_prev_of(ml) = (mallink *) ((char *)e + __bits(ml)))
-
-#ifdef	CHECK
-private Error(const char *fmt, const char *s, mallink *ml);
-#define	phys_prev_of(ml)	(mallink *) \
-	(first_mallink(ml) ? \
-		(char *)Error("phys_prev_of first_mallink %p", "somewhere", ml) : \
-		(char *)__phys_prev_of(ml) \
-	)
-#else	/* ndef	CHECK */
-#define	phys_prev_of(ml)	__phys_prev_of(ml)
-#endif	/* CHECK */
-
-#define	first_mallink(ml)	(int) (__phys_prev_of(ml) == 0)
-#define	last_mallink(ml)	(int) ((ml) == ml_last)
-
-/*	There is an ambiguity in the semantics of phys_next_of: sometimes
-	one wants it to return MAL_NULL if there is no next chunk, at
-	other times one wants the address of the virtual chunk at the
-	end of memory.  The present version returns the address of the
-	(virtual) chunk and relies on the user to test last_mallink(ml)
-	first.
-*/
-#define size_of(ml)		(_this_size_of(ml) - mallink_size())
-#define	set_phys_next(ml,e) \
-	(_this_size_of(ml) = (size_type)((char *)(e) - (char *)(ml)))
-#define	phys_next_of(ml)	(mallink *) ((char *)(ml) + _this_size_of(ml))
-
-#define	set_free(ml,e) \
-	(_phys_prev_of(ml) = (mallink *) \
-		((e) ? (size_type) _phys_prev_of(ml) | FREE_BIT : \
-		       (size_type) _phys_prev_of(ml) & ~FREE_BIT))
-#define	free_of(ml)		(__free_of(ml))
-
-#define coalesce_forw(ml,nxt)	( unlink_free_chunk(nxt), \
-				  combine_chunks((ml), (nxt)))
-
-#define coalesce_backw(ml,prv)	( unlink_free_chunk(prv), \
-				  stopped_working_on(ml), \
-				  combine_chunks((prv), (ml)), \
-				  started_working_on(prv))
-
-#ifdef	CHECK
-#define	set_print(ml,e)		(_print_of(ml) = (e))
-#define	print_of(ml)		(_print_of(ml))
-#endif	/* CHECK */
-
-private truncate(mallink *ml, size_t size);
-private combine_chunks(register mallink *ml1, register mallink *ml2);
-private mallink *create_chunk(void *p, size_t n);
-
-
-/**********************************************************/
-/*
-/*		 This was file mal.c
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include	<limits.h>
-#include	<stdlib.h>
-
-/*	Malloc space is traversed by N doubly-linked lists of chunks, each
-	containing a couple of house-keeping data addressed as a
-	'mallink' and a piece of useful space, called the block.
-	The N lists are accessed through their starting pointers in
-	free_list[].  Free_list[n] points to a list of chunks between
-	2**(n+LOG_MIN_SIZE) and 2**(n+LOG_MIN_SIZE+1)-1, which means
-	that the smallest chunk is 2**LOG_MIN_SIZE (== MIN_SIZE).
-*/
-
-#ifdef SYSTEM
-#include	<system.h>
-#define SBRK	sys_break
-#else
-#define SBRK	_sbrk
-#define	ILL_BREAK		(void *)(-1)	/* funny failure value */
-#endif
-extern void *SBRK(int incr);
-#ifdef STORE
-#define	MAX_STORE	32
-private do_free(mallink *ml), sell_out(void);
-privatedata mallink *store[MAX_STORE];
-#endif /* STORE */
-
-void *privious_free= (void *)-1;
-void *
-malloc(register size_t n)
-{check_mallinks("malloc entry");{
-	register mallink *ml;
-	register int min_class;
-	void *tmp;
-
-{ static int reent= 0; if (!reent) { reent++; printf("malloc\n"); reent--; } }
-privious_free= (void *)-1;
-	if (n == 0) {
-		return NULL;
-	}
-	if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n);
-#ifdef STORE
-	if (n <= MAX_STORE*MIN_SIZE)	{
-		/* look in the store first */
-		register mallink **stp = &store[(n >> LOG_MIN_SIZE) - 1];
-		
-		if (ml = *stp)	{
-			*stp = log_next_of(ml);
-			set_store(ml, 0);
-			check_mallinks("malloc fast exit");
-			assert(! in_store(ml));
-			tmp= block_of_mallink(ml);
-{ static int reent= 0; if (!reent) { reent++; printf("= 0x%x\n", tmp);reent--; } }
-			return tmp;
-		}
-	}
-#endif /* STORE */
-
-	check_work_empty("malloc, entry");
-
-	/*	Acquire a chunk of at least size n if at all possible;
-		Try everything.
-	*/
-	{
-		/*	Inline substitution of "smallest".
-		*/
-		register size_t n1 = n;
-
-		assert(n1 < (1L << LOG_MAX_SIZE));
-		min_class = 0;
-
-		do {
-			n1 >>= 1;
-			min_class++;
-		} while (n1 >= MIN_SIZE);
-	}
-
-	if (min_class >= MAX_FLIST)
-		return NULL;		/* we don't deal in blocks that big */
-	ml = first_present(min_class);
-	if (ml == MAL_NULL)	{
-		/*	Try and extend */
-		register void *p;
-#define	GRABSIZE	4096		/* Power of 2 */
-		register size_t req =
-			((MIN_SIZE<<min_class)+ mallink_size() + GRABSIZE - 1) &
-				~(GRABSIZE-1);
-	
-		if (!ml_last)	{
-			/* first align SBRK() */
-		
-			p = SBRK(0);
-			SBRK((int) (align((size_type) p) - (size_type) p));
-		}
-
-		/* SBRK takes an int; sorry ... */
-		if ((int) req < 0) {
-			p = ILL_BREAK;
-		} else {
-			p = SBRK((int)req);
-		}
-		if (p == ILL_BREAK) {
-			req = n + mallink_size();
-			if ((int) req >= 0) p = SBRK((int)req);
-		}
-		if (p == ILL_BREAK)	{
-			/*	Now this is bad.  The system will not give us
-				more memory.  We can only liquidate our store
-				and hope it helps.
-			*/
-#ifdef STORE
-			sell_out();
-			ml = first_present(min_class);
-			if (ml == MAL_NULL)	{
-#endif /* STORE */
-				/* In this emergency we try to locate a suitable
-				   chunk in the free_list just below the safe
-				   one; some of these chunks may fit the job.
-				*/
-				ml = search_free_list(min_class - 1, n);
-				if (!ml)	/* really out of space */
-					return NULL;
-				started_working_on(ml);
-				unlink_free_chunk(ml);
-				check_mallinks("suitable_chunk, forced");
-#ifdef STORE
-			}
-			else started_working_on(ml);
-#endif /* STORE */
-		}
-		else {
-			assert((size_type)p == align((size_type)p));
-			ml = create_chunk(p, req);
-		}
-		check_mallinks("suitable_chunk, extended");
-	}
-	else started_working_on(ml);
-
-	/* we have a chunk */
-	set_free(ml, 0);
-	calc_checksum(ml);
-	check_mallinks("suitable_chunk, removed");
-	n += mallink_size();
-	if (n + MIN_SIZE <= size_of(ml)) {
-		truncate(ml, n);
-	}
-	stopped_working_on(ml);
-	check_mallinks("malloc exit");
-	check_work_empty("malloc exit");
-#ifdef STORE
-	assert(! in_store(ml));
-#endif
-	tmp= block_of_mallink(ml);
-{ static int reent= 0; if (!reent) { reent++; printf("= 0x%x\n", tmp);reent--; } }
-	return tmp;
-}}
-
-void
-free(void *addr)
-{check_mallinks("free entry");{
-	register mallink *ml;
-
-printf("free 0x%x\n", addr);
-if (privious_free == addr) { fflush(stdout); fflush(stderr); abort(); }
-privious_free= addr;
-	if (addr == NULL) {
-		check_mallinks("free(0) very fast exit");
-		return;
-	}
-
-	ml = mallink_of_block(addr);
-#ifdef STORE
-
-	if (free_of(ml) || in_store(ml))
-		return;				/* user frees free block */
-	if (size_of(ml) <= MAX_STORE*MIN_SIZE)	{
-		/* return to store */
-		mallink **stp = &store[(size_of(ml) >> LOG_MIN_SIZE) - 1];
-		
-		set_log_next(ml, *stp);
-		*stp = ml;
-		set_store(ml, 1);
-		calc_checksum(ml);
-		check_mallinks("free fast exit");
-	}
-	else	{
-		do_free(ml);
-		check_mallinks("free exit");
-	}
-}}
-
-private
-do_free(register mallink *ml)
-{{
-#endif
-
-#ifndef STORE
-	if (free_of(ml))	return;
-#endif /* STORE */
-	started_working_on(ml);
-	set_free(ml, 1);
-	calc_checksum(ml);
-	if (! last_mallink(ml)) {
-		register mallink *next = phys_next_of(ml);
-
-		if (free_of(next)) coalesce_forw(ml, next);
-	}
-
-	if (! first_mallink(ml)) {
-		register mallink *prev = phys_prev_of(ml);
-
-		if (free_of(prev)) {
-			coalesce_backw(ml, prev);
-			ml = prev;
-		}
-	}
-	link_free_chunk(ml);
-	stopped_working_on(ml);
-	check_work_empty("free");
-
-	/* Compile-time checks on param.h */
-	switch (0)	{
-	case MIN_SIZE < OFF_SET * sizeof(mallink):	break;
-	case 1:	break;
-	/*	If this statement does not compile due to duplicate case
-		entry, the minimum size block cannot hold the links for
-		the free blocks.  Either raise LOG_MIN_SIZE or switch
-		off NON_STANDARD.
-	*/
-	}
-	switch(0)	{
-	case sizeof(void *) != sizeof(size_type):	break;
-	case 1:	break;
-	/*	If this statement does not compile due to duplicate
-		case entry, size_type is not defined correctly.
-		Redefine and compile again.
-	*/
-	}
-}}
-
-void *
-realloc(void *addr, register size_t n)
-{check_mallinks("realloc entry");{
-	register mallink *ml, *ph_next;
-	register size_type size;
-
-printf("realloc 0x%x, %d\n", addr, n);
-	if (addr == NULL) {
-		/*	Behave like most Unix realloc's when handed a
-			null-pointer
-		*/
-		return malloc(n);
-	}
-	if (n == 0) {
-		free(addr);
-		return NULL;
-	}
-	ml = mallink_of_block(addr);
-	if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n);
-#ifdef STORE
-	if (in_store(ml)) {
-		register mallink *stp = store[(size_of(ml) >> LOG_MIN_SIZE) - 1];
-		mallink *stp1 = NULL;
-		while (ml != stp)	{
-			stp1 = stp;
-			stp = log_next_of(stp);
-		}
-		stp = log_next_of(stp);
-		if (! stp1) store[(size_of(ml) >> LOG_MIN_SIZE) - 1] = stp;
-		else set_log_next(stp1, stp);
-		set_store(ml, 0);
-		calc_checksum(ml);
-	}
-#endif
-	if (free_of(ml)) {
-		unlink_free_chunk(ml);
-		set_free(ml, 0);		/* user reallocs free block */
-	}
-	started_working_on(ml);
-	size = size_of(ml);
-	if (	/* we can simplify the problem by adding the next chunk: */
-		n > size &&
-		!last_mallink(ml) &&
-		(ph_next = phys_next_of(ml), free_of(ph_next)) &&
-		n <= size + mallink_size() + size_of(ph_next)
-	)	{
-		/* add in the physically next chunk */
-		unlink_free_chunk(ph_next);
-		combine_chunks(ml, ph_next);
-		size = size_of(ml);
-		check_mallinks("realloc, combining");
-	}
-	if (n > size)	{		/* this didn't help */
-		void *new;
-		register char *l1, *l2 = addr;
-
-		stopped_working_on(ml);
-		if (!(new = l1 = malloc(n))) return NULL;	/* no way */
-		while (size--) *l1++ = *l2++;
-		free(addr);
-		check_work_empty("mv_realloc");
-#ifdef STORE
-		assert(! in_store(mallink_of_block(new)));
-#endif
-		return new;
-	}
-	/* it helped, but maybe too well */
-	n += mallink_size();
-	if (n + MIN_SIZE <= size_of(ml)) {
-		truncate(ml, n);
-	}
-	stopped_working_on(ml);
-	check_mallinks("realloc exit");
-	check_work_empty("realloc");
-#ifdef STORE
-	assert(! in_store(ml));
-#endif
-	return addr;
-}}
-
-void *
-calloc(size_t nmemb, size_t size)
-{check_mallinks("calloc entry");{
-	long *l1, *l2;
-	size_t n;
-
-printf("calloc\n");
-	if (size == 0) return NULL;
-	if (nmemb == 0) return NULL;
-
-	/* Check for overflow on the multiplication. The peephole-optimizer
-	 * will eliminate all but one of the possibilities.
-	 */
-	if (sizeof(size_t) == sizeof(int)) {
-		if (UINT_MAX / size < nmemb) return NULL;
-	} else if (sizeof(size_t) == sizeof(long)) {
-		if (ULONG_MAX / size < nmemb) return NULL;
-	} else return NULL;		/* can't happen, can it ? */
-
-	n = size * nmemb;
-	if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n);
-	if (n >= (1L << LOG_MAX_SIZE)) return NULL;
-	l1 = (long *) malloc(n);
-	l2 = l1 + (n / sizeof(long));	/* n is at least long aligned */
-	while ( l2 != l1 ) *--l2 = 0;
-	check_mallinks("calloc exit");
-	check_work_empty("calloc exit");
-	return (void *)l1;
-}}
-/*	Auxiliary routines */
-
-#ifdef STORE
-private
-sell_out(void)	{
-	/*	Frees all block in store.
-	*/
-	register mallink **stp;
-	
-	for (stp = &store[0]; stp < &store[MAX_STORE]; stp++)	{
-		register mallink *ml = *stp;
-		
-		while (ml)	{
-			*stp = log_next_of(ml);
-			set_store(ml, 0);
-			do_free(ml);
-			ml = *stp;
-		}
-	}
-
-}
-#endif /* STORE */
-
-#ifdef	ASSERT
-private
-m_assert(const char *fn, int ln)
-{
-	char ch;
-	
-	while (*fn)
-		write(2, fn++, 1);
-	write(2, ": malloc assert failed in line ", 31);
-	ch = (ln / 100) + '0'; write(2, &ch, 1); ln %= 100;
-	ch = (ln / 10) + '0'; write(2, &ch, 1); ln %= 10;
-	ch = (ln / 1) + '0'; write(2, &ch, 1);
-	write(2, "\n", 1);
-	maldump(1);
-}
-#endif	/* ASSERT */
-
-
-/**********************************************************/
-/*
-/*		 This was file log.c
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-
-/*	Logical manipulations.
-	The chunks are properly chained in the physical chain.
-*/
-
-privatedata mallink *free_list[MAX_FLIST];
-
-private
-link_free_chunk(register mallink *ml)
-{
-	/*	The free chunk ml is inserted in its proper logical
-		chain.
-	*/
-	register mallink **mlp = &free_list[-1];
-	register size_type n = size_of(ml);
-	register mallink *ml1;
-
-	assert(n < (1L << LOG_MAX_SIZE));
-
-	do {
-		n >>= 1;
-		mlp++;
-	}
-	while (n >= MIN_SIZE);
-
-	ml1 = *mlp;
-	set_log_prev(ml, MAL_NULL);
-	set_log_next(ml, ml1);
-	calc_checksum(ml);
-	if (ml1) {
-		/* link backwards
-		*/
-		set_log_prev(ml1, ml);
-		calc_checksum(ml1);
-	}
-	*mlp = ml;
-}
-
-private
-unlink_free_chunk(register mallink *ml)
-{
-	/*	Unlinks a free chunk from (the middle of) the
-		logical chain.
-	*/
-	register mallink *next = log_next_of(ml);
-	register mallink *prev = log_prev_of(ml);
-
-	if (!prev)	{
-		/* it is the first in the chain */
-		register mallink **mlp = &free_list[-1];
-		register size_type n = size_of(ml);
-
-		assert(n < (1L << LOG_MAX_SIZE));
-		do {
-			n >>= 1;
-			mlp++;
-		}
-		while (n >= MIN_SIZE);
-		*mlp = next;
-	}
-	else	{
-		set_log_next(prev, next);
-		calc_checksum(prev);
-	}
-	if (next) {
-		set_log_prev(next, prev);
-		calc_checksum(next);
-	}
-}
-
-private mallink *
-search_free_list(int class, size_t n)
-{
-	/*	Searches the free_list[class] for a chunk of at least size n;
-		since it is searching a slightly undersized list,
-		such a block may not be there.
-	*/
-	register mallink *ml;
-	
-	for (ml = free_list[class]; ml; ml = log_next_of(ml))
-		if (size_of(ml) >= n)
-			return ml;
-	return MAL_NULL;		/* nothing found */
-}
-
-private mallink *
-first_present(int class)
-{
-	/*	Find the index i in free_list[] such that:
-			i >= class && free_list[i] != MAL_NULL.
-		Return MAL_NULL if no such i exists;
-		Otherwise, return the first block of this list, after
-		unlinking it.
-	*/
-	register mallink **mlp, *ml;
-
-	for (mlp = &free_list[class]; mlp < &free_list[MAX_FLIST]; mlp++) {
-		if ((ml = *mlp) != MAL_NULL)	{
-	
-			*mlp = log_next_of(ml);	/* may be MAL_NULL */
-			if (*mlp) {
-				/* unhook backward link
-				*/
-				set_log_prev(*mlp, MAL_NULL);
-				calc_checksum(*mlp);
-			}
-			return ml;
-		}
-	}
-	return MAL_NULL;
-}
-
-#ifdef	CHECK
-private mallink *
-free_list_entry(int i)	{
-	/*	To allow maldump.c access to log.c's private data.
-	*/
-	return free_list[i];
-}
-#endif	/* CHECK */
-
-
-/**********************************************************/
-/*
-/*		 This was file phys.c
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include	<stdlib.h>
-
-/*	Physical manipulations.
-	The blocks concerned are not in any logical chain.
-*/
-
-private mallink *
-create_chunk(void *p, size_t n)
-{
-	/*	The newly acquired piece of memory at p, of length n,
-		is turned into a free chunk, properly chained in the
-		physical chain.
-		The address of the chunk is returned.
-	*/
-	register mallink *ml;
-	/*	All of malloc memory is followed by a virtual chunk, the
-		mallink of which starts mallink_size() bytes past the last
-		byte in memory.
-		Its use is prevented by testing for ml == ml_last first.
-	*/
-	register mallink *last = ml_last;
-	
-	assert(!last || p == (char *)phys_next_of(last) - mallink_size());
-	ml = (mallink *)((char *)p + mallink_size());	/* bump ml */
-	new_mallink(ml);
-	started_working_on(ml);
-	set_free(ml, 1);
-	set_phys_prev(ml, last);
-	ml_last = ml;
-
-	set_phys_next(ml, (mallink *)((char *)ml + n));
-	calc_checksum(ml);
-	assert(size_of(ml) + mallink_size() == n);
-	if (last && free_of(last)) {
-		coalesce_backw(ml, last);
-		ml = last;
-	}
-	check_mallinks("create_chunk, phys. linked");
-	return ml;
-}
-
-private
-truncate(register mallink *ml, size_t size)
-{
-	/*	The chunk ml is truncated.
-		The chunk at ml is split in two.
-		The remaining part is then freed.
-	*/
-	register mallink *new = (mallink *)((char *)ml + size);
-	register mallink *ph_next = phys_next_of(ml);
-
-	new_mallink(new);
-	set_free(new, 1);
-	set_phys_prev(new, ml);
-	set_phys_next(new, ph_next);
-	calc_checksum(new);
-	if (! last_mallink(ml))	{
-		set_phys_prev(ph_next, new);
-		calc_checksum(ph_next);
-		if (free_of(ph_next)) coalesce_forw(new, ph_next);
-	}
-	else	ml_last = new;
-	set_phys_next(ml, new);
-	calc_checksum(ml);
-
-	started_working_on(new);
-	link_free_chunk(new);
-	stopped_working_on(new);
-	check_mallinks("truncate");
-}
-
-private
-combine_chunks(register mallink *ml1, register mallink *ml2)
-{
-	/*	The chunks ml1 and ml2 are combined.
-	*/
-	register mallink *ml3 = phys_next_of(ml2);
-
-	set_phys_next(ml1, ml3);
-	calc_checksum(ml1);
-	if (!last_mallink(ml2))	{
-		set_phys_prev(ml3, ml1);
-		calc_checksum(ml3);
-	}
-	if (ml_last == ml2)
-		ml_last = ml1;
-}
-
-
-/**********************************************************/
-/*
-/*		 This was file check.c
-/*
-/**********************************************************/
-
-/* $Header: /cvsup/minix/src/commands/ash/test/malloc.c,v 1.1.1.1 2005/04/21 14:54:10 beng Exp $ */
-/*
- * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- * See the copyright notice in the ACK home directory, in the file "Copyright".
- */
-#include	<stdio.h>
-
-#ifdef	CHECK			/* otherwise this whole file is skipped */
-
-/* ??? check these later */
-private acquire_malout(void), check_ml_last(const char *s);
-private dump_all_mallinks(void), dump_free_list(int i);
-private dump_mallink(const char *s, mallink *ml), print_loop(mallink *ml);
-private working_on(mallink *ml);
-private size_type checksum(mallink *ml);
-static FILE *malout;
-
-private mallink *free_list_entry(int i);
-
-#define	for_free_list(i,p) \
-	for (p = free_list_entry(i); p; p = log_next_of(p))
-
-#define	for_all_mallinks(ml)	/* backwards! */ \
-	for (ml = ml_last; ml; \
-		ml = first_mallink(ml) ? MAL_NULL : phys_prev_of(ml))
-
-/* Maldump */
-
-static int pr_cnt = 0;
-
-maldump(int n)	{
-	/*	Dump pertinent info in pseudo-readable format;
-		abort afterwards if n != 0.
-	*/
-	static int dumping = 0;
-	int i;
-	
-	if (dumping)
-		return;
-	dumping++;
-	acquire_malout();
-	fprintf(malout,
-		">>>>>>>>>>>>>>>> DUMP OF ALL MALLINKS <<<<<<<<<<<<<<<<");
-	fprintf(malout, "    ml_last = %p\n", ml_last);
-	if (++pr_cnt == 100) pr_cnt = 0;
-	dump_all_mallinks();
-	fprintf(malout,
-		">>>>>>>>>>>>>>>> DUMP OF FREE_LISTS <<<<<<<<<<<<<<<<\n");
-	if (++pr_cnt == 100) pr_cnt = 0;
-	for (i = 0; i < MAX_FLIST; i++)
-		dump_free_list(i);
-	fprintf(malout,
-		">>>>>>>>>>>>>>>> END OF DUMP <<<<<<<<<<<<<<<<\n");
-	fclose(malout);
-	dumping--;
-	if (n)
-		abort();
-}
-
-private
-acquire_malout(void)	{
-	static char buf[BUFSIZ];
-	
-	if (!malout)	{
-		malout = freopen("mal.out", "w", stderr);	
-		setbuf(malout, buf);
-	}
-}
-
-private
-dump_all_mallinks(void)	{
-	mallink *ml;
-	
-	for_all_mallinks (ml)	{
-		if (print_loop(ml))
-			return;
-		dump_mallink((char *)0, ml);
-	}
-}
-
-private
-dump_free_list(int i)	{
-	mallink *ml = free_list_entry(i);
-	
-	if (!ml)
-		return;
-	fprintf(malout, "%2d: ", i);
-	for_free_list(i, ml)	{
-		if (print_loop(ml))
-			return;
-		fprintf(malout, "%p ", ml);
-	}
-	fprintf(malout, "<\n");
-}
-
-private int
-print_loop(mallink *ml)	{
-	if (print_of(ml) == pr_cnt)	{
-		fprintf(malout, "... PRINT LOOP\n");
-		return 1;
-	}
-	set_print(ml, pr_cnt);
-	return 0;
-}
-
-private
-dump_mallink(const char *s, mallink *ml)	{
-	acquire_malout();
-	if (s)
-		fprintf(malout, "%s: ", s);
-	fprintf(malout, "@: %p;", ml);
-	if (ml && checksum_of(ml) != checksum(ml))
-		fprintf(malout, ">>>> CORRUPTED <<<<");
-	if (!ml)	{
-		fprintf(malout, "\n");
-		return;
-	}	
-	if (free_of(ml))	{
-		fprintf(malout, " l_p: %p;", _log_prev_of(ml));
-		fprintf(malout, " l_n: %p;", _log_next_of(ml));
-	}
-	fprintf(malout, " p_s: %p;", prev_size_of(ml));
-	fprintf(malout, " t_s: %p;", _this_size_of(ml));
-	fprintf(malout, " sz: %lu;", (unsigned long) size_of(ml));
-	fprintf(malout, " fr: %d;", free_of(ml));
-	fprintf(malout, "\n");
-}
-
-/*	Check_mallinks() checks the total data structure as accessible
-	through free_list[] and ml_last.  All check_sums should be OK,
-	except those held in the small array off_colour.  This is a
-	trick to allow to continue checking even when a few mallinks
-	are temporarily out of order.
-	Check_mallinks() tests for a lot of internal consistency.
-*/
-
-/* Some arbitrary constants */
-#define	IN_ML_LAST	93
-#define	IN_FREE_LIST	57		/* and in ml_last */
-#define	CLEAR		21
-
-#define	VRIJ		1
-#define	BEZET		2
-
-private
-check_mallinks(const char *s)	{
-	mallink *ml;
-	size_type size;
-	int i;
-	char stat;
-	
-	check_ml_last(s);
-	stat = BEZET;
-	for_all_mallinks(ml)	{
-		if (checksum_of(ml) != checksum(ml))
-			Error("mallink info at %p corrupted", s, ml);
-		if (working_on(ml))	{
-			stat = BEZET;
-			continue;
-		}
-		if (	!last_mallink(ml) &&
-			phys_prev_of(phys_next_of(ml)) != ml
-		)
-			Error("upward chain bad at %p", s, ml);
-		if (	!first_mallink(ml) &&
-			phys_next_of(phys_prev_of(ml)) != ml
-		)
-			Error("downward chain bad at %p", s, ml);
-		if (free_of(ml))	{
-			if (stat == VRIJ)
-				Error("free mallink at %p follows free mallink",
-								s, ml);
-			stat = VRIJ;
-		}
-		else
-			stat = BEZET;
-		set_mark(ml, IN_ML_LAST);
-	}
-	
-	for (i = 0, size = MIN_SIZE; i < MAX_FLIST; i++, size *= 2)	{
-		for_free_list(i, ml)	{
-			if (working_on(ml))
-				continue;
-			if (!free_of(ml))
-				Error("occupied mallink %p occurs in free_list", s, ml);
-			switch (mark_of(ml))	{
-			case IN_ML_LAST:
-				set_mark(ml, IN_FREE_LIST);
-				break;
-			case IN_FREE_LIST:
-				Error("mallink %p occurs in 2 free_lists",
-								s, ml);
-			default:
-				Error("unknown mallink %p in free_list",
-								s, ml);
-			}
-			if (size_of(ml) < size)
-				Error("size of mallink %p too small", s, ml);
-			if (size_of(ml) >= 2*size)
-				Error("size of mallink %p too large", s, ml);
-		}
-	}
-	for_all_mallinks (ml)	{
-		if (working_on(ml))
-			continue;
-		if (free_of(ml) && mark_of(ml) != IN_FREE_LIST)
-			Error("free mallink %p is in no free_list", s, ml);
-		set_mark(ml, CLEAR);
-	}
-}
-
-private
-check_ml_last(const char *s)	{
-	if (ml_last && _this_size_of(ml_last) == 0)
-		Error("size of ml_last == 0, at %p", s, ml_last);
-}
-
-private size_type
-checksum(mallink *ml)	{
-	size_type sum = 0;
-	
-	if (free_of(ml))	{
-		sum += (size_type)_log_prev_of(ml);
-		sum += (size_type)_log_next_of(ml);
-	}
-	sum += (size_type)prev_size_of(ml);
-	sum += (size_type)_this_size_of(ml);
-	return sum;
-}
-
-private
-calc_checksum(mallink *ml)	{
-	set_checksum(ml, checksum(ml));
-}
-
-#define	N_COLOUR	10
-static mallink *off_colour[N_COLOUR];
-
-private
-started_working_on(mallink *ml)	{
-	int i;
-	
-	for (i = 0; i < N_COLOUR; i++)
-		if (off_colour[i] == MAL_NULL)	{
-			off_colour[i] = ml;
-			return;
-		}
-	Error("out of off_colour array at %p", "started_working_on", ml);
-}
-
-private
-stopped_working_on(mallink *ml)	{
-	int i;
-	
-	for (i = 0; i < N_COLOUR; i++)
-		if (off_colour[i] == ml)	{
-			off_colour[i] = MAL_NULL;
-			return;
-		}
-	Error("stopped working on mallink %p", "stopped_working_on", ml);
-}
-
-private int
-working_on(mallink *ml)	{
-	int i;
-	
-	for (i = 0; i < N_COLOUR; i++)
-		if (off_colour[i] == ml)
-			return 1;
-	return 0;
-}
-
-private
-check_work_empty(const char *s)	{
-	int i;
-	int cnt = 0;
-	
-	for (i = 0; i < N_COLOUR; i++)
-		if (off_colour[i] != MAL_NULL)
-			cnt++;
-	if (cnt != 0)
-		Error("off_colour not empty", s, MAL_NULL);
-}
-
-private int
-Error(const char *fmt, const char *s, mallink *ml)	{
-	static int already_called = 0;
-
-	if (already_called++) return 0;
-	setbuf(stdout, (char *) 0);
-	printf("%s: ", s);
-	printf(fmt, (long)ml);
-	printf("\n");
-	acquire_malout();
-	fprintf(malout, "%s: ", s);
-	fprintf(malout, fmt, (long)ml);
-	fprintf(malout, "\n");
-	fflush(stdout);
-	maldump(1);
-	return 0;			/* to satisfy lint */
-}
-
-#endif	/* CHECK */
-
Index: trunk/minix/commands/ash/trap.c
===================================================================
--- trunk/minix/commands/ash/trap.c	(revision 9)
+++ 	(revision )
@@ -1,328 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)trap.c	5.2 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-#include "shell.h"
-#include "main.h"
-#include "nodes.h"	/* for other headers */
-#include "eval.h"
-#include "jobs.h"
-#include "options.h"
-#include "syntax.h"
-#include "signames.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
-#include "trap.h"
-#include "mystring.h"
-#include <sys/types.h>
-#include <signal.h>
-
-
-/*
- * Sigmode records the current value of the signal handlers for the various
- * modes.  A value of zero means that the current handler is not known.
- * S_HARD_IGN indicates that the signal was ignored on entry to the shell,
- */
-
-#define S_DFL 1			/* default signal handling (SIG_DFL) */
-#define S_CATCH 2		/* signal is caught */
-#define S_IGN 3			/* signal is ignored (SIG_IGN) */
-#define S_HARD_IGN 4		/* signal is ignored permenantly */
-
-
-extern char nullstr[1];		/* null string */
-
-char *trap[MAXSIG+1];		/* trap handler commands */
-MKINIT char sigmode[MAXSIG];	/* current value of signal */
-char gotsig[MAXSIG];		/* indicates specified signal received */
-int pendingsigs;			/* indicates some signal received */
-
-/*
- * The trap builtin.
- */
-
-trapcmd(argc, argv)  char **argv; {
-	char *action;
-	char **ap;
-	int signo;
-
-	if (argc <= 1) {
-		for (signo = 0 ; signo <= MAXSIG ; signo++) {
-			if (trap[signo] != NULL)
-				out1fmt("%d: %s\n", signo, trap[signo]);
-		}
-		return 0;
-	}
-	ap = argv + 1;
-	if (is_number(*ap))
-		action = NULL;
-	else
-		action = *ap++;
-	while (*ap) {
-		if ((signo = number(*ap)) < 0 || signo > MAXSIG)
-			error("%s: bad trap", *ap);
-		INTOFF;
-		if (action)
-			action = savestr(action);
-		if (trap[signo])
-			ckfree(trap[signo]);
-		trap[signo] = action;
-		if (signo != 0)
-			setsignal(signo);
-		INTON;
-		ap++;
-	}
-	return 0;
-}
-
-
-
-/*
- * Clear traps on a fork.
- */
-
-void
-clear_traps() {
-	char **tp;
-
-	for (tp = trap ; tp <= &trap[MAXSIG] ; tp++) {
-		if (*tp && **tp) {	/* trap not NULL or SIG_IGN */
-			INTOFF;
-			ckfree(*tp);
-			*tp = NULL;
-			if (tp != &trap[0])
-				setsignal(tp - trap);
-			INTON;
-		}
-	}
-}
-
-
-
-/*
- * Set the signal handler for the specified signal.  The routine figures
- * out what it should be set to.
- */
-
-int
-setsignal(signo) {
-	int action;
-	sig_t sigact;
-	char *t;
-	extern void onsig();
-
-	if ((t = trap[signo]) == NULL)
-		action = S_DFL;
-	else if (*t != '\0')
-		action = S_CATCH;
-	else
-		action = S_IGN;
-	if (rootshell && action == S_DFL) {
-		switch (signo) {
-		case SIGINT:
-			if (iflag)
-				action = S_CATCH;
-			break;
-		case SIGQUIT:
-#if DEBUG
-			{
-			extern int debug;
-
-			if (debug)
-				break;
-			}
-#endif
-			/* FALLTHROUGH */
-		case SIGTERM:
-			if (iflag)
-				action = S_IGN;
-			break;
-#if JOBS
-		case SIGTSTP:
-		case SIGTTOU:
-			if (jflag)
-				action = S_IGN;
-			break;
-#endif
-		}
-	}
-	t = &sigmode[signo - 1];
-	if (*t == 0) {	/* current setting unknown */
-		/*
-		 * There is a race condition here if action is not S_IGN.
-		 * A signal can be ignored that shouldn't be.
-		 */
-		if ((int)(sigact = signal(signo, SIG_IGN)) == -1)
-			error("Signal system call failed");
-		if (sigact == SIG_IGN) {
-			*t = S_HARD_IGN;
-		} else {
-			*t = S_IGN;
-		}
-	}
-	if (*t == S_HARD_IGN || *t == action)
-		return 0;
-	switch (action) {
-		case S_DFL:	sigact = SIG_DFL;	break;
-		case S_CATCH:  	sigact = onsig;		break;
-		case S_IGN:	sigact = SIG_IGN;	break;
-	}
-	*t = action;
-	return (int)signal(signo, sigact);
-}
-
-
-/*
- * Ignore a signal.
- */
-
-void
-ignoresig(signo) {
-	if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
-		signal(signo, SIG_IGN);
-	}
-	sigmode[signo - 1] = S_HARD_IGN;
-}
-
-
-#ifdef mkinit
-INCLUDE "signames.h"
-INCLUDE "trap.h"
-
-SHELLPROC {
-	char *sm;
-
-	clear_traps();
-	for (sm = sigmode ; sm < sigmode + MAXSIG ; sm++) {
-		if (*sm == S_IGN)
-			*sm = S_HARD_IGN;
-	}
-}
-#endif
-
-
-
-/*
- * Signal handler.
- */
-
-void
-onsig(signo) {
-	signal(signo, onsig);
-	if (signo == SIGINT && trap[SIGINT] == NULL) {
-		onint();
-		return;
-	}
-	gotsig[signo - 1] = 1;
-	pendingsigs++;
-}
-
-
-
-/*
- * Called to execute a trap.  Perhaps we should avoid entering new trap
- * handlers while we are executing a trap handler.
- */
-
-void
-dotrap() {
-	int i;
-	int savestatus;
-
-	for (;;) {
-		for (i = 1 ; ; i++) {
-			if (gotsig[i - 1])
-				break;
-			if (i >= MAXSIG)
-				goto done;
-		}
-		gotsig[i - 1] = 0;
-		savestatus=exitstatus;
-		evalstring(trap[i]);
-		exitstatus=savestatus;
-	}
-done:
-	pendingsigs = 0;
-}
-
-
-
-/*
- * Controls whether the shell is interactive or not.
- */
-
-int is_interactive;
-
-void
-setinteractive(on) {
-	if (on == is_interactive)
-		return;
-	setsignal(SIGINT);
-	setsignal(SIGQUIT);
-	setsignal(SIGTERM);
-	is_interactive = on;
-}
-
-
-
-/*
- * Called to exit the shell.
- */
-
-void
-exitshell(status) {
-	struct jmploc loc1, loc2;
-	char *p;
-
-	TRACE(("exitshell(%d) pid=%d\n", status, getpid()));
-	if (setjmp(loc1.loc))  goto l1;
-	if (setjmp(loc2.loc))  goto l2;
-	handler = &loc1;
-	if ((p = trap[0]) != NULL && *p != '\0') {
-		trap[0] = NULL;
-		evalstring(p);
-	}
-l1:   handler = &loc2;			/* probably unnecessary */
-	flushall();
-#if JOBS
-	setjobctl(0);
-#endif
-l2:   _exit(status);
-}
Index: trunk/minix/commands/ash/trap.h
===================================================================
--- trunk/minix/commands/ash/trap.h	(revision 9)
+++ 	(revision )
@@ -1,55 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)trap.h	5.1 (Berkeley) 3/7/91
- */
-
-extern int pendingsigs;
-
-#ifdef __STDC__
-void clear_traps(void);
-int setsignal(int);
-void ignoresig(int);
-void dotrap(void);
-void setinteractive(int);
-void exitshell(int);
-#else
-void clear_traps();
-int setsignal();
-void ignoresig();
-void dotrap();
-void setinteractive();
-void exitshell();
-#endif
Index: trunk/minix/commands/ash/var.c
===================================================================
--- trunk/minix/commands/ash/var.c	(revision 9)
+++ 	(revision )
@@ -1,651 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)var.c	5.3 (Berkeley) 4/12/91";
-#endif /* not lint */
-
-/*
- * Shell variables.
- */
-
-#include "shell.h"
-#include "output.h"
-#include "expand.h"
-#include "nodes.h"	/* for other headers */
-#include "eval.h"	/* defines cmdenviron */
-#include "exec.h"
-#include "syntax.h"
-#include "options.h"
-#include "mail.h"
-#include "var.h"
-#include "memalloc.h"
-#include "error.h"
-#include "mystring.h"
-
-
-#define VTABSIZE 39
-
-
-struct varinit {
-	struct var *var;
-	int flags;
-	char *text;
-};
-
-
-#if ATTY
-struct var vatty;
-#endif
-struct var vifs;
-struct var vmail;
-struct var vmpath;
-struct var vpath;
-struct var vps1;
-struct var vps2;
-struct var vpse;
-struct var vvers;
-#if ATTY
-struct var vterm;
-#endif
-
-const struct varinit varinit[] = {
-#if ATTY
-	{&vatty,	VSTRFIXED|VTEXTFIXED|VUNSET,	"ATTY="},
-#endif
-	{&vifs,	VSTRFIXED|VTEXTFIXED,		"IFS= \t\n"},
-	{&vmail,	VSTRFIXED|VTEXTFIXED|VUNSET,	"MAIL="},
-	{&vmpath,	VSTRFIXED|VTEXTFIXED|VUNSET,	"MAILPATH="},
-	{&vpath,	VSTRFIXED|VTEXTFIXED,		"PATH=:/bin:/usr/bin"},
-	/* 
-	 * vps1 depends on uid
-	 */
-	{&vps2,	VSTRFIXED|VTEXTFIXED,		"PS2=> "},
-	{&vpse,	VSTRFIXED|VTEXTFIXED,		"PSE=* "},
-#if ATTY
-	{&vterm,	VSTRFIXED|VTEXTFIXED|VUNSET,	"TERM="},
-#endif
-	{NULL,	0,				NULL}
-};
-
-struct var *vartab[VTABSIZE];
-
-STATIC void unsetvar __P((char *));
-STATIC struct var **hashvar __P((char *));
-STATIC int varequal __P((char *, char *));
-
-/*
- * Initialize the varable symbol tables and import the environment
- */
-
-#ifdef mkinit
-INCLUDE "var.h"
-INIT {
-	char **envp;
-	extern char **environ;
-
-	initvar();
-	for (envp = environ ; *envp ; envp++) {
-		if (strchr(*envp, '=')) {
-			setvareq(*envp, VEXPORT|VTEXTFIXED);
-		}
-	}
-}
-#endif
-
-
-/*
- * This routine initializes the builtin variables.  It is called when the
- * shell is initialized and again when a shell procedure is spawned.
- */
-
-void
-initvar() {
-	const struct varinit *ip;
-	struct var *vp;
-	struct var **vpp;
-
-	for (ip = varinit ; (vp = ip->var) != NULL ; ip++) {
-		if ((vp->flags & VEXPORT) == 0) {
-			vpp = hashvar(ip->text);
-			vp->next = *vpp;
-			*vpp = vp;
-			vp->text = ip->text;
-			vp->flags = ip->flags;
-		}
-	}
-	/*
-	 * PS1 depends on uid
-	 */
-	if ((vps1.flags & VEXPORT) == 0) {
-		vpp = hashvar("PS1=");
-		vps1.next = *vpp;
-		*vpp = &vps1;
-		vps1.text = getuid() ? "PS1=$ " : "PS1=# ";
-		vps1.flags = VSTRFIXED|VTEXTFIXED;
-	}
-}
-
-/*
- * Set the value of a variable.  The flags argument is ored with the
- * flags of the variable.  If val is NULL, the variable is unset.
- */
-
-void
-setvar(name, val, flags)
-	char *name, *val;
-	{
-	char *p, *q;
-	int len;
-	int namelen;
-	char *nameeq;
-	int isbad;
-
-	isbad = 0;
-	p = name;
-	if (! is_name(*p++))
-		isbad = 1;
-	for (;;) {
-		if (! is_in_name(*p)) {
-			if (*p == '\0' || *p == '=')
-				break;
-			isbad = 1;
-		}
-		p++;
-	}
-	namelen = p - name;
-	if (isbad)
-		error("%.*s: is read only", namelen, name);
-	len = namelen + 2;		/* 2 is space for '=' and '\0' */
-	if (val == NULL) {
-		flags |= VUNSET;
-	} else {
-		len += strlen(val);
-	}
-	p = nameeq = ckmalloc(len);
-	q = name;
-	while (--namelen >= 0)
-		*p++ = *q++;
-	*p++ = '=';
-	*p = '\0';
-	if (val)
-		scopy(val, p);
-	setvareq(nameeq, flags);
-}
-
-
-
-/*
- * Same as setvar except that the variable and value are passed in
- * the first argument as name=value.  Since the first argument will
- * be actually stored in the table, it should not be a string that
- * will go away.
- */
-
-void
-setvareq(s, flags)
-	char *s;
-	{
-	struct var *vp, **vpp;
-
-	vpp = hashvar(s);
-	for (vp = *vpp ; vp ; vp = vp->next) {
-		if (varequal(s, vp->text)) {
-			if (vp->flags & VREADONLY) {
-				int len = strchr(s, '=') - s;
-				error("%.*s: is read only", len, s);
-			}
-			INTOFF;
-			if (vp == &vpath)
-				changepath(s + 5);	/* 5 = strlen("PATH=") */
-			if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0)
-				ckfree(vp->text);
-			vp->flags &=~ (VTEXTFIXED|VSTACK|VUNSET);
-			vp->flags |= flags;
-			vp->text = s;
-			if (vp == &vmpath || (vp == &vmail && ! mpathset()))
-				chkmail(1);
-			INTON;
-			return;
-		}
-	}
-	/* not found */
-	vp = ckmalloc(sizeof (*vp));
-	vp->flags = flags;
-	vp->text = s;
-	vp->next = *vpp;
-	*vpp = vp;
-}
-
-
-
-/*
- * Process a linked list of variable assignments.
- */
-
-void
-listsetvar(list)
-	struct strlist *list;
-	{
-	struct strlist *lp;
-
-	INTOFF;
-	for (lp = list ; lp ; lp = lp->next) {
-		setvareq(savestr(lp->text), 0);
-	}
-	INTON;
-}
-
-
-
-/*
- * Find the value of a variable.  Returns NULL if not set.
- */
-
-char *
-lookupvar(name)
-	char *name;
-	{
-	struct var *v;
-
-	for (v = *hashvar(name) ; v ; v = v->next) {
-		if (varequal(v->text, name)) {
-			if (v->flags & VUNSET)
-				return NULL;
-			return strchr(v->text, '=') + 1;
-		}
-	}
-	return NULL;
-}
-
-
-
-/*
- * Search the environment of a builtin command.  If the second argument
- * is nonzero, return the value of a variable even if it hasn't been
- * exported.
- */
-
-char *
-bltinlookup(name, doall)
-	char *name;
-	{
-	struct strlist *sp;
-	struct var *v;
-
-	for (sp = cmdenviron ; sp ; sp = sp->next) {
-		if (varequal(sp->text, name))
-			return strchr(sp->text, '=') + 1;
-	}
-	for (v = *hashvar(name) ; v ; v = v->next) {
-		if (varequal(v->text, name)) {
-			if (v->flags & VUNSET
-			 || ! doall && (v->flags & VEXPORT) == 0)
-				return NULL;
-			return strchr(v->text, '=') + 1;
-		}
-	}
-	return NULL;
-}
-
-
-
-/*
- * Generate a list of exported variables.  This routine is used to construct
- * the third argument to execve when executing a program.
- */
-
-char **
-environment() {
-	int nenv;
-	struct var **vpp;
-	struct var *vp;
-	char **env, **ep;
-
-	nenv = 0;
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (vp = *vpp ; vp ; vp = vp->next)
-			if (vp->flags & VEXPORT)
-				nenv++;
-	}
-	ep = env = stalloc((nenv + 1) * sizeof *env);
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (vp = *vpp ; vp ; vp = vp->next)
-			if (vp->flags & VEXPORT)
-				*ep++ = vp->text;
-	}
-	*ep = NULL;
-	return env;
-}
-
-
-/*
- * Called when a shell procedure is invoked to clear out nonexported
- * variables.  It is also necessary to reallocate variables of with
- * VSTACK set since these are currently allocated on the stack.
- */
-
-#ifdef mkinit
-MKINIT void shprocvar();
-
-SHELLPROC {
-	shprocvar();
-}
-#endif
-
-void
-shprocvar() {
-	struct var **vpp;
-	struct var *vp, **prev;
-
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (prev = vpp ; (vp = *prev) != NULL ; ) {
-			if ((vp->flags & VEXPORT) == 0) {
-				*prev = vp->next;
-				if ((vp->flags & VTEXTFIXED) == 0)
-					ckfree(vp->text);
-				if ((vp->flags & VSTRFIXED) == 0)
-					ckfree(vp);
-			} else {
-				if (vp->flags & VSTACK) {
-					vp->text = savestr(vp->text);
-					vp->flags &=~ VSTACK;
-				}
-				prev = &vp->next;
-			}
-		}
-	}
-	initvar();
-}
-
-
-
-/*
- * Command to list all variables which are set.  Currently this command
- * is invoked from the set command when the set command is called without
- * any variables.
- */
-
-int
-showvarscmd(argc, argv)  char **argv; {
-	struct var **vpp;
-	struct var *vp;
-
-	for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-		for (vp = *vpp ; vp ; vp = vp->next) {
-			if ((vp->flags & VUNSET) == 0)
-				out1fmt("%s\n", vp->text);
-		}
-	}
-	return 0;
-}
-
-
-
-/*
- * The export and readonly commands.
- */
-
-int
-exportcmd(argc, argv)  char **argv; {
-	struct var **vpp;
-	struct var *vp;
-	char *name;
-	char *p;
-	int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
-
-	listsetvar(cmdenviron);
-	if (argc > 1) {
-		while ((name = *argptr++) != NULL) {
-			if ((p = strchr(name, '=')) != NULL) {
-				p++;
-			} else {
-				vpp = hashvar(name);
-				for (vp = *vpp ; vp ; vp = vp->next) {
-					if (varequal(vp->text, name)) {
-						vp->flags |= flag;
-						goto found;
-					}
-				}
-			}
-			setvar(name, p, flag);
-found:;
-		}
-	} else {
-		for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
-			for (vp = *vpp ; vp ; vp = vp->next) {
-				if (vp->flags & flag) {
-					for (p = vp->text ; *p != '=' ; p++)
-						out1c(*p);
-					out1c('\n');
-				}
-			}
-		}
-	}
-	return 0;
-}
-
-
-/*
- * The "local" command.
- */
-
-localcmd(argc, argv)  char **argv; {
-	char *name;
-
-	if (! in_function())
-		error("Not in a function");
-	while ((name = *argptr++) != NULL) {
-		mklocal(name);
-	}
-	return 0;
-}
-
-
-/*
- * Make a variable a local variable.  When a variable is made local, it's
- * value and flags are saved in a localvar structure.  The saved values
- * will be restored when the shell function returns.  We handle the name
- * "-" as a special case.
- */
-
-void
-mklocal(name)
-	char *name;
-	{
-	struct localvar *lvp;
-	struct var **vpp;
-	struct var *vp;
-
-	INTOFF;
-	lvp = ckmalloc(sizeof (struct localvar));
-	if (name[0] == '-' && name[1] == '\0') {
-		lvp->text = ckmalloc(sizeof optval);
-		bcopy(optval, lvp->text, sizeof optval);
-		vp = NULL;
-	} else {
-		vpp = hashvar(name);
-		for (vp = *vpp ; vp && ! varequal(vp->text, name) ; vp = vp->next);
-		if (vp == NULL) {
-			if (strchr(name, '='))
-				setvareq(savestr(name), VSTRFIXED);
-			else
-				setvar(name, NULL, VSTRFIXED);
-			vp = *vpp;	/* the new variable */
-			lvp->text = NULL;
-			lvp->flags = VUNSET;
-		} else {
-			lvp->text = vp->text;
-			lvp->flags = vp->flags;
-			vp->flags |= VSTRFIXED|VTEXTFIXED;
-			if (strchr(name, '='))
-				setvareq(savestr(name), 0);
-		}
-	}
-	lvp->vp = vp;
-	lvp->next = localvars;
-	localvars = lvp;
-	INTON;
-}
-
-
-/*
- * Called after a function returns.
- */
-
-void
-poplocalvars() {
-	struct localvar *lvp;
-	struct var *vp;
-
-	while ((lvp = localvars) != NULL) {
-		localvars = lvp->next;
-		vp = lvp->vp;
-		if (vp == NULL) {	/* $- saved */
-			bcopy(lvp->text, optval, sizeof optval);
-			ckfree(lvp->text);
-		} else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
-			unsetvar(vp->text);
-		} else {
-			if ((vp->flags & VTEXTFIXED) == 0)
-				ckfree(vp->text);
-			vp->flags = lvp->flags;
-			vp->text = lvp->text;
-		}
-		ckfree(lvp);
-	}
-}
-
-
-setvarcmd(argc, argv)  char **argv; {
-	if (argc <= 2)
-		return unsetcmd(argc, argv);
-	else if (argc == 3)
-		setvar(argv[1], argv[2], 0);
-	else
-		error("List assignment not implemented");
-	return 0;
-}
-
-
-/*
- * The unset builtin command.  We unset the function before we unset the
- * variable to allow a function to be unset when there is a readonly variable
- * with the same name.
- */
-
-unsetcmd(argc, argv)  char **argv; {
-	char **ap;
-
-	for (ap = argv + 1 ; *ap ; ap++) {
-		unsetfunc(*ap);
-		unsetvar(*ap);
-	}
-	return 0;
-}
-
-
-/*
- * Unset the specified variable.
- */
-
-STATIC void
-unsetvar(s)
-	char *s;
-	{
-	struct var **vpp;
-	struct var *vp;
-
-	vpp = hashvar(s);
-	for (vp = *vpp ; vp ; vpp = &vp->next, vp = *vpp) {
-		if (varequal(vp->text, s)) {
-			INTOFF;
-			if (*(strchr(vp->text, '=') + 1) != '\0'
-			 || vp->flags & VREADONLY) {
-				setvar(s, nullstr, 0);
-			}
-			vp->flags &=~ VEXPORT;
-			vp->flags |= VUNSET;
-			if ((vp->flags & VSTRFIXED) == 0) {
-				if ((vp->flags & VTEXTFIXED) == 0)
-					ckfree(vp->text);
-				*vpp = vp->next;
-				ckfree(vp);
-			}
-			INTON;
-			return;
-		}
-	}
-}
-
-
-
-/*
- * Find the appropriate entry in the hash table from the name.
- */
-
-STATIC struct var **
-hashvar(p)
-	register char *p;
-	{
-	unsigned int hashval;
-
-	hashval = *p << 4;
-	while (*p && *p != '=')
-		hashval += *p++;
-	return &vartab[hashval % VTABSIZE];
-}
-
-
-
-/*
- * Returns true if the two strings specify the same varable.  The first
- * variable name is terminated by '='; the second may be terminated by
- * either '=' or '\0'.
- */
-
-STATIC int
-varequal(p, q)
-	register char *p, *q;
-	{
-	while (*p == *q++) {
-		if (*p++ == '=')
-			return 1;
-	}
-	if (*p == '=' && *(q - 1) == '\0')
-		return 1;
-	return 0;
-}
Index: trunk/minix/commands/ash/var.h
===================================================================
--- trunk/minix/commands/ash/var.h	(revision 9)
+++ 	(revision )
@@ -1,129 +1,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kenneth Almquist.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)var.h	5.1 (Berkeley) 3/7/91
- */
-
-/*
- * Shell variables.
- */
-
-/* flags */
-#define VEXPORT		01	/* variable is exported */
-#define VREADONLY	02	/* variable cannot be modified */
-#define VSTRFIXED	04	/* variable struct is staticly allocated */
-#define VTEXTFIXED	010	/* text is staticly allocated */
-#define VSTACK		020	/* text is allocated on the stack */
-#define VUNSET		040	/* the variable is not set */
-
-
-struct var {
-	struct var *next;		/* next entry in hash list */
-	int flags;		/* flags are defined above */
-	char *text;		/* name=value */
-};
-
-
-struct localvar {
-	struct localvar *next;	/* next local variable in list */
-	struct var *vp;		/* the variable that was made local */
-	int flags;		/* saved flags */
-	char *text;		/* saved text */
-};
-
-
-struct localvar *localvars;
-
-#if ATTY
-extern struct var vatty;
-#endif
-extern struct var vifs;
-extern struct var vmail;
-extern struct var vmpath;
-extern struct var vpath;
-extern struct var vps1;
-extern struct var vps2;
-extern struct var vpse;
-#if ATTY
-extern struct var vterm;
-#endif
-
-/*
- * The following macros access the values of the above variables.
- * They have to skip over the name.  They return the null string
- * for unset variables.
- */
-
-#define ifsval()	(vifs.text + 4)
-#define mailval()	(vmail.text + 5)
-#define mpathval()	(vmpath.text + 9)
-#define pathval()	(vpath.text + 5)
-#define ps1val()	(vps1.text + 4)
-#define ps2val()	(vps2.text + 4)
-#define pseval()	(vpse.text + 4)
-#if ATTY
-#define termval()	(vterm.text + 5)
-#endif
-
-#if ATTY
-#define attyset()	((vatty.flags & VUNSET) == 0)
-#endif
-#define mpathset()	((vmpath.flags & VUNSET) == 0)
-
-
-#ifdef __STDC__
-void initvar();
-void setvar(char *, char *, int);
-void setvareq(char *, int);
-struct strlist;
-void listsetvar(struct strlist *);
-char *lookupvar(char *);
-char *bltinlookup(char *, int);
-char **environment();
-int showvarscmd(int, char **);
-void mklocal(char *);
-void poplocalvars(void);
-#else
-void initvar();
-void setvar();
-void setvareq();
-void listsetvar();
-char *lookupvar();
-char *bltinlookup();
-char **environment();
-int showvarscmd();
-void mklocal();
-void poplocalvars();
-#endif
