optimise error messages, option parsing, and make more builtins
recognise "--", costs us 20 .text 0 .data 0 .bss
This commit is contained in:
4
check.t
4
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: 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: 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 $
|
# $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
|
# http://www.research.att.com/~gsf/public/ifs.sh
|
||||||
|
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
@(#)MIRBSD KSH R39 2010/08/28
|
@(#)MIRBSD KSH R39 2010/09/05
|
||||||
description:
|
description:
|
||||||
Check version of shell.
|
Check version of shell.
|
||||||
stdin:
|
stdin:
|
||||||
|
4
edit.c
4
edit.c
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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
|
* 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;
|
m1 = msg;
|
||||||
while (*c && m1 < (msg + sizeof(msg) - 3))
|
while (*c && m1 < (msg + sizeof(msg) - 3))
|
||||||
x_mapout2(*c++, &m1);
|
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);
|
return (1);
|
||||||
}
|
}
|
||||||
#ifndef MKSH_SMALL
|
#ifndef MKSH_SMALL
|
||||||
|
8
exec.c
8
exec.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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
|
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
#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 */
|
/* undo effects of command */
|
||||||
fcflags = FC_BI|FC_FUNC|FC_PATH;
|
fcflags = FC_BI|FC_FUNC|FC_PATH;
|
||||||
if (tp->val.f == c_builtin) {
|
if (tp->val.f == c_builtin) {
|
||||||
if ((cp = *++ap) == NULL) {
|
if ((cp = *++ap) == NULL ||
|
||||||
|
(!strcmp(cp, "--") && (cp = *++ap) == NULL)) {
|
||||||
tp = NULL;
|
tp = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tp = findcom(cp, FC_BI);
|
if ((tp = findcom(cp, FC_BI)) == NULL)
|
||||||
if (tp == NULL)
|
|
||||||
errorf("%s: %s: %s", T_builtin, cp, "not a builtin");
|
errorf("%s: %s: %s", T_builtin, cp, "not a builtin");
|
||||||
continue;
|
continue;
|
||||||
} else if (tp->val.f == c_exec) {
|
} else if (tp->val.f == c_exec) {
|
||||||
|
62
funcs.c
62
funcs.c
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -2678,7 +2678,7 @@ c_mknod(const char **wp)
|
|||||||
goto c_mknod_failed;
|
goto c_mknod_failed;
|
||||||
} else if (mkfifo(argv[0], mode)) {
|
} else if (mkfifo(argv[0], mode)) {
|
||||||
c_mknod_failed:
|
c_mknod_failed:
|
||||||
bi_errorf("%s: %s", *wp, strerror(errno));
|
bi_errorf("%s: %s", argv[0], strerror(errno));
|
||||||
c_mknod_err:
|
c_mknod_err:
|
||||||
rv = 1;
|
rv = 1;
|
||||||
}
|
}
|
||||||
@ -2693,13 +2693,6 @@ c_mknod(const char **wp)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* dummy function, special case in comexec() */
|
|
||||||
int
|
|
||||||
c_builtin(const char **wp MKSH_A_UNUSED)
|
|
||||||
{
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* test(1) accepts the following grammar:
|
/* test(1) accepts the following grammar:
|
||||||
oexpr ::= aexpr | aexpr "-o" oexpr ;
|
oexpr ::= aexpr | aexpr "-o" oexpr ;
|
||||||
aexpr ::= nexpr | nexpr "-a" aexpr ;
|
aexpr ::= nexpr | nexpr "-a" aexpr ;
|
||||||
@ -3397,13 +3390,18 @@ c_rename(const char **wp)
|
|||||||
{
|
{
|
||||||
int rv = 1;
|
int rv = 1;
|
||||||
|
|
||||||
if (wp == NULL /* argv */ ||
|
/* skip argv[0] */
|
||||||
wp[0] == NULL /* name of builtin */ ||
|
++wp;
|
||||||
wp[1] == NULL /* first argument */ ||
|
if (wp[0] && !strcmp(wp[0], "--"))
|
||||||
wp[2] == NULL /* second argument */ ||
|
/* skip "--" (options separator) */
|
||||||
wp[3] != NULL /* no further args please */)
|
++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);
|
bi_errorf(T_synerr);
|
||||||
else if ((rv = rename(wp[1], wp[2])) != 0) {
|
else if ((rv = rename(wp[0], wp[1])) != 0) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
bi_errorf("%s: %s", "failed", strerror(rv));
|
bi_errorf("%s: %s", "failed", strerror(rv));
|
||||||
}
|
}
|
||||||
@ -3417,30 +3415,24 @@ c_realpath(const char **wp)
|
|||||||
int rv = 1;
|
int rv = 1;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
if (wp != NULL && wp[0] != NULL && wp[1] != NULL) {
|
/* skip argv[0] */
|
||||||
if (strcmp(wp[1], "--")) {
|
++wp;
|
||||||
if (wp[2] == NULL) {
|
if (wp[0] && !strcmp(wp[0], "--"))
|
||||||
wp += 1;
|
/* skip "--" (options separator) */
|
||||||
rv = 0;
|
++wp;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (wp[2] != NULL && wp[3] == NULL) {
|
|
||||||
wp += 2;
|
|
||||||
rv = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rv)
|
/* check for exactly one argument */
|
||||||
|
if (wp[0] == NULL || wp[1] != NULL)
|
||||||
bi_errorf(T_synerr);
|
bi_errorf(T_synerr);
|
||||||
else if ((buf = do_realpath(*wp)) == NULL) {
|
else if ((buf = do_realpath(wp[0])) == NULL) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
bi_errorf("%s: %s", *wp, strerror(rv));
|
bi_errorf("%s: %s", wp[0], strerror(rv));
|
||||||
if ((unsigned int)rv > 255)
|
if ((unsigned int)rv > 255)
|
||||||
rv = 255;
|
rv = 255;
|
||||||
} else {
|
} else {
|
||||||
shprintf("%s\n", buf);
|
shprintf("%s\n", buf);
|
||||||
afree(buf, ATEMP);
|
afree(buf, ATEMP);
|
||||||
|
rv = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (rv);
|
return (rv);
|
||||||
@ -3462,9 +3454,11 @@ c_cat(const char **wp)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
++wp; /* argv[0] */
|
/* skip argv[0] */
|
||||||
if (wp[0] && wp[0][0] == '-' && wp[0][1] == '-' && wp[0][2] == '\0')
|
++wp;
|
||||||
++wp; /* "--" (options separator) */
|
if (wp[0] && !strcmp(wp[0], "--"))
|
||||||
|
/* skip "--" (options separator) */
|
||||||
|
++wp;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (*wp) {
|
if (*wp) {
|
||||||
|
14
mksh.1
14
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 $
|
.\" $OpenBSD: ksh.1,v 1.136 2010/07/15 20:04:35 schwarze Exp $
|
||||||
.\"-
|
.\"-
|
||||||
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
|
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
|
||||||
@ -2961,7 +2961,11 @@ loop.
|
|||||||
.Ar level
|
.Ar level
|
||||||
defaults to 1.
|
defaults to 1.
|
||||||
.Pp
|
.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
|
Execute the built-in command
|
||||||
.Ar command .
|
.Ar command .
|
||||||
.Pp
|
.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,
|
returns 0 if the pathname either exists or can be created immediately,
|
||||||
i.e. all but the last component exist and are directories.
|
i.e. all but the last component exist and are directories.
|
||||||
.Pp
|
.Pp
|
||||||
.It Ic rename Ar from to
|
.It Xo
|
||||||
|
.Ic rename
|
||||||
|
.Op Fl \-
|
||||||
|
.Ar from to
|
||||||
|
.Xc
|
||||||
Renames the file
|
Renames the file
|
||||||
.Ar from
|
.Ar from
|
||||||
to
|
to
|
||||||
|
7
sh.h
7
sh.h
@ -150,9 +150,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#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
|
#endif
|
||||||
#define MKSH_VERSION "R39 2010/08/28"
|
#define MKSH_VERSION "R39 2010/09/05"
|
||||||
|
|
||||||
#ifndef MKSH_INCLUDES_ONLY
|
#ifndef MKSH_INCLUDES_ONLY
|
||||||
|
|
||||||
@ -1475,7 +1475,8 @@ int c_times(const char **);
|
|||||||
int timex(struct op *, int, volatile int *);
|
int timex(struct op *, int, volatile int *);
|
||||||
void timex_hook(struct op *, char ** volatile *);
|
void timex_hook(struct op *, char ** volatile *);
|
||||||
int c_exec(const char **);
|
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 **);
|
int c_test(const char **);
|
||||||
#if HAVE_MKNOD
|
#if HAVE_MKNOD
|
||||||
int c_mknod(const char **);
|
int c_mknod(const char **);
|
||||||
|
Reference in New Issue
Block a user