oksh-noxz

[fork] Portable OpenBSD ksh, based on the Public Domain Korn Shell (pdksh).
git clone https://noxz.tech/git/oksh-noxz.git
oksh-noxz

commit: 2a04e92438c3d7e03ae6d36f787c8fa9f056bb4f
parent: 01fa54fc3541804e18e8b29731fbae10d559f54c
author: Brian Callahan <dodonpachi-github@mailinator.com>
date:   Sun, 1 Apr 2018 21:55:11 -0400
This is the OpenBSD 6.3 ksh.
MCVS/Entries84++++++++++----------
MREADME.md8+-
Mc_ksh.c4+-
Mc_ulimit.c4+-
Medit.c4+-
Mexec.c8+-
Mjobs.c67++++++++--------
Mksh.111++-
Mmain.c6+-
Mmisc.c4+-
Msh.114++--
Mshf.c38++++-----
Mtrap.c6+-
Mtree.c6+-
Mtty.c6+-
Mvar.c7+-
Mvi.c4+-
17 files changed, 144 insertions(+), 137 deletions(-)
diff --git a/CVS/Entries b/CVS/Entries
@@ -1,46 +1,46 @@
 /config.h/1.19/Tue Jan 16 02:21:56 2018//
 /history.c/1.80/Tue Jan 16 02:21:56 2018//
 /emacs.c/1.84/Result of merge//
