diff --git a/check.t b/check.t index afe2179..e9e122f 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.390 2010/08/28 20:22:13 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.391 2010/09/05 19:51:29 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -25,7 +25,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R39 2010/08/28 + @(#)MIRBSD KSH R39 2010/09/05 description: Check version of shell. stdin: diff --git a/edit.c b/edit.c index 80bedbb..766e57f 100644 --- a/edit.c +++ b/edit.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.199 2010/08/28 20:22:15 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.200 2010/09/05 19:51:31 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -2403,7 +2403,7 @@ x_bind(const char *a1, const char *a2, m1 = msg; while (*c && m1 < (msg + sizeof(msg) - 3)) x_mapout2(*c++, &m1); - bi_errorf("%s: %s '%s'", "bind", "too long key sequence", msg); + bi_errorf("%s: %s", "too long key sequence", msg); return (1); } #ifndef MKSH_SMALL diff --git a/exec.c b/exec.c index 41e48d0..801b120 100644 --- a/exec.c +++ b/exec.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.80 2010/08/28 20:22:17 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.81 2010/09/05 19:51:32 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL "/bin/sh" @@ -444,12 +444,12 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap, /* undo effects of command */ fcflags = FC_BI|FC_FUNC|FC_PATH; if (tp->val.f == c_builtin) { - if ((cp = *++ap) == NULL) { + if ((cp = *++ap) == NULL || + (!strcmp(cp, "--") && (cp = *++ap) == NULL)) { tp = NULL; break; } - tp = findcom(cp, FC_BI); - if (tp == NULL) + if ((tp = findcom(cp, FC_BI)) == NULL) errorf("%s: %s: %s", T_builtin, cp, "not a builtin"); continue; } else if (tp->val.f == c_exec) { diff --git a/funcs.c b/funcs.c index 72997db..6784a68 100644 --- a/funcs.c +++ b/funcs.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.160 2010/08/28 20:22:17 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.161 2010/09/05 19:51:33 tg Exp $"); #if HAVE_KILLPG /* @@ -2678,7 +2678,7 @@ c_mknod(const char **wp) goto c_mknod_failed; } else if (mkfifo(argv[0], mode)) { c_mknod_failed: - bi_errorf("%s: %s", *wp, strerror(errno)); + bi_errorf("%s: %s", argv[0], strerror(errno)); c_mknod_err: rv = 1; } @@ -2693,13 +2693,6 @@ c_mknod(const char **wp) } #endif -/* dummy function, special case in comexec() */ -int -c_builtin(const char **wp MKSH_A_UNUSED) -{ - return (0); -} - /* test(1) accepts the following grammar: oexpr ::= aexpr | aexpr "-o" oexpr ; aexpr ::= nexpr | nexpr "-a" aexpr ; @@ -3397,13 +3390,18 @@ c_rename(const char **wp) { int rv = 1; - if (wp == NULL /* argv */ || - wp[0] == NULL /* name of builtin */ || - wp[1] == NULL /* first argument */ || - wp[2] == NULL /* second argument */ || - wp[3] != NULL /* no further args please */) + /* skip argv[0] */ + ++wp; + if (wp[0] && !strcmp(wp[0], "--")) + /* skip "--" (options separator) */ + ++wp; + + /* check for exactly two arguments */ + if (wp[0] == NULL /* first argument */ || + wp[1] == NULL /* second argument */ || + wp[2] != NULL /* no further args please */) bi_errorf(T_synerr); - else if ((rv = rename(wp[1], wp[2])) != 0) { + else if ((rv = rename(wp[0], wp[1])) != 0) { rv = errno; bi_errorf("%s: %s", "failed", strerror(rv)); } @@ -3417,30 +3415,24 @@ c_realpath(const char **wp) int rv = 1; char *buf; - if (wp != NULL && wp[0] != NULL && wp[1] != NULL) { - if (strcmp(wp[1], "--")) { - if (wp[2] == NULL) { - wp += 1; - rv = 0; - } - } else { - if (wp[2] != NULL && wp[3] == NULL) { - wp += 2; - rv = 0; - } - } - } + /* skip argv[0] */ + ++wp; + if (wp[0] && !strcmp(wp[0], "--")) + /* skip "--" (options separator) */ + ++wp; - if (rv) + /* check for exactly one argument */ + if (wp[0] == NULL || wp[1] != NULL) bi_errorf(T_synerr); - else if ((buf = do_realpath(*wp)) == NULL) { + else if ((buf = do_realpath(wp[0])) == NULL) { rv = errno; - bi_errorf("%s: %s", *wp, strerror(rv)); + bi_errorf("%s: %s", wp[0], strerror(rv)); if ((unsigned int)rv > 255) rv = 255; } else { shprintf("%s\n", buf); afree(buf, ATEMP); + rv = 0; } return (rv); @@ -3462,9 +3454,11 @@ c_cat(const char **wp) return (1); } - ++wp; /* argv[0] */ - if (wp[0] && wp[0][0] == '-' && wp[0][1] == '-' && wp[0][2] == '\0') - ++wp; /* "--" (options separator) */ + /* skip argv[0] */ + ++wp; + if (wp[0] && !strcmp(wp[0], "--")) + /* skip "--" (options separator) */ + ++wp; do { if (*wp) { diff --git a/mksh.1 b/mksh.1 index 05f34d6..5b35390 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.238 2010/09/05 19:12:24 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.239 2010/09/05 19:51:33 tg Exp $ .\" $OpenBSD: ksh.1,v 1.136 2010/07/15 20:04:35 schwarze Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 @@ -2961,7 +2961,11 @@ loop. .Ar level defaults to 1. .Pp -.It Ic builtin Ar command Op Ar arg ... +.It Xo +.Ic builtin +.Op Fl \- +.Ar command Op Ar arg ... +.Xc Execute the built-in command .Ar command . .Pp @@ -3657,7 +3661,11 @@ it's also checked for existence and whether it is a directory; otherwise, returns 0 if the pathname either exists or can be created immediately, i.e. all but the last component exist and are directories. .Pp -.It Ic rename Ar from to +.It Xo +.Ic rename +.Op Fl \- +.Ar from to +.Xc Renames the file .Ar from to diff --git a/sh.h b/sh.h index 309a00f..b08b419 100644 --- a/sh.h +++ b/sh.h @@ -150,9 +150,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.411 2010/08/28 20:22:22 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.412 2010/09/05 19:51:35 tg Exp $"); #endif -#define MKSH_VERSION "R39 2010/08/28" +#define MKSH_VERSION "R39 2010/09/05" #ifndef MKSH_INCLUDES_ONLY @@ -1475,7 +1475,8 @@ int c_times(const char **); int timex(struct op *, int, volatile int *); void timex_hook(struct op *, char ** volatile *); int c_exec(const char **); -int c_builtin(const char **); +/* dummy function (just need pointer value), special case in comexec() */ +#define c_builtin shcomexec int c_test(const char **); #if HAVE_MKNOD int c_mknod(const char **);