aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2018-04-04 17:06:51 +0200
committerDuncaen <mail@duncano.de>2018-04-04 17:32:09 +0200
commit15d187865a3628ae7c899a6c0e42a1fcd943d70e (patch)
tree8ce5715f682421dc6743504560130df029dd43c0
parent35744ad3cb26064253a67907c60c8d5de9acb345 (diff)
downloadlobase-15d187865a3628ae7c899a6c0e42a1fcd943d70e.tar.gz
bin/ksh: update to OPENBSD_6_3
-rw-r--r--bin/ksh/Makefile5
-rw-r--r--bin/ksh/NOTES23
-rw-r--r--bin/ksh/PROJECTS49
-rw-r--r--bin/ksh/alloc.c12
-rw-r--r--bin/ksh/c_ksh.c19
-rw-r--r--bin/ksh/c_sh.c16
-rw-r--r--bin/ksh/c_test.c45
-rw-r--r--bin/ksh/c_ulimit.c20
-rw-r--r--bin/ksh/config.h22
-rw-r--r--bin/ksh/edit.c20
-rw-r--r--bin/ksh/emacs.c265
-rw-r--r--bin/ksh/eval.c30
-rw-r--r--bin/ksh/exec.c21
-rw-r--r--bin/ksh/expand.h6
-rw-r--r--bin/ksh/history.c34
-rw-r--r--bin/ksh/io.c38
-rw-r--r--bin/ksh/jobs.c149
-rw-r--r--bin/ksh/ksh.129
-rw-r--r--bin/ksh/lex.c33
-rw-r--r--bin/ksh/lex.h11
-rw-r--r--bin/ksh/main.c28
-rw-r--r--bin/ksh/misc.c119
-rw-r--r--bin/ksh/path.c4
-rw-r--r--bin/ksh/sh.127
-rw-r--r--bin/ksh/sh.h26
-rw-r--r--bin/ksh/shf.c38
-rw-r--r--bin/ksh/table.c6
-rw-r--r--bin/ksh/table.h4
-rw-r--r--bin/ksh/trap.c6
-rw-r--r--bin/ksh/tree.c43
-rw-r--r--bin/ksh/tty.c6
-rw-r--r--bin/ksh/var.c39
-rw-r--r--bin/ksh/vi.c35
33 files changed, 480 insertions, 748 deletions
diff --git a/bin/ksh/Makefile b/bin/ksh/Makefile
index 542a3bd..880eab2 100644
--- a/bin/ksh/Makefile
+++ b/bin/ksh/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.34 2017/08/01 14:30:05 deraadt Exp $
+# $OpenBSD: Makefile,v 1.38 2018/01/06 16:28:58 millert Exp $
.TOPDIR?=../..
@@ -8,7 +8,8 @@ SRCS= alloc.c c_ksh.c c_sh.c c_test.c c_ulimit.c edit.c emacs.c eval.c \
misc.c path.c shf.c syn.c table.c trap.c tree.c tty.c var.c \
version.c vi.c
-DEFS= -Wall -DEMACS -DVI
+WARNINGS=yes
+DEFS= -DEMACS -DVI
CFLAGS+=${DEFS} -I. -I${.CURDIR} -I${.CURDIR}/../../lib/libopenbsd/gen
MAN= ksh.1 sh.1
diff --git a/bin/ksh/NOTES b/bin/ksh/NOTES
index 5fc1080..5bda635 100644
--- a/bin/ksh/NOTES
+++ b/bin/ksh/NOTES
@@ -1,4 +1,4 @@
-$OpenBSD: NOTES,v 1.14 2016/01/29 11:50:40 tb Exp $
+$OpenBSD: NOTES,v 1.16 2018/01/12 14:20:57 jca Exp $
General features of at&t ksh88 that are not (yet) in pdksh:
- exported aliases and functions (not in ksh93).
@@ -6,13 +6,10 @@ General features of at&t ksh88 that are not (yet) in pdksh:
- signals/traps not cleared during functions.
- trap DEBUG, local ERR and EXIT traps in functions.
- ERRNO parameter.
- - doesn't have posix file globbing (eg, [[:alpha:]], etc.).
- - use of an `agent' to execute unreadable/setuid/setgid shell scripts
- (don't ask).
- read/select aren't hooked in to the command line editor
- the last command of a pipeline is not run in the parent shell
-Known bugs (see also BUG-REPORTS and PROJECTS files):
+Known bugs (see also PROJECTS files):
Variable parsing, Expansion:
- some specials behave differently when unset (eg, IFS behaves like
" \t\n") others lose their special meaning. IFS/PATH taken care of,
@@ -26,15 +23,14 @@ Known bugs (see also BUG-REPORTS and PROJECTS files):
Commands,Execution:
- setting special parameters that have side effects when
changed/restored (ie, HISTFILE, OPTIND, RANDOM) in front
- of a command (eg, HISTFILE=/foo/bar echo hi) effects the parent
+ of a command (eg, HISTFILE=/foo/bar echo hi) affects the parent
shell. Note that setting other (not so special) parameters
- does not effect the parent shell.
+ does not affect the parent shell.
- `echo hi | exec cat -n' causes at&t to exit, `exec echo hi | cat -n'
does not. pdksh exits for neither. Don't think POSIX requires
an exit, but not sure.
- `echo foo | read bar; echo $bar' prints foo in at&t ksh, nothing
in pdksh (ie, the read is done in a separate process in pdksh).
- Misc:
Known problems not caused by ksh:
- after stoping a job, emacs/vi is not re-entered. Hitting return
@@ -241,23 +237,21 @@ Oddities in ksh (pd & at&t):
- when tracing (set -x), and a command's stderr is redirected, the trace
output is also redirected. so "set -x; echo foo 2> /tmp/O > /dev/null"
will create /tmp/foo with the lines "+ > /dev/null" and "+ echo foo".
- - undocumented at&t ksh feature: FPATH is searched after PATH if no
- executable is found, even if typeset -uf wasn't used.
+ - undocumented at&t ksh88, documented in ksh93: FPATH is searched
+ after PATH if no executable is found, even if typeset -uf wasn't used.
POSIX sh questions (references are to POSIX 1003.2-1992)
- arithmetic expressions: how are empty expressions treated?
(eg, echo $(( ))). at&t ksh (and now pdksh) echo 0.
Same question goes for `test "" -eq 0' - does this generate an error
or, if not, what is the exit code?
- - should tilde expansion occur after :'s in the word part of ${..=..}?
- (me thinks it should)
- if a signal is received during the execution of a built-in,
does the builtin command exit or the whole shell?
- is it legal to execute last command of pipeline in current
execution environment (eg, can "echo foo | read bar" set
bar?)
- what action should be taken if there is an error doing a dup due
- to system limits (eg, not enough feil destriptors): is this
+ to system limits (eg, not enough file destriptors): is this
a "redirection error" (in which case a script will exit iff the
error occured while executing a special built-in)?
IMHO, shell should exit script. Couldn't find a blanket statement
@@ -280,9 +274,6 @@ POSIX sh bugs (references are to POSIX 1003.2-1992)
functions don't do the save/restore automatically). Restoring
OPTIND is kind of dumb since getopts may have been in the middle
of parsing a group of flags (eg, -abc).
- - unclear whether arithmetic expressions (eg, $((..))) should
- understand C integer constants (ie, 0x123, 0177). at&t ksh doesn't
- and neither does pdksh.
- `...` definition (3.6.3) says nothing about backslash followed by
a newline, which sh and at&t ksh strip out completely. e.g.,
$ show-args `echo 'X
diff --git a/bin/ksh/PROJECTS b/bin/ksh/PROJECTS
index 0be0e85..720620b 100644
--- a/bin/ksh/PROJECTS
+++ b/bin/ksh/PROJECTS
@@ -1,4 +1,4 @@
-$OpenBSD: PROJECTS,v 1.8 2015/09/14 09:42:33 nicm Exp $
+$OpenBSD: PROJECTS,v 1.9 2018/01/08 12:08:17 jca Exp $
Things to be done in pdksh (see also the NOTES file):
@@ -22,31 +22,11 @@ Things to be done in pdksh (see also the NOTES file):
(ulimit also needs to be examined to check that it fits the posix style)
- * test suite
- Ideally, as the builtin utilities are being POSIXized, short tests
- should be written to be used in regression testing. The tests
- directory contains some tests, but many more need to be written.
-
- * internationalization
- Need to handle with the LANG and LC_* environment variables. This
- involves changes to ensure <ctype.h> macros are being used (currently
- uses its own macros in many places), figuring out how to deal with
- bases (for integer arithmetic, eg, 12#1A), and (the nasty one) doing
- string look ups for error messages, etc.. It probably isn't worth
- translating strings to other languages yet as the code is likely
- to change a lot in the near future, but it would be good to have the
- code set up so string tables can be used.
-
* trap code
* add the DEBUG trap.
* fix up signal handling code. In particular, fatal vs tty signals,
have signal routine to call to check for pending/fatal traps, etc.
- * parsing
- * the time keyword needs to be hacked to accept options (!) since
- POSIX says it shall accept the -p option and must skip a -- argument
- (end of options). Yuck.
-
* lexing
the lexing may need a re-write since it currently doesn't parse $( .. ),
$(( .. )), (( ... )) properly.
@@ -68,30 +48,10 @@ Things to be done in pdksh (see also the NOTES file):
in general, treatment of OPTIND/OPTARG,
* history
- There are two versions of the history code, COMPLEX_HISTORY and
- EASY_HISTORY, which need to be merged. COMPLEX does at&t style history
- where the history file is written after each command and checked when
- ever looking through the history (in case another shell has added
- something). EASY simply reads the history file at startup and writes
- it before exiting.
- * re-write the COMPLEX_HISTORY code so mmap() not needed (currently
- can't be used on machines without mmap()).
- * Add multiline knowledge to COMPLEX_HISTORY (see EASY_HISTORY
- stuff).
- * change COMPLEX_HISTORY code so concurrent history files are
- controlled by an option (set -o history-concurrent?). Delete
- the EASY_HISTORY code.
+ * Add multiline knowledge
* bring history code up to POSIX standards (see POSIX description
of fc, etc.).
- * documentation
- Some sort of tutorial with examples would be good. Texinfo is probably
- the best medium for this. Also, the man page could be converted to
- texinfo (if the tutorial and man page are put in the same texinfo
- page, they should be somewhat distinct - i.e., the tutorial should
- be a separate thread - but there should be cross references between the
- two).
-
* miscellaneous
* POSIX specifies what happens when various kinds of errors occur
in special built-ins commands vs regular commands (builtin or
@@ -104,8 +64,3 @@ Things to be done in pdksh (see also the NOTES file):
* merge the emacs and vi code (should reduce the size of the shell and
make maintenance easier); handle SIGWINCH while editing a line.
[John Rochester is working on the merge]
-
- * add POSIX globbing (eg, [[:alnum:]]), see POSIX.2:2.8.3.2.
-
- * teach shf_vfprintf() about long long's (%lld); also make %p use
- long longs if appropriate.
diff --git a/bin/ksh/alloc.c b/bin/ksh/alloc.c
index e3129bf..204e835 100644
--- a/bin/ksh/alloc.c
+++ b/bin/ksh/alloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: alloc.c,v 1.18 2017/11/02 06:55:35 tb Exp $ */
+/* $OpenBSD: alloc.c,v 1.19 2018/01/16 22:52:32 jca Exp $ */
/* Public domain, like most of the rest of ksh */
@@ -45,11 +45,11 @@ alloc(size_t size, Area *ap)
/* ensure that we don't overflow by allocating space for link */
if (size > SIZE_MAX - sizeof(struct link))
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
l = malloc(sizeof(struct link) + size);
if (l == NULL)
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
l->next = ap->freelist;
l->prev = NULL;
if (ap->freelist)
@@ -73,7 +73,7 @@ areallocarray(void *ptr, size_t nmemb, size_t size, Area *ap)
/* condition logic cloned from calloc() */
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && SIZE_MAX / nmemb < size) {
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
}
return aresize(ptr, nmemb * size, ap);
@@ -89,7 +89,7 @@ aresize(void *ptr, size_t size, Area *ap)
/* ensure that we don't overflow by allocating space for link */
if (size > SIZE_MAX - sizeof(struct link))
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
l = P2L(ptr);
lprev = l->prev;
@@ -97,7 +97,7 @@ aresize(void *ptr, size_t size, Area *ap)
l2 = realloc(l, sizeof(struct link) + size);
if (l2 == NULL)
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
if (lprev)
lprev->next = l2;
else
diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c
index ac10540..87aedf6 100644
--- a/bin/ksh/c_ksh.c
+++ b/bin/ksh/c_ksh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_ksh.c,v 1.51 2017/09/03 11:52:01 jca Exp $ */
+/* $OpenBSD: c_ksh.c,v 1.59 2018/03/15 16:51:29 anton Exp $ */
/*
* built-in Korn commands: c_*
@@ -941,8 +941,8 @@ c_alias(char **wp)
afree(ap->val.s, APERM);
}
/* ignore values for -t (at&t ksh does this) */
- newval = tflag ? search(alias, path, X_OK, NULL) :
- val;
+ newval = tflag ? search(alias, search_path, X_OK, NULL)
+ : val;
if (newval) {
ap->val.s = str_save(newval, APERM);
ap->flag |= ALLOC|ISSET;
@@ -1068,7 +1068,6 @@ c_jobs(char **wp)
return rv;
}
-#ifdef JOBS
int
c_fgbg(char **wp)
{
@@ -1092,7 +1091,6 @@ c_fgbg(char **wp)
*/
return (bg || Flag(FPOSIX)) ? 0 : rv;
}
-#endif
struct kill_info {
int num_width;
@@ -1184,7 +1182,7 @@ c_kill(char **wp)
shprintf("%s%s", p, sigtraps[i].name);
shprintf("\n");
} else {
- int mess_width = 0, w, i;
+ int mess_width = 0, w;
struct kill_info ki = {
.num_width = 1,
.name_width = 0,
@@ -1194,7 +1192,8 @@ c_kill(char **wp)
ki.num_width++;
for (i = 0; i < NSIG; i++) {
- w = sigtraps[i].name ? strlen(sigtraps[i].name) :
+ w = sigtraps[i].name ?
+ (int)strlen(sigtraps[i].name) :
ki.num_width;
if (w > ki.name_width)
ki.name_width = w;
@@ -1274,7 +1273,7 @@ c_getopts(char **wp)
}
if (genv->loc->next == NULL) {
- internal_errorf(0, "c_getopts: no argv");
+ internal_warningf("%s: no argv", __func__);
return 1;
}
/* Which arguments are we parsing... */
@@ -1385,9 +1384,7 @@ const struct builtin kshbuiltins [] = {
{"+command", c_command},
{"echo", c_print},
{"*=export", c_typeset},
-#ifdef HISTORY
{"+fc", c_fc},
-#endif /* HISTORY */
{"+getopts", c_getopts},
{"+jobs", c_jobs},
{"+kill", c_kill},
@@ -1398,10 +1395,8 @@ const struct builtin kshbuiltins [] = {
{"=typeset", c_typeset},
{"+unalias", c_unalias},
{"whence", c_whence},
-#ifdef JOBS
{"+bg", c_fgbg},
{"+fg", c_fgbg},
-#endif
#ifdef EMACS
{"bind", c_bind},
#endif
diff --git a/bin/ksh/c_sh.c b/bin/ksh/c_sh.c
index 6c54839..6adacef 100644
--- a/bin/ksh/c_sh.c
+++ b/bin/ksh/c_sh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_sh.c,v 1.60 2017/07/22 09:37:21 anton Exp $ */
+/* $OpenBSD: c_sh.c,v 1.62 2017/12/27 13:02:57 millert Exp $ */
/*
* built-in Bourne commands
@@ -200,7 +200,7 @@ c_dot(char **wp)
if ((cp = wp[builtin_opt.optind]) == NULL)
return 0;
- file = search(cp, path, R_OK, &err);
+ file = search(cp, search_path, R_OK, &err);
if (file == NULL) {
bi_errorf("%s: %s", cp, err ? strerror(err) : "not found");
return 1;
@@ -250,7 +250,7 @@ int
c_read(char **wp)
{
int c = 0;
- int expand = 1, history = 0;
+ int expand = 1, savehist = 0;
int expanding;
int ecode = 0;
char *cp;
@@ -274,7 +274,7 @@ c_read(char **wp)
expand = 0;
break;
case 's':
- history = 1;
+ savehist = 1;
break;
case 'u':
if (!*(cp = builtin_opt.optarg))
@@ -320,7 +320,7 @@ c_read(char **wp)
* coproc_readw_close(fd);
*/
- if (history)
+ if (savehist)
Xinit(xs, xp, 128, ATEMP);
expanding = 0;
Xinit(cs, cp, 128, ATEMP);
@@ -348,7 +348,7 @@ c_read(char **wp)
}
break;
}
- if (history) {
+ if (savehist) {
Xcheck(xs, xp);
Xput(xs, xp, c);
}
@@ -361,7 +361,7 @@ c_read(char **wp)
/* set prompt in case this is
* called from .profile or $ENV
*/
- set_prompt(PS2, NULL);
+ set_prompt(PS2);
pprompt(prompt, 0);
}
} else if (c != EOF)
@@ -404,7 +404,7 @@ c_read(char **wp)
}
shf_flush(shf);
- if (history) {
+ if (savehist) {
Xput(xs, xp, '\0');
source->line++;
histsave(source->line, Xstring(xs, xp), 1);
diff --git a/bin/ksh/c_test.c b/bin/ksh/c_test.c
index b48e4c1..818bda8 100644
--- a/bin/ksh/c_test.c
+++ b/bin/ksh/c_test.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_test.c,v 1.23 2015/12/14 13:59:42 tb Exp $ */
+/* $OpenBSD: c_test.c,v 1.24 2017/12/26 19:10:31 millert Exp $ */
/*
* test(1); version 7-like -- author Erik Baalbergen
@@ -89,7 +89,6 @@ static const struct t_op b_ops [] = {
{"", TO_NONOP }
};
-static int test_stat(const char *, struct stat *);
static int test_eaccess(const char *, int);
static int test_oexpr(Test_env *, int);
static int test_aexpr(Test_env *, int);
@@ -241,39 +240,39 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
case TO_FILEX: /* -x */
return test_eaccess(opnd1, X_OK) == 0;
case TO_FILAXST: /* -a */
- return test_stat(opnd1, &b1) == 0;
+ return stat(opnd1, &b1) == 0;
case TO_FILEXST: /* -e */
/* at&t ksh does not appear to do the /dev/fd/ thing for
* this (unless the os itself handles it)
*/
return stat(opnd1, &b1) == 0;
case TO_FILREG: /* -r */
- return test_stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode);
+ return stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode);
case TO_FILID: /* -d */
- return test_stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode);
+ return stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode);
case TO_FILCDEV: /* -c */
- return test_stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode);
+ return stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode);
case TO_FILBDEV: /* -b */
- return test_stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode);
+ return stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode);
case TO_FILFIFO: /* -p */
- return test_stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode);
+ return stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode);
case TO_FILSYM: /* -h -L */
return lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode);
case TO_FILSOCK: /* -S */
- return test_stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode);
+ return stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode);
case TO_FILCDF:/* -H HP context dependent files (directories) */
return 0;
case TO_FILSETU: /* -u */
- return test_stat(opnd1, &b1) == 0 &&
+ return stat(opnd1, &b1) == 0 &&
(b1.st_mode & S_ISUID) == S_ISUID;
case TO_FILSETG: /* -g */
- return test_stat(opnd1, &b1) == 0 &&
+ return stat(opnd1, &b1) == 0 &&
(b1.st_mode & S_ISGID) == S_ISGID;
case TO_FILSTCK: /* -k */
- return test_stat(opnd1, &b1) == 0 &&
+ return stat(opnd1, &b1) == 0 &&
(b1.st_mode & S_ISVTX) == S_ISVTX;
case TO_FILGZ: /* -s */
- return test_stat(opnd1, &b1) == 0 && b1.st_size > 0L;
+ return stat(opnd1, &b1) == 0 && b1.st_size > 0L;
case TO_FILTT: /* -t */
if (opnd1 && !bi_getn(opnd1, &res)) {
te->flags |= TEF_ERROR;
@@ -284,9 +283,9 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
}
return res;
case TO_FILUID: /* -O */
- return test_stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid;
+ return stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid;
case TO_FILGID: /* -G */
- return test_stat(opnd1, &b1) == 0 && b1.st_gid == getegid();
+ return stat(opnd1, &b1) == 0 && b1.st_gid == getegid();
/*
* Binary Operators
*/
@@ -360,27 +359,19 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
return 1;
}
-/* Nasty kludge to handle Korn's bizarre /dev/fd hack */
-static int
-test_stat(const char *path, struct stat *statb)
-{
- return stat(path, statb);
-}
-
-/* Routine to handle Korn's /dev/fd hack, and to deal with X_OK on
- * non-directories when running as root.
+/* Routine to deal with X_OK on non-directories when running as root.
*/
static int
-test_eaccess(const char *path, int mode)
+test_eaccess(const char *path, int amode)
{
int res;
- res = access(path, mode);
+ res = access(path, amode);
/*
* On most (all?) unixes, access() says everything is executable for
* root - avoid this on files by using stat().
*/
- if (res == 0 && ksheuid == 0 && (mode & X_OK)) {
+ if (res == 0 && ksheuid == 0 && (amode & X_OK)) {
struct stat statb;
if (stat(path, &statb) < 0)
diff --git a/bin/ksh/c_ulimit.c b/bin/ksh/c_ulimit.c
index e44c480..2dd3667 100644
--- a/bin/ksh/c_ulimit.c
+++ b/bin/ksh/c_ulimit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_ulimit.c,v 1.24 2015/12/14 13:59:42 tb Exp $ */
+/* $OpenBSD: c_ulimit.c,v 1.27 2018/03/15 16:51:29 anton Exp $ */
/*
ulimit -- handle "ulimit" builtin
@@ -53,27 +53,13 @@ c_ulimit(char **wp)
{ "memory(kbytes)", RLIMIT_RSS, 1024, 'm' },
{ "nofiles(descriptors)", RLIMIT_NOFILE, 1, 'n' },
{ "processes", RLIMIT_NPROC, 1, 'p' },
-#ifdef RLIMIT_VMEM
- { "vmemory(kbytes)", RLIMIT_VMEM, 1024, 'v' },
-#endif /* RLIMIT_VMEM */
{ NULL }
};
- static char options[4 + NELEM(limits) * 2];
+ const char *options = "HSat#f#c#d#s#l#m#n#p#";
int how = SOFT | HARD;
const struct limits *l;
int optc, all = 0;
- if (!options[0]) {
- /* build options string on first call - yuck */
- char *p = options;
-
- *p++ = 'H'; *p++ = 'S'; *p++ = 'a';
- for (l = limits; l->name; l++) {
- *p++ = l->option;
- *p++ = '#';
- }
- *p = '\0';
- }
/* First check for -a, -H and -S. */
while ((optc = ksh_getopt(wp, &builtin_opt, options)) != -1)
switch (optc) {
@@ -111,7 +97,7 @@ c_ulimit(char **wp)
for (l = limits; l->name && l->option != optc; l++)
;
if (!l->name) {
- internal_errorf(0, "ulimit: %c", optc);
+ internal_warningf("%s: %c", __func__, optc);
return 1;
}
if (builtin_opt.optarg) {
diff --git a/bin/ksh/config.h b/bin/ksh/config.h
index abf6b63..2bdffb9 100644
--- a/bin/ksh/config.h
+++ b/bin/ksh/config.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.h,v 1.16 2017/08/01 14:30:05 deraadt Exp $ */
+/* $OpenBSD: config.h,v 1.19 2018/01/15 14:58:05 jca Exp $ */
/* config.h. NOT generated automatically. */
@@ -11,15 +11,6 @@
#ifndef CONFIG_H
#define CONFIG_H
-/* Include job control? */
-#define JOBS 1
-
-/* Include brace-expansion? */
-#define BRACE_EXPAND 1
-
-/* Include any history? */
-#define HISTORY 1
-
/* Strict POSIX behaviour? */
/* #undef POSIXLY_CORRECT */
@@ -30,15 +21,8 @@
* End of configuration stuff for PD ksh.
*/
-#if defined(EMACS) || defined(VI)
-# define EDIT
-#else
-# undef EDIT
+#if !defined(EMACS) && !defined(VI)
+# error "Define either EMACS or VI."
#endif
-/* Editing implies history */
-#if defined(EDIT) && !defined(HISTORY)
-# define HISTORY
-#endif /* EDIT */
-
#endif /* CONFIG_H */
diff --git a/bin/ksh/edit.c b/bin/ksh/edit.c
index 66fe96d..26a2d6a 100644
--- a/bin/ksh/edit.c
+++ b/bin/ksh/edit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: edit.c,v 1.57 2016/09/08 12:12:40 nicm Exp $ */
+/* $OpenBSD: edit.c,v 1.64 2018/03/15 16:51:29 anton Exp $ */
/*
* Command line editing - common code
@@ -8,7 +8,6 @@
#define _GNU_SOURCE
#include "config.h"
-#ifdef EDIT
#include <sys/ioctl.h>
#include <sys/stat.h>
@@ -226,13 +225,13 @@ set_editmode(const char *ed)
#endif
};
char *rcp;
- int i;
+ unsigned int ele;
if ((rcp = strrchr(ed, '/')))
ed = ++rcp;
- for (i = 0; i < NELEM(edit_flags); i++)
- if (strstr(ed, options[(int) edit_flags[i]].name)) {
- change_flag(edit_flags[i], OF_SPECIAL, 1);
+ for (ele = 0; ele < NELEM(edit_flags); ele++)
+ if (strstr(ed, sh_options[(int) edit_flags[ele]].name)) {
+ change_flag(edit_flags[ele], OF_SPECIAL, 1);
return;
}
}
@@ -375,7 +374,7 @@ x_file_glob(int flags, const char *str, int slen, char ***wordsp)
source = s;
if (yylex(ONEWORD|UNESCAPE) != LWORD) {
source = sold;
- internal_errorf(0, "fileglob: substitute error");
+ internal_warningf("%s: substitute error", __func__);
return 0;
}
source = sold;
@@ -461,7 +460,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
for (l = genv->loc; l; l = l->next)
glob_table(pat, &w, &l->funs);
- glob_path(flags, pat, &w, path);
+ glob_path(flags, pat, &w, search_path);
if ((fpath = str_val(global("FPATH"))) != null)
glob_path(flags, pat, &w, fpath);
@@ -619,12 +618,12 @@ x_try_array(const char *buf, int buflen, const char *want, int wantlen,
/* Try to find the array. */
if (asprintf(&name, "complete_%.*s_%d", cmdlen, cmd, n) < 0)
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
v = global(name);
free(name);
if (~v->flag & (ISSET|ARRAY)) {
if (asprintf(&name, "complete_%.*s", cmdlen, cmd) < 0)
- internal_errorf(1, "unable to allocate memory");
+ internal_errorf("unable to allocate memory");
v = global(name);
free(name);
if (~v->flag & (ISSET|ARRAY))
@@ -912,4 +911,3 @@ x_escape(const char *s, size_t len, int (*putbuf_func) (const char *, size_t))
return (rval);
}
-#endif /* EDIT */
diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c
index 4da667b..b88219d 100644
--- a/bin/ksh/emacs.c
+++ b/bin/ksh/emacs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: emacs.c,v 1.73 2017/08/30 17:02:53 jca Exp $ */
+/* $OpenBSD: emacs.c,v 1.84 2018/01/16 17:17:18 jca Exp $ */
/*
* Emacs-like command line editing and history
@@ -186,7 +186,6 @@ static int x_search_char_back(int);
static int x_search_hist(int);
static int x_set_mark(int);
static int x_transpose(int);
-static int x_version(int);
static int x_xchg_point_mark(int);
static int x_yank(int);
static int x_comp_list(int);
@@ -243,7 +242,6 @@ static const struct x_ftab x_ftab[] = {
{ x_search_hist, "search-history", 0 },
{ x_set_mark, "set-mark-command", 0 },
{ x_transpose, "transpose-chars", 0 },
- { x_version, "version", 0 },
{ x_xchg_point_mark, "exchange-point-and-mark", 0 },
{ x_yank, "yank", 0 },
{ x_comp_list, "complete-list", 0 },
@@ -1040,7 +1038,7 @@ x_redraw(int limit)
x_displen = xx_cols - 2;
}
xlp_valid = false;
- cp = x_lastcp();
+ x_lastcp();
x_zots(xbp);
if (xbp != xbuf || xep > xlp)
limit = xx_cols;
@@ -1251,7 +1249,7 @@ static char *
kb_decode(const char *s)
{
static char l[LINE + 1];
- int i, at = 0;
+ unsigned int i, at = 0;
l[0] = '\0';
for (i = 0; i < strlen(s); i++) {
@@ -1294,13 +1292,13 @@ kb_del(struct kb_entry *k)
static struct kb_entry *
kb_add_string(void *func, void *args, char *str)
{
- int i, count;
+ unsigned int ele, count;
struct kb_entry *k;
struct x_ftab *xf = NULL;
- for (i = 0; i < NELEM(x_ftab); i++)
- if (x_ftab[i].xf_func == func) {
- xf = (struct x_ftab *)&x_ftab[i];
+ for (ele = 0; ele < NELEM(x_ftab); ele++)
+ if (x_ftab[ele].xf_func == func) {
+ xf = (struct x_ftab *)&x_ftab[ele];
break;
}
if (xf == NULL)
@@ -1327,24 +1325,24 @@ kb_add_string(void *func, void *args, char *str)
}
static struct kb_entry *
-kb_add(void *func, void *args, ...)
+kb_add(void *func, ...)
{
va_list ap;
- int i, count;
- char l[LINE + 1];
-
- va_start(ap, args);
- count = 0;
- while (va_arg(ap, unsigned int) != 0)
- count++;
- va_end(ap);
+ unsigned char ch;
+ unsigned int i;
+ char line[LINE + 1];
- va_start(ap, args);
- for (i = 0; i <= count /* <= is correct */; i++)
- l[i] = (unsigned char)va_arg(ap, unsigned int);
+ va_start(ap, func);
+ for (i = 0; i < sizeof(line) - 1; i++) {
+ ch = va_arg(ap, unsigned int);
+ if (ch == 0)
+ break;
+ line[i] = ch;
+ }
va_end(ap);
+ line[i] = '\0';
- return (kb_add_string(func, args, l));
+ return (kb_add_string(func, NULL, line));
}
static void
@@ -1364,7 +1362,7 @@ x_bind(const char *a1, const char *a2,
int macro, /* bind -m */
int list) /* bind -l */
{
- int i;
+ unsigned int i;
struct kb_entry *k, *kb;
char in[LINE + 1];
@@ -1455,107 +1453,109 @@ x_init_emacs(void)
TAILQ_INIT(&kblist);
/* man page order */
- kb_add(x_abort, NULL, CTRL('G'), 0);
- kb_add(x_mv_back, NULL, CTRL('B'), 0);
- kb_add(x_mv_back, NULL, CTRL('X'), CTRL('D'), 0);
- kb_add(x_mv_bword, NULL, CTRL('['), 'b', 0);
- kb_add(x_beg_hist, NULL, CTRL('['), '<', 0);
- kb_add(x_mv_begin, NULL, CTRL('A'), 0);
- kb_add(x_fold_capitalize, NULL, CTRL('['), 'C', 0);
- kb_add(x_fold_capitalize, NULL, CTRL('['), 'c', 0);
- kb_add(x_comment, NULL, CTRL('['), '#', 0);
- kb_add(x_complete, NULL, CTRL('['), CTRL('['), 0);
- kb_add(x_comp_comm, NULL, CTRL('X'), CTRL('['), 0);
- kb_add(x_comp_file, NULL, CTRL('['), CTRL('X'), 0);
- kb_add(x_comp_list, NULL, CTRL('I'), 0);
- kb_add(x_comp_list, NULL, CTRL('['), '=', 0);
- kb_add(x_del_back, NULL, CTRL('?'), 0);
- kb_add(x_del_back, NULL, CTRL('H'), 0);
- kb_add(x_del_char, NULL, CTRL('['), '[', '3', '~', 0); /* delete */
- kb_add(x_del_bword, NULL, CTRL('['), CTRL('?'), 0);
- kb_add(x_del_bword, NULL, CTRL('['), CTRL('H'), 0);
- kb_add(x_del_bword, NULL, CTRL('['), 'h', 0);
- kb_add(x_del_fword, NULL, CTRL('['), 'd', 0);
- kb_add(x_next_com, NULL, CTRL('N'), 0);
- kb_add(x_next_com, NULL, CTRL('X'), 'B', 0);
- kb_add(x_fold_lower, NULL, CTRL('['), 'L', 0);
- kb_add(x_fold_lower, NULL, CTRL('['), 'l', 0);
- kb_add(x_end_hist, NULL, CTRL('['), '>', 0);
- kb_add(x_mv_end, NULL, CTRL('E'), 0);
+ kb_add(x_abort, CTRL('G'), 0);
+ kb_add(x_mv_back, CTRL('B'), 0);
+ kb_add(x_mv_back, CTRL('X'), CTRL('D'), 0);
+ kb_add(x_mv_bword, CTRL('['), 'b', 0);
+ kb_add(x_beg_hist, CTRL('['), '<', 0);
+ kb_add(x_mv_begin, CTRL('A'), 0);
+ kb_add(x_fold_capitalize, CTRL('['), 'C', 0);
+ kb_add(x_fold_capitalize, CTRL('['), 'c', 0);
+ kb_add(x_comment, CTRL('['), '#', 0);
+ kb_add(x_complete, CTRL('['), CTRL('['), 0);
+ kb_add(x_comp_comm, CTRL('X'), CTRL('['), 0);
+ kb_add(x_comp_file, CTRL('['), CTRL('X'), 0);
+ kb_add(x_comp_list, CTRL('I'), 0);
+ kb_add(x_comp_list, CTRL('['), '=', 0);
+ kb_add(x_del_back, CTRL('?'), 0);
+ kb_add(x_del_back, CTRL('H'), 0);
+ kb_add(x_del_char, CTRL('['), '[', '3', '~', 0); /* delete */
+ kb_add(x_del_bword, CTRL('W'), 0);
+ kb_add(x_del_bword, CTRL('['), CTRL('?'), 0);
+ kb_add(x_del_bword, CTRL('['), CTRL('H'), 0);
+ kb_add(x_del_bword, CTRL('['), 'h', 0);
+ kb_add(x_del_fword, CTRL('['), 'd', 0);
+ kb_add(x_next_com, CTRL('N'), 0);
+ kb_add(x_next_com, CTRL('X'), 'B', 0);
+ kb_add(x_fold_lower, CTRL('['), 'L', 0);
+ kb_add(x_fold_lower, CTRL('['), 'l', 0);
+ kb_add(x_end_hist, CTRL('['), '>', 0);
+ kb_add(x_mv_end, CTRL('E'), 0);
/* how to handle: eot: ^_, underneath copied from original keybindings */
- kb_add(x_end_of_text, NULL, CTRL('_'), 0);
- kb_add(x_eot_del, NULL, CTRL('D'), 0);
+ kb_add(x_end_of_text, CTRL('_'), 0);
+ kb_add(x_eot_del, CTRL('D'), 0);
/* error */
- kb_add(x_xchg_point_mark, NULL, CTRL('X'), CTRL('X'), 0);
- kb_add(x_expand, NULL, CTRL('['), '*', 0);
- kb_add(x_mv_forw, NULL, CTRL('F'), 0);
- kb_add(x_mv_forw, NULL, CTRL('X'), 'C', 0);
- kb_add(x_mv_fword, NULL, CTRL('['), 'f', 0);
- kb_add(x_goto_hist, NULL, CTRL('['), 'g', 0);
+ kb_add(x_xchg_point_mark, CTRL('X'), CTRL('X'), 0);
+ kb_add(x_expand, CTRL('['), '*', 0);
+ kb_add(x_mv_forw, CTRL('F'), 0);
+ kb_add(x_mv_forw, CTRL('X'), 'C', 0);
+ kb_add(x_mv_fword, CTRL('['), 'f', 0);
+ kb_add(x_goto_hist, CTRL('['), 'g', 0);
/* kill-line */
- kb_add(x_del_bword, NULL, CTRL('W'), 0); /* not what man says */
- kb_add(x_kill, NULL, CTRL('K'), 0);
- kb_add(x_enumerate, NULL, CTRL('['), '?', 0);
- kb_add(x_list_comm, NULL, CTRL('X'), '?', 0);
- kb_add(x_list_file, NULL, CTRL('X'), CTRL('Y'), 0);
- kb_add(x_newline, NULL, CTRL('J'), 0);
- kb_add(x_newline, NULL, CTRL('M'), 0);
- kb_add(x_nl_next_com, NULL, CTRL('O'), 0);
+ kb_add(x_kill, CTRL('K'), 0);
+ kb_add(x_enumerate, CTRL('['), '?', 0);
+ kb_add(x_list_comm, CTRL('X'), '?', 0);
+ kb_add(x_list_file, CTRL('X'), CTRL('Y'), 0);
+ kb_add(x_newline, CTRL('J'), 0);
+ kb_add(x_newline, CTRL('M'), 0);
+ kb_add(x_nl_next_com, CTRL('O'), 0);
/* no-op */
- kb_add(x_prev_histword, NULL, CTRL('['), '.', 0);
- kb_add(x_prev_histword, NULL, CTRL('['), '_', 0);
+ kb_add(x_prev_histword, CTRL('['), '.', 0);
+ kb_add(x_prev_histword, CTRL('['), '_', 0);
/* how to handle: quote: ^^ */
- kb_add(x_draw_line, NULL, CTRL('L'), 0);
- kb_add(x_search_char_back, NULL, CTRL('['), CTRL(']'), 0);
- kb_add(x_search_char_forw, NULL, CTRL(']'), 0);
- kb_add(x_search_hist, NULL, CTRL('R'), 0);
- kb_add(x_set_mark, NULL, CTRL('['), ' ', 0);
- kb_add(x_transpose, NULL, CTRL('T'), 0);
- kb_add(x_prev_com, NULL, CTRL('P'), 0);
- kb_add(x_prev_com, NULL, CTRL('X'), 'A', 0);
- kb_add(x_fold_upper, NULL, CTRL('['), 'U', 0);
- kb_add(x_fold_upper, NULL, CTRL('['), 'u', 0);
- kb_add(x_literal, NULL, CTRL('V'), 0);
- kb_add(x_literal, NULL, CTRL('^'), 0);
- kb_add(x_yank, NULL, CTRL('Y'), 0);
- kb_add(x_meta_yank, NULL, CTRL('['), 'y', 0);
+ kb_add(x_literal, CTRL('^'), 0);
+ kb_add(x_draw_line, CTRL('L'), 0);
+ kb_add(x_search_char_back, CTRL('['), CTRL(']'), 0);
+ kb_add(x_search_char_forw, CTRL(']'), 0);
+ kb_add(x_search_hist, CTRL('R'), 0);
+ kb_add(x_set_mark, CTRL('['), ' ', 0);
+ kb_add(x_transpose, CTRL('T'), 0);
+ kb_add(x_prev_com, CTRL('P'), 0);
+ kb_add(x_prev_com, CTRL('X'), 'A', 0);
+ kb_add(x_fold_upper, CTRL('['), 'U', 0);
+ kb_add(x_fold_upper, CTRL('['), 'u', 0);
+ kb_add(x_literal, CTRL('V'), 0);
+ kb_add(x_yank, CTRL('Y'), 0);
+ kb_add(x_meta_yank, CTRL('['), 'y', 0);
/* man page ends here */
/* arrow keys */
- kb_add(x_prev_com, NULL, CTRL('['), '[', 'A', 0); /* up */
- kb_add(x_next_com, NULL, CTRL('['), '[', 'B', 0); /* down */
- kb_add(x_mv_forw, NULL, CTRL('['), '[', 'C', 0); /* right */
- kb_add(x_mv_back, NULL, CTRL('['), '[', 'D', 0); /* left */
- kb_add(x_prev_com, NULL, CTRL('['), 'O', 'A', 0); /* up */
- kb_add(x_next_com, NULL, CTRL('['), 'O', 'B', 0); /* down */
- kb_add(x_mv_forw, NULL, CTRL('['), 'O', 'C', 0); /* right */
- kb_add(x_mv_back, NULL, CTRL('['), 'O', 'D', 0); /* left */
+ kb_add(x_prev_com, CTRL('['), '[', 'A', 0); /* up */
+ kb_add(x_next_com, CTRL('['), '[', 'B', 0); /* down */
+ kb_add(x_mv_forw, CTRL('['), '[', 'C', 0); /* right */
+ kb_add(x_mv_back, CTRL('['), '[', 'D', 0); /* left */
+ kb_add(x_prev_com, CTRL('['), 'O', 'A', 0); /* up */
+ kb_add(x_next_com, CTRL('['), 'O', 'B', 0); /* down */
+ kb_add(x_mv_forw, CTRL('['), 'O', 'C', 0); /* right */
+ kb_add(x_mv_back, CTRL('['), 'O', 'D', 0); /* left */
/* more navigation keys */
- kb_add(x_mv_begin, NULL, CTRL('['), '[', 'H', 0); /* home */
- kb_add(x_mv_end, NULL, CTRL('['), '[', 'F', 0); /* end */
- kb_add(x_mv_begin, NULL, CTRL('['), 'O', 'H', 0); /* home */
- kb_add(x_mv_end, NULL, CTRL('['), 'O', 'F', 0); /* end */
- kb_add(x_mv_begin, NULL, CTRL('['), '[', '1', '~', 0); /* home */
- kb_add(x_mv_end, NULL, CTRL('['), '[', '4', '~', 0); /* end */
+ kb_add(x_mv_begin, CTRL('['), '[', 'H', 0); /* home */
+ kb_add(x_mv_end, CTRL('['), '[', 'F', 0); /* end */
+ kb_add(x_mv_begin, CTRL('['), 'O', 'H', 0); /* home */
+ kb_add(x_mv_end, CTRL('['), 'O', 'F', 0); /* end */
+ kb_add(x_mv_begin, CTRL('['), '[', '1', '~', 0); /* home */
+ kb_add(x_mv_end, CTRL('['), '[', '4', '~', 0); /* end */
+ kb_add(x_mv_begin, CTRL('['), '[', '7', '~', 0); /* home */
+ kb_add(x_mv_end, CTRL('['), '[', '8', '~', 0); /* end */
/* can't be bound */
- kb_add(x_set_arg, NULL, CTRL('['), '0', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '1', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '2', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '3', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '4', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '5', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '6', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '7', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '8', 0);
- kb_add(x_set_arg, NULL, CTRL('['), '9', 0);
+ kb_add(x_set_arg, CTRL('['), '0', 0);
+ kb_add(x_set_arg, CTRL('['), '1', 0);
+ kb_add(x_set_arg, CTRL('['), '2', 0);
+ kb_add(x_set_arg, CTRL('['), '3', 0);
+ kb_add(x_set_arg, CTRL('['), '4', 0);
+ kb_add(x_set_arg, CTRL('['), '5', 0);
+ kb_add(x_set_arg, CTRL('['), '6', 0);
+ kb_add(x_set_arg, CTRL('['), '7', 0);
+ kb_add(x_set_arg, CTRL('['), '8', 0);
+ kb_add(x_set_arg, CTRL('['), '9', 0);
/* ctrl arrow keys */
- kb_add(x_mv_end, NULL, CTRL('['), '[', '1', ';', '5', 'A', 0); /* ctrl up */
- kb_add(x_mv_begin, NULL, CTRL('['), '[', '1', ';', '5', 'B', 0); /* ctrl down */
- kb_add(x_mv_fword, NULL, CTRL('['), '[', '1', ';', '5', 'C', 0); /* ctrl right */
- kb_add(x_mv_bword, NULL, CTRL('['), '[', '1', ';', '5', 'D', 0); /* ctrl left */
+ kb_add(x_mv_end, CTRL('['), '[', '1', ';', '5', 'A', 0); /* ctrl up */
+ kb_add(x_mv_begin, CTRL('['), '[', '1', ';', '5', 'B', 0); /* ctrl down */
+ kb_add(x_mv_fword, CTRL('['), '[', '1', ';', '5', 'C', 0); /* ctrl right */
+ kb_add(x_mv_bword, CTRL('['), '[', '1', ';', '5', 'D', 0); /* ctrl left */
}
void
@@ -1563,17 +1563,17 @@ x_emacs_keys(X_chars *ec)
{
x_bind_quiet = 1;
if (ec->erase >= 0) {
- kb_add(x_del_back, NULL, ec->erase, 0);
- kb_add(x_del_bword, NULL, CTRL('['), ec->erase, 0);
+ kb_add(x_del_back, ec->erase, 0);
+ kb_add(x_del_bword, CTRL('['), ec->erase, 0);
}
if (ec->kill >= 0)
- kb_add(x_del_line, NULL, ec->kill, 0);
+ kb_add(x_del_line, ec->kill, 0);
if (ec->werase >= 0)
- kb_add(x_del_bword, NULL, ec->werase, 0);
+ kb_add(x_del_bword, ec->werase, 0);
if (ec->intr >= 0)
- kb_add(x_abort, NULL, ec->intr, 0);
+ kb_add(x_abort, ec->intr, 0);
if (ec->quit >= 0)
- kb_add(x_noop, NULL, ec->quit, 0);
+ kb_add(x_noop, ec->quit, 0);
x_bind_quiet = 0;
}
@@ -1623,35 +1623,6 @@ x_xchg_point_mark(int c)
}
static int
-x_version(int c)
-{
- char *o_xbuf = xbuf, *o_xend = xend;
- char *o_xbp = xbp, *o_xep = xep, *o_xcp = xcp;
- int lim = x_lastcp() - xbp;
-
- xbuf = xbp = xcp = (char *) ksh_version + 4;
- xend = xep = (char *) ksh_version + 4 + strlen(ksh_version + 4);
- x_redraw(lim);
- x_flush();
-
- c = x_e_getc();
- xbuf = o_xbuf;
- xend = o_xend;
- xbp = o_xbp;
- xep = o_xep;
- xcp = o_xcp;
- x_redraw(strlen(ksh_version));
-
- if (c < 0)
- return KSTD;
- /* This is what at&t ksh seems to do... Very bizarre */
- if (c != ' ')
- x_e_ungetc(c);
-
- return KSTD;
-}
-
-static int
x_noop(int c)
{
return KSTD;
@@ -2024,8 +1995,6 @@ x_prev_histword(int c)
rcp++;
x_ins(rcp);
} else {
- int c;
-
rcp = cp;
/*
* ignore white-space at start of line
@@ -2163,4 +2132,4 @@ x_lastcp(void)
return (xlp);
}
-#endif /* EDIT */
+#endif /* EMACS */
diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c
index 49b4fdd..a8dc698 100644
--- a/bin/ksh/eval.c
+++ b/bin/ksh/eval.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eval.c,v 1.54 2017/08/27 00:29:04 nayden Exp $ */
+/* $OpenBSD: eval.c,v 1.59 2018/01/16 22:52:32 jca Exp $ */
/*
* Expansion - quoting, separation, substitution, globbing
@@ -56,9 +56,7 @@ static void globit(XString *, char **, char *, XPtrV *, int);
static char *maybe_expand_tilde(char *, XString *, char **, int);
static char *tilde(char *);
static char *homedir(char *);
-#ifdef BRACE_EXPAND
static void alt_expand(XPtrV *, char *, char *, char *, int);
-#endif
/* compile and expand word */
char *
@@ -71,7 +69,7 @@ substitute(const char *cp, int f)
s->start = s->str = cp;
source = s;
if (yylex(ONEWORD) != LWORD)
- internal_errorf(1, "substitute");
+ internal_errorf("substitute");
source = sold;
afree(s, ATEMP);
return evalstr(yylval.cp, f);
@@ -170,7 +168,7 @@ expand(char *cp, /* input word */
size_t len;
if (cp == NULL)
- internal_errorf(1, "expand(NULL)");
+ internal_errorf("expand(NULL)");
/* for alias, readonly, set, typeset commands */
if ((f & DOVACHECK) && is_wdvarassign(cp)) {
f &= ~(DOVACHECK|DOBLANK|DOGLOB|DOTILDE);
@@ -180,10 +178,8 @@ expand(char *cp, /* input word */
f &= ~DOGLOB;
if (Flag(FMARKDIRS))
f |= DOMARKDIRS;
-#ifdef BRACE_EXPAND
if (Flag(FBRACEEXPAND) && (f & DOGLOB))
f |= DOBRACE_;
-#endif /* BRACE_EXPAND */
Xinit(ds, dp, 128, ATEMP); /* init dest. string */
type = XBASE;
@@ -563,15 +559,12 @@ expand(char *cp, /* input word */
*dp++ = '\0';
p = Xclose(ds, dp);
-#ifdef BRACE_EXPAND
if (fdo & DOBRACE_)
/* also does globbing */
alt_expand(wp, p, p,
p + Xlength(ds, (dp - 1)),
fdo | (f & DOMARKDIRS));
- else
-#endif /* BRACE_EXPAND */
- if (fdo & DOGLOB)
+ else if (fdo & DOGLOB)
glob(p, wp, f & DOMARKDIRS);
else if ((f & DOPAT) || !(fdo & DOMAGIC_))
XPput(*wp, p);
@@ -594,7 +587,7 @@ expand(char *cp, /* input word */
char *p;
if ((p = strdup("")) == NULL)
- internal_errorf(1, "unable "
+ internal_errorf("unable "
"to allocate memory");
XPput(*wp, p);
}
@@ -628,7 +621,6 @@ expand(char *cp, /* input word */
*dp++ = MAGIC;
}
break;
-#ifdef BRACE_EXPAND
case OBRACE:
case ',':
case CBRACE:
@@ -638,7 +630,6 @@ expand(char *cp, /* input word */
*dp++ = MAGIC;
}
break;
-#endif /* BRACE_EXPAND */
case '=':
/* Note first unquoted = for ~ */
if (!(f & DOTEMP_) && !saw_eq) {
@@ -1114,10 +1105,11 @@ debunk(char *dp, const char *sp, size_t dlen)
char *d, *s;
if ((s = strchr(sp, MAGIC))) {
- if (s - sp >= dlen)
+ size_t slen = s - sp;
+ if (slen >= dlen)
return dp;
- memcpy(dp, sp, s - sp);
- for (d = dp + (s - sp); *s && (d - dp < dlen); s++)
+ memcpy(dp, sp, slen);
+ for (d = dp + slen; *s && (d < dp + dlen); s++)
if (!ISMAGIC(*s) || !(*++s & 0x80) ||
!strchr("*+?@! ", *s & 0x7f))
*d++ = *s;
@@ -1125,7 +1117,7 @@ debunk(char *dp, const char *sp, size_t dlen)
/* extended pattern operators: *+?@! */
if ((*s & 0x7f) != ' ')
*d++ = *s & 0x7f;
- if (d - dp < dlen)
+ if (d < dp + dlen)
*d++ = '(';
}
*d = '\0';
@@ -1220,7 +1212,6 @@ homedir(char *name)
return ap->val.s;
}
-#ifdef BRACE_EXPAND
static void
alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
{
@@ -1295,4 +1286,3 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
}
return;
}
-#endif /* BRACE_EXPAND */
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c
index 7cabcaa..1d27491 100644
--- a/bin/ksh/exec.c
+++ b/bin/ksh/exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec.c,v 1.68 2016/12/11 17:49:19 millert Exp $ */
+/* $OpenBSD: exec.c,v 1.73 2018/03/15 16:51:29 anton Exp $ */
/*
* execute command tree
@@ -409,7 +409,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags,
volatile int rv = 0;
char *cp;
char **lastp;
- static struct op texec; /* Must be static (XXX but why?) */
+ struct op texec;
int type_flags;
int keepasn_ok;
int fcflags = FC_BI|FC_FUNC|FC_PATH;
@@ -644,7 +644,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags,
/* NOTREACHED */
default:
quitenv(NULL);
- internal_errorf(1, "CFUNC %d", i);
+ internal_errorf("CFUNC %d", i);
}
break;
}
@@ -684,6 +684,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags,
}
/* to fork we set up a TEXEC node and call execute */
+ memset(&texec, 0, sizeof(texec));
texec.type = TEXEC;
texec.left = t; /* for tprint */
texec.str = tp->val.s;
@@ -706,7 +707,7 @@ scriptexec(struct op *tp, char **ap)
shell = str_val(global("EXECSHELL"));
if (shell && *shell)
- shell = search(shell, path, X_OK, NULL);
+ shell = search(shell, search_path, X_OK, NULL);
if (!shell || !*shell)
shell = _PATH_BSHELL;
@@ -726,7 +727,7 @@ shcomexec(char **wp)
tp = ktsearch(&builtins, *wp, hash(*wp));
if (tp == NULL)
- internal_errorf(1, "shcomexec: %s", *wp);
+ internal_errorf("%s: %s", __func__, *wp);
return call_builtin(tp, wp);
}
@@ -899,8 +900,8 @@ findcom(const char *name, int flags)
}
tp->flag = DEFINED; /* make ~ISSET */
}
- npath = search(name, flags & FC_DEFPATH ? def_path : path,
- X_OK, &tp->u2.errno_);
+ npath = search(name, flags & FC_DEFPATH ? def_path :
+ search_path, X_OK, &tp->u2.errno_);
if (npath) {
if (tp == &temp) {
tp->val.s = npath;
@@ -1220,7 +1221,7 @@ herein(const char *content, int sub)
s->start = s->str = content;
source = s;
if (yylex(ONEWORD|HEREDOC) != LWORD)
- internal_errorf(1, "herein: yylex");
+ internal_errorf("%s: yylex", __func__);
source = osource;
shf_puts(evalstr(yylval.cp, 0), shf);
} else
@@ -1238,7 +1239,6 @@ herein(const char *content, int sub)
return fd;
}
-#ifdef EDIT
/*
* ksh special - the select command processing section
* print the args in column form - assuming that we can
@@ -1364,7 +1364,6 @@ pr_list(char *const *ap)
return n;
}
-#endif /* EDIT */
/*
* [[ ... ]] evaluation routines
@@ -1447,5 +1446,5 @@ static void
dbteste_error(Test_env *te, int offset, const char *msg)
{
te->flags |= TEF_ERROR;
- internal_errorf(0, "dbteste_error: %s (offset %d)", msg, offset);
+ internal_warningf("%s: %s (offset %d)", __func__, msg, offset);
}
diff --git a/bin/ksh/expand.h b/bin/ksh/expand.h
index 9262ef9..21d8cdd 100644
--- a/bin/ksh/expand.h
+++ b/bin/ksh/expand.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: expand.h,v 1.12 2015/11/08 17:52:43 mmcc Exp $ */
+/* $OpenBSD: expand.h,v 1.15 2018/01/06 16:28:58 millert Exp $ */
/*
* Expanding strings
@@ -46,7 +46,7 @@ typedef char * XStringP;
/* check if there are at least n bytes left */
#define XcheckN(xs, xp, n) do { \
- int more = ((xp) + (n)) - (xs).end; \
+ ptrdiff_t more = ((xp) + (n)) - (xs).end; \
if (more > 0) \
xp = Xcheck_grow_(&xs, xp, more); \
} while (0)
@@ -68,7 +68,7 @@ typedef char * XStringP;
#define Xsavepos(xs, xp) ((xp) - (xs).beg)
#define Xrestpos(xs, xp, n) ((xs).beg + (n))
-char * Xcheck_grow_(XString *xsp, char *xp, int more);
+char * Xcheck_grow_(XString *xsp, char *xp, size_t more);
/*
* expandable vector of generic pointers
diff --git a/bin/ksh/history.c b/bin/ksh/history.c
index a09ad32..8facece 100644
--- a/bin/ksh/history.c
+++ b/bin/ksh/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.74 2017/10/23 15:43:38 jca Exp $ */
+/* $OpenBSD: history.c,v 1.80 2018/01/15 22:30:38 jca Exp $ */
/*
* command history
@@ -27,8 +27,6 @@
#include "sh.h"
-#ifdef HISTORY
-
static void history_write(void);
static FILE *history_open(void);
static void history_load(Source *);
@@ -547,7 +545,7 @@ sethistcontrol(const char *str)
void
sethistsize(int n)
{
- if (n > 0 && n != histsize) {
+ if (n > 0 && (uint32_t)n != histsize) {
int offset = histptr - history;
/* save most recent history */
@@ -609,6 +607,7 @@ init_histvec(void)
*/
histbase = areallocarray(NULL, histsize + 1, sizeof(char *),
APERM);
+ *histbase = NULL;
history = histbase + 1;
histptr = history - 1;
}
@@ -801,10 +800,9 @@ hist_init(Source *s)
hist_source = s;
- hname = str_val(global("HISTFILE"));
- if (hname == NULL)
+ if (str_val(global("HISTFILE")) == null)
return;
- hname = str_save(hname, APERM);
+ hname = str_save(str_val(global("HISTFILE")), APERM);
histfh = history_open();
if (histfh == NULL)
return;
@@ -864,25 +862,3 @@ hist_finish(void)
{
history_close();
}
-
-#else /* HISTORY */
-
-/* No history to be compiled in: dummy routines to avoid lots more ifdefs */
-void
-init_histvec(void)
-{
-}
-void
-hist_init(Source *s)
-{
-}
-void
-hist_finish(void)
-{
-}
-void
-histsave(int lno, const char *cmd, int dowrite)
-{
- errorf("history not enabled");
-}
-#endif /* HISTORY */
diff --git a/bin/ksh/io.c b/bin/ksh/io.c
index 99fa0a8..e62b505 100644
--- a/bin/ksh/io.c
+++ b/bin/ksh/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.35 2016/03/20 00:01:21 krw Exp $ */
+/* $OpenBSD: io.c,v 1.36 2018/01/16 22:52:32 jca Exp $ */
/*
* shell buffered IO and formatted output
@@ -87,21 +87,37 @@ bi_errorf(const char *fmt, ...)
}
}
-/* Called when something that shouldn't happen does */
-void
-internal_errorf(int jump, const char *fmt, ...)
+static void
+internal_error_vwarn(const char *fmt, va_list va)
{
- va_list va;
-
error_prefix(true);
shf_fprintf(shl_out, "internal error: ");
- va_start(va, fmt);
shf_vfprintf(shl_out, fmt, va);
- va_end(va);
shf_putchar('\n', shl_out);
shf_flush(shl_out);
- if (jump)
- unwind(LERROR);
+}
+
+/* Warn when something that shouldn't happen does */
+void
+internal_warningf(const char *fmt, ...)
+{
+ va_list va;
+
+ va_start(va, fmt);
+ internal_error_vwarn(fmt, va);
+ va_end(va);
+}
+
+/* Warn and unwind when something that shouldn't happen does */
+__dead void
+internal_errorf(const char *fmt, ...)
+{
+ va_list va;
+
+ va_start(va, fmt);
+ internal_error_vwarn(fmt, va);
+ va_end(va);
+ unwind(LERROR);
}
/* used by error reporting functions to print "ksh: .kshrc[25]: " */
@@ -140,7 +156,7 @@ shprintf(const char *fmt, ...)
va_list va;
if (!shl_stdout_ok)
- internal_errorf(1, "shl_stdout not valid");
+ internal_errorf("shl_stdout not valid");
va_start(va, fmt);
shf_vfprintf(shl_stdout, fmt, va);
va_end(va);
diff --git a/bin/ksh/jobs.c b/bin/ksh/jobs.c
index 53858a3..ba73866 100644
--- a/bin/ksh/jobs.c
+++ b/bin/ksh/jobs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: jobs.c,v 1.55 2016/03/17 23:33:23 mmcc Exp $ */
+/* $OpenBSD: jobs.c,v 1.60 2018/03/15 16:51:29 anton Exp $ */
/*
* Process and job control
@@ -67,7 +67,7 @@ struct proc {
#define JF_CHANGED 0x040 /* process has changed state */
#define JF_KNOWN 0x080 /* $! referenced */
#define JF_ZOMBIE 0x100 /* known, unwaited process */
-#define JF_REMOVE 0x200 /* flagged for removal (j_jobs()/j_noityf()) */
+#define JF_REMOVE 0x200 /* flagged for removal (j_jobs()/j_notify()) */
#define JF_USETTYMODE 0x400 /* tty mode saved if process exits normally */
#define JF_SAVEDTTYPGRP 0x800 /* j->saved_ttypgrp is valid */
@@ -86,10 +86,8 @@ struct job {
Proc *proc_list; /* process list */
Proc *last_proc; /* last process in list */
Coproc_id coproc_id; /* 0 or id of coprocess output pipe */
-#ifdef JOBS
struct termios ttystate;/* saved tty state for stopped jobs */
pid_t saved_ttypgrp; /* saved tty process group for stopped jobs */
-#endif /* JOBS */
};
/* Flags for j_waitj() */
@@ -127,13 +125,11 @@ static int child_max; /* CHILD_MAX */
/* held_sigchld is set if sigchld occurs before a job is completely started */
static volatile sig_atomic_t held_sigchld;
-#ifdef JOBS
static struct shf *shl_j;
static int ttypgrp_ok; /* set if can use tty pgrps */
static pid_t restore_ttypgrp = -1;
static pid_t our_pgrp;
static int const tt_sigs[] = { SIGTSTP, SIGTTIN, SIGTTOU };
-#endif /* JOBS */
static void j_set_async(Job *);
static void j_startjob(Job *);
@@ -163,7 +159,6 @@ j_init(int mflagset)
setsig(&sigtraps[SIGCHLD], j_sigchld,
SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP);
-#ifdef JOBS
if (!mflagset && Flag(FTALKING))
Flag(FMONITOR) = 1;
@@ -189,10 +184,8 @@ j_init(int mflagset)
/* j_change() calls tty_init() */
if (Flag(FMONITOR))
j_change();
- else
-#endif /* JOBS */
- if (Flag(FTALKING))
- tty_init(true);
+ else if (Flag(FTALKING))
+ tty_init(true);
}
/* suspend the shell */
@@ -206,14 +199,13 @@ j_suspend(void)
tcsetattr(tty_fd, TCSADRAIN, &tty_state);
if (restore_ttypgrp >= 0) {
if (tcsetpgrp(tty_fd, restore_ttypgrp) < 0) {
- warningf(false,
- "j_suspend: tcsetpgrp() failed: %s",
- strerror(errno));
+ warningf(false, "%s: tcsetpgrp() failed: %s",
+ __func__, strerror(errno));
} else {
if (setpgid(0, restore_ttypgrp) < 0) {
warningf(false,
- "j_suspend: setpgid() failed: %s",
- strerror(errno));
+ "%s: setpgid() failed: %s",
+ __func__, strerror(errno));
}
}
}
@@ -231,15 +223,14 @@ j_suspend(void)
if (ttypgrp_ok) {
if (restore_ttypgrp >= 0) {
if (setpgid(0, kshpid) < 0) {
- warningf(false,
- "j_suspend: setpgid() failed: %s",
- strerror(errno));
+ warningf(false, "%s: setpgid() failed: %s",
+ __func__, strerror(errno));
ttypgrp_ok = 0;
} else {
if (tcsetpgrp(tty_fd, kshpid) < 0) {
warningf(false,
- "j_suspend: tcsetpgrp() failed: %s",
- strerror(errno));
+ "%s: tcsetpgrp() failed: %s",
+ __func__, strerror(errno));
ttypgrp_ok = 0;
}
}
@@ -267,21 +258,18 @@ j_exit(void)
kill_job(j, SIGHUP);
else
killpg(j->pgrp, SIGHUP);
-#ifdef JOBS
if (j->state == PSTOPPED) {
if (j->pgrp == 0)
kill_job(j, SIGCONT);
else
killpg(j->pgrp, SIGCONT);
}
-#endif /* JOBS */
}
}
if (killed)
sleep(1);
j_notify();
-#ifdef JOBS
if (kshpid == procpid && restore_ttypgrp >= 0) {
/* Need to restore the tty pgrp to what it was when the
* shell started up, so that the process that started us
@@ -297,10 +285,8 @@ j_exit(void)
Flag(FMONITOR) = 0;
j_change();
}
-#endif /* JOBS */
}
-#ifdef JOBS
/* turn job control on or off according to Flag(FMONITOR) */
void
j_change(void)
@@ -321,8 +307,8 @@ j_change(void)
ttypgrp_ok = use_tty && tty_fd >= 0 && tty_devtty;
if (ttypgrp_ok && (our_pgrp = getpgrp()) < 0) {
- warningf(false, "j_init: getpgrp() failed: %s",
- strerror(errno));
+ warningf(false, "%s: getpgrp() failed: %s",
+ __func__, strerror(errno));
ttypgrp_ok = 0;
}
if (ttypgrp_ok) {
@@ -334,8 +320,8 @@ j_change(void)
if ((ttypgrp = tcgetpgrp(tty_fd)) < 0) {
warningf(false,
- "j_init: tcgetpgrp() failed: %s",
- strerror(errno));
+ "%s: tcgetpgrp() failed: %s",
+ __func__, strerror(errno));
ttypgrp_ok = 0;
break;
}
@@ -349,15 +335,14 @@ j_change(void)
SS_RESTORE_DFL|SS_FORCE);
if (ttypgrp_ok && our_pgrp != kshpid) {
if (setpgid(0, kshpid) < 0) {
- warningf(false,
- "j_init: setpgid() failed: %s",
- strerror(errno));
+ warningf(false, "%s: setpgid() failed: %s",
+ __func__, strerror(errno));
ttypgrp_ok = 0;
} else {
if (tcsetpgrp(tty_fd, kshpid) < 0) {
warningf(false,
- "j_init: tcsetpgrp() failed: %s",
- strerror(errno));
+ "%s: tcsetpgrp() failed: %s",
+ __func__, strerror(errno));
ttypgrp_ok = 0;
} else
restore_ttypgrp = our_pgrp;
@@ -366,7 +351,8 @@ j_change(void)
}
if (use_tty) {
if (!ttypgrp_ok)
- warningf(false, "warning: won't have full job control");
+ warningf(false,
+ "warning: won't have full job control");
}
if (tty_fd >= 0)
tcgetattr(tty_fd, &tty_state);
@@ -389,7 +375,6 @@ j_change(void)
tty_close();
}
}
-#endif /* JOBS */
/* execute tree in child subprocess */
int
@@ -424,9 +409,8 @@ exchild(struct op *t, int flags, volatile int *xerrok,
/* link process into jobs list */
if (flags&XPIPEI) { /* continuing with a pipe */
if (!last_job)
- internal_errorf(1,
- "exchild: XPIPEI and no last_job - pid %d",
- (int) procpid);
+ internal_errorf("%s: XPIPEI and no last_job - pid %d",
+ __func__, (int) procpid);
j = last_job;
last_proc->next = p;
last_proc = p;
@@ -472,7 +456,6 @@ exchild(struct op *t, int flags, volatile int *xerrok,
else
p->pid = i;
-#ifdef JOBS
/* job control set up */
if (Flag(FMONITOR) && !(flags&XXCOM)) {
int dotty = 0;
@@ -493,7 +476,6 @@ exchild(struct op *t, int flags, volatile int *xerrok,
if (ttypgrp_ok && dotty && !(flags & XBGND))
tcsetpgrp(tty_fd, j->pgrp);
}
-#endif /* JOBS */
/* used to close pipe input fd */
if (close_fd >= 0 && (((flags & XPCLOSE) && !ischild) ||
@@ -505,7 +487,6 @@ exchild(struct op *t, int flags, volatile int *xerrok,
coproc_cleanup(false);
sigprocmask(SIG_SETMASK, &omask, NULL);
cleanup_parents_env();
-#ifdef JOBS
/* If FMONITOR or FTALKING is set, these signals are ignored,
* if neither FMONITOR nor FTALKING are set, the signals have
* their inherited values.
@@ -515,7 +496,6 @@ exchild(struct op *t, int flags, volatile int *xerrok,
setsig(&sigtraps[tt_sigs[i]], SIG_DFL,
SS_RESTORE_DFL|SS_FORCE);
}
-#endif /* JOBS */
if (Flag(FBGNICE) && (flags & XBGND))
nice(4);
if ((flags & XBGND) && !Flag(FMONITOR)) {
@@ -533,15 +513,13 @@ exchild(struct op *t, int flags, volatile int *xerrok,
}
remove_job(j, "child"); /* in case of `jobs` command */
nzombie = 0;
-#ifdef JOBS
ttypgrp_ok = 0;
Flag(FMONITOR) = 0;
-#endif /* JOBS */
Flag(FTALKING) = 0;
tty_close();
cleartraps();
execute(t, (flags & XERROK) | XEXEC, NULL); /* no return */
- internal_errorf(0, "exchild: execute() returned");
+ internal_warningf("%s: execute() returned", __func__);
unwind(LLEAVE);
/* NOTREACHED */
}
@@ -550,12 +528,10 @@ exchild(struct op *t, int flags, volatile int *xerrok,
/* Ensure next child gets a (slightly) different $RANDOM sequence */
change_random();
if (!(flags & XPIPEO)) { /* last process in a job */
-#ifdef JOBS
/* YYY: Is this needed? (see also YYY above)
if (Flag(FMONITOR) && !(flags&(XXCOM|XBGND)))
tcsetpgrp(tty_fd, j->pgrp);
*/
-#endif /* JOBS */
j_startjob(j);
if (flags & XCOPROC) {
j->coproc_id = coproc.id;
@@ -609,9 +585,9 @@ waitlast(void)
j = last_job;
if (!j || !(j->flags & JF_STARTED)) {
if (!j)
- warningf(true, "waitlast: no last job");
+ warningf(true, "%s: no last job", __func__);
else
- internal_errorf(0, "waitlast: not started");
+ internal_warningf("%s: not started", __func__);
sigprocmask(SIG_SETMASK, &omask, NULL);
return 125; /* not so arbitrary, non-zero value */
}
@@ -697,10 +673,8 @@ j_kill(const char *cp, int sig)
rv = 1;
}
} else {
-#ifdef JOBS
if (j->state == PSTOPPED && (sig == SIGTERM || sig == SIGHUP))
(void) killpg(j->pgrp, SIGCONT);
-#endif /* JOBS */
if (killpg(j->pgrp, sig) < 0) {
bi_errorf("%s: %s", cp, strerror(errno));
rv = 1;
@@ -712,7 +686,6 @@ j_kill(const char *cp, int sig)
return rv;
}
-#ifdef JOBS
/* fg and bg built-ins: called only if Flag(FMONITOR) set */
int
j_resume(const char *cp, int bg)
@@ -759,7 +732,6 @@ j_resume(const char *cp, int bg)
if (bg)
j_set_async(j);
else {
-# ifdef JOBS
/* attach tty to job */
if (j->state == PRUNNING) {
if (ttypgrp_ok && (j->flags & JF_SAVEDTTY))
@@ -779,7 +751,6 @@ j_resume(const char *cp, int bg)
return 1;
}
}
-# endif /* JOBS */
j->flags |= JF_FG;
j->flags &= ~JF_KNOWN;
if (j == async_job)
@@ -791,7 +762,6 @@ j_resume(const char *cp, int bg)
if (!bg) {
j->flags &= ~JF_FG;
-# ifdef JOBS
if (ttypgrp_ok && (j->flags & JF_SAVEDTTY))
tcsetattr(tty_fd, TCSADRAIN, &tty_state);
if (ttypgrp_ok && tcsetpgrp(tty_fd, our_pgrp) < 0) {
@@ -800,7 +770,6 @@ j_resume(const char *cp, int bg)
tty_fd, (int) our_pgrp,
strerror(errno));
}
-# endif /* JOBS */
}
sigprocmask(SIG_SETMASK, &omask, NULL);
bi_errorf("cannot continue job %s: %s",
@@ -808,17 +777,14 @@ j_resume(const char *cp, int bg)
return 1;
}
if (!bg) {
-# ifdef JOBS
if (ttypgrp_ok) {
j->flags &= ~(JF_SAVEDTTY | JF_SAVEDTTYPGRP);
}
-# endif /* JOBS */
rv = j_waitj(j, JW_NONE, "jw:resume");
}
sigprocmask(SIG_SETMASK, &omask, NULL);
return rv;
}
-#endif /* JOBS */
/* are there any running or stopped jobs ? */
int
@@ -828,10 +794,8 @@ j_stopped_running(void)
int which = 0;
for (j = job_list; j != NULL; j = j->next) {
-#ifdef JOBS
if (j->ppid == procpid && j->state == PSTOPPED)
which |= 1;
-#endif /* JOBS */
if (Flag(FLOGIN) && !Flag(FNOHUP) && procpid == kshpid &&
j->ppid == procpid && j->state == PRUNNING)
which |= 2;
@@ -919,10 +883,8 @@ j_notify(void)
sigprocmask(SIG_BLOCK, &sm_sigchld, &omask);
for (j = job_list; j; j = j->next) {
-#ifdef JOBS
if (Flag(FMONITOR) && (j->flags & JF_CHANGED))
j_print(j, JP_MEDIUM, shl_out);
-#endif /* JOBS */
/* Remove job after doing reports so there aren't
* multiple +/- jobs.
*/
@@ -956,7 +918,7 @@ j_async(void)
/* Make j the last async process
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static void
j_set_async(Job *j)
@@ -966,7 +928,7 @@ j_set_async(Job *j)
if (async_job && (async_job->flags & (JF_KNOWN|JF_ZOMBIE)) == JF_ZOMBIE)
remove_job(async_job, "async");
if (!(j->flags & JF_STARTED)) {
- internal_errorf(0, "j_async: job not started");
+ internal_warningf("%s: job not started", __func__);
return;
}
async_job = j;
@@ -980,8 +942,8 @@ j_set_async(Job *j)
if (!oldest) {
/* XXX debugging */
if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) {
- internal_errorf(0,
- "j_async: bad nzombie (%d)", nzombie);
+ internal_warningf("%s: bad nzombie (%d)",
+ __func__, nzombie);
nzombie = 0;
}
break;
@@ -992,7 +954,7 @@ j_set_async(Job *j)
/* Start a job: set STARTED, check for held signals and set j->last_proc
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static void
j_startjob(Job *j)
@@ -1014,7 +976,7 @@ j_startjob(Job *j)
/*
* wait for job to complete or change state
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static int
j_waitj(Job *j,
@@ -1053,7 +1015,6 @@ j_waitj(Job *j,
int status;
j->flags &= ~JF_FG;
-#ifdef JOBS
if (Flag(FMONITOR) && ttypgrp_ok && j->pgrp) {
/*
* Save the tty's current pgrp so it can be restored
@@ -1071,8 +1032,8 @@ j_waitj(Job *j,
j->flags |= JF_SAVEDTTYPGRP;
if (tcsetpgrp(tty_fd, our_pgrp) < 0) {
warningf(true,
- "j_waitj: tcsetpgrp(%d, %d) failed: %s",
- tty_fd, (int) our_pgrp,
+ "%s: tcsetpgrp(%d, %d) failed: %s",
+ __func__, tty_fd, (int)our_pgrp,
strerror(errno));
}
if (j->state == PSTOPPED) {
@@ -1080,7 +1041,6 @@ j_waitj(Job *j,
tcgetattr(tty_fd, &j->ttystate);
}
}
-#endif /* JOBS */
if (tty_fd >= 0) {
/* Only restore tty settings if job was originally
* started in the foreground. Problems can be
@@ -1110,7 +1070,6 @@ j_waitj(Job *j,
j->flags &= ~JF_USETTYMODE;
}
}
-#ifdef JOBS
/* If it looks like user hit ^C to kill a job, pretend we got
* one too to break out of for loops, etc. (at&t ksh does this
* even when not monitoring, but this doesn't make sense since
@@ -1121,7 +1080,6 @@ j_waitj(Job *j,
WIFSIGNALED(status) &&
(sigtraps[WTERMSIG(status)].flags & TF_TTY_INTR))
trapsig(WTERMSIG(status));
-#endif /* JOBS */
}
j_usrtime = j->usrtime;
@@ -1142,7 +1100,7 @@ j_waitj(Job *j,
/* SIGCHLD handler to reap children and update job states
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static void
j_sigchld(int sig)
@@ -1195,12 +1153,9 @@ found:
timersub(&j->systime, &ru0.ru_stime, &j->systime);
ru0 = ru1;
p->status = status;
-#ifdef JOBS
if (WIFSTOPPED(status))
p->state = PSTOPPED;
- else
-#endif /* JOBS */
- if (WIFSIGNALED(status))
+ else if (WIFSIGNALED(status))
p->state = PSIGNALLED;
else
p->state = PEXITED;
@@ -1218,7 +1173,7 @@ finished:
* and state are updated, asynchronous job notification is done and,
* if unneeded, the job is removed.
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static void
check_job(Job *j)
@@ -1228,8 +1183,8 @@ check_job(Job *j)
/* XXX debugging (nasty - interrupt routine using shl_out) */
if (!(j->flags & JF_STARTED)) {
- internal_errorf(0, "check_job: job started (flags 0x%x)",
- j->flags);
+ internal_warningf("%s: job started (flags 0x%x)",
+ __func__, j->flags);
return;
}
@@ -1278,7 +1233,6 @@ check_job(Job *j)
}
j->flags |= JF_CHANGED;
-#ifdef JOBS
if (Flag(FMONITOR) && !(j->flags & JF_XXCOM)) {
/* Only put stopped jobs at the front to avoid confusing
* the user (don't want finished jobs effecting %+ or %-)
@@ -1307,7 +1261,6 @@ check_job(Job *j)
remove_job(j, "notify");
}
}
-#endif /* JOBS */
if (!Flag(FMONITOR) && !(j->flags & (JF_WAITING|JF_FG)) &&
j->state != PSTOPPED) {
if (j == async_job || (j->flags & JF_KNOWN)) {
@@ -1322,7 +1275,7 @@ check_job(Job *j)
/*
* Print job status in either short, medium or long format.
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static void
j_print(Job *j, int how, struct shf *shf)
@@ -1337,7 +1290,7 @@ j_print(Job *j, int how, struct shf *shf)
int output = 0;
if (how == JP_PGRP) {
- /* POSIX doesn't say what to do it there is no process
+ /* POSIX doesn't say what to do if there is no process
* group leader (ie, !FMONITOR). We arbitrarily return
* last pid (which is what $! returns).
*/
@@ -1429,7 +1382,7 @@ j_print(Job *j, int how, struct shf *shf)
/* Convert % sequence to job
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static Job *
j_lookup(const char *cp, int *ecodep)
@@ -1530,7 +1483,7 @@ static Proc *free_procs;
/* allocate a new job and fill in the job number.
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static Job *
new_job(void)
@@ -1558,7 +1511,7 @@ new_job(void)
/* Allocate new process struct
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static Proc *
new_proc(void)
@@ -1577,7 +1530,7 @@ new_proc(void)
/* Take job out of job_list and put old structures into free list.
* Keeps nzombies, last_job and async_job up to date.
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static void
remove_job(Job *j, const char *where)
@@ -1590,7 +1543,7 @@ remove_job(Job *j, const char *where)
for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev)
;
if (curr != j) {
- internal_errorf(0, "remove_job: job not found (%s)", where);
+ internal_warningf("%s: job not found (%s)", __func__, where);
return;
}
*prev = curr->next;
@@ -1614,10 +1567,10 @@ remove_job(Job *j, const char *where)
async_job = NULL;
}
-/* put j in a particular location (taking it out job_list if it is there
- * already)
+/* Put j in a particular location (taking it out of job_list if it is
+ * there already)
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static void
put_job(Job *j, int where)
@@ -1652,7 +1605,7 @@ put_job(Job *j, int where)
/* nuke a job (called when unable to start full job).
*
- * If jobs are compiled in then this routine expects sigchld to be blocked.
+ * Expects sigchld to be blocked.
*/
static int
kill_job(Job *j, int sig)
diff --git a/bin/ksh/ksh.1 b/bin/ksh/ksh.1
index 4471043..1da3063 100644
--- a/bin/ksh/ksh.1
+++ b/bin/ksh/ksh.1
@@ -1,8 +1,10 @@
-.\" $OpenBSD: ksh.1,v 1.195 2017/08/30 17:08:45 jca Exp $
+<<<<<<< bin/ksh/ksh.1
+=======
.\"
.\" Public Domain
.\"
-.Dd $Mdocdate: August 30 2017 $
+<<<<<<< bin/ksh/ksh.1
+=======
.Dt KSH 1
.Os
.Sh NAME
@@ -1539,7 +1541,7 @@ By the way, don't blame me for
this hack; it's in the original
.Nm .
.Pp
-The default prompt is
+The default prompt is the first part of the hostname, followed by
.Sq $\ \&
for non-root users,
.Sq #\ \&
@@ -2788,11 +2790,18 @@ for more information.
.Ar string Ns = Ns Op Ar editing-command
.Ar ...
.Xc
-The specified editing command is bound to the given
+<<<<<<< bin/ksh/ksh.1
+In
+=======
+In
.Ar string .
Future input of the
.Ar string
will cause the editing command to be immediately invoked.
+<<<<<<< bin/ksh/ksh.1
+Bindings have no effect in
+=======
+Bindings have no effect in
If the
.Fl m
flag is given, the specified input
@@ -4656,7 +4665,8 @@ Simply causes the character to appear as literal input.
Most ordinary characters are bound to this.
.It Xo backward-char:
.Op Ar n
-.No ^B , ^XD
+<<<<<<< bin/ksh/ksh.1
+=======
.Xc
Moves the cursor backward
.Ar n
@@ -4749,7 +4759,8 @@ Deletes
characters after the cursor.
.It Xo delete-word-backward:
.Op Ar n
-.No ERASE , ^[^? , ^[^H , ^[h
+<<<<<<< bin/ksh/ksh.1
+=======
.Xc
Deletes
.Ar n
@@ -4758,9 +4769,9 @@ words before the cursor.
.Op Ar n
.No ^[d
.Xc
-Deletes characters after the cursor up to the end of
+Deletes
.Ar n
-words.
+words after the cursor.
.It Xo down-history:
.Op Ar n
.No ^N , ^XB
@@ -4830,8 +4841,6 @@ Goes to history number
.Ar n .
.It kill-line: KILL
Deletes the entire input line.
-.It kill-region: ^W
-Deletes the input between the cursor and the mark.
.It Xo kill-to-eol:
.Op Ar n
.No ^K
diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c
index 7a329c3..efc4cea 100644
--- a/bin/ksh/lex.c
+++ b/bin/ksh/lex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.c,v 1.71 2017/07/04 11:46:15 anton Exp $ */
+/* $OpenBSD: lex.c,v 1.78 2018/01/15 14:58:05 jca Exp $ */
/*
* lexical analysis and source input
@@ -102,9 +102,9 @@ YYSTYPE yylval; /* result from yylex */
struct ioword *heres[HERES], **herep;
char ident[IDENT+1];
-char **history; /* saved commands */
-char **histptr; /* last history item */
-int histsize; /* history size */
+char **history; /* saved commands */
+char **histptr; /* last history item */
+uint32_t histsize; /* history size */
/* optimized getsc_bn() */
#define getsc() (*source->str != '\0' && *source->str != '\\' \
@@ -1090,14 +1090,13 @@ getsc_line(Source *s)
ksh_tmout_state = TMOUT_READING;
alarm(ksh_tmout);
}
-#ifdef EDIT
if (have_tty && (0
-# ifdef VI
+#ifdef VI
|| Flag(FVI)
-# endif /* VI */
-# ifdef EMACS
+#endif /* VI */
+#ifdef EMACS
|| Flag(FEMACS) || Flag(FGMACS)
-# endif /* EMACS */
+#endif /* EMACS */
)) {
int nread;
@@ -1106,10 +1105,7 @@ getsc_line(Source *s)
nread = 0;
xp[nread] = '\0';
xp += nread;
- }
- else
-#endif /* EDIT */
- {
+ } else {
if (interactive) {
pprompt(prompt, 0);
} else
@@ -1157,7 +1153,6 @@ getsc_line(Source *s)
shf_fdclose(s->u.shf);
s->str = NULL;
} else if (interactive) {
-#ifdef HISTORY
char *p = Xstring(s->xs, xp);
if (cur_prompt == PS1)
while (*p && ctype(*p, C_IFS) && ctype(*p, C_IFSWS))
@@ -1166,10 +1161,9 @@ getsc_line(Source *s)
s->line++;
histsave(s->line, s->str, 1);
}
-#endif /* HISTORY */
}
if (interactive)
- set_prompt(PS2, NULL);
+ set_prompt(PS2);
}
static char *
@@ -1184,7 +1178,7 @@ special_prompt_expand(char *str)
}
void
-set_prompt(int to, Source *s)
+set_prompt(int to)
{
char *ps1;
Area *saved_atemp;
@@ -1250,7 +1244,8 @@ dopprompt(const char *sp, int ntruncate, const char **spp, int doprint)
cp++;
if (!*cp)
break;
- if (Flag(FSH))
+ /* Expand \h and \$ for both, sh(1) and ksh(1) */
+ if (Flag(FSH) && !(*cp == 'h' || *cp == 'p'))
snprintf(strbuf, sizeof strbuf, "\\%c", *cp);
else switch (*cp) {
case 'a': /* '\' 'a' bell */
@@ -1449,8 +1444,6 @@ dopprompt(const char *sp, int ntruncate, const char **spp, int doprint)
else if (*++cp == '!')
c = *cp++;
else {
- char *p;
-
shf_snprintf(p = nbuf, sizeof(nbuf), "%d",
source->line + 1);
len = strlen(nbuf);
diff --git a/bin/ksh/lex.h b/bin/ksh/lex.h
index 0b006d0..bf9072c 100644
--- a/bin/ksh/lex.h
+++ b/bin/ksh/lex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.h,v 1.16 2015/10/10 07:35:16 nicm Exp $ */
+/* $OpenBSD: lex.h,v 1.21 2018/01/15 14:58:05 jca Exp $ */
/*
* Source input, lexer and parser
@@ -105,18 +105,15 @@ extern YYSTYPE yylval; /* result from yylex */
extern struct ioword *heres[HERES], **herep;
extern char ident[IDENT+1];
-#ifdef HISTORY
-# define HISTORYSIZE 500 /* size of saved history */
+#define HISTORYSIZE 500 /* size of saved history */
extern char **history; /* saved commands */
extern char **histptr; /* last history item */
-extern int histsize; /* history size */
-
-#endif /* HISTORY */
+extern uint32_t histsize; /* history size */
int yylex(int);
void yyerror(const char *, ...)
__attribute__((__noreturn__, __format__ (printf, 1, 2)));
Source * pushs(int, Area *);
-void set_prompt(int, Source *);
+void set_prompt(int);
void pprompt(const char *, int);
diff --git a/bin/ksh/main.c b/bin/ksh/main.c
index 8ec5925..62d8180 100644
--- a/bin/ksh/main.c
+++ b/bin/ksh/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.83 2017/08/11 23:10:55 guenther Exp $ */
+/* $OpenBSD: main.c,v 1.90 2018/03/15 16:51:29 anton Exp $ */
/*
* startup, main loop, environments and error handling
@@ -69,9 +69,7 @@ int builtin_flag;
char *current_wd;
int current_wd_size;
-#ifdef EDIT
int x_cols = 80;
-#endif /* EDIT */
/*
* shell initialization
@@ -91,14 +89,10 @@ static const char *initcoms [] = {
/* Standard ksh aliases */
"hash=alias -t", /* not "alias -t --": hash -r needs to work */
"type=whence -v",
-#ifdef JOBS
"stop=kill -STOP",
-#endif
"autoload=typeset -fu",
"functions=typeset -f",
-#ifdef HISTORY
"history=fc -l",
-#endif /* HISTORY */
"integer=typeset -i",
"nohup=nohup ",
"local=typeset",
@@ -228,9 +222,7 @@ main(int argc, char *argv[])
* brace expansion, so set this before setting up FPOSIX
* (change_flag() clears FBRACEEXPAND when FPOSIX is set).
*/
-#ifdef BRACE_EXPAND
Flag(FBRACEEXPAND) = 1;
-#endif /* BRACE_EXPAND */
/* set posix flag just before environment so that it will have
* exactly the same effect as the POSIXLY_CORRECT environment
@@ -253,12 +245,12 @@ main(int argc, char *argv[])
/* Set edit mode to emacs by default, may be overridden
* by the environment or the user. Also, we want tab completion
* on in vi by default. */
-#if defined(EDIT) && defined(EMACS)
+#if defined(EMACS)
change_flag(FEMACS, OF_SPECIAL, 1);
-#endif /* EDIT && EMACS */
-#if defined(EDIT) && defined(VI)
+#endif /* EMACS */
+#if defined(VI)
Flag(FVITABCOMPLETE) = 1;
-#endif /* EDIT && VI */
+#endif /* VI */
/* import environment */
if (environ != NULL)
@@ -316,7 +308,7 @@ main(int argc, char *argv[])
/* Set PS1 if it isn't set */
if (!(vp->flag & ISSET)) {
/* setstr can't fail here */
- setstr(vp, safe_prompt, KSH_RETURN_ERROR);
+ setstr(vp, "\\h\\$ ", KSH_RETURN_ERROR);
}
}
@@ -371,11 +363,9 @@ main(int argc, char *argv[])
i = Flag(FMONITOR) != 127;
Flag(FMONITOR) = 0;
j_init(i);
-#ifdef EDIT
/* Do this after j_init(), as tty_fd is not initialized 'til then */
if (Flag(FTALKING))
x_init();
-#endif
l = genv->loc;
l->argv = make_argv(argc - (argi - 1), &argv[argi - 1]);
@@ -502,7 +492,7 @@ include(const char *name, int argc, char **argv, int intr_ok)
unwind(i);
/* NOTREACHED */
default:
- internal_errorf(1, "include: %d", i);
+ internal_errorf("%s: %d", __func__, i);
/* NOTREACHED */
}
}
@@ -589,7 +579,7 @@ shell(Source *volatile s, volatile int toplevel)
default:
source = old_source;
quitenv(NULL);
- internal_errorf(1, "shell: %d", i);
+ internal_errorf("%s: %d", __func__, i);
/* NOTREACHED */
}
}
@@ -609,7 +599,7 @@ shell(Source *volatile s, volatile int toplevel)
got_sigwinch = 1;
j_notify();
mcheck();
- set_prompt(PS1, s);
+ set_prompt(PS1);
}
t = compile(s);
diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c
index c1a6006..7cc5a16 100644
--- a/bin/ksh/misc.c
+++ b/bin/ksh/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.60 2017/10/19 07:54:05 jca Exp $ */
+/* $OpenBSD: misc.c,v 1.69 2018/03/15 16:51:29 anton Exp $ */
/*
* Miscellaneous functions
@@ -105,7 +105,7 @@ str_nsave(const char *s, int n, Area *ap)
/* called from expand.h:XcheckN() to grow buffer */
char *
-Xcheck_grow_(XString *xsp, char *xp, int more)
+Xcheck_grow_(XString *xsp, char *xp, size_t more)
{
char *old_beg = xsp->beg;
@@ -115,15 +115,13 @@ Xcheck_grow_(XString *xsp, char *xp, int more)
return xsp->beg + (xp - old_beg);
}
-const struct option options[] = {
+const struct option sh_options[] = {
/* Special cases (see parse_args()): -A, -o, -s.
* Options are sorted by their longnames - the order of these
* entries MUST match the order of sh_flag F* enumerations in sh.h.
*/
{ "allexport", 'a', OF_ANY },
-#ifdef BRACE_EXPAND
{ "braceexpand", 0, OF_ANY }, /* non-standard */
-#endif
{ "bgnice", 0, OF_ANY },
{ NULL, 'c', OF_CMDLINE },
{ "csh-history", 0, OF_ANY }, /* non-standard */
@@ -139,19 +137,13 @@ const struct option options[] = {
{ "keyword", 'k', OF_ANY },
{ "login", 'l', OF_CMDLINE },
{ "markdirs", 'X', OF_ANY },
-#ifdef JOBS
{ "monitor", 'm', OF_ANY },
-#else /* JOBS */
- { NULL, 'm', 0 }, /* so FMONITOR not ifdef'd */
-#endif /* JOBS */
{ "noclobber", 'C', OF_ANY },
{ "noexec", 'n', OF_ANY },
{ "noglob", 'f', OF_ANY },
{ "nohup", 0, OF_ANY },
{ "nolog", 0, OF_ANY }, /* no effect */
-#ifdef JOBS
{ "notify", 'b', OF_ANY },
-#endif /* JOBS */
{ "nounset", 'u', OF_ANY },
{ "physical", 0, OF_ANY }, /* non-standard */
{ "posix", 0, OF_ANY }, /* non-standard */
@@ -181,11 +173,11 @@ const struct option options[] = {
int
option(const char *n)
{
- int i;
+ unsigned int ele;
- for (i = 0; i < NELEM(options); i++)
- if (options[i].name && strcmp(options[i].name, n) == 0)
- return i;
+ for (ele = 0; ele < NELEM(sh_options); ele++)
+ if (sh_options[ele].name && strcmp(sh_options[ele].name, n) == 0)
+ return ele;
return -1;
}
@@ -195,7 +187,7 @@ struct options_info {
struct {
const char *name;
int flag;
- } opts[NELEM(options)];
+ } opts[NELEM(sh_options)];
};
static char *options_fmt_entry(void *arg, int i, char *buf, int buflen);
@@ -216,20 +208,21 @@ options_fmt_entry(void *arg, int i, char *buf, int buflen)
static void
printoptions(int verbose)
{
- int i;
+ unsigned int ele;
if (verbose) {
struct options_info oi;
- int n, len;
+ unsigned int n;
+ int len;
/* verbose version */
shprintf("Current option settings\n");
- for (i = n = oi.opt_width = 0; i < NELEM(options); i++) {
- if (options[i].name) {
- len = strlen(options[i].name);
- oi.opts[n].name = options[i].name;
- oi.opts[n++].flag = i;
+ for (ele = n = oi.opt_width = 0; ele < NELEM(sh_options); ele++) {
+ if (sh_options[ele].name) {
+ len = strlen(sh_options[ele].name);
+ oi.opts[n].name = sh_options[ele].name;
+ oi.opts[n++].flag = ele;
if (len > oi.opt_width)
oi.opt_width = len;
}
@@ -239,11 +232,11 @@ printoptions(int verbose)
} else {
/* short version ala ksh93 */
shprintf("set");
- for (i = 0; i < NELEM(options); i++) {
- if (options[i].name)
+ for (ele = 0; ele < NELEM(sh_options); ele++) {
+ if (sh_options[ele].name)
shprintf(" %co %s",
- Flag(i) ? '-' : '+',
- options[i].name);
+ Flag(ele) ? '-' : '+',
+ sh_options[ele].name);
}
shprintf("\n");
}
@@ -252,13 +245,13 @@ printoptions(int verbose)
char *
getoptions(void)
{
- int i;
+ unsigned int ele;
char m[(int) FNFLAGS + 1];
char *cp = m;
- for (i = 0; i < NELEM(options); i++)
- if (options[i].c && Flag(i))
- *cp++ = options[i].c;
+ for (ele = 0; ele < NELEM(sh_options); ele++)
+ if (sh_options[ele].c && Flag(ele))
+ *cp++ = sh_options[ele].c;
*cp = 0;
return str_save(m, ATEMP);
}
@@ -273,33 +266,29 @@ change_flag(enum sh_flag f,
oldval = Flag(f);
Flag(f) = newval;
-#ifdef JOBS
if (f == FMONITOR) {
if (what != OF_CMDLINE && newval != oldval)
j_change();
} else
-#endif /* JOBS */
-#ifdef EDIT
if (0
-# ifdef VI
+#ifdef VI
|| f == FVI
-# endif /* VI */
-# ifdef EMACS
+#endif /* VI */
+#ifdef EMACS
|| f == FEMACS || f == FGMACS
-# endif /* EMACS */
+#endif /* EMACS */
)
{
if (newval) {
-# ifdef VI
+#ifdef VI
Flag(FVI) = 0;
-# endif /* VI */
-# ifdef EMACS
+#endif /* VI */
+#ifdef EMACS
Flag(FEMACS) = Flag(FGMACS) = 0;
-# endif /* EMACS */
+#endif /* EMACS */
Flag(f) = newval;
}
} else
-#endif /* EDIT */
/* Turning off -p? */
if (f == FPRIVILEGED && oldval && !newval) {
gid_t gid = getgid();
@@ -308,10 +297,7 @@ change_flag(enum sh_flag f,
setgroups(1, &gid);
setresuid(ksheuid, ksheuid, ksheuid);
} else if (f == FPOSIX && newval) {
-#ifdef BRACE_EXPAND
- Flag(FBRACEEXPAND) = 0
-#endif /* BRACE_EXPAND */
- ;
+ Flag(FBRACEEXPAND) = 0;
}
/* Changing interactive flag? */
if (f == FTALKING) {
@@ -328,12 +314,13 @@ parse_args(char **argv,
int what, /* OF_CMDLINE or OF_SET */
int *setargsp)
{
- static char cmd_opts[NELEM(options) + 3]; /* o:\0 */
- static char set_opts[NELEM(options) + 5]; /* Ao;s\0 */
+ static char cmd_opts[NELEM(sh_options) + 3]; /* o:\0 */
+ static char set_opts[NELEM(sh_options) + 5]; /* Ao;s\0 */
char *opts;
char *array = NULL;
Getopt go;
- int i, optc, set, sortargs = 0, arrayset = 0;
+ int i, optc, sortargs = 0, arrayset = 0;
+ unsigned int ele;
/* First call? Build option strings... */
if (cmd_opts[0] == '\0') {
@@ -345,12 +332,12 @@ parse_args(char **argv,
/* see set_opts[] declaration */
strlcpy(set_opts, "A:o;s", sizeof set_opts);
q = set_opts + strlen(set_opts);
- for (i = 0; i < NELEM(options); i++) {
- if (options[i].c) {
- if (options[i].flags & OF_CMDLINE)
- *p++ = options[i].c;
- if (options[i].flags & OF_SET)
- *q++ = options[i].c;
+ for (ele = 0; ele < NELEM(sh_options); ele++) {
+ if (sh_options[ele].c) {
+ if (sh_options[ele].flags & OF_CMDLINE)
+ *p++ = sh_options[ele].c;
+ if (sh_options[ele].flags & OF_SET)
+ *q++ = sh_options[ele].c;
}
}
*p = '\0';
@@ -369,7 +356,7 @@ parse_args(char **argv,
opts = set_opts;
ksh_getopt_reset(&go, GF_ERROR|GF_PLUSOPT);
while ((optc = ksh_getopt(argv, &go, opts)) != -1) {
- set = (go.info & GI_PLUS) ? 0 : 1;
+ int set = (go.info & GI_PLUS) ? 0 : 1;
switch (optc) {
case 'A':
arrayset = set ? 1 : -1;
@@ -388,14 +375,14 @@ parse_args(char **argv,
break;
}
i = option(go.optarg);
- if (i >= 0 && set == Flag(i))
+ if (i != -1 && set == Flag(i))
/* Don't check the context if the flag
* isn't changing - makes "set -o interactive"
* work if you're already interactive. Needed
* if the output of "set +o" is to be used.
*/
;
- else if (i >= 0 && (options[i].flags & what))
+ else if (i != -1 && (sh_options[i].flags & what))
change_flag((enum sh_flag) i, what, set);
else {
bi_errorf("%s: bad option", go.optarg);
@@ -412,15 +399,15 @@ parse_args(char **argv,
sortargs = 1;
break;
}
- for (i = 0; i < NELEM(options); i++)
- if (optc == options[i].c &&
- (what & options[i].flags)) {
- change_flag((enum sh_flag) i, what,
+ for (ele = 0; ele < NELEM(sh_options); ele++)
+ if (optc == sh_options[ele].c &&
+ (what & sh_options[ele].flags)) {
+ change_flag((enum sh_flag) ele, what,
set);
break;
}
- if (i == NELEM(options)) {
- internal_errorf(1, "parse_args: `%c'", optc);
+ if (ele == NELEM(sh_options)) {
+ internal_errorf("%s: `%c'", __func__, optc);
return -1; /* not reached */
}
}
@@ -508,7 +495,7 @@ gmatch(const char *s, const char *p, int isfile)
* the pattern. If check fails, just to a strcmp().
*/
if (!isfile && !has_globbing(p, pe)) {
- int len = pe - p + 1;
+ size_t len = pe - p + 1;
char tbuf[64];
char *t = len <= sizeof(tbuf) ? tbuf :
alloc(len, ATEMP);
diff --git a/bin/ksh/path.c b/bin/ksh/path.c
index 62e45a1..5da57a3 100644
--- a/bin/ksh/path.c
+++ b/bin/ksh/path.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: path.c,v 1.19 2017/09/03 11:52:01 jca Exp $ */
+/* $OpenBSD: path.c,v 1.22 2018/01/06 16:28:58 millert Exp $ */
#include <sys/stat.h>
@@ -228,7 +228,7 @@ do_phys_path(XString *xsp, char *xp, const char *path)
p++;
if (!*p)
break;
- len = (q = strchr(p, '/')) ? q - p : strlen(p);
+ len = (q = strchr(p, '/')) ? (size_t)(q - p) : strlen(p);
if (len == 1 && p[0] == '.')
continue;
if (len == 2 && p[0] == '.' && p[1] == '.') {
diff --git a/bin/ksh/sh.1 b/bin/ksh/sh.1
index 7ea6cfa..025b7a8 100644
--- a/bin/ksh/sh.1
+++ b/bin/ksh/sh.1
@@ -1,4 +1,5 @@
-.\" $OpenBSD: sh.1,v 1.143 2017/06/01 20:37:38 tb Exp $
+<<<<<<< bin/ksh/sh.1
+=======
.\"
.\" Copyright (c) 2015 Jason McIntyre <jmc@openbsd.org>
.\"
@@ -14,7 +15,8 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: June 1 2017 $
+<<<<<<< bin/ksh/sh.1
+=======
.Dt SH 1
.Os
.Sh NAME
@@ -700,10 +702,12 @@ display the names and values of all shell variables.
The options are described in the options description
at the beginning of this manual.
The sequence
-.Qq set -o
+<<<<<<< bin/ksh/sh.1
+=======
displays the current option settings;
the sequence
-.Qq set +o
+<<<<<<< bin/ksh/sh.1
+=======
displays,
in a format suitable to be reinput to the shell,
a command suitable to achieve the current option settings.
@@ -713,10 +717,12 @@ with the special parameter
.Sq #
set to the number of positional parameters.
The sequence
-.Qq set --
+<<<<<<< bin/ksh/sh.1
+=======
indicates an end to option processing
(i.e. only arguments follow);
-.Qq set --
+<<<<<<< bin/ksh/sh.1
+=======
by itself unsets all positional parameters
and sets
.Sq #
@@ -1165,7 +1171,7 @@ if the user wants to indicate to the shell not to interpret them as such.
The following characters need quoting if their literal meaning is desired:
.Bd -literal -offset indent
| & ; < > ( ) $ \` \e " \(aq <space> <tab> <newline>
-* ? [ # ~ = %
+* ? [ # ~ = %
.Ed
.Pp
A backslash
@@ -1190,7 +1196,7 @@ A backslash
.Pq \e
within double quotes retains its special meaning,
but only when followed by a backquote, dollar sign,
-double quote, or another backslash.
+double quote, newline, or another backslash.
An at sign
.Pq @
within double quotes has a special meaning
@@ -2101,11 +2107,6 @@ A
.Sq !\&
in the prompt is expanded to the number of the next command in history
to be typed.
-The default value is
-.Sq $\ \&
-for normal users and
-.Sq #\ \&
-for root.
.It Ev PS2
Newline prompt displayed in an interactive shell
when a newline has been entered
diff --git a/bin/ksh/sh.h b/bin/ksh/sh.h
index 06e7b0e..4fc5940 100644
--- a/bin/ksh/sh.h
+++ b/bin/ksh/sh.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sh.h,v 1.65 2017/10/19 07:54:05 jca Exp $ */
+/* $OpenBSD: sh.h,v 1.71 2018/01/16 22:52:32 jca Exp $ */
/*
* Public Domain Bourne/Korn shell
@@ -13,8 +13,10 @@
#include <limits.h>
#include <setjmp.h>
#include <stdarg.h>
+#include <stddef.h>
#include <signal.h>
#include <stdbool.h>
+#include <stdint.h>
/* end of common headers */
@@ -124,16 +126,14 @@ struct option {
char c; /* character flag (if any) */
short flags; /* OF_* */
};
-extern const struct option options[];
+extern const struct option sh_options[];
/*
* flags (the order of these enums MUST match the order in misc.c(options[]))
*/
enum sh_flag {
FEXPORT = 0, /* -a: export all */
-#ifdef BRACE_EXPAND
FBRACEEXPAND, /* enable {} globbing */
-#endif
FBGNICE, /* bgnice */
FCOMMAND, /* -c: (invocation) execute specified command */
FCSHHISTORY, /* csh-style history enabled */
@@ -155,9 +155,7 @@ enum sh_flag {
FNOGLOB, /* -f: don't do file globbing */
FNOHUP, /* -H: don't kill running jobs when login shell exits */
FNOLOG, /* don't save functions in history (ignored) */
-#ifdef JOBS
FNOTIFY, /* -b: asynchronous job completion notification */
-#endif
FNOUNSET, /* -u: using an unset var is an error */
FPHYSICAL, /* -o physical: don't do logical cd's/pwd's */
FPOSIX, /* -o posix: be posixly correct */
@@ -341,18 +339,14 @@ extern int builtin_flag; /* flags of called builtin (SPEC_BI, etc.) */
extern char *current_wd;
extern int current_wd_size;
-#ifdef EDIT
/* Minimum required space to work with on a line - if the prompt leaves less
* space than this on a line, the prompt is truncated.
*/
-# define MIN_EDIT_SPACE 7
+#define MIN_EDIT_SPACE 7
/* Minimum allowed value for x_cols: 2 for prompt, 3 for " < " at end of line
*/
-# define MIN_COLS (2 + MIN_EDIT_SPACE + 3)
+#define MIN_COLS (2 + MIN_EDIT_SPACE + 3)
extern int x_cols; /* tty columns */
-#else
-# define x_cols 80 /* for pr_menu(exec.c) */
-#endif
/* These to avoid bracket matching problems */
#define OPAREN '('
@@ -454,7 +448,6 @@ void init_histvec(void);
void hist_init(Source *);
void hist_finish(void);
void histsave(int, const char *, int);
-#ifdef HISTORY
int c_fc(char **);
void sethistcontrol(const char *);
void sethistsize(int);
@@ -465,7 +458,6 @@ int findhist(int, int, const char *, int);
int findhistrel(const char *);
char **hist_get_newest(int);
-#endif /* HISTORY */
/* io.c */
void errorf(const char *, ...)
__attribute__((__noreturn__, __format__ (printf, 1, 2)));
@@ -473,8 +465,10 @@ void warningf(bool, const char *, ...)
__attribute__((__format__ (printf, 2, 3)));
void bi_errorf(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void internal_errorf(int, const char *, ...)
- __attribute__((__format__ (printf, 2, 3)));
+void internal_errorf(const char *, ...)
+ __attribute__((__noreturn__, __format__ (printf, 1, 2)));
+void internal_warningf(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
void error_prefix(int);
void shellf(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
diff --git a/bin/ksh/shf.c b/bin/ksh/shf.c
index 68be9b9..9809771 100644
--- a/bin/ksh/shf.c
+++ b/bin/ksh/shf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: shf.c,v 1.31 2016/03/20 00:01:21 krw Exp $ */
+/* $OpenBSD: shf.c,v 1.33 2018/03/15 16:51:29 anton Exp $ */
/*
* Shell file I/O routines
@@ -100,7 +100,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
}
if (!(sflags & (SHF_RD | SHF_WR)))
- internal_errorf(1, "shf_fdopen: missing read/write");
+ internal_errorf("%s: missing read/write", __func__);
if (shf) {
if (bsize) {
@@ -157,9 +157,9 @@ shf_reopen(int fd, int sflags, struct shf *shf)
}
if (!(sflags & (SHF_RD | SHF_WR)))
- internal_errorf(1, "shf_reopen: missing read/write");
+ internal_errorf("%s: missing read/write", __func__);
if (!shf || !shf->buf || shf->bsize < bsize)
- internal_errorf(1, "shf_reopen: bad shf/buf/bsize");
+ internal_errorf("%s: bad shf/buf/bsize", __func__);
/* assumes shf->buf and shf->bsize already set up */
shf->fd = fd;
@@ -189,7 +189,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
/* can't have a read+write string */
if (!(sflags & (SHF_RD | SHF_WR)) ||
(sflags & (SHF_RD | SHF_WR)) == (SHF_RD | SHF_WR))
- internal_errorf(1, "shf_sopen: flags 0x%x", sflags);
+ internal_errorf("%s: flags 0x%x", __func__, sflags);
if (!shf) {
shf = alloc(sizeof(struct shf), ATEMP);
@@ -282,7 +282,7 @@ shf_flush(struct shf *shf)
return (shf->flags & SHF_WR) ? EOF : 0;
if (shf->fd < 0)
- internal_errorf(1, "shf_flush: no fd");
+ internal_errorf("%s: no fd", __func__);
if (shf->flags & SHF_ERROR) {
errno = shf->errno_;
@@ -312,7 +312,7 @@ shf_emptybuf(struct shf *shf, int flags)
int ret = 0;
if (!(shf->flags & SHF_STRING) && shf->fd < 0)
- internal_errorf(1, "shf_emptybuf: no fd");
+ internal_errorf("%s: no fd", __func__);
if (shf->flags & SHF_ERROR) {
errno = shf->errno_;
@@ -392,7 +392,7 @@ shf_fillbuf(struct shf *shf)
return 0;
if (shf->fd < 0)
- internal_errorf(1, "shf_fillbuf: no fd");
+ internal_errorf("%s: no fd", __func__);
if (shf->flags & (SHF_EOF | SHF_ERROR)) {
if (shf->flags & SHF_ERROR)
@@ -438,10 +438,10 @@ shf_read(char *buf, int bsize, struct shf *shf)
int ncopy;
if (!(shf->flags & SHF_RD))
- internal_errorf(1, "shf_read: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
if (bsize <= 0)
- internal_errorf(1, "shf_read: bsize %d", bsize);
+ internal_errorf("%s: bsize %d", __func__, bsize);
while (bsize > 0) {
if (shf->rnleft == 0 &&
@@ -473,7 +473,7 @@ shf_getse(char *buf, int bsize, struct shf *shf)
char *orig_buf = buf;
if (!(shf->flags & SHF_RD))
- internal_errorf(1, "shf_getse: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
if (bsize <= 0)
return NULL;
@@ -508,7 +508,7 @@ int
shf_getchar(struct shf *shf)
{
if (!(shf->flags & SHF_RD))
- internal_errorf(1, "shf_getchar: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
return EOF;
@@ -523,7 +523,7 @@ int
shf_ungetc(int c, struct shf *shf)
{
if (!(shf->flags & SHF_RD))
- internal_errorf(1, "shf_ungetc: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
if ((shf->flags & SHF_ERROR) || c == EOF ||
(shf->rp == shf->buf && shf->rnleft))
@@ -558,7 +558,7 @@ int
shf_putchar(int c, struct shf *shf)
{
if (!(shf->flags & SHF_WR))
- internal_errorf(1, "shf_putchar: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
if (c == EOF)
return EOF;
@@ -568,7 +568,7 @@ shf_putchar(int c, struct shf *shf)
int n;
if (shf->fd < 0)
- internal_errorf(1, "shf_putchar: no fd");
+ internal_errorf("%s: no fd", __func__);
if (shf->flags & SHF_ERROR) {
errno = shf->errno_;
return EOF;
@@ -614,10 +614,10 @@ shf_write(const char *buf, int nbytes, struct shf *shf)
int ncopy;
if (!(shf->flags & SHF_WR))
- internal_errorf(1, "shf_write: flags %x", shf->flags);
+ internal_errorf("%s: flags %x", __func__, shf->flags);
if (nbytes < 0)
- internal_errorf(1, "shf_write: nbytes %d", nbytes);
+ internal_errorf("%s: nbytes %d", __func__, nbytes);
/* Don't buffer if buffer is empty and we're writting a large amount. */
if ((ncopy = shf->wnleft) &&
@@ -687,8 +687,8 @@ shf_snprintf(char *buf, int bsize, const char *fmt, ...)
int n;
if (!buf || bsize <= 0)
- internal_errorf(1, "shf_snprintf: buf %lx, bsize %d",
- (long) buf, bsize);
+ internal_errorf("%s: buf %lx, bsize %d",
+ __func__, (long) buf, bsize);
shf_sopen(buf, bsize, SHF_WR, &shf);
va_start(args, fmt);
diff --git a/bin/ksh/table.c b/bin/ksh/table.c
index 074fc13..32845dd 100644
--- a/bin/ksh/table.c
+++ b/bin/ksh/table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.c,v 1.23 2015/11/01 15:38:53 mmcc Exp $ */
+/* $OpenBSD: table.c,v 1.25 2018/01/16 22:52:32 jca Exp $ */
/*
* dynamic hashed associative table for commands and variables
@@ -18,7 +18,7 @@ struct table aliases; /* aliases */
struct table keywords; /* keywords */
struct table homedirs; /* homedir() cache */
-char *path; /* copy of either PATH or def_path */
+char *search_path; /* copy of either PATH or def_path */
const char *def_path; /* path to use if PATH not set */
char *tmpdir; /* TMPDIR value */
const char *prompt;
@@ -128,7 +128,7 @@ ktenter(struct table *tp, const char *n, unsigned int h)
if (tp->size <= INT_MAX/2)
texpand(tp, 2*tp->size);
else
- internal_errorf(1, "too many vars");
+ internal_errorf("too many vars");
goto Search;
}
diff --git a/bin/ksh/table.h b/bin/ksh/table.h
index 107790d..063ae8f 100644
--- a/bin/ksh/table.h
+++ b/bin/ksh/table.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.h,v 1.12 2017/08/30 17:08:45 jca Exp $ */
+/* $OpenBSD: table.h,v 1.13 2017/12/27 13:02:57 millert Exp $ */
/* $From: table.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */
@@ -175,7 +175,7 @@ extern const struct builtin shbuiltins [], kshbuiltins [];
#define PS1 0 /* command */
#define PS2 1 /* command continuation */
-extern char *path; /* copy of either PATH or def_path */
+extern char *search_path; /* copy of either PATH or def_path */
extern const char *def_path; /* path to use if PATH not set */
extern char *tmpdir; /* TMPDIR value */
extern const char *prompt;
diff --git a/bin/ksh/trap.c b/bin/ksh/trap.c
index 3144ea6..fd4d9b2 100644
--- a/bin/ksh/trap.c
+++ b/bin/ksh/trap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: trap.c,v 1.30 2016/03/17 23:33:23 mmcc Exp $ */
+/* $OpenBSD: trap.c,v 1.32 2018/03/15 16:51:29 anton Exp $ */
/*
* signal handling
@@ -402,8 +402,8 @@ setexecsig(Trap *p, int restore)
{
/* XXX debugging */
if (!(p->flags & (TF_ORIG_IGN|TF_ORIG_DFL)))
- internal_errorf(1, "setexecsig: unset signal %d(%s)",
- p->signal, p->name);
+ internal_errorf("%s: unset signal %d(%s)",
+ __func__, p->signal, p->name);
/* restore original value for exec'd kids */
p->flags &= ~(TF_EXEC_IGN|TF_EXEC_DFL);
diff --git a/bin/ksh/tree.c b/bin/ksh/tree.c
index dc879dd..172a416 100644
--- a/bin/ksh/tree.c
+++ b/bin/ksh/tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tree.c,v 1.27 2015/11/01 15:38:53 mmcc Exp $ */
+/* $OpenBSD: tree.c,v 1.33 2018/03/15 16:51:29 anton Exp $ */
/*
* command tree climbing
@@ -47,25 +47,8 @@ ptree(struct op *t, int indent, struct shf *shf)
fptreef(shf, indent, "#no-args# ");
break;
case TEXEC:
-#if 0 /* ?not useful - can't be called? */
- /* Print original vars */
- if (t->left->vars)
- for (w = t->left->vars; *w != NULL; )
- fptreef(shf, indent, "%S ", *w++);
- else
- fptreef(shf, indent, "#no-vars# ");
- /* Print expanded vars */
- if (t->args)
- for (w = t->args; *w != NULL; )
- fptreef(shf, indent, "%s ", *w++);
- else
- fptreef(shf, indent, "#no-args# ");
- /* Print original io */
- t = t->left;
-#else
t = t->left;
goto Chain;
-#endif
case TPAREN:
fptreef(shf, indent + 2, "( %T) ", t->left);
break;
@@ -390,6 +373,15 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
case 'c':
tputc(va_arg(va, int), shf);
break;
+ case 'd': /* decimal */
+ n = va_arg(va, int);
+ neg = n < 0;
+ p = ulton(neg ? -n : n, 10);
+ if (neg)
+ *--p = '-';
+ while (*p)
+ tputc(*p++, shf);
+ break;
case 's':
p = va_arg(va, char *);
while (*p)
@@ -399,13 +391,8 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
p = va_arg(va, char *);
tputS(p, shf);
break;
- case 'd': case 'u': /* decimal */
- n = (c == 'd') ? va_arg(va, int) :
- va_arg(va, unsigned int);
- neg = c=='d' && n<0;
- p = ulton((neg) ? -n : n, 10);
- if (neg)
- *--p = '-';
+ case 'u': /* unsigned decimal */
+ p = ulton(va_arg(va, unsigned int), 10);
while (*p)
tputc(*p++, shf);
break;
@@ -545,9 +532,9 @@ wdscan(const char *wp, int c)
nest--;
break;
default:
- internal_errorf(0,
- "wdscan: unknown char 0x%x (carrying on)",
- wp[-1]);
+ internal_warningf(
+ "%s: unknown char 0x%x (carrying on)",
+ __func__, wp[-1]);
}
}
diff --git a/bin/ksh/tty.c b/bin/ksh/tty.c
index 648bdb7..e93b0a5 100644
--- a/bin/ksh/tty.c
+++ b/bin/ksh/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.16 2015/12/14 13:59:42 tb Exp $ */
+/* $OpenBSD: tty.c,v 1.17 2018/03/15 16:51:29 anton Exp $ */
#include <errno.h>
#include <fcntl.h>
@@ -50,8 +50,8 @@ tty_init(int init_ttystate)
}
}
if ((tty_fd = fcntl(tfd, F_DUPFD_CLOEXEC, FDBASE)) < 0) {
- warningf(false, "j_ttyinit: dup of tty fd failed: %s",
- strerror(errno));
+ warningf(false, "%s: dup of tty fd failed: %s",
+ __func__, strerror(errno));
} else if (init_ttystate)
tcgetattr(tty_fd, &tty_state);
if (do_close)
diff --git a/bin/ksh/var.c b/bin/ksh/var.c
index 1680546..6761358 100644
--- a/bin/ksh/var.c
+++ b/bin/ksh/var.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: var.c,v 1.59 2017/08/30 17:08:45 jca Exp $ */
+/* $OpenBSD: var.c,v 1.66 2018/03/15 16:51:29 anton Exp $ */
#include <sys/stat.h>
@@ -97,15 +97,11 @@ initvar(void)
{ "PATH", V_PATH },
{ "POSIXLY_CORRECT", V_POSIXLY_CORRECT },
{ "TMPDIR", V_TMPDIR },
-#ifdef HISTORY
{ "HISTCONTROL", V_HISTCONTROL },
{ "HISTFILE", V_HISTFILE },
{ "HISTSIZE", V_HISTSIZE },
-#endif /* HISTORY */
-#ifdef EDIT
{ "EDITOR", V_EDITOR },
{ "VISUAL", V_VISUAL },
-#endif /* EDIT */
{ "MAIL", V_MAIL },
{ "MAILCHECK", V_MAILCHECK },
{ "MAILPATH", V_MAILPATH },
@@ -306,7 +302,7 @@ str_val(struct tbl *vp)
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" :
"0123456789abcdefghijklmnopqrstuvwxyz";
unsigned long n;
- int base;
+ unsigned int base;
s = strbuf + sizeof(strbuf);
if (vp->flag & INT_U)
@@ -370,9 +366,8 @@ setstr(struct tbl *vq, const char *s, int error_ok)
/* debugging */
if (s >= vq->val.s &&
s <= vq->val.s + strlen(vq->val.s))
- internal_errorf(true,
- "setstr: %s=%s: assigning to self",
- vq->name, s);
+ internal_errorf("%s: %s=%s: assigning to self",
+ __func__, vq->name, s);
afree(vq->val.s, vq->areap);
}
vq->flag &= ~(ISSET|ALLOC);
@@ -525,11 +520,11 @@ formatstr(struct tbl *vp, const char *s)
int slen;
if (vp->flag & RJUST) {
- const char *q = s + olen;
- /* strip trailing spaces (at&t ksh uses q[-1] == ' ') */
- while (q > s && isspace((unsigned char)q[-1]))
- --q;
- slen = q - s;
+ const char *r = s + olen;
+ /* strip trailing spaces (at&t ksh uses r[-1] == ' ') */
+ while (r > s && isspace((unsigned char)r[-1]))
+ --r;
+ slen = r - s;
if (slen > vp->u2.field) {
s += slen - vp->u2.field;
slen = vp->u2.field;
@@ -933,13 +928,11 @@ getspec(struct tbl *vp)
setint(vp, (long) (rand() & 0x7fff));
vp->flag |= SPECIAL;
break;
-#ifdef HISTORY
case V_HISTSIZE:
vp->flag &= ~SPECIAL;
setint(vp, (long) histsize);
vp->flag |= SPECIAL;
break;
-#endif /* HISTORY */
case V_OPTIND:
vp->flag &= ~SPECIAL;
setint(vp, (long) user_opt.uoptind);
@@ -960,8 +953,8 @@ setspec(struct tbl *vp)
switch (special(vp->name)) {
case V_PATH:
- afree(path, APERM);
- path = str_save(str_val(vp), APERM);
+ afree(search_path, APERM);
+ search_path = str_save(str_val(vp), APERM);
flushcom(1); /* clear tracked aliases */
break;
case V_IFS:
@@ -991,7 +984,6 @@ setspec(struct tbl *vp)
tmpdir = str_save(s, APERM);
}
break;
-#ifdef HISTORY
case V_HISTCONTROL:
sethistcontrol(str_val(vp));
break;
@@ -1003,8 +995,6 @@ setspec(struct tbl *vp)
case V_HISTFILE:
sethistfile(str_val(vp));
break;
-#endif /* HISTORY */
-#ifdef EDIT
case V_VISUAL:
set_editmode(str_val(vp));
break;
@@ -1026,7 +1016,6 @@ setspec(struct tbl *vp)
x_cols = l;
}
break;
-#endif /* EDIT */
case V_MAIL:
mbset(str_val(vp));
break;
@@ -1067,8 +1056,8 @@ unsetspec(struct tbl *vp)
{
switch (special(vp->name)) {
case V_PATH:
- afree(path, APERM);
- path = str_save(def_path, APERM);
+ afree(search_path, APERM);
+ search_path = str_save(def_path, APERM);
flushcom(1); /* clear tracked aliases */
break;
case V_IFS:
@@ -1086,11 +1075,9 @@ unsetspec(struct tbl *vp)
case V_MAILPATH:
mpset(NULL);
break;
-#ifdef HISTORY
case V_HISTCONTROL:
sethistcontrol(NULL);
break;
-#endif
case V_LINENO:
case V_MAILCHECK: /* at&t ksh leaves previous value in place */
case V_RANDOM:
diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c
index 83f5406..12202d5 100644
--- a/bin/ksh/vi.c
+++ b/bin/ksh/vi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vi.c,v 1.49 2017/09/02 18:53:53 deraadt Exp $ */
+/* $OpenBSD: vi.c,v 1.56 2018/03/15 16:51:29 anton Exp $ */
/*
* vi command editing
@@ -61,7 +61,7 @@ static void display(char *, char *, int);
static void ed_mov_opt(int, char *);
static int expand_word(int);
static int complete_word(int, int);
-static int print_expansions(struct edstate *, int);
+static int print_expansions(struct edstate *);
static int char_len(int);
static void x_vi_zotc(int);
static void vi_pprompt(int);
@@ -140,7 +140,6 @@ const unsigned char classify[128] = {
#define VREDO 7 /* . */
#define VLIT 8 /* ^V */
#define VSEARCH 9 /* /, ? */
-#define VVERSION 10 /* <ESC> ^V */
static char undocbuf[LINE];
@@ -223,7 +222,7 @@ x_vi(char *buf, size_t len)
trapsig(c == edchars.intr ? SIGINT : SIGQUIT);
x_mode(false);
unwind(LSHELL);
- } else if (c == edchars.eof && state != VVERSION) {
+ } else if (c == edchars.eof) {
if (es->linelen == 0) {
x_vi_zotc(edchars.eof);
c = -1;
@@ -239,7 +238,7 @@ x_vi(char *buf, size_t len)
x_putc('\r'); x_putc('\n'); x_flush();
- if (c == -1 || len <= es->linelen)
+ if (c == -1 || len <= (size_t)es->linelen)
return -1;
if (es->cbuf != buf)
@@ -301,14 +300,6 @@ vi_hook(int ch)
return -1;
refresh(0);
}
- if (state == VVERSION) {
- save_cbuf();
- es->cursor = 0;
- es->linelen = 0;
- putbuf(ksh_version + 4,
- strlen(ksh_version + 4), 0);
- refresh(0);
- }
}
}
break;
@@ -323,12 +314,6 @@ vi_hook(int ch)
state = VNORMAL;
break;
- case VVERSION:
- restore_cbuf();
- state = VNORMAL;
- refresh(0);
- break;
-
case VARG1:
if (isdigit(ch))
argc1 = argc1 * 10 + ch - '0';
@@ -554,8 +539,6 @@ nextstate(int ch)
return VXCH;
else if (ch == '.')
return VREDO;
- else if (ch == CTRL('v'))
- return VVERSION;
else if (is_cmd(ch))
return VCMD;
else
@@ -665,7 +648,7 @@ vi_insert(int ch)
break;
case CTRL('e'):
- print_expansions(es, 0);
+ print_expansions(es);
break;
case CTRL('i'):
@@ -1142,7 +1125,7 @@ vi_cmd(int argcnt, const char *cmd)
case '=': /* at&t ksh */
case CTRL('e'): /* Nonstandard vi/ksh */
- print_expansions(es, 1);
+ print_expansions(es);
break;
@@ -1686,7 +1669,7 @@ grabhist(int save, int n)
}
(void) histnum(n);
if ((hptr = *histpos()) == NULL) {
- internal_errorf(0, "grabhist: bad history array");
+ internal_warningf("%s: bad history array", __func__);
return -1;
}
if (save)
@@ -2069,7 +2052,7 @@ complete_word(int command, int count)
/* Undo previous completion */
if (command == 0 && expanded == COMPLETE && buf) {
- print_expansions(buf, 0);
+ print_expansions(buf);
expanded = PRINT;
return 0;
}
@@ -2160,7 +2143,7 @@ complete_word(int command, int count)
}
static int
-print_expansions(struct edstate *e, int command)
+print_expansions(struct edstate *e)
{
int nwords;
int start, end;