-/main.c/1.89/Result of merge//
-/CONTRIBUTORS/1.10/Sat Jan 20 16:15:16 2018//
-/LEGAL/1.2/Sat Jan 20 16:15:16 2018//
-/Makefile/1.38/Sat Jan 20 16:15:49 2018//
-/NOTES/1.16/Sat Jan 20 16:15:16 2018//
-/PROJECTS/1.9/Sat Jan 20 16:15:16 2018//
-/README/1.16/Sat Jan 20 16:17:11 2018//
-/alloc.c/1.19/Sat Jan 20 16:15:16 2018//
-/c_ksh.c/1.58/Sat Jan 20 16:15:16 2018//
-/c_sh.c/1.62/Sat Jan 20 16:15:16 2018//
-/c_test.c/1.24/Sat Jan 20 16:15:16 2018//
-/c_test.h/1.4/Sat Jan 20 16:15:16 2018//
-/c_ulimit.c/1.26/Sat Jan 20 16:15:16 2018//
-/edit.c/1.63/Sat Jan 20 16:15:16 2018//
-/edit.h/1.11/Sat Jan 20 16:15:16 2018//
-/eval.c/1.59/Sat Jan 20 16:15:16 2018//
-/exec.c/1.72/Sat Jan 20 16:15:16 2018//
-/expand.h/1.15/Sat Jan 20 16:15:16 2018//
-/expr.c/1.32/Sat Jan 20 16:15:16 2018//
-/io.c/1.36/Sat Jan 20 16:15:16 2018//
-/jobs.c/1.59/Sat Jan 20 16:15:16 2018//
-/ksh.1/1.197/Sat Jan 20 16:15:16 2018//
-/lex.c/1.78/Sat Jan 20 16:15:16 2018//
-/lex.h/1.21/Sat Jan 20 16:15:16 2018//
-/mail.c/1.22/Sat Jan 20 16:15:16 2018//
-/misc.c/1.68/Sat Jan 20 16:15:16 2018//
-/path.c/1.22/Sat Jan 20 16:15:16 2018//
-/sh.1/1.146/Sat Jan 20 16:15:16 2018//
-/sh.h/1.71/Sat Jan 20 16:15:16 2018//
-/shf.c/1.32/Sat Jan 20 16:15:16 2018//
-/shf.h/1.8/Sat Jan 20 16:15:16 2018//
-/syn.c/1.38/Sat Jan 20 16:15:16 2018//
-/table.c/1.25/Sat Jan 20 16:15:16 2018//
-/table.h/1.13/Sat Jan 20 16:15:16 2018//
-/trap.c/1.31/Sat Jan 20 16:15:16 2018//
-/tree.c/1.32/Sat Jan 20 16:17:11 2018//
-/tree.h/1.12/Sat Jan 20 16:15:16 2018//
-/tty.c/1.16/Sat Jan 20 16:15:16 2018//
-/tty.h/1.6/Sat Jan 20 16:15:16 2018//
-/var.c/1.65/Sat Jan 20 16:15:16 2018//
-/version.c/1.12/Sat Jan 20 16:15:16 2018//
-/vi.c/1.55/Sat Jan 20 16:15:16 2018//
+/CONTRIBUTORS/1.10/Mon Apr  2 01:50:45 2018//
+/LEGAL/1.2/Mon Apr  2 01:50:45 2018//
+/Makefile/1.38/Mon Apr  2 01:50:52 2018//
+/NOTES/1.16/Mon Apr  2 01:50:45 2018//
+/PROJECTS/1.9/Mon Apr  2 01:50:45 2018//
+/README/1.16/Mon Apr  2 01:50:52 2018//
+/alloc.c/1.19/Mon Apr  2 01:50:45 2018//
+/c_ksh.c/1.59/Mon Apr  2 01:50:52 2018//
+/c_sh.c/1.62/Mon Apr  2 01:50:45 2018//
+/c_test.c/1.24/Mon Apr  2 01:50:45 2018//
+/c_test.h/1.4/Mon Apr  2 01:50:45 2018//
+/c_ulimit.c/1.27/Mon Apr  2 01:50:52 2018//
+/edit.c/1.64/Mon Apr  2 01:50:52 2018//
+/edit.h/1.11/Mon Apr  2 01:50:45 2018//
+/eval.c/1.59/Mon Apr  2 01:50:45 2018//
+/exec.c/1.73/Mon Apr  2 01:50:52 2018//
+/expand.h/1.15/Mon Apr  2 01:50:45 2018//
+/expr.c/1.32/Mon Apr  2 01:50:45 2018//
+/io.c/1.36/Mon Apr  2 01:50:45 2018//
+/jobs.c/1.60/Mon Apr  2 01:50:52 2018//
+/ksh.1/1.198/Mon Apr  2 01:50:52 2018//
+/lex.c/1.78/Mon Apr  2 01:50:45 2018//
+/lex.h/1.21/Mon Apr  2 01:50:45 2018//
+/mail.c/1.22/Mon Apr  2 01:50:45 2018//
+/main.c/1.90/Result of merge//
+/misc.c/1.69/Mon Apr  2 01:50:52 2018//
+/path.c/1.22/Mon Apr  2 01:50:45 2018//
+/sh.1/1.148/Mon Apr  2 01:50:52 2018//
+/sh.h/1.71/Mon Apr  2 01:50:45 2018//
+/shf.c/1.33/Mon Apr  2 01:50:53 2018//
+/shf.h/1.8/Mon Apr  2 01:50:45 2018//
+/syn.c/1.38/Mon Apr  2 01:50:45 2018//
+/table.c/1.25/Mon Apr  2 01:50:45 2018//
+/table.h/1.13/Mon Apr  2 01:50:45 2018//
+/trap.c/1.32/Mon Apr  2 01:50:53 2018//
+/tree.c/1.33/Mon Apr  2 01:50:53 2018//
+/tree.h/1.12/Mon Apr  2 01:50:45 2018//
+/tty.c/1.17/Mon Apr  2 01:50:53 2018//
+/tty.h/1.6/Mon Apr  2 01:50:45 2018//
+/var.c/1.66/Mon Apr  2 01:50:53 2018//
+/version.c/1.12/Mon Apr  2 01:50:45 2018//
+/vi.c/1.56/Mon Apr  2 01:50:53 2018//
 D
diff --git a/README.md b/README.md
@@ -19,6 +19,12 @@ Supported systems
 
 Running on a system not listed here? Add it and send a pull request!
 
