summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-09-01 10:22:36 +0000
committerpeter <peter@FreeBSD.org>1996-09-01 10:22:36 +0000
commit5195be912eb257c05a0c97e561e72f01af2583ff (patch)
treee47ab3981b495c675a987dd1e943d1f4c823f314 /bin
parent2fc7d7d1fa299368ccdddede67b31695266698bd (diff)
downloadFreeBSD-src-5195be912eb257c05a0c97e561e72f01af2583ff.zip
FreeBSD-src-5195be912eb257c05a0c97e561e72f01af2583ff.tar.gz
Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is a
merge of parallel duplicate work by Steve Price and myself. :-] There are some changes to the build that are my fault... mkinit.c was trying (poorly) to duplicate some of the work that make(1) is designed to do. The Makefile hackery is my fault too, the depend list was incomplete because of some explicit OBJS+= entries, so mkdep wasn't picking up their source file #includes. This closes a pile of /bin/sh PR's, but not all of them.. Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/Makefile64
-rw-r--r--bin/sh/TOUR4
-rw-r--r--bin/sh/alias.c25
-rw-r--r--bin/sh/alias.h9
-rw-r--r--bin/sh/arith.h1
-rw-r--r--bin/sh/arith.y67
-rw-r--r--bin/sh/arith_lex.l58
-rw-r--r--bin/sh/bltin/bltin.h4
-rw-r--r--bin/sh/bltin/echo.16
-rw-r--r--bin/sh/bltin/echo.c10
-rwxr-xr-xbin/sh/builtins92
-rw-r--r--bin/sh/builtins.def1
-rw-r--r--bin/sh/cd.c58
-rw-r--r--bin/sh/errmsg.c129
-rw-r--r--bin/sh/errmsg.h48
-rw-r--r--bin/sh/error.c99
-rw-r--r--bin/sh/error.h24
-rw-r--r--bin/sh/eval.c220
-rw-r--r--bin/sh/eval.h24
-rw-r--r--bin/sh/exec.c89
-rw-r--r--bin/sh/exec.h35
-rw-r--r--bin/sh/expand.c388
-rw-r--r--bin/sh/expand.h23
-rw-r--r--bin/sh/funcs/cmv4
-rw-r--r--bin/sh/funcs/dirs4
-rw-r--r--bin/sh/funcs/kill4
-rw-r--r--bin/sh/funcs/login4
-rw-r--r--bin/sh/funcs/newgrp4
-rw-r--r--bin/sh/funcs/popd4
-rw-r--r--bin/sh/funcs/pushd4
-rw-r--r--bin/sh/funcs/suspend4
-rw-r--r--bin/sh/histedit.c52
-rw-r--r--bin/sh/init.h16
-rw-r--r--bin/sh/input.c35
-rw-r--r--bin/sh/input.h42
-rw-r--r--bin/sh/jobs.c141
-rw-r--r--bin/sh/jobs.h32
-rw-r--r--bin/sh/machdep.h6
-rw-r--r--bin/sh/mail.c8
-rw-r--r--bin/sh/mail.h10
-rw-r--r--bin/sh/main.c98
-rw-r--r--bin/sh/main.h15
-rw-r--r--bin/sh/memalloc.c27
-rw-r--r--bin/sh/memalloc.h47
-rw-r--r--bin/sh/miscbltin.c424
-rwxr-xr-xbin/sh/mkbuiltins28
-rw-r--r--bin/sh/mkinit.c118
-rw-r--r--bin/sh/mknodes.c144
-rw-r--r--bin/sh/mksignames.c199
-rw-r--r--bin/sh/mksyntax.c112
-rw-r--r--bin/sh/mktokens4
-rw-r--r--bin/sh/myhistedit.h11
-rw-r--r--bin/sh/mystring.c5
-rw-r--r--bin/sh/mystring.h19
-rw-r--r--bin/sh/nodes.c.pat140
-rw-r--r--bin/sh/nodetypes6
-rw-r--r--bin/sh/options.c59
-rw-r--r--bin/sh/options.h54
-rw-r--r--bin/sh/output.c35
-rw-r--r--bin/sh/output.h57
-rw-r--r--bin/sh/parser.c247
-rw-r--r--bin/sh/parser.h38
-rw-r--r--bin/sh/redir.c36
-rw-r--r--bin/sh/redir.h23
-rw-r--r--bin/sh/sh.118
-rw-r--r--bin/sh/shell.h10
-rw-r--r--bin/sh/show.c127
-rw-r--r--bin/sh/show.h3
-rw-r--r--bin/sh/trap.c87
-rw-r--r--bin/sh/trap.h27
-rw-r--r--bin/sh/var.c63
-rw-r--r--bin/sh/var.h43
72 files changed, 2136 insertions, 2040 deletions
diff --git a/bin/sh/Makefile b/bin/sh/Makefile
index cacba41..ca5b779 100644
--- a/bin/sh/Makefile
+++ b/bin/sh/Makefile
@@ -1,57 +1,45 @@
-# @(#)Makefile 8.1 (Berkeley) 6/8/93
-# $Id: Makefile,v 1.11 1996/06/02 17:06:39 phk Exp $
+# @(#)Makefile 8.4 (Berkeley) 5/5/95
+# $Id: Makefile,v 1.12 1996/06/24 04:22:21 jkh Exp $
PROG= sh
-SRCS= alias.c builtins.c cd.c echo.c error.c eval.c exec.c expand.c \
+SHSRCS= alias.c cd.c echo.c error.c eval.c exec.c expand.c \
histedit.c input.c jobs.c mail.c main.c memalloc.c miscbltin.c \
- mystring.c nodes.c options.c parser.c printf.c redir.c show.c \
- signames.c syntax.c trap.c output.c var.c
-OBJS+= init.o arith.o arith_lex.o
-DPADD= ${LIBL} ${LIBEDIT} ${LIBTERMCAP}
-LDADD= -ll -ledit -ltermcap
+ mystring.c options.c parser.c printf.c redir.c show.c \
+ trap.c output.c var.c
+
+GENSRCS=arith.c arith_lex.c builtins.c init.c nodes.c syntax.c
+
+SRCS= ${GENSRCS} ${SHSRCS}
+
+DPADD+= ${LIBL} ${LIBEDIT} ${LIBTERMCAP}
+LDADD+= -ll -ledit -ltermcap
+
LFLAGS= -8 # 8-bit lex scanner for arithmetic
CFLAGS+=-DSHELL -I. -I${.CURDIR}
-# for debugging:
-#CFLAGS+=-g -DDEBUG=2
+
.PATH: ${.CURDIR}/bltin ${.CURDIR}/../../usr.bin/printf
-CLEANFILES+=\
- builtins.c builtins.h init.c mkinit mknodes mksignames mksyntax \
- nodes.c nodes.h signames.c signames.h syntax.c syntax.h token.def \
- y.tab.h
-.depend parser.o: token.def
-token.def: mktokens
- sh ${.CURDIR}/mktokens
+CLEANFILES+= builtins.h mkinit mknodes mksyntax \
+ nodes.h syntax.h token.h y.tab.h
+CLEANFILES+= ${GENSRCS}
-${.CURDIR}/builtins:
- # just override the default rule
+beforedepend: token.h
-builtins.h builtins.c: ${.CURDIR}/mkbuiltins ${.CURDIR}/builtins
- cd ${.CURDIR} && env OBJDIR=${.OBJDIR} sh mkbuiltins
+token.h: mktokens
+ sh ${.CURDIR}/mktokens
-init.c: mkinit ${SRCS}
- ./mkinit '${CC} -c ${CFLAGS} ${LDFLAGS} init.c' ${.ALLSRC}
- touch ${.TARGET}
+builtins.h builtins.c: mkbuiltins builtins.def
+ cd ${.CURDIR}; sh mkbuiltins ${.OBJDIR}
-mkinit: ${.CURDIR}/mkinit.c
- ${CC} ${CFLAGS} ${LDFLAGS} ${.CURDIR}/mkinit.c -o $@
+init.c: mkinit ${SHSRCS}
+ ./mkinit ${.ALLSRC:S/^mkinit$//}
-nodes.c nodes.h: mknodes ${.CURDIR}/nodetypes ${.CURDIR}/nodes.c.pat
+nodes.c nodes.h: mknodes nodetypes nodes.c.pat
./mknodes ${.CURDIR}/nodetypes ${.CURDIR}/nodes.c.pat
-mknodes: ${.CURDIR}/mknodes.c
- ${CC} ${CFLAGS} ${LDFLAGS} ${.CURDIR}/mknodes.c -o $@
-
-signames.c signames.h: mksignames
- ./mksignames
-
-mksignames: ${.CURDIR}/mksignames.c
- ${CC} ${CFLAGS} ${LDFLAGS} ${.CURDIR}/mksignames.c -o $@
-
syntax.c syntax.h: mksyntax
./mksyntax
-mksyntax: ${.CURDIR}/mksyntax.c ${.CURDIR}/parser.h
- ${CC} ${CFLAGS} ${LDFLAGS} ${.CURDIR}/mksyntax.c -o $@
+parser.o: token.h
.include <bsd.prog.mk>
diff --git a/bin/sh/TOUR b/bin/sh/TOUR
index 23925e4..44e849017 100644
--- a/bin/sh/TOUR
+++ b/bin/sh/TOUR
@@ -1,5 +1,5 @@
# @(#)TOUR 8.1 (Berkeley) 5/31/93
-# $Id$
+# $Id: TOUR,v 1.2 1994/09/24 02:57:19 davidg Exp $
NOTE -- This is the original TOUR paper distributed with ash and
does not represent the current state of the shell. It is provided anyway
@@ -29,7 +29,7 @@ programs is:
mknodes nodetypes nodes.h nodes.c
mksignames - signames.h signames.c
mksyntax - syntax.h syntax.c
- mktokens - token.def
+ mktokens - token.h
bltin/mkexpr unary_op binary_op operators.h operators.c
There are undoubtedly too many of these. Mkinit searches all the
diff --git a/bin/sh/alias.c b/bin/sh/alias.c
index c851287..d6ae730 100644
--- a/bin/sh/alias.c
+++ b/bin/sh/alias.c
@@ -33,13 +33,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: alias.c,v 1.2 1994/09/24 02:57:20 davidg Exp $
+ * $Id: alias.c,v 1.3 1995/05/30 00:07:10 rgrimes Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)alias.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)alias.c 8.3 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <stdlib.h>
#include "shell.h"
#include "input.h"
#include "output.h"
@@ -53,12 +54,15 @@ static char sccsid[] = "@(#)alias.c 8.1 (Berkeley) 5/31/93";
struct alias *atab[ATABSIZE];
+STATIC void setalias __P((char *, char *));
+STATIC int unalias __P((char *));
STATIC struct alias **hashalias __P((char *));
STATIC
+void
setalias(name, val)
char *name, *val;
- {
+{
struct alias *ap, **app;
app = hashalias(name);
@@ -98,7 +102,7 @@ setalias(name, val)
{
int len = strlen(val);
ap->val = ckmalloc(len + 2);
- bcopy(val, ap->val, len);
+ memcpy(ap->val, val, len);
ap->val[len] = ' '; /* fluff */
ap->val[len+1] = '\0';
}
@@ -173,7 +177,8 @@ rmaliases() {
struct alias *
lookupalias(name, check)
char *name;
- {
+ int check;
+{
struct alias *ap = *hashalias(name);
for (; ap; ap = ap->next) {
@@ -190,9 +195,11 @@ lookupalias(name, check)
/*
* TODO - sort output
*/
+int
aliascmd(argc, argv)
+ int argc;
char **argv;
- {
+{
char *n, *v;
int ret = 0;
struct alias *ap;
@@ -207,7 +214,7 @@ aliascmd(argc, argv)
}
return (0);
}
- while (n = *++argv) {
+ while ((n = *++argv) != NULL) {
if ((v = strchr(n+1, '=')) == NULL) /* n+1: funny ksh stuff */
if ((ap = lookupalias(n, 0)) == NULL) {
outfmt(out2, "alias: %s not found\n", n);
@@ -223,9 +230,11 @@ aliascmd(argc, argv)
return (ret);
}
+int
unaliascmd(argc, argv)
+ int argc;
char **argv;
- {
+{
int i;
while ((i = nextopt("a")) != '\0') {
diff --git a/bin/sh/alias.h b/bin/sh/alias.h
index b5fed8d..7abaccf 100644
--- a/bin/sh/alias.h
+++ b/bin/sh/alias.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)alias.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)alias.h 8.2 (Berkeley) 5/4/95
+ * $Id: alias.h,v 1.2 1994/09/24 02:57:20 davidg Exp $
*/
#define ALIASINUSE 1
@@ -46,4 +46,7 @@ struct alias {
int flag;
};
-struct alias *lookupalias();
+struct alias *lookupalias __P((char *, int));
+int aliascmd __P((int, char **));
+int unaliascmd __P((int, char **));
+void rmaliases __P((void));
diff --git a/bin/sh/arith.h b/bin/sh/arith.h
index d6d7303..34eb73c 100644
--- a/bin/sh/arith.h
+++ b/bin/sh/arith.h
@@ -31,6 +31,7 @@
* SUCH DAMAGE.
*
* @(#)arith.h 1.1 (Berkeley) 5/4/95
+ * $Id$
*/
int arith __P((char *));
diff --git a/bin/sh/arith.y b/bin/sh/arith.y
index b71be6b..0a08dc5 100644
--- a/bin/sh/arith.y
+++ b/bin/sh/arith.y
@@ -1,13 +1,16 @@
-%token ARITH_OR ARITH_AND ARITH_ADD ARITH_SUBT ARITH_MULT ARITH_DIV ARITH_REM ARITH_EQ ARITH_GT ARITH_GEQ ARITH_LT ARITH_LEQ ARITH_NEQ
-%token ARITH_NUM ARITH_LPAREN ARITH_RPAREN ARITH_NOT ARITH_UNARYMINUS
+%token ARITH_NUM ARITH_LPAREN ARITH_RPAREN
%left ARITH_OR
%left ARITH_AND
-%left ARITH_EQ ARITH_NEQ
-%left ARITH_LT ARITH_GT ARITH_GEQ ARITH_LEQ
-%left ARITH_ADD ARITH_SUBT
-%left ARITH_MULT ARITH_DIV ARITH_REM
-%left ARITH_UNARYMINUS ARITH_NOT
+%left ARITH_BOR
+%left ARITH_BXOR
+%left ARITH_BAND
+%left ARITH_EQ ARITH_NE
+%left ARITH_LT ARITH_GT ARITH_GE ARITH_LE
+%left ARITH_LSHIFT ARITH_RSHIFT
+%left ARITH_ADD ARITH_SUB
+%left ARITH_MUL ARITH_DIV ARITH_REM
+%left ARITH_UNARYMINUS ARITH_UNARYPLUS ARITH_NOT ARITH_BNOT
%%
exp: expr = {
@@ -17,25 +20,36 @@ exp: expr = {
expr: ARITH_LPAREN expr ARITH_RPAREN = { $$ = $2; }
- | expr ARITH_OR expr = { $$ = $1 ? $1 : $3 ? $3 : 0; }
- | expr ARITH_AND expr = { $$ = $1 ? ( $3 ? $3 : 0 ) : 0; }
- | expr ARITH_EQ expr = { $$ = $1 == $3; }
- | expr ARITH_GT expr = { $$ = $1 > $3; }
- | expr ARITH_GEQ expr = { $$ = $1 >= $3; }
- | expr ARITH_LT expr = { $$ = $1 < $3; }
- | expr ARITH_LEQ expr = { $$ = $1 <= $3; }
- | expr ARITH_NEQ expr = { $$ = $1 != $3; }
- | expr ARITH_ADD expr = { $$ = $1 + $3; }
- | expr ARITH_SUBT expr = { $$ = $1 - $3; }
- | expr ARITH_MULT expr = { $$ = $1 * $3; }
- | expr ARITH_DIV expr = {
+ | expr ARITH_OR expr = { $$ = $1 ? $1 : $3 ? $3 : 0; }
+ | expr ARITH_AND expr = { $$ = $1 ? ( $3 ? $3 : 0 ) : 0; }
+ | expr ARITH_BOR expr = { $$ = $1 | $3; }
+ | expr ARITH_BXOR expr = { $$ = $1 ^ $3; }
+ | expr ARITH_BAND expr = { $$ = $1 & $3; }
+ | expr ARITH_EQ expr = { $$ = $1 == $3; }
+ | expr ARITH_GT expr = { $$ = $1 > $3; }
+ | expr ARITH_GE expr = { $$ = $1 >= $3; }
+ | expr ARITH_LT expr = { $$ = $1 < $3; }
+ | expr ARITH_LE expr = { $$ = $1 <= $3; }
+ | expr ARITH_NE expr = { $$ = $1 != $3; }
+ | expr ARITH_LSHIFT expr = { $$ = $1 << $3; }
+ | expr ARITH_RSHIFT expr = { $$ = $1 >> $3; }
+ | expr ARITH_ADD expr = { $$ = $1 + $3; }
+ | expr ARITH_SUB expr = { $$ = $1 - $3; }
+ | expr ARITH_MUL expr = { $$ = $1 * $3; }
+ | expr ARITH_DIV expr = {
if ($3 == 0)
yyerror("division by zero");
$$ = $1 / $3;
}
- | expr ARITH_REM expr = { $$ = $1 % $3; }
+ | expr ARITH_REM expr = {
+ if ($3 == 0)
+ yyerror("division by zero");
+ $$ = $1 % $3;
+ }
| ARITH_NOT expr = { $$ = !($2); }
- | ARITH_UNARYMINUS expr = { $$ = -($2); }
+ | ARITH_BNOT expr = { $$ = ~($2); }
+ | ARITH_SUB expr %prec ARITH_UNARYMINUS = { $$ = -($2); }
+ | ARITH_ADD expr %prec ARITH_UNARYPLUS = { $$ = $2; }
| ARITH_NUM
;
%%
@@ -74,11 +88,11 @@ expr: ARITH_LPAREN expr ARITH_RPAREN = { $$ = $2; }
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: arith.y,v 1.2 1994/09/24 02:57:21 davidg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)arith.y 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)arith.y 8.3 (Berkeley) 5/4/95";
#endif /* not lint */
#include "shell.h"
@@ -88,13 +102,12 @@ static char sccsid[] = "@(#)arith.y 8.1 (Berkeley) 5/31/93";
char *arith_buf, *arith_startbuf;
+int
arith(s)
char *s;
{
- extern arith_wasoper;
long result;
- arith_wasoper = 1;
arith_buf = arith_startbuf = s;
INTOFF;
@@ -105,10 +118,10 @@ arith(s)
return (result);
}
+void
yyerror(s)
char *s;
{
- extern yytext, yylval;
yyerrok;
yyclearin;
@@ -119,7 +132,9 @@ yyerror(s)
/*
* The exp(1) builtin.
*/
+int
expcmd(argc, argv)
+ int argc;
char **argv;
{
char *p;
diff --git a/bin/sh/arith_lex.l b/bin/sh/arith_lex.l
index 9c3b851..61f21da 100644
--- a/bin/sh/arith_lex.l
+++ b/bin/sh/arith_lex.l
@@ -34,18 +34,19 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: arith_lex.l,v 1.2 1994/09/24 02:57:22 davidg Exp $
+ * $Id: arith_lex.l,v 1.4 1996/06/02 17:06:40 phk Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)arith_lex.l 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)arith_lex.l 8.3 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <unistd.h>
#include "y.tab.h"
+#include "error.h"
extern yylval;
extern char *arith_buf, *arith_startbuf;
-int arith_wasoper;
#undef YY_INPUT
#define YY_INPUT(buf,result,max) \
result = (*buf = *arith_buf++) ? 1 : YY_NULL;
@@ -53,36 +54,33 @@ int arith_wasoper;
%%
[ \t\n] { ; }
-[0-9]+ { arith_wasoper = 0; yylval = atol(yytext); return(ARITH_NUM); }
-"(" { arith_wasoper = 1; return(ARITH_LPAREN); }
-")" { arith_wasoper = 0; return(ARITH_RPAREN); }
-"||" { arith_wasoper = 1; return(ARITH_OR); }
-"&&" { arith_wasoper = 1; return(ARITH_AND); }
-"==" { arith_wasoper = 1; return(ARITH_EQ); }
-">" { arith_wasoper = 1; return(ARITH_GT); }
-">=" { arith_wasoper = 1; return(ARITH_GEQ); }
-"<" { arith_wasoper = 1; return(ARITH_LT); }
-"<=" { arith_wasoper = 1; return(ARITH_LEQ); }
-"!=" { arith_wasoper = 1; return(ARITH_NEQ); }
-"*" { arith_wasoper = 1; return(ARITH_MULT); }
-"/" { arith_wasoper = 1; return(ARITH_DIV); }
-"%" { arith_wasoper = 1; return(ARITH_REM); }
-"+" { if (!arith_wasoper) { /* ignore unary plus */
- arith_wasoper = 1;
- return(ARITH_ADD);
- }
- }
-"-" { if (arith_wasoper) {
- return(ARITH_UNARYMINUS);
- } else {
- arith_wasoper = 1;
- return(ARITH_SUBT);
- }
- }
-"!" { arith_wasoper = 1; return(ARITH_NOT); }
+[0-9]+ { yylval = atol(yytext); return(ARITH_NUM); }
+"(" { return(ARITH_LPAREN); }
+")" { return(ARITH_RPAREN); }
+"||" { return(ARITH_OR); }
+"&&" { return(ARITH_AND); }
+"|" { return(ARITH_BOR); }
+"^" { return(ARITH_BXOR); }
+"&" { return(ARITH_BAND); }
+"==" { return(ARITH_EQ); }
+"!=" { return(ARITH_NE); }
+">" { return(ARITH_GT); }
+">=" { return(ARITH_GE); }
+"<" { return(ARITH_LT); }
+"<=" { return(ARITH_LE); }
+"<<" { return(ARITH_LSHIFT); }
+">>" { return(ARITH_RSHIFT); }
+"*" { return(ARITH_MUL); }
+"/" { return(ARITH_DIV); }
+"%" { return(ARITH_REM); }
+"+" { return(ARITH_ADD); }
+"-" { return(ARITH_SUB); }
+"~" { return(ARITH_BNOT); }
+"!" { return(ARITH_NOT); }
. { error("arith: syntax error: \"%s\"\n", arith_startbuf); }
%%
+void
arith_lex_reset() {
YY_NEW_FILE;
}
diff --git a/bin/sh/bltin/bltin.h b/bin/sh/bltin/bltin.h
index e543e9b..7745dac 100644
--- a/bin/sh/bltin/bltin.h
+++ b/bin/sh/bltin/bltin.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)bltin.h 8.1 (Berkeley) 5/31/93
- * $Id: bltin.h,v 1.3 1995/12/10 15:37:44 joerg Exp $
+ * @(#)bltin.h 8.2 (Berkeley) 5/4/95
+ * $Id: bltin.h,v 1.4 1995/12/14 23:19:36 bde Exp $
*/
/*
diff --git a/bin/sh/bltin/echo.1 b/bin/sh/bltin/echo.1
index 435b851..39a5aa1 100644
--- a/bin/sh/bltin/echo.1
+++ b/bin/sh/bltin/echo.1
@@ -33,10 +33,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)echo.1 8.1 (Berkeley) 5/31/93
-.\" $Id$
+.\" @(#)echo.1 8.2 (Berkeley) 5/4/95
+.\" $Id: echo.1,v 1.2 1994/09/24 02:58:27 davidg Exp $
.\"
-.Dd May 31, 1993
+.Dd May 4, 1995
.Dt ECHO 1
.Os BSD 4.4
.Sh NAME
diff --git a/bin/sh/bltin/echo.c b/bin/sh/bltin/echo.c
index f9f1928..7c6e0f1 100644
--- a/bin/sh/bltin/echo.c
+++ b/bin/sh/bltin/echo.c
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)echo.c 8.1 (Berkeley) 5/31/93
- * $Id: echo.c,v 1.2 1994/09/24 02:58:29 davidg Exp $
+ * @(#)echo.c 8.2 (Berkeley) 5/4/95
+ * $Id: echo.c,v 1.3 1995/08/23 05:31:06 pst Exp $
*/
/*
@@ -50,7 +50,11 @@
/* #define eflag 1 */
-main(argc, argv) char **argv; {
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
register char **ap;
register char *p;
register char c;
diff --git a/bin/sh/builtins b/bin/sh/builtins
deleted file mode 100755
index a0b0f8f..0000000
--- a/bin/sh/builtins
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991, 1993
-# 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 8.1 (Berkeley) 5/31/93
-# $Id: builtins,v 1.2 1994/09/24 02:57:23 davidg Exp $
-
-#
-# 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 bltincmd, 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.
-#
-# NOTE: bltincmd must come first!
-
-bltincmd command
-#alloccmd alloc
-bgcmd -j bg
-breakcmd break continue
-#catfcmd catf
-cdcmd cd chdir
-dotcmd .
-echocmd echo
-evalcmd eval
-execcmd exec
-exitcmd exit
-expcmd exp let
-exportcmd export readonly
-#exprcmd expr test [
-histcmd fc
-fgcmd -j fg
-getoptscmd getopts
-hashcmd hash
-jobidcmd jobid
-jobscmd jobs
-#linecmd line
-localcmd local
-#nlechocmd nlecho
-printfcmd printf
-pwdcmd pwd
-readcmd read
-returncmd return
-setcmd set
-setvarcmd setvar
-shiftcmd shift
-trapcmd trap
-truecmd : true
-ulimitcmd ulimit
-umaskcmd umask
-unaliascmd unalias
-unsetcmd unset
-waitcmd wait
-#foocmd foo
-aliascmd alias
diff --git a/bin/sh/builtins.def b/bin/sh/builtins.def
index aa5b2c9..8a62429 100644
--- a/bin/sh/builtins.def
+++ b/bin/sh/builtins.def
@@ -35,6 +35,7 @@
# SUCH DAMAGE.
#
# @(#)builtins.def 8.4 (Berkeley) 5/4/95
+# $Id$
#
# This file lists all the builtin commands. The first column is the name
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index 31a0001..34d1bd2 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -33,13 +33,19 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: cd.c,v 1.4 1994/12/26 13:02:05 bde Exp $
+ * $Id: cd.c,v 1.5 1995/11/14 01:04:52 peter Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)cd.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
/*
* The cd and pwd commands.
*/
@@ -52,32 +58,24 @@ static char sccsid[] = "@(#)cd.c 8.1 (Berkeley) 5/31/93";
#include "output.h"
#include "memalloc.h"
#include "error.h"
+#include "redir.h"
#include "mystring.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/unistd.h>
-#include <errno.h>
-
-
-#ifdef __STDC__
-STATIC int docd(char *, 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
+#include "show.h"
+STATIC int docd __P((char *, int));
+STATIC char *getcomponent __P((void));
+STATIC void updatepwd __P((char *));
+STATIC void getpwd __P((void));
char *curdir; /* current working directory */
char *prevdir; /* previous working directory */
STATIC char *cdcomppath;
int
-cdcmd(argc, argv) char **argv; {
+cdcmd(argc, argv)
+ int argc;
+ char **argv;
+{
char *dest;
char *path;
char *p;
@@ -100,8 +98,7 @@ cdcmd(argc, argv) char **argv; {
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) {
+ if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
if (!print) {
/*
* XXX - rethink
@@ -116,6 +113,8 @@ cdcmd(argc, argv) char **argv; {
}
}
error("can't cd to %s", dest);
+ /*NOTREACHED*/
+ return 0;
}
@@ -133,6 +132,7 @@ cdcmd(argc, argv) char **argv; {
STATIC int
docd(dest, print)
char *dest;
+ int print;
{
INTOFF;
if (chdir(dest) < 0) {
@@ -153,7 +153,8 @@ docd(dest, print)
STATIC int
docd(dest, print)
char *dest;
- {
+ int print;
+{
register char *p;
register char *q;
char *symlink;
@@ -173,7 +174,7 @@ top:
}
first = 1;
while ((q = getcomponent()) != NULL) {
- if (q[0] == '\0' || q[0] == '.' && q[1] == '\0')
+ if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0'))
continue;
if (! first)
STPUTC('/', p);
@@ -186,7 +187,7 @@ top:
STACKSTRNUL(p);
if (lstat(stackblock(), &statb) < 0)
error("lstat %s failed", stackblock());
- if ((statb.st_mode & S_IFMT) != S_IFLNK)
+ if (!S_ISLNK(statb.st_mode))
continue;
/* Hit a symbolic link. We have to start all over again. */
@@ -316,7 +317,10 @@ updatepwd(dir)
int
-pwdcmd(argc, argv) char **argv; {
+pwdcmd(argc, argv)
+ int argc;
+ char **argv;
+{
getpwd();
out1str(curdir);
out1c('\n');
@@ -367,7 +371,7 @@ getpwd() {
pip[1] = -1;
p = buf;
while ((i = read(pip[0], p, buf + MAXPWD - p)) > 0
- || i == -1 && errno == EINTR) {
+ || (i == -1 && errno == EINTR)) {
if (i > 0)
p += i;
}
diff --git a/bin/sh/errmsg.c b/bin/sh/errmsg.c
deleted file mode 100644
index 87a8d0c..0000000
--- a/bin/sh/errmsg.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * 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.
- *
- * $Id$
- */
-
-#ifndef lint
-static char sccsid[] = "@(#)errmsg.c 8.1 (Berkeley) 5/31/93";
-#endif /* not lint */
-
-#include "shell.h"
-#include "output.h"
-#include "errmsg.h"
-#include <errno.h>
-
-
-#define ALL (E_OPEN|E_CREAT|E_EXEC)
-
-
-struct errname {
- short errcode; /* error number */
- short action; /* operation which encountered the error */
- char *msg; /* text describing the error */
-};
-
-
-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",
- 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) {
- struct errname const *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;
-}
diff --git a/bin/sh/errmsg.h b/bin/sh/errmsg.h
deleted file mode 100644
index 209094a..0000000
--- a/bin/sh/errmsg.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * 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.
- *
- * @(#)errmsg.h 8.1 (Berkeley) 5/31/93
- * $Id$
- */
-
-#define E_OPEN 01
-#define E_CREAT 02
-#define E_EXEC 04
-
-#ifdef __STDC__
-char *errmsg(int, int);
-#else
-char *errmsg();
-#endif
diff --git a/bin/sh/error.c b/bin/sh/error.c
index c1c3b82..ca5c17b 100644
--- a/bin/sh/error.c
+++ b/bin/sh/error.c
@@ -33,11 +33,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: error.c,v 1.2 1994/09/24 02:57:27 davidg Exp $
+ * $Id: error.c,v 1.3 1995/05/30 00:07:10 rgrimes Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)error.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
/*
@@ -49,12 +49,9 @@ static char sccsid[] = "@(#)error.c 8.1 (Berkeley) 5/31/93";
#include "options.h"
#include "output.h"
#include "error.h"
+#include "show.h"
#include <signal.h>
-#ifdef __STDC__
-#include "stdarg.h"
-#else
-#include <varargs.h>
-#endif
+#include <unistd.h>
#include <errno.h>
@@ -76,7 +73,9 @@ char *commandname;
*/
void
-exraise(e) {
+exraise(e)
+ int e;
+{
if (handler == NULL)
abort();
exception = e;
@@ -96,14 +95,15 @@ exraise(e) {
void
onint() {
+ sigset_t sigset;
+
if (suppressint) {
intpending++;
return;
}
intpending = 0;
-#ifdef BSD
- sigsetmask(0);
-#endif
+ sigemptyset(&sigset);
+ sigprocmask(SIG_SETMASK, &sigset, NULL);
if (rootshell && iflag)
exraise(EXINT);
else
@@ -126,21 +126,23 @@ error2(a, b)
* formatting. It then raises the error exception.
*/
-#ifdef __STDC__
+#if __STDC__
void
-error(char *msg, ...) {
+error(char *msg, ...)
#else
void
error(va_alist)
va_dcl
- {
+#endif
+{
+#if !__STDC__
char *msg;
#endif
va_list ap;
-
CLEAR_PENDING_INT;
INTOFF;
-#ifdef __STDC__
+
+#if __STDC__
va_start(ap, msg);
#else
va_start(ap);
@@ -179,55 +181,57 @@ struct errname {
#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",
- EISDIR, ALL, "is a directory",
-/* EMFILE, ALL, "too many open files", */
- ENFILE, ALL, "file table overflow",
- ENOSPC, ALL, "file system full",
+ { 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" },
+ { EISDIR, ALL, "is a directory" },
+#ifdef notdef
+ { EMFILE, ALL, "too many open files" },
+#endif
+ { ENFILE, ALL, "file table overflow" },
+ { ENOSPC, ALL, "file system full" },
#ifdef EDQUOT
- EDQUOT, ALL, "disk quota exceeded",
+ { EDQUOT, ALL, "disk quota exceeded" },
#endif
#ifdef ENOSR
- ENOSR, ALL, "no streams resources",
+ { ENOSR, ALL, "no streams resources" },
#endif
- ENXIO, ALL, "no such device or address",
- EROFS, ALL, "read-only file system",
- ETXTBSY, ALL, "text busy",
+ { 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",
+ { EAGAIN, E_EXEC, "not enough memory" },
#endif
- ENOMEM, ALL, "not enough memory",
+ { ENOMEM, ALL, "not enough memory" },
#ifdef ENOLINK
- ENOLINK, ALL, "remote access failed",
+ { ENOLINK, ALL, "remote access failed" },
#endif
#ifdef EMULTIHOP
- EMULTIHOP, ALL, "remote access failed",
+ { EMULTIHOP, ALL, "remote access failed" },
#endif
#ifdef ECOMM
- ECOMM, ALL, "remote access failed",
+ { ECOMM, ALL, "remote access failed" },
#endif
#ifdef ESTALE
- ESTALE, ALL, "remote access failed",
+ { ESTALE, ALL, "remote access failed" },
#endif
#ifdef ETIMEDOUT
- ETIMEDOUT, ALL, "remote access failed",
+ { ETIMEDOUT, ALL, "remote access failed" },
#endif
#ifdef ELOOP
- ELOOP, ALL, "symbolic link loop",
+ { ELOOP, ALL, "symbolic link loop" },
#endif
- E2BIG, E_EXEC, "argument list too long",
+ { E2BIG, E_EXEC, "argument list too long" },
#ifdef ELIBACC
- ELIBACC, E_EXEC, "shared library missing",
+ { ELIBACC, E_EXEC, "shared library missing" },
#endif
- 0, 0, NULL
+ { 0, 0, NULL },
};
@@ -238,7 +242,10 @@ STATIC const struct errname errormsg[] = {
*/
char *
-errmsg(e, action) {
+errmsg(e, action)
+ int e;
+ int action;
+{
struct errname const *ep;
static char buf[12];
diff --git a/bin/sh/error.h b/bin/sh/error.h
index 03a2f89..261b096 100644
--- a/bin/sh/error.h
+++ b/bin/sh/error.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)error.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)error.h 8.2 (Berkeley) 5/4/95
+ * $Id: error.h,v 1.2 1994/09/24 02:57:28 davidg Exp $
*/
/*
@@ -83,24 +83,16 @@ 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 INTON { if (--suppressint == 0 && intpending) onint(); }
#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
+void exraise __P((int));
+void onint __P((void));
+void error2 __P((char *, char *));
+void error __P((char *, ...));
+char *errmsg __P((int, int));
/*
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 34417df..cfb0d0b 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -33,13 +33,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: eval.c,v 1.3 1995/05/30 00:07:11 rgrimes Exp $
+ * $Id: eval.c,v 1.4 1995/09/20 08:30:56 davidg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)eval.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
#endif /* not lint */
+#include <signal.h>
+#include <unistd.h>
+
/*
* Evaluate a command.
*/
@@ -61,9 +64,11 @@ static char sccsid[] = "@(#)eval.c 8.1 (Berkeley) 5/31/93";
#include "var.h"
#include "memalloc.h"
#include "error.h"
+#include "show.h"
#include "mystring.h"
+#ifndef NO_HISTORY
#include "myhistedit.h"
-#include <signal.h>
+#endif
/* flags in argument to evaltree */
@@ -86,28 +91,17 @@ 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
-
+STATIC void evalloop __P((union node *));
+STATIC void evalfor __P((union node *));
+STATIC void evalcase __P((union node *, int));
+STATIC void evalsubshell __P((union node *, int));
+STATIC void expredir __P((union node *));
+STATIC void evalpipe __P((union node *));
+STATIC void evalcommand __P((union node *, int, struct backcmd *));
+STATIC void prehash __P((union node *));
/*
@@ -134,8 +128,10 @@ SHELLPROC {
* The eval commmand.
*/
-evalcmd(argc, argv)
- char **argv;
+int
+evalcmd(argc, argv)
+ int argc;
+ char **argv;
{
char *p;
char *concat;
@@ -193,14 +189,17 @@ evalstring(s)
void
evaltree(n, flags)
union node *n;
- {
+ int flags;
+{
if (n == NULL) {
TRACE(("evaltree(NULL) called\n"));
exitstatus = 0;
goto out;
}
+#ifndef NO_HISTORY
displayhist = 1; /* show history substitutions done with fc */
- TRACE(("evaltree(0x%x: %d) called\n", (int)n, n->type));
+#endif
+ TRACE(("evaltree(0x%lx: %d) called\n", (long)n, n->type));
switch (n->type) {
case NSEMI:
evaltree(n->nbinary.ch1, 0);
@@ -233,19 +232,17 @@ evaltree(n, flags)
evalsubshell(n, flags);
break;
case NIF: {
- int status = 0;
+ int status;
evaltree(n->nif.test, EV_TESTED);
+ status = exitstatus;
+ exitstatus = 0;
if (evalskip)
goto out;
- if (exitstatus == 0) {
+ if (status == 0)
evaltree(n->nif.ifpart, flags);
- status = exitstatus;
- } else if (n->nif.elsepart) {
+ else if (n->nif.elsepart)
evaltree(n->nif.elsepart, flags);
- status = exitstatus;
- }
- exitstatus = status;
break;
}
case NWHILE:
@@ -289,7 +286,7 @@ out:
STATIC void
evalloop(n)
union node *n;
- {
+{
int status;
loopnest++;
@@ -325,8 +322,8 @@ skipping: if (evalskip == SKIPCONT && --skipcount <= 0) {
STATIC void
evalfor(n)
- union node *n;
- {
+ union node *n;
+{
struct arglist arglist;
union node *argp;
struct strlist *sp;
@@ -335,6 +332,7 @@ evalfor(n)
setstackmark(&smark);
arglist.lastp = &arglist.list;
for (argp = n->nfor.args ; argp ; argp = argp->narg.next) {
+ oexitstatus = exitstatus;
expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
if (evalskip)
goto out;
@@ -366,7 +364,8 @@ out:
STATIC void
evalcase(n, flags)
union node *n;
- {
+ int flags;
+{
union node *cp;
union node *patp;
struct arglist arglist;
@@ -374,6 +373,7 @@ evalcase(n, flags)
setstackmark(&smark);
arglist.lastp = &arglist.list;
+ oexitstatus = exitstatus;
expandarg(n->ncase.expr, &arglist, EXP_TILDE);
for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
@@ -398,7 +398,8 @@ out:
STATIC void
evalsubshell(n, flags)
union node *n;
- {
+ int flags;
+{
struct job *jp;
int backgnd = (n->type == NBACKGND);
@@ -426,17 +427,27 @@ evalsubshell(n, flags)
STATIC void
expredir(n)
union node *n;
- {
+{
register union node *redir;
for (redir = n ; redir ; redir = redir->nfile.next) {
- if (redir->type == NFROM
- || redir->type == NTO
- || redir->type == NAPPEND) {
- struct arglist fn;
- fn.lastp = &fn.list;
+ struct arglist fn;
+ fn.lastp = &fn.list;
+ oexitstatus = exitstatus;
+ switch (redir->type) {
+ case NFROM:
+ case NTO:
+ case NAPPEND:
expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
redir->nfile.expfname = fn.list->text;
+ break;
+ case NFROMFD:
+ case NTOFD:
+ if (redir->ndup.vname) {
+ expandarg(redir->ndup.vname, &fn, EXP_FULL | EXP_TILDE);
+ fixredir(redir, fn.list->text, 1);
+ }
+ break;
}
}
}
@@ -453,14 +464,14 @@ expredir(n)
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));
+ TRACE(("evalpipe(0x%lx) called\n", (long)n));
pipelen = 0;
for (lp = n->npipe.cmdlist ; lp ; lp = lp->next)
pipelen++;
@@ -520,7 +531,7 @@ void
evalbackcmd(n, result)
union node *n;
struct backcmd *result;
- {
+{
int pip[2];
struct job *jp;
struct stackmark smark; /* unnecessary */
@@ -530,12 +541,15 @@ evalbackcmd(n, result)
result->buf = NULL;
result->nleft = 0;
result->jp = NULL;
- exitstatus = 0;
- if (n == NULL)
+ if (n == NULL) {
+ exitstatus = 0;
goto out;
+ }
if (n->type == NCMD) {
+ exitstatus = oexitstatus;
evalcommand(n, EV_BACKCMD, result);
} else {
+ exitstatus = 0;
if (pipe(pip) < 0)
error("Pipe call failed");
jp = makejob(n, 1);
@@ -568,8 +582,9 @@ out:
STATIC void
evalcommand(cmd, flags, backcmd)
union node *cmd;
+ int flags;
struct backcmd *backcmd;
- {
+{
struct stackmark smark;
union node *argp;
struct arglist arglist;
@@ -579,7 +594,6 @@ evalcommand(cmd, flags, backcmd)
char **envp;
int varflag;
struct strlist *sp;
- register char *p;
int mode;
int pip[2];
struct cmdentry cmdentry;
@@ -591,15 +605,24 @@ evalcommand(cmd, flags, backcmd)
struct localvar *volatile savelocalvars;
volatile int e;
char *lastarg;
+#if __GNUC__
+ /* Avoid longjmp clobbering */
+ (void) &argv;
+ (void) &argc;
+ (void) &lastarg;
+ (void) &flags;
+#endif
/* First expand the arguments. */
- TRACE(("evalcommand(0x%x, %d) called\n", (int)cmd, flags));
+ TRACE(("evalcommand(0x%lx, %d) called\n", (long)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;
+ char *p = argp->narg.text;
if (varflag && is_name(*p)) {
do {
p++;
@@ -650,9 +673,20 @@ evalcommand(cmd, flags, backcmd)
cmdentry.cmdtype = CMDBUILTIN;
cmdentry.u.index = BLTINCMD;
} else {
- find_command(argv[0], &cmdentry, 1);
+ static const char PATH[] = "PATH=";
+ char *path = pathval();
+
+ /*
+ * Modify the command lookup path, if a PATH= assignment
+ * is present
+ */
+ for (sp = varlist.list ; sp ; sp = sp->next)
+ if (strncmp(sp->text, PATH, sizeof(PATH) - 1) == 0)
+ path = sp->text + sizeof(PATH) - 1;
+
+ find_command(argv[0], &cmdentry, 1, path);
if (cmdentry.cmdtype == CMDUNKNOWN) { /* command not found */
- exitstatus = 2;
+ exitstatus = 1;
flushout(&errout);
return;
}
@@ -664,7 +698,7 @@ evalcommand(cmd, flags, backcmd)
break;
if ((cmdentry.u.index = find_builtin(*argv)) < 0) {
outfmt(&errout, "%s: not found\n", *argv);
- exitstatus = 2;
+ exitstatus = 1;
flushout(&errout);
return;
}
@@ -676,11 +710,11 @@ evalcommand(cmd, flags, backcmd)
/* Fork off a child process if necessary. */
if (cmd->ncmd.backgnd
- || cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0
- || (flags & EV_BACKCMD) != 0
+ || (cmdentry.cmdtype == CMDNORMAL && (flags & EV_EXIT) == 0)
+ || ((flags & EV_BACKCMD) != 0
&& (cmdentry.cmdtype != CMDBUILTIN
|| cmdentry.u.index == DOTCMD
- || cmdentry.u.index == EVALCMD)) {
+ || cmdentry.u.index == EVALCMD))) {
jp = makejob(cmd, 1);
mode = cmd->ncmd.backgnd;
if (flags & EV_BACKCMD) {
@@ -789,7 +823,9 @@ cmddone:
if (e != EXERROR || cmdentry.u.index == BLTINCMD
|| cmdentry.u.index == DOTCMD
|| cmdentry.u.index == EVALCMD
+#ifndef NO_HISTORY
|| cmdentry.u.index == HISTCMD
+#endif
|| cmdentry.u.index == EXECCMD)
exraise(e);
FORCEINTON;
@@ -805,16 +841,10 @@ cmddone:
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);
+ shellexec(argv, envp, pathval(), cmdentry.u.index);
/*NOTREACHED*/
}
goto out;
@@ -848,12 +878,13 @@ out:
STATIC void
prehash(n)
union node *n;
- {
+{
struct cmdentry entry;
- if (n->type == NCMD && n->ncmd.args &&
- goodname(n->ncmd.args->narg.text))
- find_command(n->ncmd.args->narg.text, &entry, 0);
+ if (n->type == NCMD && n->ncmd.args)
+ if (goodname(n->ncmd.args->narg.text))
+ find_command(n->ncmd.args->narg.text, &entry, 0,
+ pathval());
}
@@ -868,8 +899,16 @@ prehash(n)
* specified variables.
*/
-bltincmd(argc, argv) char **argv; {
+int
+bltincmd(argc, argv)
+ int argc;
+ char **argv;
+{
listsetvar(cmdenviron);
+ /*
+ * Preserve exitstatus of a previous possible redirection
+ * as POSIX mandates
+ */
return exitstatus;
}
@@ -885,7 +924,11 @@ bltincmd(argc, argv) char **argv; {
* in the standard shell so we don't make it one here.
*/
-breakcmd(argc, argv) char **argv; {
+int
+breakcmd(argc, argv)
+ int argc;
+ char **argv;
+{
int n;
n = 1;
@@ -905,7 +948,11 @@ breakcmd(argc, argv) char **argv; {
* The return command.
*/
-returncmd(argc, argv) char **argv; {
+int
+returncmd(argc, argv)
+ int argc;
+ char **argv;
+{
int ret;
ret = exitstatus;
@@ -919,16 +966,37 @@ returncmd(argc, argv) char **argv; {
}
-truecmd(argc, argv) char **argv; {
+int
+falsecmd(argc, argv)
+ int argc;
+ char **argv;
+{
+ return 1;
+}
+
+
+int
+truecmd(argc, argv)
+ int argc;
+ char **argv;
+{
return 0;
}
-execcmd(argc, argv) char **argv; {
+int
+execcmd(argc, argv)
+ int argc;
+ char **argv;
+{
if (argc > 1) {
+ struct strlist *sp;
+
iflag = 0; /* exit on error */
mflag = 0;
optschanged();
+ for (sp = cmdenviron; sp ; sp = sp->next)
+ setvareq(sp->text, VEXPORT|VSTACK);
shellexec(argv + 1, environment(), pathval(), 0);
}
diff --git a/bin/sh/eval.h b/bin/sh/eval.h
index 6d644495..8649bf8 100644
--- a/bin/sh/eval.h
+++ b/bin/sh/eval.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)eval.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)eval.h 8.2 (Berkeley) 5/4/95
+ * $Id: eval.h,v 1.2 1994/09/24 02:57:31 davidg Exp $
*/
extern char *commandname; /* currently executing command */
@@ -49,17 +49,17 @@ struct backcmd { /* result of evalbackcmd */
struct job *jp; /* job structure for command */
};
-
-#ifdef __STDC__
-void evalstring(char *);
+int evalcmd __P((int, char **));
+void evalstring __P((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
+void evaltree __P((union node *, int));
+void evalbackcmd __P((union node *, struct backcmd *));
+int bltincmd __P((int, char **));
+int breakcmd __P((int, char **));
+int returncmd __P((int, char **));
+int falsecmd __P((int, char **));
+int truecmd __P((int, char **));
+int execcmd __P((int, char **));
/* in_function returns nonzero if we are currently evaluating a function */
#define in_function() funcnest
diff --git a/bin/sh/exec.c b/bin/sh/exec.c
index e9061e8..4b6b1b4 100644
--- a/bin/sh/exec.c
+++ b/bin/sh/exec.c
@@ -33,13 +33,20 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: exec.c,v 1.3 1994/09/24 02:57:32 davidg Exp $
+ * $Id: exec.c,v 1.4 1995/05/30 00:07:12 rgrimes Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
#endif /* not lint */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+
/*
* 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
@@ -66,11 +73,8 @@ static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 5/31/93";
#include "error.h"
#include "init.h"
#include "mystring.h"
+#include "show.h"
#include "jobs.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
#define CMDTABLESIZE 31 /* should be prime */
@@ -91,21 +95,12 @@ 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 *, int);
-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
+STATIC void tryexec __P((char *, char **, char **));
+STATIC void execinterp __P((char **, char **));
+STATIC void printentry __P((struct tblentry *, int));
+STATIC void clearcmdentry __P((int));
+STATIC struct tblentry *cmdlookup __P((char *, int));
+STATIC void delete_cmd_entry __P((void));
@@ -118,7 +113,8 @@ void
shellexec(argv, envp, path, index)
char **argv, **envp;
char *path;
- {
+ int index;
+{
char *cmdname;
int e;
@@ -147,7 +143,9 @@ tryexec(cmd, argv, envp)
char **envp;
{
int e;
+#ifndef BSD
char *p;
+#endif
#ifdef SYSV
do {
@@ -286,7 +284,7 @@ padvance(path, name)
growstackblock();
q = stackblock();
if (p != start) {
- bcopy(start, q, p - start);
+ memcpy(q, start, p - start);
q += p - start;
*q++ = '/';
}
@@ -308,7 +306,11 @@ padvance(path, name)
/*** Command hashing code ***/
-hashcmd(argc, argv) char **argv; {
+int
+hashcmd(argc, argv)
+ int argc;
+ char **argv;
+{
struct tblentry **pp;
struct tblentry *cmdp;
int c;
@@ -335,9 +337,9 @@ hashcmd(argc, argv) char **argv; {
while ((name = *argptr) != NULL) {
if ((cmdp = cmdlookup(name, 0)) != NULL
&& (cmdp->cmdtype == CMDNORMAL
- || cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0))
+ || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)))
delete_cmd_entry();
- find_command(name, &entry, 1);
+ find_command(name, &entry, 1, pathval());
if (verbose) {
if (entry.cmdtype != CMDUNKNOWN) { /* if no error msg */
cmdp = cmdlookup(name, 0);
@@ -398,14 +400,15 @@ printentry(cmdp, verbose)
*/
void
-find_command(name, entry, printerr)
+find_command(name, entry, printerr, path)
char *name;
struct cmdentry *entry;
- {
+ int printerr;
+ char *path;
+{
struct tblentry *cmdp;
int index;
int prev;
- char *path;
char *fullname;
struct stat statb;
int e;
@@ -441,7 +444,6 @@ find_command(name, entry, printerr)
prev = cmdp->param.index;
}
- path = pathval();
e = ENOENT;
index = -1;
loop:
@@ -481,7 +483,7 @@ loop:
goto loop;
}
e = EACCES; /* if we fail, this will be the error */
- if ((statb.st_mode & S_IFMT) != S_IFREG)
+ if (!S_ISREG(statb.st_mode))
goto loop;
if (pathopt) { /* this is a %func directory */
stalloc(strlen(fullname) + 1);
@@ -535,8 +537,8 @@ success:
int
find_builtin(name)
char *name;
- {
- const register struct builtincmd *bp;
+{
+ register const struct builtincmd *bp;
for (bp = builtincmd ; bp->name ; bp++) {
if (*bp->name == *name && equal(bp->name, name))
@@ -560,7 +562,7 @@ hashcd() {
for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
if (cmdp->cmdtype == CMDNORMAL
- || cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)
+ || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0))
cmdp->rehash = 1;
}
}
@@ -577,7 +579,7 @@ hashcd() {
void
changepath(newval)
char *newval;
- {
+{
char *old, *new;
int index;
int firstchange;
@@ -591,8 +593,8 @@ changepath(newval)
for (;;) {
if (*old != *new) {
firstchange = index;
- if (*old == '\0' && *new == ':'
- || *old == ':' && *new == '\0')
+ if ((*old == '\0' && *new == ':')
+ || (*old == ':' && *new == '\0'))
firstchange++;
old = new; /* ignore subsequent differences */
}
@@ -620,7 +622,9 @@ changepath(newval)
*/
STATIC void
-clearcmdentry(firstchange) {
+clearcmdentry(firstchange)
+ int firstchange;
+{
struct tblentry **tblp;
struct tblentry **pp;
struct tblentry *cmdp;
@@ -629,8 +633,10 @@ clearcmdentry(firstchange) {
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) {
+ if ((cmdp->cmdtype == CMDNORMAL &&
+ cmdp->param.index >= firstchange)
+ || (cmdp->cmdtype == CMDBUILTIN &&
+ builtinloc >= firstchange)) {
*pp = cmdp->next;
ckfree(cmdp);
} else {
@@ -692,7 +698,8 @@ struct tblentry **lastcmdentry;
STATIC struct tblentry *
cmdlookup(name, add)
char *name;
- {
+ int add;
+{
int hashval;
register char *p;
struct tblentry *cmdp;
diff --git a/bin/sh/exec.h b/bin/sh/exec.h
index 90d9100..fea5bd5 100644
--- a/bin/sh/exec.h
+++ b/bin/sh/exec.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)exec.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)exec.h 8.3 (Berkeley) 6/8/95
+ * $Id: exec.h,v 1.2 1994/09/24 02:57:33 davidg Exp $
*/
/* values of cmdtype */
@@ -55,22 +55,15 @@ struct cmdentry {
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 *);
-int unsetfunc(char *);
-#else
-void shellexec();
-char *padvance();
-void find_command();
-int find_builtin();
-void hashcd();
-void changepath();
-void defun();
-int unsetfunc();
-#endif
+void shellexec __P((char **, char **, char *, int));
+char *padvance __P((char **, char *));
+int hashcmd __P((int, char **));
+void find_command __P((char *, struct cmdentry *, int, char *));
+int find_builtin __P((char *));
+void hashcd __P((void));
+void changepath __P((char *));
+void deletefuncs __P((void));
+void getcmdentry __P((char *, struct cmdentry *));
+void addcmdentry __P((char *, struct cmdentry *));
+void defun __P((char *, union node *));
+int unsetfunc __P((char *));
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 922ae98..99bbb3c 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -33,13 +33,23 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: expand.c,v 1.5 1996/08/11 22:50:58 ache Exp $
+ * $Id: expand.c,v 1.6 1996/08/12 19:31:11 ache Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)expand.c 8.2 (Berkeley) 10/22/93";
+static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95";
#endif /* not lint */
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <locale.h>
+
/*
* Routines to expand arguments to commands. We have to deal with
* backquotes, shell variables, and file metacharacters.
@@ -60,13 +70,8 @@ static char sccsid[] = "@(#)expand.c 8.2 (Berkeley) 10/22/93";
#include "memalloc.h"
#include "error.h"
#include "mystring.h"
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <locale.h>
-#include <errno.h>
-#include <dirent.h>
-#include <pwd.h>
+#include "arith.h"
+#include "show.h"
/*
* Structure specifying which parts of the string should be searched
@@ -87,39 +92,22 @@ struct ifsregion ifsfirst; /* first struct in list of ifs regions */
struct ifsregion *ifslastp; /* last struct in list */
struct arglist exparg; /* holds expanded arg list */
-#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 *, int);
-STATIC void expmeta(char *, char *);
-STATIC void expari(int);
-STATIC void addfname(char *);
-STATIC struct strlist *expsort(struct strlist *);
-STATIC struct strlist *msort(struct strlist *, int);
-STATIC int pmatch(char *, char *);
-STATIC char *exptilde(char *, int);
-#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 expari();
-STATIC void addfname();
-STATIC struct strlist *expsort();
-STATIC struct strlist *msort();
-STATIC int pmatch();
-STATIC char *exptilde();
-#endif
+STATIC void argstr __P((char *, int));
+STATIC char *exptilde __P((char *, int));
+STATIC void expbackq __P((union node *, int, int));
+STATIC int subevalvar __P((char *, char *, int, int, int));
+STATIC char *evalvar __P((char *, int));
+STATIC int varisset __P((int));
+STATIC void varvalue __P((int, int, int));
+STATIC void recordregion __P((int, int, int));
+STATIC void ifsbreakup __P((char *, struct arglist *));
+STATIC void expandmeta __P((struct strlist *, int));
+STATIC void expmeta __P((char *, char *));
+STATIC void addfname __P((char *));
+STATIC struct strlist *expsort __P((struct strlist *));
+STATIC struct strlist *msort __P((struct strlist *, int));
+STATIC int pmatch __P((char *, char *));
+STATIC char *cvtnum __P((int, char *));
/*
* Expand shell variables and backquotes inside a here document.
@@ -147,7 +135,8 @@ void
expandarg(arg, arglist, flag)
union node *arg;
struct arglist *arglist;
- {
+ int flag;
+{
struct strlist *sp;
char *p;
@@ -204,7 +193,8 @@ expandarg(arg, arglist, flag)
STATIC void
argstr(p, flag)
register char *p;
- {
+ int flag;
+{
register char c;
int quotes = flag & (EXP_FULL | EXP_CASE); /* do CTLESC */
int firsteq = 1;
@@ -260,13 +250,14 @@ breakloop:;
STATIC char *
exptilde(p, flag)
char *p;
- {
+ int flag;
+{
char c, *startp = p;
struct passwd *pw;
char *home;
int quotes = flag & (EXP_FULL | EXP_CASE);
- while (c = *p) {
+ while ((c = *p) != '\0') {
switch(c) {
case CTLESC:
return (startp);
@@ -292,7 +283,7 @@ done:
if (*home == '\0')
goto lose;
*p = c;
- while (c = *home++) {
+ while ((c = *home++) != '\0') {
if (quotes && SQSYNTAX[c] == CCTL)
STPUTC(CTLESC, expdest);
STPUTC(c, expdest);
@@ -310,7 +301,8 @@ lose:
*/
void
expari(flag)
- {
+ int flag;
+{
char *p, *start;
int result;
int quotes = flag & (EXP_FULL | EXP_CASE);
@@ -355,7 +347,9 @@ expari(flag)
STATIC void
expbackq(cmd, quoted, flag)
union node *cmd;
- {
+ int quoted;
+ int flag;
+{
struct backcmd in;
int i;
char buf[128];
@@ -403,11 +397,11 @@ expbackq(cmd, quoted, flag)
STPUTC(lastc, dest);
}
}
- p--;
- while (lastc == '\n') {
+
+ /* Eat all trailing newlines */
+ for (p--; lastc == '\n'; lastc = *--p)
STUNPUTC(dest);
- lastc = *--p;
- }
+
if (in.fd >= 0)
close(in.fd);
if (in.buf)
@@ -426,6 +420,101 @@ expbackq(cmd, quoted, flag)
+STATIC int
+subevalvar(p, str, subtype, startloc, varflags)
+ char *p;
+ char *str;
+ int subtype;
+ int startloc;
+ int varflags;
+{
+
+ char *startp;
+ char *loc = NULL;
+ int c = 0;
+ int saveherefd = herefd;
+ struct nodelist *saveargbackq = argbackq;
+ herefd = -1;
+ argstr(p, 0);
+ STACKSTRNUL(expdest);
+ herefd = saveherefd;
+ argbackq = saveargbackq;
+ startp = stackblock() + startloc;
+
+ switch (subtype) {
+ case VSASSIGN:
+ setvar(str, startp, 0);
+ STADJUST(startp - expdest, expdest);
+ varflags &= ~VSNUL;
+ if (c != 0)
+ *loc = c;
+ return 1;
+
+ case VSQUESTION:
+ if (*p != CTLENDVAR) {
+ outfmt(&errout, "%s\n", startp);
+ error((char *)NULL);
+ }
+ error("%.*s: parameter %snot set", p - str - 1,
+ str, (varflags & VSNUL) ? "null or "
+ : nullstr);
+ return 0;
+
+ case VSTRIMLEFT:
+ for (loc = startp; loc < str - 1; loc++) {
+ c = *loc;
+ *loc = '\0';
+ if (patmatch(str, startp)) {
+ *loc = c;
+ goto recordleft;
+ }
+ *loc = c;
+ }
+ return 0;
+
+ case VSTRIMLEFTMAX:
+ for (loc = str - 1; loc >= startp; loc--) {
+ c = *loc;
+ *loc = '\0';
+ if (patmatch(str, startp)) {
+ *loc = c;
+ goto recordleft;
+ }
+ *loc = c;
+ }
+ return 0;
+
+ case VSTRIMRIGHT:
+ for (loc = str - 1; loc >= startp; loc--) {
+ if (patmatch(str, loc)) {
+ expdest = loc;
+ return 1;
+ }
+ }
+ return 0;
+
+ case VSTRIMRIGHTMAX:
+ for (loc = startp; loc < str - 1; loc++) {
+ if (patmatch(str, loc)) {
+ expdest = loc;
+ return 1;
+ }
+ }
+ return 0;
+
+
+ default:
+ abort();
+ }
+
+recordleft:
+ expdest = (str - 1) - (loc - startp);
+ while (loc != str - 1)
+ *startp++ = *loc++;
+ return 1;
+}
+
+
/*
* Expand a variable, and return a pointer to the next character in the
* input string.
@@ -434,15 +523,19 @@ expbackq(cmd, quoted, flag)
STATIC char *
evalvar(p, flag)
char *p;
- {
+ int flag;
+{
int subtype;
int varflags;
char *var;
char *val;
+ char *pat;
int c;
int set;
int special;
int startloc;
+ int varlen;
+ int easy;
int quotes = flag & (EXP_FULL | EXP_CASE);
varflags = *p++;
@@ -458,60 +551,104 @@ again: /* jump here after setting a variable with ${var=text} */
val = NULL;
} else {
val = lookupvar(var);
- if (val == NULL || (varflags & VSNUL) && val[0] == '\0') {
+ if (val == NULL || ((varflags & VSNUL) && val[0] == '\0')) {
val = NULL;
set = 0;
} else
set = 1;
}
+ varlen = 0;
startloc = expdest - stackblock();
if (set && subtype != VSPLUS) {
/* insert the value of the variable */
if (special) {
+ char *exp, *oexpdest = expdest;
varvalue(*var, varflags & VSQUOTE, flag & EXP_FULL);
+ if (subtype == VSLENGTH) {
+ for (exp = oexpdest;exp != expdest; exp++)
+ varlen++;
+ expdest = oexpdest;
+ }
} else {
- char const *syntax = (varflags & VSQUOTE)? DQSYNTAX : BASESYNTAX;
+ char const *syntax = (varflags & VSQUOTE) ? DQSYNTAX
+ : BASESYNTAX;
+
+ if (subtype == VSLENGTH) {
+ for (;*val; val++)
+ varlen++;
+ }
+ else {
+ while (*val) {
+ if (quotes && syntax[*val] == CCTL)
+ STPUTC(CTLESC, expdest);
+ STPUTC(*val++, expdest);
+ }
- while (*val) {
- if (quotes && syntax[*val] == CCTL)
- STPUTC(CTLESC, expdest);
- STPUTC(*val++, expdest);
}
}
}
+
if (subtype == VSPLUS)
set = ! set;
- if (((varflags & VSQUOTE) == 0 || (*var == '@' && shellparam.nparam != 1))
- && (set || subtype == VSNORMAL))
- recordregion(startloc, expdest - stackblock(), varflags & VSQUOTE);
- if (! set && subtype != VSNORMAL) {
- if (subtype == VSPLUS || subtype == VSMINUS) {
+
+ easy = ((varflags & VSQUOTE) == 0 ||
+ (*var == '@' && shellparam.nparam != 1));
+
+
+ switch (subtype) {
+ case VSLENGTH:
+ expdest = cvtnum(varlen, expdest);
+ goto record;
+
+ case VSNORMAL:
+ if (!easy)
+ break;
+record:
+ recordregion(startloc, expdest - stackblock(),
+ varflags & VSQUOTE);
+ break;
+
+ case VSPLUS:
+ case VSMINUS:
+ if (!set) {
argstr(p, flag);
- } else {
- char *startp;
- int saveherefd = herefd;
- struct nodelist *saveargbackq = argbackq;
- herefd = -1;
- argstr(p, 0);
- STACKSTRNUL(expdest);
- herefd = saveherefd;
- argbackq = saveargbackq;
- startp = stackblock() + startloc;
- if (subtype == VSASSIGN) {
- setvar(var, startp, 0);
- STADJUST(startp - expdest, expdest);
- varflags &=~ VSNUL;
+ break;
+ }
+ if (easy)
+ goto record;
+ break;
+
+ case VSTRIMLEFT:
+ case VSTRIMLEFTMAX:
+ case VSTRIMRIGHT:
+ case VSTRIMRIGHTMAX:
+ if (!set)
+ break;
+ /*
+ * Terminate the string and start recording the pattern
+ * right after it
+ */
+ STPUTC('\0', expdest);
+ pat = expdest;
+ if (subevalvar(p, pat, subtype, startloc, varflags))
+ goto record;
+ break;
+
+ case VSASSIGN:
+ case VSQUESTION:
+ if (!set) {
+ if (subevalvar(p, var, subtype, startloc, varflags))
goto again;
- }
- /* subtype == VSQUESTION */
- if (*p != CTLENDVAR) {
- outfmt(&errout, "%s\n", startp);
- error((char *)NULL);
- }
- error("%.*s: parameter %snot set", p - var - 1,
- var, (varflags & VSNUL)? "null or " : nullstr);
+ break;
}
+ if (easy)
+ goto record;
+ break;
+
+ default:
+ abort();
}
+
if (subtype != VSNORMAL) { /* skip to end of alternative */
int nesting = 1;
for (;;) {
@@ -569,12 +706,13 @@ varisset(name)
STATIC void
varvalue(name, quoted, allow_split)
char name;
- {
+ int quoted;
+ int allow_split;
+{
int num;
- char temp[32];
char *p;
int i;
- extern int exitstatus;
+ extern int oexitstatus;
char sep;
char **ap;
char const *syntax;
@@ -599,7 +737,7 @@ varvalue(name, quoted, allow_split)
num = rootpid;
goto numvar;
case '?':
- num = exitstatus;
+ num = oexitstatus;
goto numvar;
case '#':
num = shellparam.nparam;
@@ -607,13 +745,7 @@ varvalue(name, quoted, allow_split)
case '!':
num = backgndpid;
numvar:
- p = temp + 31;
- temp[31] = '\0';
- do {
- *--p = num % 10 + '0';
- } while ((num /= 10) != 0);
- while (*p)
- STPUTC(*p++, expdest);
+ expdest = cvtnum(num, expdest);
break;
case '-':
for (i = 0 ; i < NOPTS ; i++) {
@@ -657,7 +789,11 @@ allargs:
*/
STATIC void
-recordregion(start, end, nulonly) {
+recordregion(start, end, nulonly)
+ int start;
+ int end;
+ int nulonly;
+{
register struct ifsregion *ifsp;
if (ifslastp == NULL) {
@@ -680,7 +816,6 @@ recordregion(start, end, nulonly) {
* 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;
@@ -692,6 +827,8 @@ ifsbreakup(string, arglist)
register char *p;
char *q;
char *ifs;
+ int ifsspc;
+
start = string;
if (ifslastp != NULL) {
@@ -699,19 +836,20 @@ ifsbreakup(string, arglist)
do {
p = string + ifsp->begoff;
ifs = ifsp->nulonly? nullstr : ifsval();
+ ifsspc = strchr(ifs, ' ') != NULL;
while (p < string + ifsp->endoff) {
q = p;
if (*p == CTLESC)
p++;
if (strchr(ifs, *p++)) {
- if (q > start || *ifs != ' ') {
+ if (q > start || !ifsspc) {
*q = '\0';
sp = (struct strlist *)stalloc(sizeof *sp);
sp->text = start;
*arglist->lastp = sp;
arglist->lastp = &sp->next;
}
- if (*ifs == ' ') {
+ if (ifsspc) {
for (;;) {
if (p >= string + ifsp->endoff)
break;
@@ -728,7 +866,7 @@ ifsbreakup(string, arglist)
}
}
} while ((ifsp = ifsp->next) != NULL);
- if (*start || (*ifs != ' ' && start > string)) {
+ if (*start || (!ifsspc && start > string)) {
sp = (struct strlist *)stalloc(sizeof *sp);
sp->text = start;
*arglist->lastp = sp;
@@ -755,7 +893,8 @@ char *expdir;
STATIC void
expandmeta(str, flag)
struct strlist *str;
- {
+ int flag;
+{
char *p;
struct strlist **savelastp;
struct strlist *sp;
@@ -896,7 +1035,7 @@ expmeta(enddir, name)
*endname++ = '\0';
}
matchdot = 0;
- if (start[0] == '.' || start[0] == CTLESC && start[1] == '.')
+ if (start[0] == '.' || (start[0] == CTLESC && start[1] == '.'))
matchdot++;
while (! int_pending() && (dp = readdir(dirp)) != NULL) {
if (dp->d_name[0] == '.' && ! matchdot)
@@ -907,7 +1046,9 @@ expmeta(enddir, name)
addfname(expdir);
} else {
char *q;
- for (p = enddir, q = dp->d_name ; *p++ = *q++ ;);
+ for (p = enddir, q = dp->d_name;
+ (*p++ = *q++) != '\0';)
+ continue;
p[-1] = '/';
expmeta(p, endname);
}
@@ -962,8 +1103,9 @@ expsort(str)
STATIC struct strlist *
msort(list, len)
struct strlist *list;
- {
- struct strlist *p, *q;
+ int len;
+{
+ struct strlist *p, *q = NULL;
struct strlist **lpp;
int half;
int n;
@@ -1019,6 +1161,7 @@ patmatch(pattern, string)
return pmatch(pattern, string);
}
+
STATIC int
pmatch(pattern, string)
char *pattern;
@@ -1078,6 +1221,8 @@ pmatch(pattern, string)
}
found = 0;
chr = *q++;
+ if (chr == '\0')
+ return 0;
c = *p++;
do {
if (c == CTLESC)
@@ -1164,3 +1309,30 @@ casematch(pattern, val)
popstackmark(&smark);
return result;
}
+
+/*
+ * Our own itoa().
+ */
+
+STATIC char *
+cvtnum(num, buf)
+ int num;
+ char *buf;
+ {
+ char temp[32];
+ int neg = num < 0;
+ char *p = temp + 31;
+
+ temp[31] = '\0';
+
+ do {
+ *--p = num % 10 + '0';
+ } while ((num /= 10) != 0);
+
+ if (neg)
+ *--p = '-';
+
+ while (*p)
+ STPUTC(*p++, buf);
+ return buf;
+}
diff --git a/bin/sh/expand.h b/bin/sh/expand.h
index 6af4360..4d621a3 100644
--- a/bin/sh/expand.h
+++ b/bin/sh/expand.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)expand.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)expand.h 8.2 (Berkeley) 5/4/95
+ * $Id: expand.h,v 1.2 1994/09/24 02:57:35 davidg Exp $
*/
struct strlist {
@@ -58,17 +58,10 @@ struct arglist {
#define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */
-#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
+void expandhere __P((union node *, int));
+void expandarg __P((union node *, struct arglist *, int));
+void expari __P((int));
+int patmatch __P((char *, char *));
+void rmescapes __P((char *));
+int casematch __P((union node *, char *));
diff --git a/bin/sh/funcs/cmv b/bin/sh/funcs/cmv
index cacb5ba..f988753 100644
--- a/bin/sh/funcs/cmv
+++ b/bin/sh/funcs/cmv
@@ -32,8 +32,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)cmv 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)cmv 8.2 (Berkeley) 5/4/95
+# $Id: cmv,v 1.2 1994/09/24 02:58:33 davidg Exp $
# Conditional move--don't replace an existing file.
diff --git a/bin/sh/funcs/dirs b/bin/sh/funcs/dirs
index fe70c68..e9146d3 100644
--- a/bin/sh/funcs/dirs
+++ b/bin/sh/funcs/dirs
@@ -32,8 +32,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)dirs 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)dirs 8.2 (Berkeley) 5/4/95
+# $Id: dirs,v 1.2 1994/09/24 02:58:34 davidg Exp $
# pushd, popd, and dirs --- written by Chris Bertin
# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
diff --git a/bin/sh/funcs/kill b/bin/sh/funcs/kill
index f3489b5..4de6d8f 100644
--- a/bin/sh/funcs/kill
+++ b/bin/sh/funcs/kill
@@ -32,8 +32,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)kill 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)kill 8.2 (Berkeley) 5/4/95
+# $Id: kill,v 1.2 1994/09/24 02:58:36 davidg Exp $
# Convert job names to process ids and then run /bin/kill.
diff --git a/bin/sh/funcs/login b/bin/sh/funcs/login
index f44d3a5..52f41f1 100644
--- a/bin/sh/funcs/login
+++ b/bin/sh/funcs/login
@@ -32,8 +32,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)login 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)login 8.2 (Berkeley) 5/4/95
+# $Id: login,v 1.2 1994/09/24 02:58:38 davidg Exp $
# replaces the login builtin in the BSD shell
login () exec login "$@"
diff --git a/bin/sh/funcs/newgrp b/bin/sh/funcs/newgrp
index fc02baa..ba538fa 100644
--- a/bin/sh/funcs/newgrp
+++ b/bin/sh/funcs/newgrp
@@ -32,7 +32,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)newgrp 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)newgrp 8.2 (Berkeley) 5/4/95
+# $Id: newgrp,v 1.2 1994/09/24 02:58:40 davidg Exp $
newgrp() exec newgrp "$@"
diff --git a/bin/sh/funcs/popd b/bin/sh/funcs/popd
index 938aabc..f39a710 100644
--- a/bin/sh/funcs/popd
+++ b/bin/sh/funcs/popd
@@ -32,8 +32,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)popd 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)popd 8.2 (Berkeley) 5/4/95
+# $Id: popd,v 1.2 1994/09/24 02:58:41 davidg Exp $
# pushd, popd, and dirs --- written by Chris Bertin
# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
diff --git a/bin/sh/funcs/pushd b/bin/sh/funcs/pushd
index 879ae20..a823713 100644
--- a/bin/sh/funcs/pushd
+++ b/bin/sh/funcs/pushd
@@ -32,8 +32,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)pushd 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)pushd 8.2 (Berkeley) 5/4/95
+# $Id: pushd,v 1.2 1994/09/24 02:58:43 davidg Exp $
# pushd, popd, and dirs --- written by Chris Bertin
# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris
diff --git a/bin/sh/funcs/suspend b/bin/sh/funcs/suspend
index 3a0735c..e68564e 100644
--- a/bin/sh/funcs/suspend
+++ b/bin/sh/funcs/suspend
@@ -32,8 +32,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)suspend 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)suspend 8.2 (Berkeley) 5/4/95
+# $Id: suspend,v 1.2 1994/09/24 02:58:44 davidg Exp $
suspend() {
local -
diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c
index 9cf8a23..56f4d02 100644
--- a/bin/sh/histedit.c
+++ b/bin/sh/histedit.c
@@ -33,26 +33,33 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: histedit.c,v 1.3 1995/05/05 06:34:13 davidg Exp $
+ * $Id: histedit.c,v 1.4 1995/05/30 00:07:14 rgrimes Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)histedit.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)histedit.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
-/*
- * Editline and history functions (and glue).
- */
#include <sys/param.h>
#include <paths.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+/*
+ * Editline and history functions (and glue).
+ */
#include "shell.h"
#include "parser.h"
#include "var.h"
#include "options.h"
+#include "main.h"
+#include "output.h"
#include "mystring.h"
+#ifndef NO_HISTORY
+#include "myhistedit.h"
+#endif
#include "error.h"
-#include "histedit.h"
+#include "eval.h"
#include "memalloc.h"
#define MAXHISTLOOPS 4 /* max recursions through fc */
@@ -69,7 +76,9 @@ STATIC char *fc_replace __P((const char *, char *, char *));
* Set history and editing status. Called whenever the status may
* have changed (figures out what to do).
*/
-histedit() {
+void
+histedit()
+{
#define editing (Eflag || Vflag)
@@ -134,7 +143,10 @@ bad:
}
}
-sethistsize() {
+
+void
+sethistsize()
+{
char *cp;
int histsize;
@@ -151,8 +163,10 @@ sethistsize() {
* This command is provided since POSIX decided to standardize
* the Korn shell fc command. Oh well...
*/
+int
histcmd(argc, argv)
- char *argv[];
+ int argc;
+ char **argv;
{
extern char *optarg;
extern int optind, optopt, optreset;
@@ -169,6 +183,21 @@ histcmd(argc, argv)
struct jmploc *volatile savehandler;
char editfile[MAXPATHLEN + 1];
FILE *efp;
+#ifdef __GNUC__
+ /* Avoid longjmp clobbering */
+ (void) &editor;
+ (void) &lflg;
+ (void) &nflg;
+ (void) &rflg;
+ (void) &sflg;
+ (void) &firststr;
+ (void) &laststr;
+ (void) &pat;
+ (void) &repl;
+ (void) &efp;
+ (void) &argc;
+ (void) &argv;
+#endif
if (hist == NULL)
error("history not active");
@@ -360,6 +389,7 @@ histcmd(argc, argv)
--active;
if (displayhist)
displayhist = 0;
+ return 0;
}
STATIC char *
@@ -386,6 +416,7 @@ fc_replace(s, p, r)
return (dest);
}
+int
not_fcnumber(s)
char *s;
{
@@ -398,6 +429,7 @@ not_fcnumber(s)
return (!is_number(s));
}
+int
str_to_event(str, last)
char *str;
int last;
@@ -405,7 +437,7 @@ str_to_event(str, last)
const HistEvent *he;
char *s = str;
int relative = 0;
- int i, j;
+ int i;
he = history(hist, H_FIRST);
switch (*s) {
diff --git a/bin/sh/init.h b/bin/sh/init.h
index 8466409..eff47ef 100644
--- a/bin/sh/init.h
+++ b/bin/sh/init.h
@@ -33,16 +33,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)init.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)init.h 8.2 (Berkeley) 5/4/95
+ * $Id: init.h,v 1.2 1994/09/24 02:57:37 davidg Exp $
*/
-#ifdef __STDC__
-void init(void);
-void reset(void);
-void initshellproc(void);
-#else
-void init();
-void reset();
-void initshellproc();
-#endif
+void init __P((void));
+void reset __P((void));
+void initshellproc __P((void));
diff --git a/bin/sh/input.c b/bin/sh/input.c
index 80c26ef..1d41bb2 100644
--- a/bin/sh/input.c
+++ b/bin/sh/input.c
@@ -33,21 +33,26 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: input.c,v 1.3 1995/05/30 00:07:15 rgrimes Exp $
+ * $Id: input.c,v 1.4 1995/11/03 18:50:14 peter Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)input.c 8.3 (Berkeley) 6/9/95";
#endif /* not lint */
+#include <stdio.h> /* defines BUFSIZ */
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
/*
* This file implements the input routines used by the parser.
*/
-#include <stdio.h> /* defines BUFSIZ */
#include "shell.h"
-#include <fcntl.h>
-#include <errno.h>
+#include "redir.h"
#include "syntax.h"
#include "input.h"
#include "output.h"
@@ -100,13 +105,7 @@ int whichprompt; /* 1 == PS1, 2 == PS2 */
EditLine *el; /* cookie for editline package */
-#ifdef __STDC__
-STATIC void pushfile(void);
-#else
-STATIC void pushfile();
-#endif
-
-
+STATIC void pushfile __P((void));
#ifdef mkinit
INCLUDE "input.h"
@@ -137,7 +136,8 @@ SHELLPROC {
char *
pfgets(line, len)
char *line;
- {
+ int len;
+{
register char *p = line;
int nleft = len;
int c;
@@ -346,6 +346,7 @@ pushstring(s, len, ap)
INTON;
}
+void
popstring()
{
struct strpush *sp = parsefile->strpush;
@@ -371,7 +372,8 @@ popstring()
void
setinputfile(fname, push)
char *fname;
- {
+ int push;
+{
int fd;
int fd2;
@@ -396,7 +398,9 @@ setinputfile(fname, push)
*/
void
-setinputfd(fd, push) {
+setinputfd(fd, push)
+ int fd, push;
+{
if (push) {
pushfile();
parsefile->buf = ckmalloc(BUFSIZ);
@@ -418,6 +422,7 @@ setinputfd(fd, push) {
void
setinputstring(string, push)
char *string;
+ int push;
{
INTOFF;
if (push)
diff --git a/bin/sh/input.h b/bin/sh/input.h
index 77b193b..b90725a 100644
--- a/bin/sh/input.h
+++ b/bin/sh/input.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)input.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)input.h 8.2 (Berkeley) 5/4/95
+ * $Id: input.h,v 1.2 1994/09/24 02:57:40 davidg Exp $
*/
/* PEOF (the end of file marker) is defined in syntax.h */
@@ -49,31 +49,17 @@ extern int parsenleft; /* number of characters left in input buffer */
extern char *parsenextc; /* next character in input buffer */
extern int init_editline; /* 0 == not setup, 1 == OK, -1 == failed */
-
-#ifdef __STDC__
-char *pfgets(char *, int);
-int pgetc(void);
-int preadbuffer(void);
-void pungetc(void);
-void pushstring(char *, int, void *);
-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 setinputfile();
-void setinputfd();
-void setinputstring();
-void popfile();
-void popallfiles();
-void pushstring();
-void closescript();
-#endif
+char *pfgets __P((char *, int));
+int pgetc __P((void));
+int preadbuffer __P((void));
+void pungetc __P((void));
+void pushstring __P((char *, int, void *));
+void popstring __P((void));
+void setinputfile __P((char *, int));
+void setinputfd __P((int, int));
+void setinputstring __P((char *, int));
+void popfile __P((void));
+void popallfiles __P((void));
+void closescript __P((void));
#define pgetc_macro() (--parsenleft >= 0? *parsenextc++ : preadbuffer())
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index ec8a649..65dea1d 100644
--- a/bin/sh/jobs.c
+++ b/bin/sh/jobs.c
@@ -33,41 +33,49 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: jobs.c,v 1.3 1995/05/30 00:07:18 rgrimes Exp $
+ * $Id: jobs.c,v 1.4 1995/09/21 13:24:20 bde Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)jobs.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#ifdef BSD
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#endif
+
#include "shell.h"
#if JOBS
+#ifdef OLD_TTY_DRIVER
#include "sgtty.h"
+#else
+#include <termios.h>
+#endif
#undef CEOF /* syntax.h redefines this */
#endif
+#include "redir.h"
+#include "show.h"
#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 <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
-
struct job *jobtab; /* array of jobs */
@@ -78,22 +86,14 @@ int initialpgrp; /* pgrp of shell on invocation */
short 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 *);
-#else
-STATIC void restartjob();
-STATIC struct job *getjob();
-STATIC void freejob();
-STATIC int procrunning();
-STATIC int dowait();
-STATIC int waitproc();
-#endif
-
+STATIC void restartjob __P((struct job *));
+STATIC void freejob __P((struct job *));
+STATIC struct job *getjob __P((char *));
+STATIC int dowait __P((int, struct job *));
+STATIC int onsigchild __P((void));
+STATIC int waitproc __P((int, int *));
+STATIC void cmdtxt __P((union node *));
+STATIC void cmdputs __P((char *));
/*
@@ -107,7 +107,9 @@ STATIC int waitproc();
MKINIT int jobctl;
void
-setjobctl(on) {
+setjobctl(on)
+ int on;
+{
#ifdef OLD_TTY_DRIVER
int ldisc;
#endif
@@ -122,8 +124,8 @@ setjobctl(on) {
return;
}
if (initialpgrp == -1)
- initialpgrp = getpgrp(0);
- else if (initialpgrp != getpgrp(0)) {
+ initialpgrp = getpgrp();
+ else if (initialpgrp != getpgrp()) {
killpg(initialpgrp, SIGTTIN);
continue;
}
@@ -138,10 +140,10 @@ setjobctl(on) {
setsignal(SIGTSTP);
setsignal(SIGTTOU);
setsignal(SIGTTIN);
- setpgrp(0, rootpid);
+ setpgid(0, rootpid);
ioctl(2, TIOCSPGRP, (char *)&rootpid);
} else { /* turning job control off */
- setpgrp(0, initialpgrp);
+ setpgid(0, initialpgrp);
ioctl(2, TIOCSPGRP, (char *)&initialpgrp);
setsignal(SIGTSTP);
setsignal(SIGTTOU);
@@ -152,6 +154,7 @@ setjobctl(on) {
#ifdef mkinit
+INCLUDE <stdlib.h>
SHELLPROC {
backgndpid = -1;
@@ -165,7 +168,11 @@ SHELLPROC {
#if JOBS
-fgcmd(argc, argv) char **argv; {
+int
+fgcmd(argc, argv)
+ int argc;
+ char **argv;
+{
struct job *jp;
int pgrp;
int status;
@@ -183,7 +190,11 @@ fgcmd(argc, argv) char **argv; {
}
-bgcmd(argc, argv) char **argv; {
+int
+bgcmd(argc, argv)
+ int argc;
+ char **argv;
+{
struct job *jp;
do {
@@ -199,7 +210,7 @@ bgcmd(argc, argv) char **argv; {
STATIC void
restartjob(jp)
struct job *jp;
- {
+{
struct procstat *ps;
int i;
@@ -219,7 +230,10 @@ restartjob(jp)
int
-jobscmd(argc, argv) char **argv; {
+jobscmd(argc, argv)
+ int argc;
+ char **argv;
+{
showjobs(0);
return 0;
}
@@ -235,7 +249,9 @@ jobscmd(argc, argv) char **argv; {
*/
void
-showjobs(change) {
+showjobs(change)
+ int change;
+{
int jobno;
int procno;
int i;
@@ -274,8 +290,8 @@ showjobs(change) {
if ((i & 0xFF) == 0177)
i >>= 8;
#endif
- if ((i & 0x7F) <= MAXSIG && sigmesg[i & 0x7F])
- scopy(sigmesg[i & 0x7F], s);
+ if ((i & 0x7F) < NSIG && sys_siglist[i & 0x7F])
+ scopy(sys_siglist[i & 0x7F], s);
else
fmtstr(s, 64, "Signal %d", i & 0x7F);
if (i & 0x80)
@@ -329,7 +345,10 @@ freejob(jp)
int
-waitcmd(argc, argv) char **argv; {
+waitcmd(argc, argv)
+ int argc;
+ char **argv;
+{
struct job *job;
int status;
struct job *jp;
@@ -370,7 +389,11 @@ waitcmd(argc, argv) char **argv; {
-jobidcmd(argc, argv) char **argv; {
+int
+jobidcmd(argc, argv)
+ int argc;
+ char **argv;
+{
struct job *jp;
int i;
@@ -438,6 +461,8 @@ currentjob:
}
}
error("No such job: %s", name);
+ /*NOTREACHED*/
+ return NULL;
}
@@ -449,7 +474,8 @@ currentjob:
struct job *
makejob(node, nprocs)
union node *node;
- {
+ int nprocs;
+{
int i;
struct job *jp;
@@ -467,7 +493,7 @@ makejob(node, nprocs)
if (ojp->ps == &ojp->ps0)
ojp->ps = &jp->ps0;
jp -= njobs;
- bcopy(jobtab, jp, njobs * sizeof jp[0]);
+ memcpy(jp, jobtab, njobs * sizeof jp[0]);
ckfree(jobtab);
jobtab = jp;
}
@@ -493,7 +519,8 @@ makejob(node, nprocs)
jp->ps = &jp->ps0;
}
INTON;
- TRACE(("makejob(0x%x, %d) returns %%%d\n", (int)node, nprocs, jp - jobtab + 1));
+ TRACE(("makejob(0x%lx, %d) returns %%%d\n", (long)node, nprocs,
+ jp - jobtab + 1));
return jp;
}
@@ -517,11 +544,13 @@ int
forkshell(jp, n, mode)
union node *n;
struct job *jp;
- {
+ int mode;
+{
int pid;
int pgrp;
- TRACE(("forkshell(%%%d, 0x%x, %d) called\n", jp - jobtab, (int)n, mode));
+ TRACE(("forkshell(%%%d, 0x%lx, %d) called\n", jp - jobtab, (long)n,
+ mode));
INTOFF;
pid = fork();
if (pid == -1) {
@@ -550,7 +579,7 @@ forkshell(jp, n, mode)
pgrp = getpid();
else
pgrp = jp->ps[0].pid;
- setpgrp(0, pgrp);
+ setpgid(0, pgrp);
if (mode == FORK_FG) {
/*** this causes superfluous TIOCSPGRPS ***/
if (ioctl(2, TIOCSPGRP, (char *)&pgrp) < 0)
@@ -592,7 +621,7 @@ forkshell(jp, n, mode)
pgrp = pid;
else
pgrp = jp->ps[0].pid;
- setpgrp(pid, pgrp);
+ setpgid(pid, pgrp);
}
if (mode == FORK_BG)
backgndpid = pid; /* set $! */
@@ -635,7 +664,7 @@ waitforjob(jp)
register struct job *jp;
{
#if JOBS
- int mypgrp = getpgrp(0);
+ int mypgrp = getpgrp();
#endif
int status;
int st;
@@ -680,8 +709,9 @@ waitforjob(jp)
STATIC int
dowait(block, job)
+ int block;
struct job *job;
- {
+{
int pid;
int status;
struct procstat *sp;
@@ -745,8 +775,8 @@ dowait(block, job)
if (status == SIGTSTP && rootshell && iflag)
outfmt(out2, "%%%d ", job - jobtab + 1);
#endif
- if (status <= MAXSIG && sigmesg[status])
- out2str(sigmesg[status]);
+ if (status < NSIG && sys_siglist[status])
+ out2str(sys_siglist[status]);
else
outfmt(out2, "Signal %d", status);
if (core)
@@ -806,8 +836,9 @@ STATIC int onsigchild() {
STATIC int
waitproc(block, status)
+ int block;
int *status;
- {
+{
#ifdef BSD
int flags;
diff --git a/bin/sh/jobs.h b/bin/sh/jobs.h
index fd08023..fa42549 100644
--- a/bin/sh/jobs.h
+++ b/bin/sh/jobs.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)jobs.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)jobs.h 8.2 (Berkeley) 5/4/95
+ * $Id: jobs.h,v 1.2 1994/09/24 02:57:42 davidg Exp $
*/
/* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */
@@ -78,22 +78,18 @@ struct job {
extern short backgndpid; /* pid of last background process */
extern int job_warning; /* user was warned about stopped jobs */
-
-#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 *);
-char *commandtext(union node *);
-#else
-void setjobctl();
-void showjobs();
-struct job *makejob();
-int forkshell();
-int waitforjob();
-char *commandtext();
-#endif
+void setjobctl __P((int));
+int fgcmd __P((int, char **));
+int bgcmd __P((int, char **));
+int jobscmd __P((int, char **));
+void showjobs __P((int));
+int waitcmd __P((int, char **));
+int jobidcmd __P((int, char **));
+struct job *makejob __P((union node *, int));
+int forkshell __P((struct job *, union node *, int));
+int waitforjob __P((struct job *));
+int stoppedjobs __P((void));
+char *commandtext __P((union node *));
#if ! JOBS
#define setjobctl(on) /* do nothing */
diff --git a/bin/sh/machdep.h b/bin/sh/machdep.h
index 97d82a9..2f2aea0 100644
--- a/bin/sh/machdep.h
+++ b/bin/sh/machdep.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)machdep.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)machdep.h 8.2 (Berkeley) 5/4/95
+ * $Id: machdep.h,v 1.2 1994/09/24 02:57:43 davidg Exp $
*/
/*
@@ -48,5 +48,5 @@ union align {
char *cp;
};
-#define ALIGN(nbytes) ((nbytes) + sizeof(union align) - 1 &~ (sizeof(union align) - 1))
+#define ALIGN(nbytes) (((nbytes) + sizeof(union align) - 1) & ~(sizeof(union align) - 1))
#endif
diff --git a/bin/sh/mail.c b/bin/sh/mail.c
index a122c9b..8b747c2 100644
--- a/bin/sh/mail.c
+++ b/bin/sh/mail.c
@@ -33,11 +33,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: mail.c,v 1.2 1994/09/24 02:57:44 davidg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)mail.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)mail.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
/*
@@ -69,7 +69,9 @@ STATIC time_t mailtime[MAXMBOXES]; /* times of mailboxes */
*/
void
-chkmail(silent) {
+chkmail(silent)
+ int silent;
+{
register int i;
char *mpath;
char *p;
diff --git a/bin/sh/mail.h b/bin/sh/mail.h
index d7b4fe3..644d808 100644
--- a/bin/sh/mail.h
+++ b/bin/sh/mail.h
@@ -33,12 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)mail.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)mail.h 8.2 (Berkeley) 5/4/95
+ * $Id: mail.h,v 1.2 1994/09/24 02:57:45 davidg Exp $
*/
-#ifdef __STDC__
-void chkmail(int);
-#else
-void chkmail();
-#endif
+void chkmail __P((int));
diff --git a/bin/sh/main.c b/bin/sh/main.c
index 34a0abb..edebcd7 100644
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: main.c,v 1.3 1995/05/30 00:07:18 rgrimes Exp $
+ * $Id: main.c,v 1.4 1996/08/11 22:50:58 ache Exp $
*/
#ifndef lint
@@ -43,13 +43,17 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/28/95";
#endif /* not lint */
+#include <stdio.h>
#include <signal.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <fcntl.h>
#include <locale.h>
+
#include "shell.h"
#include "main.h"
#include "mail.h"
@@ -57,15 +61,18 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#include "output.h"
#include "parser.h"
#include "nodes.h"
+#include "expand.h"
#include "eval.h"
#include "jobs.h"
#include "input.h"
#include "trap.h"
#include "var.h"
+#include "show.h"
#include "memalloc.h"
#include "error.h"
#include "init.h"
#include "mystring.h"
+#include "exec.h"
#define PROFILE 0
@@ -79,14 +86,8 @@ 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
-
+STATIC void read_profile __P((char *));
+STATIC char *find_dot_file __P((char *));
/*
* Main routine. We initialize things, parse the arguments, execute
@@ -96,7 +97,11 @@ char *getenv();
* is used to figure out how far we had gotten.
*/
-main(argc, argv) char **argv; {
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
struct jmploc jmploc;
struct stackmark smark;
volatile int state;
@@ -113,6 +118,8 @@ main(argc, argv) char **argv; {
* exception EXSHELLPROC to clean up before executing
* the shell procedure.
*/
+ if (exception == EXERROR)
+ exitstatus = 2;
if (exception == EXSHELLPROC) {
rootpid = getpid();
rootshell = 1;
@@ -159,10 +166,11 @@ state1:
}
state2:
state = 3;
- if ((shinit = lookupvar("ENV")) != NULL &&
- *shinit != '\0') {
- state = 3;
- read_profile(shinit);
+ if (getuid() == geteuid() && getgid() == getegid()) {
+ if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') {
+ state = 3;
+ read_profile(shinit);
+ }
}
state3:
state = 4;
@@ -177,6 +185,8 @@ state4: /* XXX ??? - why isn't this before the "if" statement */
monitor(0);
#endif
exitshell(exitstatus);
+ /*NOTREACHED*/
+ return 0;
}
@@ -186,7 +196,9 @@ state4: /* XXX ??? - why isn't this before the "if" statement */
*/
void
-cmdloop(top) {
+cmdloop(top)
+ int top;
+{
union node *n;
struct stackmark smark;
int inter;
@@ -256,7 +268,7 @@ read_profile(name)
void
readcmdfile(name)
char *name;
- {
+{
int fd;
INTOFF;
@@ -273,14 +285,48 @@ readcmdfile(name)
/*
* 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.
+ * search for the file, which is necessary to find sub-commands.
*/
-dotcmd(argc, argv) char **argv; {
+
+STATIC char *
+find_dot_file(basename)
+ char *basename;
+{
+ static char localname[FILENAME_MAX+1];
+ char *fullname;
+ char *path = pathval();
+ struct stat statb;
+
+ /* don't try this for absolute or relative paths */
+ if( strchr(basename, '/'))
+ return basename;
+
+ while ((fullname = padvance(&path, basename)) != NULL) {
+ strcpy(localname, fullname);
+ stunalloc(fullname);
+ if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode))
+ return localname;
+ }
+ return basename;
+}
+
+int
+dotcmd(argc, argv)
+ int argc;
+ char **argv;
+{
+ struct strlist *sp;
exitstatus = 0;
+
+ for (sp = cmdenviron; sp ; sp = sp->next)
+ setvareq(savestr(sp->text), VSTRFIXED|VTEXTFIXED);
+
if (argc >= 2) { /* That's what SVR2 does */
- setinputfile(argv[1], 1);
- commandname = argv[1];
+ char *fullname = find_dot_file(argv[1]);
+
+ setinputfile(fullname, 1);
+ commandname = fullname;
cmdloop(0);
popfile();
}
@@ -288,12 +334,18 @@ dotcmd(argc, argv) char **argv; {
}
-exitcmd(argc, argv) char **argv; {
+int
+exitcmd(argc, argv)
+ int argc;
+ char **argv;
+{
if (stoppedjobs())
- return;
+ return 0;
if (argc > 1)
exitstatus = number(argv[1]);
exitshell(exitstatus);
+ /*NOTREACHED*/
+ return 0;
}
diff --git a/bin/sh/main.h b/bin/sh/main.h
index b43f041..611f00a 100644
--- a/bin/sh/main.h
+++ b/bin/sh/main.h
@@ -33,17 +33,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)main.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)main.h 8.2 (Berkeley) 5/4/95
+ * $Id: main.h,v 1.2 1994/09/24 02:57:49 davidg Exp $
*/
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
+void readcmdfile __P((char *));
+void cmdloop __P((int));
+int dotcmd __P((int, char **));
+int exitcmd __P((int, char **));
diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c
index 873e30c..38b32a9 100644
--- a/bin/sh/memalloc.c
+++ b/bin/sh/memalloc.c
@@ -33,11 +33,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: memalloc.c,v 1.2 1994/09/24 02:57:50 davidg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)memalloc.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)memalloc.c 8.3 (Berkeley) 5/4/95";
#endif /* not lint */
#include "shell.h"
@@ -46,15 +46,18 @@ static char sccsid[] = "@(#)memalloc.c 8.1 (Berkeley) 5/31/93";
#include "error.h"
#include "machdep.h"
#include "mystring.h"
+#include <stdlib.h>
+#include <unistd.h>
/*
* Like malloc, but returns an error when out of space.
*/
pointer
-ckmalloc(nbytes) {
+ckmalloc(nbytes)
+ int nbytes;
+{
register pointer p;
- pointer malloc();
if ((p = malloc(nbytes)) == NULL)
error("Out of space");
@@ -69,8 +72,8 @@ ckmalloc(nbytes) {
pointer
ckrealloc(p, nbytes)
register pointer p;
- {
- pointer realloc();
+ int nbytes;
+{
if ((p = realloc(p, nbytes)) == NULL)
error("Out of space");
@@ -121,7 +124,9 @@ int herefd = -1;
pointer
-stalloc(nbytes) {
+stalloc(nbytes)
+ int nbytes;
+{
register char *p;
nbytes = ALIGN(nbytes);
@@ -219,16 +224,18 @@ growstackblock() {
INTON;
} else {
p = stalloc(newlen);
- bcopy(oldspace, p, oldlen);
+ memcpy(p, oldspace, oldlen);
stacknxt = p; /* free the space */
- stacknleft += newlen; /* we just allocated */
+ stacknleft += ALIGN(newlen); /* we just allocated */
}
}
void
-grabstackblock(len) {
+grabstackblock(len)
+ int len;
+{
len = ALIGN(len);
stacknxt += len;
stacknleft -= len;
diff --git a/bin/sh/memalloc.h b/bin/sh/memalloc.h
index 43f3335..c7f101e 100644
--- a/bin/sh/memalloc.h
+++ b/bin/sh/memalloc.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)memalloc.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)memalloc.h 8.2 (Berkeley) 5/4/95
+ * $Id: memalloc.h,v 1.2 1994/09/24 02:57:51 davidg Exp $
*/
struct stackmark {
@@ -49,35 +49,18 @@ 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
+pointer ckmalloc __P((int));
+pointer ckrealloc __P((pointer, int));
+char *savestr __P((char *));
+pointer stalloc __P((int));
+void stunalloc __P((pointer));
+void setstackmark __P((struct stackmark *));
+void popstackmark __P((struct stackmark *));
+void growstackblock __P((void));
+void grabstackblock __P((int));
+char *growstackstr __P((void));
+char *makestrspace __P((void));
+void ungrabstackstr __P((char *, char *));
@@ -85,7 +68,7 @@ void ungrabstackstr();
#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 CHECKSTRSPACE(n, p) { if (sstrnleft < n) p = makestrspace(); }
#define USTPUTC(c, p) (--sstrnleft, *p++ = (c))
#define STACKSTRNUL(p) (sstrnleft == 0? (p = growstackstr(), *p = '\0') : (*p = '\0'))
#define STUNPUTC(p) (++sstrnleft, --p)
diff --git a/bin/sh/miscbltin.c b/bin/sh/miscbltin.c
index 414ed81..ca37fc1 100644
--- a/bin/sh/miscbltin.c
+++ b/bin/sh/miscbltin.c
@@ -4,7 +4,6 @@
*
* This code is derived from software contributed to Berkeley by
* Kenneth Almquist.
- * The ulimit() builtin has been contributed by Joerg Wunsch.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -34,17 +33,24 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: miscbltin.c,v 1.3 1995/10/19 18:42:10 joerg Exp $
+ * $Id: miscbltin.c,v 1.4 1995/10/21 00:47:30 joerg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)miscbltin.c 8.2 (Berkeley) 4/16/94";
+static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95";
#endif /* not lint */
/*
* Miscelaneous builtins.
*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+#include <ctype.h>
+
#include "shell.h"
#include "options.h"
#include "var.h"
@@ -53,18 +59,6 @@ static char sccsid[] = "@(#)miscbltin.c 8.2 (Berkeley) 4/16/94";
#include "error.h"
#include "mystring.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#if BSD
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif
-
#undef eflag
extern char **argptr; /* argument list for builtin command */
@@ -77,7 +71,11 @@ extern char **argptr; /* argument list for builtin command */
* This uses unbuffered input, which may be avoidable in some cases.
*/
-readcmd(argc, argv) char **argv; {
+int
+readcmd(argc, argv)
+ int argc;
+ char **argv;
+{
char **ap;
int backslash;
char c;
@@ -157,225 +155,235 @@ readcmd(argc, argv) char **argv; {
-umaskcmd(argc, argv) char **argv; {
+int
+umaskcmd(argc, argv)
+ int argc;
+ char **argv;
+{
+ char *ap;
int mask;
- char *p;
int i;
+ int symbolic_mode = 0;
+
+ while ((i = nextopt("S")) != '\0') {
+ symbolic_mode = 1;
+ }
+
+ INTOFF;
+ mask = umask(0);
+ umask(mask);
+ INTON;
+
+ if ((ap = *argptr) == NULL) {
+ if (symbolic_mode) {
+ char u[4], g[4], o[4];
- if ((p = argv[1]) == NULL) {
- INTOFF;
- mask = umask(0);
- umask(mask);
- INTON;
- out1fmt("%.4o\n", mask); /* %#o might be better */
+ i = 0;
+ if ((mask & S_IRUSR) == 0)
+ u[i++] = 'r';
+ if ((mask & S_IWUSR) == 0)
+ u[i++] = 'w';
+ if ((mask & S_IXUSR) == 0)
+ u[i++] = 'x';
+ u[i] = '\0';
+
+ i = 0;
+ if ((mask & S_IRGRP) == 0)
+ g[i++] = 'r';
+ if ((mask & S_IWGRP) == 0)
+ g[i++] = 'w';
+ if ((mask & S_IXGRP) == 0)
+ g[i++] = 'x';
+ g[i] = '\0';
+
+ i = 0;
+ if ((mask & S_IROTH) == 0)
+ o[i++] = 'r';
+ if ((mask & S_IWOTH) == 0)
+ o[i++] = 'w';
+ if ((mask & S_IXOTH) == 0)
+ o[i++] = 'x';
+ o[i] = '\0';
+
+ out1fmt("u=%s,g=%s,o=%s\n", u, g, o);
+ } else {
+ out1fmt("%.4o\n", mask);
+ }
} 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);
+ if (isdigit(*ap)) {
+ mask = 0;
+ do {
+ if (*ap >= '8' || *ap < '0')
+ error("Illegal number: %s", argv[1]);
+ mask = (mask << 3) + (*ap - '0');
+ } while (*++ap != '\0');
+ umask(mask);
+ } else {
+ void *set;
+ if ((set = setmode (ap)) == 0)
+ error("Illegal number: %s", ap);
+
+ mask = getmode (set, ~mask & 0777);
+ umask(~mask & 0777);
+ }
}
return 0;
}
+/*
+ * ulimit builtin
+ *
+ * This code, originally by Doug Gwyn, Doug Kingston, Eric Gisin, and
+ * Michael Rendell was ripped from pdksh 5.0.8 and hacked for use with
+ * ash by J.T. Conklin.
+ *
+ * Public domain.
+ */
-#if BSD
-struct restab {
- int resource;
- int scale;
- char *descript;
+struct limits {
+ const char *name;
+ int cmd;
+ int factor; /* multiply by to get rlim_{cur,max} values */
+ char option;
};
-/* multi-purpose */
-#define RLIMIT_UNSPEC (-2)
-
-/* resource */
-#define RLIMIT_ALL (-1)
-
-/* mode */
-#define RLIMIT_SHOW 0
-#define RLIMIT_SET 1
-
-/* what */
-#define RLIMIT_SOFT 1
-#define RLIMIT_HARD 2
-
-static struct restab restab[] = {
- {RLIMIT_CORE, 512, "coredump(512-blocks) "},
- {RLIMIT_CPU, 1, "time(seconds) "},
- {RLIMIT_DATA, 1024, "datasize(kilobytes) "},
- {RLIMIT_FSIZE, 512, "filesize(512-blocks) "},
- {RLIMIT_MEMLOCK, 1024, "lockedmem(kilobytes) "},
- {RLIMIT_NOFILE, 1, "nofiles(descriptors) "},
- {RLIMIT_NPROC, 1, "userprocs(max) "},
- {RLIMIT_RSS, 1024, "memoryuse(kilobytes) "},
- {RLIMIT_STACK, 1024, "stacksize(kilobytes) "}
+static const struct limits limits[] = {
+#ifdef RLIMIT_CPU
+ { "time(seconds)", RLIMIT_CPU, 1, 't' },
+#endif
+#ifdef RLIMIT_FSIZE
+ { "file(512-blocks)", RLIMIT_FSIZE, 512, 'f' },
+#endif
+#ifdef RLIMIT_DATA
+ { "data(kbytes)", RLIMIT_DATA, 1024, 'd' },
+#endif
+#ifdef RLIMIT_STACK
+ { "stack(kbytes)", RLIMIT_STACK, 1024, 's' },
+#endif
+#ifdef RLIMIT_CORE
+ { "coredump(512-blocks)", RLIMIT_CORE, 512, 'c' },
+#endif
+#ifdef RLIMIT_RSS
+ { "memory(kbytes)", RLIMIT_RSS, 1024, 'm' },
+#endif
+#ifdef RLIMIT_MEMLOCK
+ { "lockedmem(kbytes)", RLIMIT_MEMLOCK, 1024, 'l' },
+#endif
+#ifdef RLIMIT_NPROC
+ { "process(processes)", RLIMIT_NPROC, 1, 'u' },
+#endif
+#ifdef RLIMIT_NOFILE
+ { "nofiles(descriptors)", RLIMIT_NOFILE, 1, 'n' },
+#endif
+#ifdef RLIMIT_VMEM
+ { "vmemory(kbytes)", RLIMIT_VMEM, 1024, 'v' },
+#endif
+#ifdef RLIMIT_SWAP
+ { "swap(kbytes)", RLIMIT_SWAP, 1024, 'w' },
+#endif
+ { (char *) 0, 0, 0, '\0' }
};
-/* get entry into above table */
-static struct restab *
-find_resource(resource) {
- int i;
- struct restab *rp;
-
- for(i = 0, rp = restab;
- i < sizeof restab / sizeof(struct restab);
- i++, rp++)
- if(rp->resource == resource)
- return rp;
- error("internal error: resource not in table");
- return 0;
-}
-
-static void
-print_resource(rp, what, with_descript) struct restab *rp; {
- struct rlimit rlim;
+int
+ulimitcmd(argc, argv)
+ int argc;
+ char **argv;
+{
+ register int c;
quad_t val;
+ enum { SOFT = 0x1, HARD = 0x2 }
+ how = SOFT | HARD;
+ const struct limits *l;
+ int set, all = 0;
+ int optc, what;
+ struct rlimit limit;
- (void)getrlimit(rp->resource, &rlim);
- val = (what == RLIMIT_SOFT)?
- rlim.rlim_cur: rlim.rlim_max;
- if(with_descript)
- out1str(rp->descript);
- if(val == RLIM_INFINITY)
- out1str("unlimited\n");
- else {
- val /= (quad_t)rp->scale;
- if(val > (quad_t)ULONG_MAX)
- out1fmt("> %lu\n", (unsigned long)ULONG_MAX);
- else
- out1fmt("%lu\n", (unsigned long)val);
- }
-}
-
-ulimitcmd(argc, argv) char **argv; {
- struct rlimit rlim;
- char *p;
- int i;
- int resource = RLIMIT_UNSPEC;
- quad_t val;
- int what = RLIMIT_UNSPEC;
- int mode = RLIMIT_UNSPEC;
- int errs = 0, arg = 1;
- struct restab *rp;
- extern int optreset; /* XXX should be declared in <stdlib.h> */
-
- opterr = 0; /* use own error processing */
- optreset = 1;
- optind = 1;
- while ((i = getopt(argc, argv, "HSacdfnstmlu")) != EOF) {
- arg++;
- switch(i) {
+ what = 'f';
+ while ((optc = nextopt("HSatfdsmcnpl")) != '\0')
+ switch (optc) {
case 'H':
- if(what == RLIMIT_UNSPEC) what = 0;
- what |= RLIMIT_HARD;
+ how = HARD;
break;
case 'S':
- if(what == RLIMIT_UNSPEC) what = 0;
- what |= RLIMIT_SOFT;
+ how = SOFT;
break;
case 'a':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_ALL;
- mode = RLIMIT_SHOW;
- break;
- case 'c':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_CORE;
- break;
- case 'd':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_DATA;
- break;
- case 'f':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_FSIZE;
- break;
- case 'n':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_NOFILE;
- break;
- case 's':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_STACK;
- break;
- case 't':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_CPU;
- break;
- case 'm':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_RSS;
+ all = 1;
break;
- case 'l':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_MEMLOCK;
- break;
- case 'u':
- if(resource != RLIMIT_UNSPEC) errs++;
- resource = RLIMIT_NPROC;
- break;
- case '?':
- error("illegal option -%c", optopt);
+ default:
+ what = optc;
}
- }
- argc -= optind;
- argv += optind;
- if(argc > 1)
- error("too many arguments");
- if(argc == 0)
- mode = RLIMIT_SHOW;
- else if (resource == RLIMIT_ALL)
- errs++;
- else
- mode = RLIMIT_SET;
- if(mode == RLIMIT_UNSPEC)
- mode = RLIMIT_SHOW;
- if(resource == RLIMIT_UNSPEC)
- resource = RLIMIT_FSIZE;
- if(what == RLIMIT_UNSPEC)
- what = (mode == RLIMIT_SHOW)?
- RLIMIT_SOFT: (RLIMIT_SOFT|RLIMIT_HARD);
- if(mode == RLIMIT_SHOW && what == (RLIMIT_SOFT|RLIMIT_HARD))
- errs++;
- if(errs)
- error("Wrong option combination");
-
- if(resource == RLIMIT_ALL)
- for(i = 0; i < sizeof restab / sizeof(struct restab); i++)
- print_resource(restab + i, what, 1);
- else if(mode == RLIMIT_SHOW)
- print_resource(find_resource(resource), what, 0);
- else {
- rp = find_resource(resource);
- if(strcmp(argv[0], "unlimited") == 0)
+ for (l = limits; l->name && l->option != what; l++)
+ ;
+ if (!l->name)
+ error("ulimit: internal error (%c)\n", what);
+
+ set = *argptr ? 1 : 0;
+ if (set) {
+ char *p = *argptr;
+
+ if (all || argptr[1])
+ error("ulimit: too many arguments\n");
+ if (strcmp(p, "unlimited") == 0)
val = RLIM_INFINITY;
else {
- val = 0;
- p = argv[0];
- do {
- if((i = *p - '0') < 0 || i > 9)
- error("Illegal number: %s", argv[0]);
- val = (10 * val) + (quad_t)i;
- } while (*++p != '\0');
- val *= (quad_t)rp->scale;
+ val = (quad_t) 0;
+
+ while ((c = *p++) >= '0' && c <= '9')
+ {
+ val = (val * 10) + (long)(c - '0');
+ if (val < (quad_t) 0)
+ break;
+ }
+ if (c)
+ error("ulimit: bad number\n");
+ val *= l->factor;
+ }
+ }
+ if (all) {
+ for (l = limits; l->name; l++) {
+ getrlimit(l->cmd, &limit);
+ if (how & SOFT)
+ val = limit.rlim_cur;
+ else if (how & HARD)
+ val = limit.rlim_max;
+
+ out1fmt("%-20s ", l->name);
+ if (val == RLIM_INFINITY)
+ out1fmt("unlimited\n");
+ else
+ {
+ val /= l->factor;
+ out1fmt("%ld\n", (long) val);
+ }
}
- (void)getrlimit(resource, &rlim);
- if(what & RLIMIT_HARD)
- rlim.rlim_max = val;
- if(what & RLIMIT_SOFT)
- rlim.rlim_cur = val;
- if(setrlimit(resource, &rlim) == -1) {
- outfmt(&errout, "ulimit: bad limit: %s\n",
- strerror(errno));
- return 1;
+ return 0;
+ }
+
+ getrlimit(l->cmd, &limit);
+ if (set) {
+ if (how & SOFT)
+ limit.rlim_cur = val;
+ if (how & HARD)
+ limit.rlim_max = val;
+ if (setrlimit(l->cmd, &limit) < 0)
+ error("ulimit: bad limit\n");
+ } else {
+ if (how & SOFT)
+ val = limit.rlim_cur;
+ else if (how & HARD)
+ val = limit.rlim_max;
+ }
+
+ if (!set) {
+ if (val == RLIM_INFINITY)
+ out1fmt("unlimited\n");
+ else
+ {
+ val /= l->factor;
+ out1fmt("%ld\n", (long) val);
}
}
return 0;
}
-#else /* !BSD */
-#error ulimit() not implemented
-#endif /* BSD */
diff --git a/bin/sh/mkbuiltins b/bin/sh/mkbuiltins
index 104ded6..7c610d5 100755
--- a/bin/sh/mkbuiltins
+++ b/bin/sh/mkbuiltins
@@ -34,19 +34,21 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)mkbuiltins 8.1 (Berkeley) 5/31/93
-# $Id: mkbuiltins,v 1.3 1995/03/30 19:45:20 phk Exp $
+# @(#)mkbuiltins 8.2 (Berkeley) 5/4/95
+# $Id: mkbuiltins,v 1.4 1996/06/24 04:22:22 jkh Exp $
temp=/tmp/ka$$
havejobs=0
if grep '^#define JOBS[ ]*1' shell.h > /dev/null
then havejobs=1
fi
-if [ -d ${OBJDIR} ] ; then
- exec > ${OBJDIR}/builtins.c
-else
- exec > builtins.c
+havehist=1
+if [ "X$1" = "X-h" ]; then
+ havehist=0
+ shift
fi
+objdir=$1
+exec > ${objdir}/builtins.c
cat <<\!
/*
* This file was generated by the mkbuiltins program.
@@ -56,8 +58,8 @@ cat <<\!
#include "builtins.h"
!
-awk '/^[^#]/ {if('$havejobs' || $2 != "-j") print $0}' builtins |
- sed 's/-j//' > $temp
+awk '/^[^#]/ {if(('$havejobs' || $2 != "-j") && ('$havehist' || $2 != "-h")) \
+ print $0}' builtins.def | sed 's/-j//' > $temp
awk '{ printf "int %s();\n", $1}' $temp
echo '
int (*const builtinfunc[])() = {'
@@ -66,16 +68,12 @@ echo '};
const struct builtincmd builtincmd[] = {'
awk '{ for (i = 2 ; i <= NF ; i++) {
- printf "\t\"%s\", %d,\n", $i, NR-1
+ printf "\t{ \"%s\", %d },\n", $i, NR-1
}}' $temp
-echo ' NULL, 0
+echo ' { NULL, 0 }
};'
-if [ -d ${OBJDIR} ] ; then
- exec > ${OBJDIR}/builtins.h
-else
- exec > builtins.h
-fi
+exec > ${objdir}/builtins.h
cat <<\!
/*
* This file was generated by the mkbuiltins program.
diff --git a/bin/sh/mkinit.c b/bin/sh/mkinit.c
index bb63cd68..6afe601 100644
--- a/bin/sh/mkinit.c
+++ b/bin/sh/mkinit.c
@@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: mkinit.c,v 1.4 1995/05/30 00:07:19 rgrimes Exp $
+ * $Id: mkinit.c,v 1.5 1995/10/01 15:13:31 joerg Exp $
*/
#ifndef lint
@@ -43,7 +43,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)mkinit.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)mkinit.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
/*
@@ -51,16 +51,17 @@ static char sccsid[] = "@(#)mkinit.c 8.1 (Berkeley) 5/31/93";
* 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.
+ * operations on particular events.
*
- * Usage: mkinit command sourcefile...
+ * Usage: mkinit sourcefile...
*/
#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <fcntl.h>
#include <unistd.h>
@@ -73,7 +74,6 @@ static char sccsid[] = "@(#)mkinit.c 8.1 (Berkeley) 5/31/93";
#define OUTFILE "init.c"
#define OUTTEMP "init.c.new"
-#define OUTOBJ "init.o"
/*
@@ -150,42 +150,41 @@ struct text decls; /* declarations */
int amiddecls; /* for formatting */
-void readfile(), doevent(), doinclude(), dodecl(), output();
-void addstr(), addchar(), writetext();
+void readfile __P((char *));
+int match __P((char *, char *));
+int gooddefine __P((char *));
+void doevent __P((struct event *, FILE *, char *));
+void doinclude __P((char *));
+void dodecl __P((char *, FILE *));
+void output __P((void));
+void addstr __P((char *, struct text *));
+void addchar __P((int, struct text *));
+void writetext __P((struct text *, FILE *));
+FILE *ckfopen __P((char *, char *));
+void *ckmalloc __P((int));
+char *savestr __P((char *));
+void error __P((char *));
#define equal(s1, s2) (strcmp(s1, s2) == 0)
-FILE *ckfopen();
-char *savestr();
-void *ckmalloc __P((int));
-void error();
-
+int
main(argc, argv)
+ int argc;
char **argv;
- {
+{
char **ap;
- int fd;
- char c;
if (argc < 2)
- error("Usage: mkinit command file...");
+ error("Usage: mkinit file...");
header_files[0] = "\"shell.h\"";
header_files[1] = "\"mystring.h\"";
- for (ap = argv + 2 ; *ap ; ap++)
+ for (ap = argv + 1 ; *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");
+ unlink(OUTFILE);
+ link(OUTTEMP, OUTFILE);
+ unlink(OUTTEMP);
+ exit(0);
}
@@ -240,7 +239,7 @@ int
match(name, line)
char *name;
char *line;
- {
+{
register char *p, *q;
p = name, q = line;
@@ -257,7 +256,7 @@ match(name, line)
int
gooddefine(line)
char *line;
- {
+{
register char *p;
if (! match("#define", line))
@@ -364,7 +363,7 @@ dodecl(line1, fp)
if (! amiddecls)
addchar('\n', &decls);
q = NULL;
- for (p = line1 + 6 ; *p != '=' && *p != '/' && *p != '\n'; p++);
+ for (p = line1 + 6 ; *p != '\0' && *p != '=' && *p != '/' && *p != '\n'; p++);
if (*p == '=') { /* eliminate initialization */
for (q = p ; *q && *q != ';' ; q++);
if (*q == '\0')
@@ -415,51 +414,6 @@ output() {
/*
- * 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, (off_t)0, 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.
@@ -481,8 +435,9 @@ addstr(s, text)
void
addchar(c, text)
+ int c;
register struct text *text;
- {
+{
struct block *bp;
if (--text->nleft < 0) {
@@ -530,9 +485,10 @@ ckfopen(file, mode)
}
void *
-ckmalloc(nbytes) {
+ckmalloc(nbytes)
+ int nbytes;
+{
register char *p;
- char *malloc();
if ((p = malloc(nbytes)) == NULL)
error("Out of space");
diff --git a/bin/sh/mknodes.c b/bin/sh/mknodes.c
index 5ede3af..4ed88d0 100644
--- a/bin/sh/mknodes.c
+++ b/bin/sh/mknodes.c
@@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: mknodes.c,v 1.2 1994/09/24 02:57:55 davidg Exp $
*/
#ifndef lint
@@ -43,7 +43,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)mknodes.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)mknodes.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
/*
@@ -52,6 +52,13 @@ static char sccsid[] = "@(#)mknodes.c 8.1 (Berkeley) 5/31/93";
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
#define MAXTYPES 50 /* max number of node types */
@@ -82,27 +89,35 @@ struct str { /* struct representing a node structure */
};
-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)
+static int ntypes; /* number of node types */
+static char *nodename[MAXTYPES]; /* names of the nodes */
+static struct str *nodestr[MAXTYPES]; /* type of structure used by the node */
+static int nstr; /* number of structures */
+static struct str str[MAXTYPES]; /* the structures */
+static struct str *curstr; /* current structure */
+static FILE *infp = stdin;
+static char line[1024];
+static int linno;
+static char *linep;
+
+static void parsenode __P((void));
+static void parsefield __P((void));
+static void output __P((char *));
+static void outsizes __P((FILE *));
+static void outfunc __P((FILE *, int));
+static void indent __P((int, FILE *));
+static int nextfield __P((char *));
+static void skipbl __P((void));
+static int readline __P((void));
+static void error __P((const char *, ...));
+static char *savestr __P((const char *));
+int
main(argc, argv)
+ int argc;
char **argv;
- {
+{
if (argc != 3)
error("usage: mknodes file\n");
if ((infp = fopen(argv[1], "r")) == NULL)
@@ -119,7 +134,9 @@ main(argc, argv)
-parsenode() {
+static void
+parsenode()
+{
char name[BUFLEN];
char tag[BUFLEN];
struct str *sp;
@@ -133,7 +150,7 @@ parsenode() {
error("Garbage at end of line");
nodename[ntypes] = savestr(name);
for (sp = str ; sp < str + nstr ; sp++) {
- if (equal(sp->tag, tag))
+ if (strcmp(sp->tag, tag) == 0)
break;
}
if (sp >= str + nstr) {
@@ -147,7 +164,9 @@ parsenode() {
}
-parsefield() {
+static void
+parsefield()
+{
char name[BUFLEN];
char type[BUFLEN];
char decl[2 * BUFLEN];
@@ -161,21 +180,21 @@ parsefield() {
error("No field type");
fp = &curstr->field[curstr->nfields];
fp->name = savestr(name);
- if (equal(type, "nodeptr")) {
+ if (strcmp(type, "nodeptr") == 0) {
fp->type = T_NODE;
sprintf(decl, "union node *%s", name);
- } else if (equal(type, "nodelist")) {
+ } else if (strcmp(type, "nodelist") == 0) {
fp->type = T_NODELIST;
sprintf(decl, "struct nodelist *%s", name);
- } else if (equal(type, "string")) {
+ } else if (strcmp(type, "string") == 0) {
fp->type = T_STRING;
sprintf(decl, "char *%s", name);
- } else if (equal(type, "int")) {
+ } else if (strcmp(type, "int") == 0) {
fp->type = T_INT;
sprintf(decl, "int %s", name);
- } else if (equal(type, "other")) {
+ } else if (strcmp(type, "other") == 0) {
fp->type = T_OTHER;
- } else if (equal(type, "temp")) {
+ } else if (strcmp(type, "temp") == 0) {
fp->type = T_TEMP;
} else {
error("Unknown type %s", type);
@@ -198,9 +217,10 @@ char writer[] = "\
*/\n\
\n";
+static void
output(file)
char *file;
- {
+{
FILE *hfile;
FILE *cfile;
FILE *patfile;
@@ -247,11 +267,11 @@ output(file)
fputs(writer, cfile);
while (fgets(line, sizeof line, patfile) != NULL) {
for (p = line ; *p == ' ' || *p == '\t' ; p++);
- if (equal(p, "%SIZES\n"))
+ if (strcmp(p, "%SIZES\n") == 0)
outsizes(cfile);
- else if (equal(p, "%CALCSIZE\n"))
+ else if (strcmp(p, "%CALCSIZE\n") == 0)
outfunc(cfile, 1);
- else if (equal(p, "%COPY\n"))
+ else if (strcmp(p, "%COPY\n") == 0)
outfunc(cfile, 0);
else
fputs(line, cfile);
@@ -260,9 +280,10 @@ output(file)
+static void
outsizes(cfile)
FILE *cfile;
- {
+{
int i;
fprintf(cfile, "static const short nodesize[%d] = {\n", ntypes);
@@ -273,9 +294,11 @@ outsizes(cfile)
}
+static void
outfunc(cfile, calcsize)
FILE *cfile;
- {
+ int calcsize;
+{
struct str *sp;
struct field *fp;
int i;
@@ -352,9 +375,11 @@ outfunc(cfile, calcsize)
}
+static void
indent(amount, fp)
+ int amount;
FILE *fp;
- {
+{
while (amount >= 8) {
putc('\t', fp);
amount -= 8;
@@ -365,10 +390,10 @@ indent(amount, fp)
}
-int
+static int
nextfield(buf)
char *buf;
- {
+{
register char *p, *q;
p = linep;
@@ -383,14 +408,17 @@ nextfield(buf)
}
-skipbl() {
+static void
+skipbl()
+{
while (*linep == ' ' || *linep == '\t')
linep++;
}
-int
-readline() {
+static int
+readline()
+{
register char *p;
if (fgets(line, 1024, infp) == NULL)
@@ -408,26 +436,42 @@ readline() {
-error(msg, a1, a2, a3, a4, a5, a6)
+static void
+#if __STDC__
+error(const char *msg, ...)
+#else
+error(va_alist)
+ va_dcl
+#endif
+{
+ va_list va;
+#if __STDC__
+ va_start(va, msg);
+#else
char *msg;
- {
- fprintf(stderr, "line %d: ", linno);
- fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
- putc('\n', stderr);
+ va_start(va);
+ msg = va_arg(va, char *);
+#endif
+
+ (void) fprintf(stderr, "line %d: ", linno);
+ (void) vfprintf(stderr, msg, va);
+ (void) fputc('\n', stderr);
+
+ va_end(va);
+
exit(2);
}
-char *
+static char *
savestr(s)
- char *s;
- {
+ const char *s;
+{
register char *p;
- char *malloc();
if ((p = malloc(strlen(s) + 1)) == NULL)
error("Out of space");
- strcpy(p, s);
+ (void) strcpy(p, s);
return p;
}
diff --git a/bin/sh/mksignames.c b/bin/sh/mksignames.c
deleted file mode 100644
index 5d7b9da..0000000
--- a/bin/sh/mksignames.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * 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.
- *
- * $Id: mksignames.c,v 1.2 1994/09/24 02:57:56 davidg Exp $
- */
-
-#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1991, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-static char sccsid[] = "@(#)mksignames.c 8.1 (Berkeley) 5/31/93";
-#endif /* not lint */
-
-/*
- * This program generates the signames.h and signames.c files.
- */
-#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",
- SIGSYS, "SYS", "Bad system call",
- 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);
-}
diff --git a/bin/sh/mksyntax.c b/bin/sh/mksyntax.c
index a4948c0..5b6a30e 100644
--- a/bin/sh/mksyntax.c
+++ b/bin/sh/mksyntax.c
@@ -33,7 +33,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: mksyntax.c,v 1.4 1996/08/12 12:31:28 ache Exp $
+ * $Id: mksyntax.c,v 1.5 1996/08/12 22:14:47 ache Exp $
*/
#ifndef lint
@@ -43,7 +43,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)mksyntax.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)mksyntax.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
/*
@@ -51,6 +51,7 @@ static char sccsid[] = "@(#)mksyntax.c 8.1 (Berkeley) 5/31/93";
*/
#include <stdio.h>
+#include <string.h>
#include "parser.h"
@@ -61,21 +62,21 @@ struct synclass {
/* 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",
- "CLP", "a left paren in arithmetic",
- "CRP", "a right paren in arithmetic",
- "CEOF", "end of file",
- "CCTL", "like CWORD, except it must be escaped",
- "CSPCL", "these terminate a word",
- NULL, NULL
+ { "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" },
+ { "CLP", "a left paren in arithmetic" },
+ { "CRP", "a right paren in arithmetic" },
+ { "CEOF", "end of file" },
+ { "CCTL", "like CWORD, except it must be escaped" },
+ { "CSPCL", "these terminate a word" },
+ { NULL, NULL }
};
@@ -84,31 +85,41 @@ struct synclass synclass[] = {
* 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,
+ { "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[] = "\
+static 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() {
+static FILE *cfile;
+static FILE *hfile;
+static char *syntax[513];
+static int base;
+static int size; /* number of values which a char variable can have */
+static int nbits; /* number of bits in a character */
+static int digit_contig;/* true if digits are contiguous */
+
+static void filltable __P((char *));
+static void init __P((void));
+static void add __P((char *, char *));
+static void print __P((char *));
+static void output_type_macros __P((void));
+static void digit_convert __P((void));
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
char c;
char d;
int sign;
@@ -163,7 +174,7 @@ main() {
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)
+ for (pos = strlen(buf) ; pos < 32 ; pos = (pos + 8) & ~07)
putc('\t', hfile);
fprintf(hfile, "/* %s */\n", synclass[i].comment);
}
@@ -172,7 +183,7 @@ main() {
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)
+ for (pos = strlen(buf) ; pos < 32 ; pos = (pos + 8) & ~07)
putc('\t', hfile);
fprintf(hfile, "/* %s */\n", is_entry[i].comment);
}
@@ -210,13 +221,15 @@ main() {
add("`", "CBQUOTE");
add("$", "CVAR");
add("}", "CENDVAR");
- add("!*?[=~:/", "CCTL"); /* ':/' for tilde - yuck */
+ /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
+ add("!*?[=~:/-", "CCTL");
print("dqsyntax");
init();
fputs("\n/* syntax table used when in single quotes */\n", cfile);
add("\n", "CNL");
add("'", "CENDQUOTE");
- add("!*?[=~:/", "CCTL"); /* ':/' for tilde - yuck */
+ /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */
+ add("!*?[=~:/-", "CCTL");
print("sqsyntax");
init();
fputs("\n/* syntax table used when in arithmetic */\n", cfile);
@@ -249,9 +262,10 @@ main() {
* Clear the syntax table.
*/
+static void
filltable(dftval)
char *dftval;
- {
+{
int i;
for (i = 0 ; i < size ; i++)
@@ -263,7 +277,9 @@ filltable(dftval)
* Initialize the syntax table with default values.
*/
-init() {
+static void
+init()
+{
filltable("CWORD");
syntax[0] = "CEOF";
syntax[base + CTLESC] = "CCTL";
@@ -280,9 +296,10 @@ init() {
* Add entries to the syntax table.
*/
+static void
add(p, type)
char *p, *type;
- {
+{
while (*p)
syntax[*p++ + base] = type;
}
@@ -293,9 +310,10 @@ add(p, type)
* Output the syntax table.
*/
+static void
print(name)
char *name;
- {
+{
int i;
int col;
@@ -326,7 +344,7 @@ print(name)
* contiguous, we can test for them quickly.
*/
-char *macro[] = {
+static char *macro[] = {
"#define is_digit(c)\t((is_type+SYNBASE)[c] & ISDIGIT)",
"#define is_alpha(c)\t((c) != PEOF && ((c) < CTLESC || (c) > CTLENDARI) && isalpha((unsigned char) (c)))",
"#define is_name(c)\t((c) != PEOF && ((c) < CTLESC || (c) > CTLENDARI) && ((c) == '_' || isalpha((unsigned char) (c))))",
@@ -335,7 +353,9 @@ char *macro[] = {
NULL
};
-output_type_macros() {
+static void
+output_type_macros()
+{
char **pp;
if (digit_contig)
@@ -354,7 +374,9 @@ output_type_macros() {
* Output digit conversion table (if digits are not contiguous).
*/
-digit_convert() {
+static void
+digit_convert()
+{
int maxdigit;
static char digit[] = "0123456789";
char *p;
diff --git a/bin/sh/mktokens b/bin/sh/mktokens
index 12983e8..375ff8e 100644
--- a/bin/sh/mktokens
+++ b/bin/sh/mktokens
@@ -35,7 +35,7 @@
# SUCH DAMAGE.
#
# @(#)mktokens 8.1 (Berkeley) 5/31/93
-# $Id$
+# $Id: mktokens,v 1.2 1994/09/24 02:57:58 davidg Exp $
# 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
@@ -72,7 +72,7 @@ TESAC 1 "esac"
TNOT 0 "!"
!
nl=`wc -l /tmp/ka$$`
-exec > token.def
+exec > token.h
awk '{print "#define " $1 " " NR-1}' /tmp/ka$$
echo '
/* Array indicating which tokens mark the end of a list */
diff --git a/bin/sh/myhistedit.h b/bin/sh/myhistedit.h
index c089511..3f69381 100644
--- a/bin/sh/myhistedit.h
+++ b/bin/sh/myhistedit.h
@@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)myhistedit.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)myhistedit.h 8.2 (Berkeley) 5/4/95
+ * $Id: myhistedit.h,v 1.2 1994/09/24 02:57:59 davidg Exp $
*/
#include <histedit.h>
@@ -39,3 +39,10 @@
extern History *hist;
extern EditLine *el;
extern int displayhist;
+
+void histedit __P((void));
+void sethistsize __P((void));
+int histcmd __P((int, char **));
+int not_fcnumber __P((char *));
+int str_to_event __P((char *, int));
+
diff --git a/bin/sh/mystring.c b/bin/sh/mystring.c
index 01b1add..5cec9e6 100644
--- a/bin/sh/mystring.c
+++ b/bin/sh/mystring.c
@@ -33,11 +33,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: mystring.c,v 1.2 1994/09/24 02:57:59 davidg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)mystring.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)mystring.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
/*
@@ -50,6 +50,7 @@ static char sccsid[] = "@(#)mystring.c 8.1 (Berkeley) 5/31/93";
* is_number(s) Return true if s is a string of digits.
*/
+#include <stdlib.h>
#include "shell.h"
#include "syntax.h"
#include "error.h"
diff --git a/bin/sh/mystring.h b/bin/sh/mystring.h
index ca04daa..a1caa06 100644
--- a/bin/sh/mystring.h
+++ b/bin/sh/mystring.h
@@ -33,23 +33,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)mystring.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)mystring.h 8.2 (Berkeley) 5/4/95
+ * $Id: mystring.h,v 1.2 1994/09/24 02:58:00 davidg Exp $
*/
#include <string.h>
-#ifdef __STDC__
-void scopyn(const char *, char *, int);
-int prefix(const char *, const char *);
-int number(const char *);
-int is_number(const char *);
-#else
-void scopyn();
-int prefix();
-int number();
-int is_number();
-#endif
+void scopyn __P((const char *, char *, int));
+int prefix __P((const char *, const char *));
+int number __P((const char *));
+int is_number __P((const char *));
#define equal(s1, s2) (strcmp(s1, s2) == 0)
#define scopy(s1, s2) ((void)strcpy(s2, s1))
diff --git a/bin/sh/nodes.c.pat b/bin/sh/nodes.c.pat
index e0602ed..739616d 100644
--- a/bin/sh/nodes.c.pat
+++ b/bin/sh/nodes.c.pat
@@ -33,10 +33,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)nodes.c.pat 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)nodes.c.pat 8.2 (Berkeley) 5/4/95
+ * $Id: nodes.c.pat,v 1.2 1994/09/24 02:58:02 davidg Exp $
*/
+#include <stdlib.h>
/*
* Routine for dealing with parsed shell commands.
*/
@@ -48,31 +49,19 @@
#include "mystring.h"
-int funcblocksize; /* size of structures in function */
-int funcstringsize; /* size of strings in node */
-#ifdef __STDC__
+int funcblocksize; /* size of structures in function */
+int funcstringsize; /* size of strings in node */
pointer funcblock; /* block to allocate function from */
-#else
-char *funcblock; /* block to allocate function from */
-#endif
-char *funcstring; /* block to allocate strings from */
+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
+STATIC void calcsize __P((union node *));
+STATIC void sizenodelist __P((struct nodelist *));
+STATIC union node *copynode __P((union node *));
+STATIC struct nodelist *copynodelist __P((struct nodelist *));
+STATIC char *nodesavestr __P((char *));
@@ -82,85 +71,86 @@ STATIC char *nodesavestr();
union node *
copyfunc(n)
- union node *n;
- {
- if (n == NULL)
- return NULL;
- funcblocksize = 0;
- funcstringsize = 0;
- calcsize(n);
- funcblock = ckmalloc(funcblocksize + funcstringsize);
- funcstring = funcblock + funcblocksize;
- return copynode(n);
+ union node *n;
+{
+ if (n == NULL)
+ return NULL;
+ funcblocksize = 0;
+ funcstringsize = 0;
+ calcsize(n);
+ funcblock = ckmalloc(funcblocksize + funcstringsize);
+ funcstring = funcblock + funcblocksize;
+ return copynode(n);
}
STATIC void
calcsize(n)
- union node *n;
- {
- %CALCSIZE
+ union node *n;
+{
+ %CALCSIZE
}
STATIC void
sizenodelist(lp)
- struct nodelist *lp;
- {
- while (lp) {
- funcblocksize += ALIGN(sizeof (struct nodelist));
- calcsize(lp->n);
- lp = lp->next;
- }
+ 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;
+ union node *n;
+{
+ union node *new;
- %COPY
- return new;
+ %COPY
+ return new;
}
STATIC struct nodelist *
copynodelist(lp)
- struct nodelist *lp;
- {
- struct nodelist *start;
- struct nodelist **lpp;
-
- lpp = &start;
- while (lp) {
- *lpp = funcblock;
- funcblock += ALIGN(sizeof (struct nodelist));
- (*lpp)->n = copynode(lp->n);
- lp = lp->next;
- lpp = &(*lpp)->next;
- }
- *lpp = NULL;
- return start;
+ struct nodelist *lp;
+{
+ struct nodelist *start;
+ struct nodelist **lpp;
+
+ lpp = &start;
+ while (lp) {
+ *lpp = funcblock;
+ 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;
+ char *s;
+{
+ register char *p = s;
+ register char *q = funcstring;
+ char *rtn = funcstring;
+
+ while ((*q++ = *p++) != '\0')
+ continue;
+ funcstring = q;
+ return rtn;
}
@@ -171,8 +161,8 @@ nodesavestr(s)
void
freefunc(n)
- union node *n;
- {
- if (n)
- ckfree(n);
+ union node *n;
+{
+ if (n)
+ ckfree(n);
}
diff --git a/bin/sh/nodetypes b/bin/sh/nodetypes
index 5f33a17..a2b12bf 100644
--- a/bin/sh/nodetypes
+++ b/bin/sh/nodetypes
@@ -33,8 +33,8 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# @(#)nodetypes 8.1 (Berkeley) 5/31/93
-# $Id$
+# @(#)nodetypes 8.2 (Berkeley) 5/4/95
+# $Id: nodetypes,v 1.2 1994/09/24 02:58:03 davidg Exp $
# This file describes the nodes used in parse trees. Unindented lines
# contain a node type followed by a structure tag. Subsequent indented
@@ -131,6 +131,8 @@ NFROMFD ndup # fd>&dupfd
next nodeptr # next redirection in list
fd int # file descriptor being redirected
dupfd int # file descriptor to duplicate
+ vname nodeptr # file name if fd>&$var
+
NHERE nhere # fd<<\!
NXHERE nhere # fd<<!
diff --git a/bin/sh/options.c b/bin/sh/options.c
index 5613302..095c7a9 100644
--- a/bin/sh/options.c
+++ b/bin/sh/options.c
@@ -33,13 +33,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: options.c,v 1.5 1995/10/01 15:11:42 joerg Exp $
+ * $Id: options.c,v 1.6 1995/10/09 17:56:32 joerg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)options.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <signal.h>
+#include <unistd.h>
+#include <stdlib.h>
+
#include "shell.h"
#define DEFINE_OPTIONS
#include "options.h"
@@ -54,6 +58,9 @@ static char sccsid[] = "@(#)options.c 8.1 (Berkeley) 5/31/93";
#include "memalloc.h"
#include "error.h"
#include "mystring.h"
+#ifndef NO_HISTORY
+#include "myhistedit.h"
+#endif
char *arg0; /* value of $0 */
struct shparam shellparam; /* current positional parameters */
@@ -64,16 +71,9 @@ char *optptr; /* used by nextopt */
char *minusc; /* argument to -c option */
-#ifdef __STDC__
-STATIC void options(int);
-STATIC void setoption(int, int);
-STATIC void minus_o(char *, int);
-#else
-STATIC void options();
-STATIC void setoption();
-STATIC void minus_o();
-#endif
-
+STATIC void options __P((int));
+STATIC void minus_o __P((char *, int));
+STATIC void setoption __P((int, int));
/*
@@ -82,8 +82,9 @@ STATIC void minus_o();
void
procargs(argc, argv)
+ int argc;
char **argv;
- {
+{
int i;
argptr = argv;
@@ -119,9 +120,13 @@ procargs(argc, argv)
}
-optschanged() {
+void
+optschanged()
+{
setinteractive(iflag);
+#ifndef NO_HISTORY
histedit();
+#endif
setjobctl(mflag);
}
@@ -131,7 +136,9 @@ optschanged() {
*/
STATIC void
-options(cmdline) {
+options(cmdline)
+ int cmdline;
+{
register char *p;
int val;
int c;
@@ -142,14 +149,14 @@ options(cmdline) {
argptr++;
if ((c = *p++) == '-') {
val = 1;
- if (p[0] == '\0' || p[0] == '-' && p[1] == '\0') {
+ 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);
+ setparam(argptr);
}
break; /* "-" or "--" terminates options */
}
@@ -293,7 +300,11 @@ freeparam(param)
* The shift builtin command.
*/
-shiftcmd(argc, argv) char **argv; {
+int
+shiftcmd(argc, argv)
+ int argc;
+ char **argv;
+{
int n;
char **ap1, **ap2;
@@ -321,7 +332,11 @@ shiftcmd(argc, argv) char **argv; {
* The set command builtin.
*/
-setcmd(argc, argv) char **argv; {
+int
+setcmd(argc, argv)
+ int argc;
+ char **argv;
+{
if (argc == 1)
return showvarscmd(argc, argv);
INTOFF;
@@ -342,7 +357,11 @@ setcmd(argc, argv) char **argv; {
* then it's the first time getopts has been called.
*/
-getoptscmd(argc, argv) char **argv; {
+int
+getoptscmd(argc, argv)
+ int argc;
+ char **argv;
+{
register char *p, *q;
char c;
char s[10];
diff --git a/bin/sh/options.h b/bin/sh/options.h
index 095dc29..33131d3 100644
--- a/bin/sh/options.h
+++ b/bin/sh/options.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)options.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)options.h 8.2 (Berkeley) 5/4/95
+ * $Id: options.h,v 1.2 1994/09/24 02:58:05 davidg Exp $
*/
struct shparam {
@@ -73,21 +73,21 @@ struct optent {
#ifdef DEFINE_OPTIONS
struct optent optlist[NOPTS] = {
- "errexit", 'e', 0,
- "noglob", 'f', 0,
- "ignoreeof", 'I', 0,
- "interactive", 'i', 0,
- "monitor", 'm', 0,
- "noexec", 'n', 0,
- "stdin", 's', 0,
- "xtrace", 'x', 0,
- "verbose", 'v', 0,
- "vi", 'V', 0,
- "emacs", 'E', 0,
- "noclobber", 'C', 0,
- "allexport", 'a', 0,
- "notify", 'b', 0,
- "nounset", 'u', 0,
+ { "errexit", 'e', 0 },
+ { "noglob", 'f', 0 },
+ { "ignoreeof", 'I', 0 },
+ { "interactive",'i', 0 },
+ { "monitor", 'm', 0 },
+ { "noexec", 'n', 0 },
+ { "stdin", 's', 0 },
+ { "xtrace", 'x', 0 },
+ { "verbose", 'v', 0 },
+ { "vi", 'V', 0 },
+ { "emacs", 'E', 0 },
+ { "noclobber", 'C', 0 },
+ { "allexport", 'a', 0 },
+ { "notify", 'b', 0 },
+ { "nounset", 'u', 0 },
};
#else
extern struct optent optlist[NOPTS];
@@ -101,15 +101,11 @@ extern char **argptr; /* argument list for builtin commands */
extern char *optarg; /* set by nextopt */
extern char *optptr; /* used by nextopt */
-
-#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
+void procargs __P((int, char **));
+void optschanged __P((void));
+void setparam __P((char **));
+void freeparam __P((struct shparam *));
+int shiftcmd __P((int, char **));
+int setcmd __P((int, char **));
+int getoptscmd __P((int, char **));
+int nextopt __P((char *));
diff --git a/bin/sh/output.c b/bin/sh/output.c
index 914df67..a52cea9 100644
--- a/bin/sh/output.c
+++ b/bin/sh/output.c
@@ -33,11 +33,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: output.c,v 1.2 1994/09/24 02:58:06 davidg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)output.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)output.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
/*
@@ -51,18 +51,24 @@ static char sccsid[] = "@(#)output.c 8.1 (Berkeley) 5/31/93";
* Our output routines may be smaller than the stdio routines.
*/
+#include <sys/ioctl.h>
+
#include <stdio.h> /* defines BUFSIZ */
-#include "shell.h"
-#include "syntax.h"
-#include "output.h"
-#include "memalloc.h"
-#include "error.h"
+#include <string.h>
#ifdef __STDC__
-#include "stdarg.h"
+#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "shell.h"
+#include "syntax.h"
+#include "output.h"
+#include "memalloc.h"
+#include "error.h"
#define OUTBUFSIZ BUFSIZ
@@ -117,7 +123,7 @@ open_mem(block, length, file)
void
out1str(p)
- char *p;
+ const char *p;
{
outstr(p, out1);
}
@@ -125,7 +131,7 @@ out1str(p)
void
out2str(p)
- char *p;
+ const char *p;
{
outstr(p, out2);
}
@@ -133,7 +139,7 @@ out2str(p)
void
outstr(p, file)
- register char *p;
+ register const char *p;
register struct output *file;
{
while (*p)
@@ -545,10 +551,15 @@ xwrite(fd, buf, nbytes)
/*
* Version of ioctl that retries after a signal is caught.
+ * XXX unused function
*/
int
-xioctl(fd, request, arg) {
+xioctl(fd, request, arg)
+ int fd;
+ unsigned long request;
+ char * arg;
+{
int i;
while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR);
diff --git a/bin/sh/output.h b/bin/sh/output.h
index e4318f3..92e03b9 100644
--- a/bin/sh/output.h
+++ b/bin/sh/output.h
@@ -33,12 +33,18 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)output.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)output.h 8.2 (Berkeley) 5/4/95
+ * $Id: output.h,v 1.2 1994/09/24 02:58:08 davidg Exp $
*/
#ifndef OUTPUT_INCL
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
struct output {
char *nextc;
int nleft;
@@ -54,38 +60,21 @@ 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
+void open_mem __P((char *, int, struct output *));
+void out1str __P((const char *));
+void out2str __P((const char *));
+void outstr __P((const char *, struct output *));
+void emptyoutbuf __P((struct output *));
+void flushall __P((void));
+void flushout __P((struct output *));
+void freestdout __P((void));
+void outfmt __P((struct output *, char *, ...));
+void out1fmt __P((char *, ...));
+void dprintf __P((char *, ...));
+void fmtstr __P((char *, int, char *, ...));
+void doformat __P((struct output *, char *, va_list));
+int xwrite __P((int, char *, int));
+int xioctl __P((int, unsigned long, char *));
#define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
#define out1c(c) outc(c, out1);
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index ef9c40c..64a0cd0 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -33,13 +33,15 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: parser.c,v 1.10 1995/12/10 17:59:23 joerg Exp $
+ * $Id: parser.c,v 1.11 1996/02/03 13:27:55 joerg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)parser.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
#endif /* not lint */
+#include <stdlib.h>
+
#include "shell.h"
#include "parser.h"
#include "nodes.h"
@@ -54,8 +56,10 @@ static char sccsid[] = "@(#)parser.c 8.1 (Berkeley) 5/31/93";
#include "memalloc.h"
#include "mystring.h"
#include "alias.h"
+#include "show.h"
+#ifndef NO_HISTORY
#include "myhistedit.h"
-
+#endif
/*
* Shell command parser.
@@ -64,7 +68,7 @@ static char sccsid[] = "@(#)parser.c 8.1 (Berkeley) 5/31/93";
#define EOFMARKLEN 79
/* values returned by readtoken */
-#include "token.def"
+#include "token.h"
@@ -104,15 +108,18 @@ 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 union node *makename __P((void));
STATIC void parsefname __P((void));
STATIC void parseheredoc __P((void));
+STATIC int peektoken __P((void));
STATIC int readtoken __P((void));
+STATIC int xxreadtoken __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 *));
-STATIC void setprompt __P((int));
+STATIC void setprompt __P((int));
+
/*
* Read and parse a command. Returns NEOF on end of file. (NULL is a
@@ -120,7 +127,9 @@ STATIC void setprompt __P((int));
*/
union node *
-parsecmd(interact) {
+parsecmd(interact)
+ int interact;
+{
int t;
doprompt = interact;
@@ -140,31 +149,58 @@ parsecmd(interact) {
STATIC union node *
-list(nlflag) {
+list(nlflag)
+ int nlflag;
+{
union node *n1, *n2, *n3;
+ int tok;
checkkwd = 2;
if (nlflag == 0 && tokendlist[peektoken()])
return NULL;
- n1 = andor();
+ n1 = NULL;
for (;;) {
- switch (readtoken()) {
- case TBACKGND:
- case TNL:
- parseheredoc();
- if (nlflag)
- return n1;
- /* fall through */
- case TSEMI:
- checkkwd = 2;
- if (tokendlist[peektoken()])
- return n1;
- n2 = andor();
+ n2 = andor();
+ tok = readtoken();
+ if (tok == TBACKGND) {
+ if (n2->type == NCMD || n2->type == NPIPE) {
+ n2->ncmd.backgnd = 1;
+ } else if (n2->type == NREDIR) {
+ n2->type = NBACKGND;
+ } else {
+ n3 = (union node *)stalloc(sizeof (struct nredir));
+ n3->type = NBACKGND;
+ n3->nredir.n = n2;
+ n3->nredir.redirect = NULL;
+ n2 = n3;
+ }
+ }
+ if (n1 == NULL) {
+ n1 = n2;
+ }
+ else {
n3 = (union node *)stalloc(sizeof (struct nbinary));
n3->type = NSEMI;
n3->nbinary.ch1 = n1;
n3->nbinary.ch2 = n2;
n1 = n3;
+ }
+ switch (tok) {
+ case TBACKGND:
+ case TSEMI:
+ tok = readtoken();
+ /* fall through */
+ case TNL:
+ if (tok == TNL) {
+ parseheredoc();
+ if (nlflag)
+ return n1;
+ } else {
+ tokpushback++;
+ }
+ checkkwd = 2;
+ if (tokendlist[peektoken()])
+ return n1;
break;
case TEOF:
if (heredoclist)
@@ -195,19 +231,6 @@ andor() {
} else if (t == TOR) {
t = NOR;
} else {
- if (t == TBACKGND) {
- if (n1->type == NCMD || n1->type == NPIPE) {
- n1->ncmd.backgnd = 1;
- } else if (n1->type == NREDIR) {
- n1->type = NBACKGND;
- } else {
- n3 = (union node *)stalloc(sizeof (struct nredir));
- n3->type = NBACKGND;
- n3->nredir.n = n1;
- n3->nredir.redirect = NULL;
- n1 = n3;
- }
- }
tokpushback++;
return n1;
}
@@ -272,7 +295,8 @@ command() {
int t;
checkkwd = 2;
- redir = 0;
+ redir = NULL;
+ n1 = NULL;
rpp = &redir;
/* Check for redirection which may precede command */
while (readtoken() == TREDIR) {
@@ -438,13 +462,19 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
checkkwd = 1;
break;
/* Handle an empty command like other simple commands. */
- case TAND:
- case TOR:
- case TNL:
case TSEMI:
- /* Handle EOF as an empty command, too */
+ /*
+ * An empty command before a ; doesn't make much sense, and
+ * should certainly be disallowed in the case of `if ;'.
+ */
+ if (!redir)
+ synexpect(-1);
+ case TAND: /* XXX merge query! */
+ case TOR: /* XXX merge query! */
+ case TNL:
case TEOF:
case TWORD:
+ case TRP:
tokpushback++;
return simplecmd(rpp, redir);
default:
@@ -478,7 +508,7 @@ simplecmd(rpp, redir)
{
union node *args, **app;
union node **orig_rpp = rpp;
- union node *n;
+ union node *n = NULL;
/* If we don't have any redirections already, then we must reset */
/* rpp to be the address of the local redir variable. */
@@ -533,6 +563,40 @@ simplecmd(rpp, redir)
return n;
}
+STATIC union node *
+makename() {
+ union node *n;
+
+ n = (union node *)stalloc(sizeof (struct narg));
+ n->type = NARG;
+ n->narg.next = NULL;
+ n->narg.text = wordtext;
+ n->narg.backquote = backquotelist;
+ return n;
+}
+
+void fixredir(n, text, err)
+ union node *n;
+ const char *text;
+ int err;
+ {
+ TRACE(("Fix redir %s %d\n", text, err));
+ if (!err)
+ n->ndup.vname = NULL;
+
+ if (is_digit(text[0]) && text[1] == '\0')
+ n->ndup.dupfd = digit_val(text[0]);
+ else if (text[0] == '-' && text[1] == '\0')
+ n->ndup.dupfd = -1;
+ else {
+
+ if (err)
+ synerror("Bad fd number");
+ else
+ n->ndup.vname = makename();
+ }
+}
+
STATIC void
parsefname() {
@@ -564,23 +628,9 @@ parsefname() {
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");
- }
+ fixredir(n, wordtext, 0);
} 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;
+ n->nfile.fname = makename();
}
}
@@ -650,17 +700,19 @@ readtoken() {
/*
* check for keywords and aliases
*/
- if (t == TWORD && !quoteflag) {
- register char * const *pp, *s;
+ if (t == TWORD && !quoteflag)
+ {
+ register char * const *pp;
for (pp = (char **)parsekwd; *pp; pp++) {
- if (**pp == *wordtext && equal(*pp, wordtext)) {
+ if (**pp == *wordtext && equal(*pp, wordtext))
+ {
lasttoken = t = pp - parsekwd + KWDOFFSET;
TRACE(("keyword %s recognized\n", tokname[t]));
goto out;
}
}
- if (ap = lookupalias(wordtext, 1)) {
+ if ((ap = lookupalias(wordtext, 1)) != NULL) {
pushstring(ap->val, strlen(ap->val), ap);
checkkwd = savecheckkwd;
goto top;
@@ -796,8 +848,8 @@ readtoken1(firstc, syntax, eofmark, striptabs)
char *eofmark;
int striptabs;
{
- register c = firstc;
- register char *out;
+ int c = firstc;
+ char *out;
int len;
char line[EOFMARKLEN + 1];
struct nodelist *bqlist;
@@ -808,6 +860,18 @@ readtoken1(firstc, syntax, eofmark, striptabs)
int parenlevel; /* levels of parens in arithmetic */
int oldstyle;
char const *prevsyntax; /* syntax before arithmetic */
+#if __GNUC__
+ /* Avoid longjmp clobbering */
+ (void) &out;
+ (void) &quotef;
+ (void) &dblquote;
+ (void) &varnest;
+ (void) &arinest;
+ (void) &parenlevel;
+ (void) &oldstyle;
+ (void) &prevsyntax;
+ (void) &syntax;
+#endif
startlinno = plinno;
dblquote = 0;
@@ -834,13 +898,6 @@ readtoken1(firstc, syntax, eofmark, striptabs)
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 */
- if (parsebackquote && c == '\\') {
- c = pgetc(); /* XXX - compat with old /bin/sh */
- if (/*c != '\\' && */c != '`' && c != '$') {
- pungetc();
- c = '\\';
- }
- }
switch(syntax[c]) {
case CNL: /* '\n' */
if (syntax == BASESYNTAX)
@@ -1098,7 +1155,14 @@ parsesub: {
subtype = VSNORMAL;
if (c == '{') {
c = pgetc();
- subtype = 0;
+ if (c == '#') {
+ if ((c = pgetc()) == '}')
+ c = '#';
+ else
+ subtype = VSLENGTH;
+ }
+ else
+ subtype = 0;
}
if (is_name(c)) {
do {
@@ -1114,14 +1178,31 @@ badsub: synerror("Bad substitution");
STPUTC('=', out);
flags = 0;
if (subtype == 0) {
- if (c == ':') {
+ switch (c) {
+ case ':':
flags = VSNUL;
c = pgetc();
+ /*FALLTHROUGH*/
+ default:
+ p = strchr(types, c);
+ if (p == NULL)
+ goto badsub;
+ subtype = p - types + VSNORMAL;
+ break;
+ case '%':
+ case '#':
+ {
+ int cc = c;
+ subtype = c == '#' ? VSTRIMLEFT :
+ VSTRIMRIGHT;
+ c = pgetc();
+ if (c == cc)
+ subtype++;
+ else
+ pungetc();
+ break;
+ }
}
- p = strchr(types, c);
- if (p == NULL)
- goto badsub;
- subtype = p - types + VSNORMAL;
} else {
pungetc();
}
@@ -1164,7 +1245,7 @@ parsebackq: {
savelen = out - stackblock();
if (savelen > 0) {
str = ckmalloc(savelen);
- bcopy(stackblock(), str, savelen);
+ memcpy(str, stackblock(), savelen);
}
savehandler = handler;
handler = &jmploc;
@@ -1186,7 +1267,7 @@ parsebackq: {
}
if (c == '\\') {
c = pgetc ();
- if ( c != '\\' && c != '`' && c != '$'
+ if (c != '\\' && c != '`' && c != '$'
&& (!dblquote || c != '"'))
STPUTC('\\', out);
}
@@ -1196,9 +1277,9 @@ parsebackq: {
savelen = out - stackblock();
if (savelen > 0) {
str = ckmalloc(savelen);
- bcopy(stackblock(), str, savelen);
+ memcpy(str, stackblock(), savelen);
+ setinputstring(str, 1);
}
- setinputstring(str, 1);
}
nlpp = &bqlist;
while (*nlpp)
@@ -1217,7 +1298,7 @@ parsebackq: {
growstackblock();
STARTSTACKSTR(out);
if (str) {
- bcopy(str, out, savelen);
+ memcpy(out, str, savelen);
STADJUST(savelen, out);
INTOFF;
ckfree(str);
@@ -1318,7 +1399,9 @@ goodname(name)
*/
STATIC void
-synexpect(token) {
+synexpect(token)
+ int token;
+{
char msg[64];
if (token >= 0) {
@@ -1347,7 +1430,9 @@ setprompt(which)
{
whichprompt = which;
+#ifndef NO_HISTORY
if (!el)
+#endif
out2str(getprompt(NULL));
}
diff --git a/bin/sh/parser.h b/bin/sh/parser.h
index 7408bd7..4bc1e9e 100644
--- a/bin/sh/parser.h
+++ b/bin/sh/parser.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)parser.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)parser.h 8.3 (Berkeley) 5/4/95
+ * $Id: parser.h,v 1.2 1994/09/24 02:58:09 davidg Exp $
*/
/* control characters in argument strings */
@@ -48,16 +48,21 @@
#define CTLENDARI '\207'
/* 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 */
+#define VSTYPE 0x0f /* type of variable substitution */
+#define VSNUL 0x10 /* colon--treat the empty string as unset */
+#define VSQUOTE 0x80 /* 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} */
+#define VSNORMAL 0x1 /* normal variable: $var or ${var} */
+#define VSMINUS 0x2 /* ${var-text} */
+#define VSPLUS 0x3 /* ${var+text} */
+#define VSQUESTION 0x4 /* ${var?message} */
+#define VSASSIGN 0x5 /* ${var=text} */
+#define VSTRIMLEFT 0x6 /* ${var#pattern} */
+#define VSTRIMLEFTMAX 0x7 /* ${var##pattern} */
+#define VSTRIMRIGHT 0x8 /* ${var%pattern} */
+#define VSTRIMRIGHTMAX 0x9 /* ${var%%pattern} */
+#define VSLENGTH 0xa /* ${#var} */
/*
@@ -70,12 +75,7 @@ extern int tokpushback;
extern int whichprompt; /* 1 == PS1, 2 == PS2 */
-#ifdef __STDC__
-union node *parsecmd(int);
-int goodname(char *);
-char *getprompt(void *);
-#else
-union node *parsecmd();
-int goodname();
-char *getprompt();
-#endif
+union node *parsecmd __P((int));
+void fixredir __P((union node *, const char *, int));
+int goodname __P((char *));
+char *getprompt __P((void *));
diff --git a/bin/sh/redir.c b/bin/sh/redir.c
index 47f964f..ae2d335 100644
--- a/bin/sh/redir.c
+++ b/bin/sh/redir.c
@@ -33,13 +33,21 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: redir.c,v 1.3 1995/05/30 00:07:22 rgrimes Exp $
+ * $Id: redir.c,v 1.4 1995/10/21 00:47:31 joerg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)redir.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <sys/types.h>
+#include <signal.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+
/*
* Code for dealing with input/output redirection.
*/
@@ -52,11 +60,6 @@ static char sccsid[] = "@(#)redir.c 8.1 (Berkeley) 5/31/93";
#include "output.h"
#include "memalloc.h"
#include "error.h"
-#include <sys/types.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
#define EMPTY -2 /* marks an unused slot in redirtab */
@@ -79,14 +82,8 @@ MKINIT struct redirtab *redirlist;
*/
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
-
+STATIC void openredirect __P((union node *, char[10 ]));
+STATIC int openhere __P((union node *));
/*
@@ -103,7 +100,7 @@ redirect(redir, flags)
int flags;
{
union node *n;
- struct redirtab *sv;
+ struct redirtab *sv = NULL;
int i;
int fd;
char memory[10]; /* file descriptors to write to memory */
@@ -226,7 +223,7 @@ openhere(redir)
union node *redir;
{
int pip[2];
- int len;
+ int len = 0;
if (pipe(pip) < 0)
error("Pipe call failed");
@@ -338,7 +335,10 @@ clearredir() {
*/
int
-copyfd(from, to) {
+copyfd(from, to)
+ int from;
+ int to;
+{
int newfd;
newfd = fcntl(from, F_DUPFD, to);
diff --git a/bin/sh/redir.h b/bin/sh/redir.h
index 05842bb..14acdb6 100644
--- a/bin/sh/redir.h
+++ b/bin/sh/redir.h
@@ -33,25 +33,18 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)redir.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)redir.h 8.2 (Berkeley) 5/4/95
+ * $Id: redir.h,v 1.2 1994/09/24 02:58:11 davidg Exp $
*/
/* 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
+void redirect __P((union node *, int));
+void popredir __P((void));
+int fd0_redirected_p __P((void));
+void clearredir __P((void));
+int copyfd __P((int, int));
+
diff --git a/bin/sh/sh.1 b/bin/sh/sh.1
index df79bd7..5be3e07 100644
--- a/bin/sh/sh.1
+++ b/bin/sh/sh.1
@@ -32,10 +32,8 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)sh.1 8.4 (Berkeley) 4/18/94
-.\" $Id: sh.1,v 1.5 1995/10/21 00:47:32 joerg Exp $
-.\"
-.\"
+.\" @(#)sh.1 8.6 (Berkeley) 5/4/95
+.\" $Id: sh.1,v 1.6 1996/08/29 18:06:10 wosch Exp $
.\"
.na
.TH SH 1
@@ -1035,6 +1033,12 @@ to these, there are several other commands that may
be builtin for efficiency (e.g. printf(1), echo(1), test(1),
etc).
.TP
+:
+A null command that returns a 0 (true) exit value.
+.TP
+\&. file
+The commands in the specified file are read and executed by the shell.
+.TP
alias [ name[=string] ... ]
If name=string is specified, the shell defines the
alias ``name'' with value ``string''. If just ``name''
@@ -1064,9 +1068,6 @@ different from the name that the user gave. These
may be different either because the CDPATH mechanism
was used or because a symbolic link was crossed.
.TP
-\&. file
-The commands in the specified file are read and executed by the shell.
-.TP
eval string...
Concatenate all the arguments with spaces. Then
re-parse and execute the command.
@@ -1182,7 +1183,8 @@ table. Entries which have not been looked at since
the last cd command are marked with an asterisk; it
is possible for these entries to be invalid.
.sp
-With arguments, the hash command removes the specified commands from the hash table (unless they are
+With arguments, the hash command removes the specified
+commands from the hash table (unless they are
functions) and then locates them. With the -v
option, hash prints the locations of the commands as
it finds them. The -r option causes the hash command
diff --git a/bin/sh/shell.h b/bin/sh/shell.h
index d038f91..0d42e9d 100644
--- a/bin/sh/shell.h
+++ b/bin/sh/shell.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)shell.h 8.1 (Berkeley) 5/31/93
- * $Id: shell.h,v 1.2 1994/09/24 02:58:15 davidg Exp $
+ * @(#)shell.h 8.2 (Berkeley) 5/4/95
+ * $Id: shell.h,v 1.3 1995/08/27 20:26:44 joerg Exp $
*/
/*
@@ -57,7 +57,9 @@
#ifndef BSD
#define BSD 1
#endif
-/* #define DEBUG 1 */
+#ifndef DEBUG
+#define DEBUG 1
+#endif
#ifdef __STDC__
typedef void *pointer;
@@ -79,7 +81,7 @@ extern char nullstr[1]; /* null string */
#ifdef DEBUG
-#define TRACE(param) trace param
+#define TRACE(param) shtrace param
#else
#define TRACE(param)
#endif
diff --git a/bin/sh/show.c b/bin/sh/show.c
index 43fb34c..ac1992a 100644
--- a/bin/sh/show.c
+++ b/bin/sh/show.c
@@ -33,41 +33,57 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: show.c,v 1.2 1994/09/24 02:58:16 davidg Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)show.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)show.c 8.3 (Berkeley) 5/4/95";
#endif /* not lint */
#include <stdio.h>
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
#include "shell.h"
#include "parser.h"
#include "nodes.h"
#include "mystring.h"
+#include "show.h"
#ifdef DEBUG
-static shtree(), shcmd(), sharg(), indent();
+static void shtree __P((union node *, int, char *, FILE*));
+static void shcmd __P((union node *, FILE *));
+static void sharg __P((union node *, FILE *));
+static void indent __P((int, char *, FILE *));
+static void trstring __P((char *));
+void
showtree(n)
union node *n;
- {
+{
trputs("showtree called\n");
shtree(n, 1, NULL, stdout);
}
-static
+static void
shtree(n, ind, pfx, fp)
union node *n;
+ int ind;
char *pfx;
FILE *fp;
- {
+{
struct nodelist *lp;
char *s;
+ if (n == NULL)
+ return;
+
indent(ind, pfx, fp);
switch(n->type) {
case NSEMI:
@@ -110,11 +126,11 @@ binop:
-static
+static void
shcmd(cmd, fp)
union node *cmd;
FILE *fp;
- {
+{
union node *np;
int first;
char *s;
@@ -136,6 +152,7 @@ shcmd(cmd, fp)
case NTOFD: s = ">&"; dftfd = 1; break;
case NFROM: s = "<"; dftfd = 0; break;
case NFROMFD: s = "<&"; dftfd = 0; break;
+ default: s = "*error*"; dftfd = 0; break;
}
if (np->nfile.fd != dftfd)
fprintf(fp, "%d", np->nfile.fd);
@@ -151,7 +168,7 @@ shcmd(cmd, fp)
-static
+static void
sharg(arg, fp)
union node *arg;
FILE *fp;
@@ -175,10 +192,15 @@ sharg(arg, fp)
putc('$', fp);
putc('{', fp);
subtype = *++p;
+ if (subtype == VSLENGTH)
+ putc('#', fp);
+
while (*p != '=')
putc(*p++, fp);
+
if (subtype & VSNUL)
putc(':', fp);
+
switch (subtype & VSTYPE) {
case VSNORMAL:
putc('}', fp);
@@ -195,6 +217,22 @@ sharg(arg, fp)
case VSASSIGN:
putc('=', fp);
break;
+ case VSTRIMLEFT:
+ putc('#', fp);
+ break;
+ case VSTRIMLEFTMAX:
+ putc('#', fp);
+ putc('#', fp);
+ break;
+ case VSTRIMRIGHT:
+ putc('%', fp);
+ break;
+ case VSTRIMRIGHTMAX:
+ putc('%', fp);
+ putc('%', fp);
+ break;
+ case VSLENGTH:
+ break;
default:
printf("<subtype %d>", subtype);
}
@@ -217,11 +255,12 @@ sharg(arg, fp)
}
-static
+static void
indent(amount, pfx, fp)
+ int amount;
char *pfx;
FILE *fp;
- {
+{
int i;
for (i = 0 ; i < amount ; i++) {
@@ -248,7 +287,10 @@ int debug = 0;
#endif
-trputc(c) {
+void
+trputc(c)
+ int c;
+{
#ifdef DEBUG
if (tracefile == NULL)
return;
@@ -258,23 +300,37 @@ trputc(c) {
#endif
}
-
-trace(fmt, a1, a2, a3, a4, a5, a6, a7, a8)
- char *fmt;
- {
+void
+#if __STDC__
+shtrace(const char *fmt, ...)
+#else
+shtrace(va_alist)
+ va_dcl
+#endif
+{
#ifdef DEBUG
- if (tracefile == NULL)
- return;
- fprintf(tracefile, fmt, a1, a2, a3, a4, a5, a6, a7, a8);
- if (strchr(fmt, '\n'))
- fflush(tracefile);
+ va_list va;
+#if __STDC__
+ va_start(va, fmt);
+#else
+ char *fmt;
+ va_start(va);
+ fmt = va_arg(va, char *);
+#endif
+ if (tracefile != NULL) {
+ (void) vfprintf(tracefile, fmt, va);
+ if (strchr(fmt, '\n'))
+ (void) fflush(tracefile);
+ }
+ va_end(va);
#endif
}
+void
trputs(s)
char *s;
- {
+{
#ifdef DEBUG
if (tracefile == NULL)
return;
@@ -285,9 +341,10 @@ trputs(s)
}
+static void
trstring(s)
char *s;
- {
+{
register char *p;
char c;
@@ -327,9 +384,10 @@ backslash: putc('\\', tracefile);
}
+void
trargs(ap)
char **ap;
- {
+{
#ifdef DEBUG
if (tracefile == NULL)
return;
@@ -345,24 +403,29 @@ trargs(ap)
}
+void
opentrace() {
char s[100];
- char *p;
char *getenv();
+#ifdef O_APPEND
int flags;
+#endif
#ifdef DEBUG
if (!debug)
return;
#ifdef not_this_way
- if ((p = getenv("HOME")) == NULL) {
- if (geteuid() == 0)
- p = "/";
- else
- p = "/tmp";
+ {
+ char *p;
+ if ((p = getenv("HOME")) == NULL) {
+ if (geteuid() == 0)
+ p = "/";
+ else
+ p = "/tmp";
+ }
+ scopy(p, s);
+ strcat(s, "/trace");
}
- scopy(p, s);
- strcat(s, "/trace");
#else
scopy("./trace", s);
#endif /* not_this_way */
diff --git a/bin/sh/show.h b/bin/sh/show.h
index 2d620d7..18ffcb6 100644
--- a/bin/sh/show.h
+++ b/bin/sh/show.h
@@ -31,11 +31,12 @@
* SUCH DAMAGE.
*
* @(#)show.h 1.1 (Berkeley) 5/4/95
+ * $Id$
*/
void showtree __P((union node *));
void trputc __P((int));
-void trace __P((const char *, ...));
+void shtrace __P((const char *, ...));
void trputs __P((char *));
void trargs __P((char **));
void opentrace __P((void));
diff --git a/bin/sh/trap.c b/bin/sh/trap.c
index a09a0cf9..ec905d7 100644
--- a/bin/sh/trap.c
+++ b/bin/sh/trap.c
@@ -33,27 +33,30 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: trap.c,v 1.2 1994/09/24 02:58:18 davidg Exp $
+ * $Id: trap.c,v 1.3 1995/05/30 00:07:23 rgrimes Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)trap.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95";
#endif /* not lint */
+#include <signal.h>
+#include <unistd.h>
+#include <stdlib.h>
+
#include "shell.h"
#include "main.h"
#include "nodes.h" /* for other headers */
#include "eval.h"
#include "jobs.h"
+#include "show.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 <signal.h>
/*
@@ -71,22 +74,28 @@ static char sccsid[] = "@(#)trap.c 8.1 (Berkeley) 5/31/93";
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 */
+char *trap[NSIG+1]; /* trap handler commands */
+MKINIT char sigmode[NSIG]; /* current value of signal */
+char gotsig[NSIG]; /* indicates specified signal received */
int pendingsigs; /* indicates some signal received */
+static int getsigaction __P((int, sig_t *));
+
/*
* The trap builtin.
*/
-trapcmd(argc, argv) char **argv; {
+int
+trapcmd(argc, argv)
+ int argc;
+ char **argv;
+{
char *action;
char **ap;
int signo;
if (argc <= 1) {
- for (signo = 0 ; signo <= MAXSIG ; signo++) {
+ for (signo = 0 ; signo <= NSIG ; signo++) {
if (trap[signo] != NULL)
out1fmt("%d: %s\n", signo, trap[signo]);
}
@@ -98,7 +107,7 @@ trapcmd(argc, argv) char **argv; {
else
action = *ap++;
while (*ap) {
- if ((signo = number(*ap)) < 0 || signo > MAXSIG)
+ if ((signo = number(*ap)) < 0 || signo > NSIG)
error("%s: bad trap", *ap);
INTOFF;
if (action)
@@ -124,7 +133,7 @@ void
clear_traps() {
char **tp;
- for (tp = trap ; tp <= &trap[MAXSIG] ; tp++) {
+ for (tp = trap ; tp <= &trap[NSIG] ; tp++) {
if (*tp && **tp) { /* trap not NULL or SIG_IGN */
INTOFF;
ckfree(*tp);
@@ -143,13 +152,14 @@ clear_traps() {
* out what it should be set to.
*/
-int
-setsignal(signo) {
+long
+setsignal(signo)
+ int signo;
+{
int action;
- sig_t sigact;
+ sig_t sigact = SIG_DFL;
char *t;
extern void onsig();
- extern sig_t getsigaction();
if ((t = trap[signo]) == NULL)
action = S_DFL;
@@ -186,12 +196,20 @@ setsignal(signo) {
#endif
}
}
+
t = &sigmode[signo - 1];
if (*t == 0) {
/*
* current setting unknown
*/
- sigact = getsigaction(signo);
+ if (!getsigaction(signo, &sigact)) {
+ /*
+ * Pretend it worked; maybe we should give a warning
+ * here, but other shells don't. We don't alter
+ * sigmode, so that we retry every time.
+ */
+ return 0;
+ }
if (sigact == SIG_IGN) {
if (mflag && (signo == SIGTSTP ||
signo == SIGTTIN || signo == SIGTTOU)) {
@@ -210,20 +228,23 @@ setsignal(signo) {
case S_IGN: sigact = SIG_IGN; break;
}
*t = action;
- return (int)signal(signo, sigact);
+ return (long)signal(signo, sigact);
}
/*
* Return the current setting for sig w/o changing it.
*/
-sig_t
-getsigaction(signo) {
+static int
+getsigaction(signo, sigact)
+ int signo;
+ sig_t *sigact;
+{
struct sigaction sa;
if (sigaction(signo, (struct sigaction *)0, &sa) == -1)
- error("Sigaction system call failed");
-
- return sa.sa_handler;
+ return 0;
+ *sigact = (sig_t) sa.sa_handler;
+ return 1;
}
/*
@@ -231,7 +252,9 @@ getsigaction(signo) {
*/
void
-ignoresig(signo) {
+ignoresig(signo)
+ int signo;
+{
if (sigmode[signo - 1] != S_IGN && sigmode[signo - 1] != S_HARD_IGN) {
signal(signo, SIG_IGN);
}
@@ -240,14 +263,14 @@ ignoresig(signo) {
#ifdef mkinit
-INCLUDE "signames.h"
+INCLUDE <signal.h>
INCLUDE "trap.h"
SHELLPROC {
char *sm;
clear_traps();
- for (sm = sigmode ; sm < sigmode + MAXSIG ; sm++) {
+ for (sm = sigmode ; sm < sigmode + NSIG ; sm++) {
if (*sm == S_IGN)
*sm = S_HARD_IGN;
}
@@ -261,7 +284,9 @@ SHELLPROC {
*/
void
-onsig(signo) {
+onsig(signo)
+ int signo;
+{
signal(signo, onsig);
if (signo == SIGINT && trap[SIGINT] == NULL) {
onint();
@@ -287,7 +312,7 @@ dotrap() {
for (i = 1 ; ; i++) {
if (gotsig[i - 1])
break;
- if (i >= MAXSIG)
+ if (i >= NSIG)
goto done;
}
gotsig[i - 1] = 0;
@@ -307,7 +332,9 @@ done:
void
-setinteractive(on) {
+setinteractive(on)
+ int on;
+{
static int is_interactive;
if (on == is_interactive)
@@ -325,7 +352,9 @@ setinteractive(on) {
*/
void
-exitshell(status) {
+exitshell(status)
+ int status;
+{
struct jmploc loc1, loc2;
char *p;
diff --git a/bin/sh/trap.h b/bin/sh/trap.h
index a588432..f63af1a 100644
--- a/bin/sh/trap.h
+++ b/bin/sh/trap.h
@@ -33,24 +33,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)trap.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)trap.h 8.3 (Berkeley) 6/5/95
+ * $Id: trap.h,v 1.2 1994/09/24 02:58:20 davidg Exp $
*/
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
+int trapcmd __P((int, char **));
+void clear_traps __P((void));
+long setsignal __P((int));
+void ignoresig __P((int));
+void onsig __P((int));
+void dotrap __P((void));
+void setinteractive __P((int));
+void exitshell __P((int));
diff --git a/bin/sh/var.c b/bin/sh/var.c
index e452001..14de566 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -33,13 +33,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: var.c,v 1.4 1996/08/11 22:51:00 ache Exp $
+ * $Id: var.c,v 1.5 1996/08/12 22:14:50 ache Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)var.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95";
#endif /* not lint */
+#include <unistd.h>
+#include <stdlib.h>
+
/*
* Shell variables.
*/
@@ -60,6 +63,9 @@ static char sccsid[] = "@(#)var.c 8.1 (Berkeley) 5/31/93";
#include "memalloc.h"
#include "error.h"
#include "mystring.h"
+#ifndef NO_HISTORY
+#include "myhistedit.h"
+#endif
#define VTABSIZE 39
@@ -75,7 +81,9 @@ struct varinit {
#if ATTY
struct var vatty;
#endif
+#ifndef NO_HISTORY
struct var vhistsize;
+#endif
struct var vifs;
struct var vmail;
struct var vmpath;
@@ -91,11 +99,13 @@ const struct varinit varinit[] = {
#if ATTY
{&vatty, VSTRFIXED|VTEXTFIXED|VUNSET, "ATTY="},
#endif
+#ifndef NO_HISTORY
{&vhistsize, VSTRFIXED|VTEXTFIXED|VUNSET, "HISTSIZE="},
+#endif
{&vifs, VSTRFIXED|VTEXTFIXED, "IFS= \t\n"},
{&vmail, VSTRFIXED|VTEXTFIXED|VUNSET, "MAIL="},
{&vmpath, VSTRFIXED|VTEXTFIXED|VUNSET, "MAILPATH="},
- {&vpath, VSTRFIXED|VTEXTFIXED, "PATH=:/bin:/usr/bin"},
+ {&vpath, VSTRFIXED|VTEXTFIXED, "PATH=/bin:/usr/bin"},
/*
* vps1 depends on uid
*/
@@ -173,7 +183,8 @@ initvar() {
void
setvar(name, val, flags)
char *name, *val;
- {
+ int flags;
+{
char *p, *q;
int len;
int namelen;
@@ -245,7 +256,8 @@ localevar(s)
void
setvareq(s, flags)
char *s;
- {
+ int flags;
+{
struct var *vp, **vpp;
vpp = hashvar(s);
@@ -265,8 +277,10 @@ setvareq(s, flags)
vp->text = s;
if (vp == &vmpath || (vp == &vmail && ! mpathset()))
chkmail(1);
+#ifndef NO_HISTORY
if (vp == &vhistsize)
sethistsize();
+#endif
if ((vp->flags & VEXPORT) && localevar(s)) {
putenv(s);
(void) setlocale(LC_ALL, "");
@@ -341,7 +355,8 @@ lookupvar(name)
char *
bltinlookup(name, doall)
char *name;
- {
+ int doall;
+{
struct strlist *sp;
struct var *v;
@@ -351,8 +366,8 @@ bltinlookup(name, doall)
}
for (v = *hashvar(name) ; v ; v = v->next) {
if (varequal(v->text, name)) {
- if (v->flags & VUNSET
- || ! doall && (v->flags & VEXPORT) == 0)
+ if ((v->flags & VUNSET)
+ || (!doall && (v->flags & VEXPORT) == 0))
return NULL;
return strchr(v->text, '=') + 1;
}
@@ -439,7 +454,10 @@ shprocvar() {
*/
int
-showvarscmd(argc, argv) char **argv; {
+showvarscmd(argc, argv)
+ int argc;
+ char **argv;
+{
struct var **vpp;
struct var *vp;
@@ -459,7 +477,10 @@ showvarscmd(argc, argv) char **argv; {
*/
int
-exportcmd(argc, argv) char **argv; {
+exportcmd(argc, argv)
+ int argc;
+ char **argv;
+{
struct var **vpp;
struct var *vp;
char *name;
@@ -506,7 +527,11 @@ found:;
* The "local" command.
*/
-localcmd(argc, argv) char **argv; {
+int
+localcmd(argc, argv)
+ int argc;
+ char **argv;
+{
char *name;
if (! in_function())
@@ -537,7 +562,7 @@ mklocal(name)
lvp = ckmalloc(sizeof (struct localvar));
if (name[0] == '-' && name[1] == '\0') {
lvp->text = ckmalloc(sizeof optlist);
- bcopy(optlist, lvp->text, sizeof optlist);
+ memcpy(lvp->text, optlist, sizeof optlist);
vp = NULL;
} else {
vpp = hashvar(name);
@@ -578,7 +603,7 @@ poplocalvars() {
localvars = lvp->next;
vp = lvp->vp;
if (vp == NULL) { /* $- saved */
- bcopy(lvp->text, optlist, sizeof optlist);
+ memcpy(optlist, lvp->text, sizeof optlist);
ckfree(lvp->text);
} else if ((lvp->flags & (VUNSET|VSTRFIXED)) == VUNSET) {
(void)unsetvar(vp->text);
@@ -593,7 +618,11 @@ poplocalvars() {
}
-setvarcmd(argc, argv) char **argv; {
+int
+setvarcmd(argc, argv)
+ int argc;
+ char **argv;
+{
if (argc <= 2)
return unsetcmd(argc, argv);
else if (argc == 3)
@@ -610,7 +639,11 @@ setvarcmd(argc, argv) char **argv; {
* with the same name.
*/
-unsetcmd(argc, argv) char **argv; {
+int
+unsetcmd(argc, argv)
+ int argc;
+ char **argv;
+{
char **ap;
int i;
int flg_func = 0;
diff --git a/bin/sh/var.h b/bin/sh/var.h
index 38e61ef..c07b22e 100644
--- a/bin/sh/var.h
+++ b/bin/sh/var.h
@@ -33,8 +33,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)var.h 8.1 (Berkeley) 5/31/93
- * $Id$
+ * @(#)var.h 8.2 (Berkeley) 5/4/95
+ * $Id: var.h,v 1.2 1994/09/24 02:58:23 davidg Exp $
*/
/*
@@ -101,28 +101,19 @@ extern struct var vterm;
#endif
#define mpathset() ((vmpath.flags & VUNSET) == 0)
-
-#ifdef __STDC__
-void initvar();
-void setvar(char *, char *, int);
-void setvareq(char *, int);
+void initvar __P((void));
+void setvar __P((char *, char *, int));
+void setvareq __P((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
+void listsetvar __P((struct strlist *));
+char *lookupvar __P((char *));
+char *bltinlookup __P((char *, int));
+char **environment __P((void));
+void shprocvar __P((void));
+int showvarscmd __P((int, char **));
+int exportcmd __P((int, char **));
+int localcmd __P((int, char **));
+void mklocal __P((char *));
+void poplocalvars __P((void));
+int setvarcmd __P((int, char **));
+int unsetcmd __P((int, char **));
OpenPOWER on IntegriCloud