+Current porting efforts
+-----------------------
+`oksh` is currently being ported to the following platforms.
+Help is greatly appreciated and encouraged!
+* AIX
+
 Supported compilers
 -------------------
 `oksh` is known to build with the following C compilers:
@@ -65,4 +71,4 @@ for details.
 
 Get a tarball
 -------------
-http://devio.us/~bcallah/oksh/oksh-20180120.tar.gz
+http://devio.us/~bcallah/oksh/oksh-20180401.tar.gz
diff --git a/c_ksh.c b/c_ksh.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: c_ksh.c,v 1.58 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: c_ksh.c,v 1.59 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
  * built-in Korn commands: c_*
@@ -1273,7 +1273,7 @@ c_getopts(char **wp)
 	}
 
 	if (genv->loc->next == NULL) {
-		internal_warningf("c_getopts: no argv");
+		internal_warningf("%s: no argv", __func__);
 		return 1;
 	}
 	/* Which arguments are we parsing... */
diff --git a/c_ulimit.c b/c_ulimit.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: c_ulimit.c,v 1.26 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: c_ulimit.c,v 1.27 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
 	ulimit -- handle "ulimit" builtin
@@ -97,7 +97,7 @@ c_ulimit(char **wp)
 			for (l = limits; l->name && l->option != optc; l++)
 				;
 			if (!l->name) {
-				internal_warningf("ulimit: %c", optc);
+				internal_warningf("%s: %c", __func__, optc);
 				return 1;
 			}
 			if (builtin_opt.optarg) {
diff --git a/edit.c b/edit.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: edit.c,v 1.63 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: edit.c,v 1.64 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
  * Command line editing - common code
@@ -372,7 +372,7 @@ x_file_glob(int flags, const char *str, int slen, char ***wordsp)
 	source = s;
 	if (yylex(ONEWORD|UNESCAPE) != LWORD) {
 		source = sold;
-		internal_warningf("fileglob: substitute error");
+		internal_warningf("%s: substitute error", __func__);
 		return 0;
 	}
 	source = sold;
diff --git a/exec.c b/exec.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: exec.c,v 1.72 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: exec.c,v 1.73 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
  * execute command tree
@@ -727,7 +727,7 @@ shcomexec(char **wp)
 
 	tp = ktsearch(&builtins, *wp, hash(*wp));
 	if (tp == NULL)
-		internal_errorf("shcomexec: %s", *wp);
+		internal_errorf("%s: %s", __func__, *wp);
 	return call_builtin(tp, wp);
 }
 
@@ -1221,7 +1221,7 @@ herein(const char *content, int sub)
 		s->start = s->str = content;
 		source = s;
 		if (yylex(ONEWORD|HEREDOC) != LWORD)
-			internal_errorf("herein: yylex");
+			internal_errorf("%s: yylex", __func__);
 		source = osource;
 		shf_puts(evalstr(yylval.cp, 0), shf);
 	} else
@@ -1446,5 +1446,5 @@ static void
 dbteste_error(Test_env *te, int offset, const char *msg)
 {
 	te->flags |= TEF_ERROR;
-	internal_warningf("dbteste_error: %s (offset %d)", msg, offset);
+	internal_warningf("%s: %s (offset %d)", __func__, msg, offset);
 }
diff --git a/jobs.c b/jobs.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: jobs.c,v 1.59 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: jobs.c,v 1.60 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
  * Process and job control
@@ -199,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));
 				}
 			}
 		}
@@ -224,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;
 				}
 			}
@@ -309,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) {
@@ -322,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;
 				}
@@ -337,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;
@@ -354,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);
@@ -411,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(
-			    "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;
@@ -522,7 +519,7 @@ exchild(struct op *t, int flags, volatile int *xerrok,
 		tty_close();
 		cleartraps();
 		execute(t, (flags & XERROK) | XEXEC, NULL); /* no return */
-		internal_warningf("exchild: execute() returned");
+		internal_warningf("%s: execute() returned", __func__);
 		unwind(LLEAVE);
 		/* NOTREACHED */
 	}
@@ -588,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_warningf("waitlast: not started");
+			internal_warningf("%s: not started", __func__);
 		sigprocmask(SIG_SETMASK, &omask, NULL);
 		return 125; /* not so arbitrary, non-zero value */
 	}
@@ -931,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_warningf("j_async: job not started");
+		internal_warningf("%s: job not started", __func__);
 		return;
 	}
 	async_job = j;
@@ -945,8 +942,8 @@ j_set_async(Job *j)
 		if (!oldest) {
 			/* XXX debugging */
 			if (!(async_job->flags & JF_ZOMBIE) || nzombie != 1) {
-				internal_warningf("j_async: bad nzombie (%d)",
-				    nzombie);
+				internal_warningf("%s: bad nzombie (%d)",
+				    __func__, nzombie);
 				nzombie = 0;
 			}
 			break;
@@ -1035,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) {
@@ -1186,8 +1183,8 @@ check_job(Job *j)
 
 	/* XXX debugging (nasty - interrupt routine using shl_out) */
 	if (!(j->flags & JF_STARTED)) {
-		internal_warningf("check_job: job started (flags 0x%x)",
-		    j->flags);
+		internal_warningf("%s: job started (flags 0x%x)",
+		    __func__, j->flags);
 		return;
 	}
 
@@ -1546,7 +1543,7 @@ remove_job(Job *j, const char *where)
 	for (; curr != NULL && curr != j; prev = &curr->next, curr = *prev)
 		;
 	if (curr != j) {
-		internal_warningf("remove_job: job not found (%s)", where);
+		internal_warningf("%s: job not found (%s)", __func__, where);
 		return;
 	}
 	*prev = curr->next;
diff --git a/ksh.1 b/ksh.1
@@ -1,8 +1,8 @@
-.\"	$OpenBSD: ksh.1,v 1.197 2017/12/12 11:34:38 tb Exp $
+.\"	$OpenBSD: ksh.1,v 1.198 2018/02/06 15:13:32 schwarze Exp $
 .\"
 .\"	Public Domain
 .\"
-.Dd $Mdocdate: December 12 2017 $
+.Dd $Mdocdate: February 6 2018 $
 .Dt KSH 1
 .Os
 .Sh NAME
@@ -2788,11 +2788,16 @@ for more information.
 .Ar string Ns = Ns Op Ar editing-command
 .Ar ...
 .Xc
-The specified editing command is bound to the given
+In
+.Sx Emacs editing mode ,
+the specified editing command is bound to the given
 .Ar string .
 Future input of the
 .Ar string
 will cause the editing command to be immediately invoked.
+Bindings have no effect in
+.Sx Vi editing mode .
+.Pp
 If the
 .Fl m
 flag is given, the specified input
diff --git a/main.c b/main.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: main.c,v 1.89 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: main.c,v 1.90 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
  * startup, main loop, environments and error handling
@@ -494,7 +494,7 @@ include(const char *name, int argc, char **argv, int intr_ok)
 			unwind(i);
 			/* NOTREACHED */
 		default:
-			internal_errorf("include: %d", i);
+			internal_errorf("%s: %d", __func__, i);
 			/* NOTREACHED */
 		}
 	}
@@ -581,7 +581,7 @@ shell(Source *volatile s, volatile int toplevel)
 		default:
 			source = old_source;
 			quitenv(NULL);
-			internal_errorf("shell: %d", i);
+			internal_errorf("%s: %d", __func__, i);
 			/* NOTREACHED */
 		}
 	}
diff --git a/misc.c b/misc.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: misc.c,v 1.68 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: misc.c,v 1.69 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
  * Miscellaneous functions
@@ -407,7 +407,7 @@ parse_args(char **argv,
 					break;
 				}
 			if (ele == NELEM(sh_options)) {
-				internal_errorf("parse_args: `%c'", optc);
+				internal_errorf("%s: `%c'", __func__, optc);
 				return -1; /* not reached */
 			}
 		}
diff --git a/sh.1 b/sh.1
@@ -1,4 +1,4 @@
-.\"	$OpenBSD: sh.1,v 1.146 2017/12/30 07:32:09 jmc Exp $
+.\"	$OpenBSD: sh.1,v 1.148 2018/03/31 14:58:19 anton Exp $
 .\"
 .\" Copyright (c) 2015 Jason McIntyre <jmc@openbsd.org>
 .\"
@@ -14,7 +14,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: December 30 2017 $
+.Dd $Mdocdate: March 31 2018 $
 .Dt SH 1
 .Os
 .Sh NAME
@@ -700,10 +700,10 @@ 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
+.Ql set -o
 displays the current option settings;
 the sequence
-.Qq set +o
+.Ql set +o
 displays,
 in a format suitable to be reinput to the shell,
 a command suitable to achieve the current option settings.
@@ -713,10 +713,10 @@ with the special parameter
 .Sq #
 set to the number of positional parameters.
 The sequence
-.Qq set --
+.Ql set --
 indicates an end to option processing
 (i.e. only arguments follow);
-.Qq set --
+.Ql set --
 by itself unsets all positional parameters
 and sets
 .Sq #
@@ -1738,7 +1738,7 @@ or within
 to have them executed in the current environment:
 .Pp
 .D1 Pq Ar command ...
-.D1 Brq Ar \ \&command ... Ns ;\&
+.D1 Brq \& Ar command ... ; No \&
 .Pp
 Any redirections specified after the closing bracket apply to all commands
 within the brackets.
diff --git a/shf.c b/shf.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: shf.c,v 1.32 2018/01/16 22:52:32 jca 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("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("shf_reopen: missing read/write");
+		internal_errorf("%s: missing read/write", __func__);
 	if (!shf || !shf->buf || shf->bsize < bsize)
-		internal_errorf("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("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("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("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("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("shf_read: flags %x", shf->flags);
+		internal_errorf("%s: flags %x", __func__, shf->flags);
 
 	if (bsize <= 0)
-		internal_errorf("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("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("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("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("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("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("shf_write: flags %x", shf->flags);
+		internal_errorf("%s: flags %x", __func__, shf->flags);
 
 	if (nbytes < 0)
-		internal_errorf("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("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/trap.c b/trap.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: trap.c,v 1.31 2018/01/16 22:52:32 jca 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("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/tree.c b/tree.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: tree.c,v 1.32 2018/01/20 15:32:20 anton Exp $	*/
+/*	$OpenBSD: tree.c,v 1.33 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
  * command tree climbing
@@ -533,8 +533,8 @@ wdscan(const char *wp, int c)
 			break;
 		default:
 			internal_warningf(
-			    "wdscan: unknown char 0x%x (carrying on)",
-			    wp[-1]);
+			    "%s: unknown char 0x%x (carrying on)",
+			    __func__, wp[-1]);
 		}
 }
 
diff --git a/tty.c b/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/var.c b/var.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: var.c,v 1.65 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: var.c,v 1.66 2018/03/15 16:51:29 anton Exp $	*/
 
 #include <sys/stat.h>
 
@@ -366,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(
-				    "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);
diff --git a/vi.c b/vi.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: vi.c,v 1.55 2018/01/16 22:52:32 jca Exp $	*/
+/*	$OpenBSD: vi.c,v 1.56 2018/03/15 16:51:29 anton Exp $	*/
 
 /*
  *	vi command editing
@@ -1669,7 +1669,7 @@ grabhist(int save, int n)
 	}
 	(void) histnum(n);
 	if ((hptr = *histpos()) == NULL) {
-		internal_warningf("grabhist: bad history array");
+		internal_warningf("%s: bad history array", __func__);
 		return -1;
 	}
 	if (save)