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: e30f4d775d16e6537ad0371becb6a0176bff06cc
parent: 6642191a139ba00f0b64f82138ea62de81da8208
author: Brian Callahan <bcallah@openbsd.org>
date:   Sun, 14 Jan 2018 00:01:51 -0500
Build oksh with musl-libc (checked with Alpine Linux).
Mconfigure30+++++++-
Mportable.h7+-
Mrescue.sh7+-
Asiglist.c73++++++++++++++++++++
Mvis.h2-
5 files changed, 112 insertions(+), 7 deletions(-)
diff --git a/configure b/configure
@@ -113,6 +113,23 @@ EOF
   fi
 }
 
+siglistcheck() {
+  cat << EOF > conftest.c
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+int main(void){printf("%s",sys_siglist[0]);return 0;}
+EOF
+  $cc $tflags -o conftest conftest.c > /dev/null 2>&1
+  if [ $? -eq 0 ] ; then
+    rm -f conftest conftest.c
+    return 0
+  else
+    rm -f conftest conftest.c
+    return 1
+  fi
+}
+
 signamecheck() {
   cat << EOF > conftest.c
 #include <signal.h>
@@ -414,6 +431,15 @@ else
   echo "no"
 fi
 
+printf "checking for sys_siglist... "
+siglistcheck
+if [ $? -eq 0 ] ; then
+  echo "#define HAVE_SIGLIST" >> pconfig.h
+  echo "yes"
+else
+  echo "no"
+fi
+
 printf "checking for sys_signame... "
 signamecheck
 if [ $? -eq 0 ] ; then
@@ -436,8 +462,8 @@ PROG =		oksh
 OBJS =	alloc.o c_ksh.o c_sh.o c_test.o c_ulimit.o edit.o emacs.o eval.o \\
 	exec.o expr.o history.o io.o jobs.o lex.o mail.o main.o misc.o \\
 	path.o shf.o syn.o table.o trap.o tree.o tty.o var.o version.o vi.o \\
-	confstr.o reallocarray.o signame.o strlcat.o strlcpy.o strtonum.o \\
-	unvis.o vis.o
+	confstr.o reallocarray.o siglist.o signame.o strlcat.o strlcpy.o \\
+	strtonum.o unvis.o vis.o
 
 ETS =	\`grep -w \${PREFIX}/bin/\${PROG} /etc/shells > /dev/null; \\
 	[ \$\$? -ne 0 ] && echo "\${PREFIX}/bin/\${PROG}" >> /etc/shells\`
diff --git a/portable.h b/portable.h
@@ -153,13 +153,18 @@ int	  strunvis(char *, const char *);
  * Externs
  */
 
-#ifndef HAVE_SIGNAME
+#if !defined(HAVE_SIGLIST) || !defined(HAVE_SIGNAME)
 #ifdef NSIG
 #undef NSIG
 #endif /* NSIG */
 #define NSIG 33
+#ifndef HAVE_SIGLIST
+extern const char *const sys_siglist[NSIG];
+#endif /* !HAVE_SIGLIST */
+#ifndef HAVE_SIGNAME
 extern const char *const sys_signame[NSIG];
 #endif /* !HAVE_SIGNAME */
+#endif /* !HAVE_SIGLIST || !HAVE_SIGNAME */
 
 /*
  * OpenBSD sys/queue.h
diff --git a/rescue.sh b/rescue.sh
@@ -99,6 +99,9 @@ cc -DEMACS -DVI -o reallocarray.o -c reallocarray.c
 echo cc -DEMACS -DVI -o strtonum.o -c strtonum.c
 cc -DEMACS -DVI -o strtonum.o -c strtonum.c
 
+echo cc -DEMACS -DVI -o siglist.o -c siglist.c
+cc -DEMACS -DVI -o siglist.o -c siglist.c
+
 echo cc -DEMACS -DVI -o signame.o -c signame.c
 cc -DEMACS -DVI -o signame.o -c signame.c
 
@@ -114,5 +117,5 @@ cc -DEMACS -DVI -o unvis.o -c unvis.c
 echo cc -DEMACS -DVI -o vis.o -c vis.c
 cc -DEMACS -DVI -o vis.o -c vis.c
 
-echo cc -o oksh alloc.o c_ksh.o c_sh.o c_test.o c_ulimit.o edit.o emacs.o eval.o exec.o expr.o history.o io.o jobs.o lex.o mail.o main.o misc.o path.o shf.o syn.o table.o trap.o tree.o tty.o var.o version.o vi.o confstr.o reallocarray.o strtonum.o signame.o strlcat.o strlcpy.o unvis.o vis.o -lc
-cc -o oksh alloc.o c_ksh.o c_sh.o c_test.o c_ulimit.o edit.o emacs.o eval.o exec.o expr.o history.o io.o jobs.o lex.o mail.o main.o misc.o path.o shf.o syn.o table.o trap.o tree.o tty.o var.o version.o vi.o confstr.o reallocarray.o strtonum.o signame.o strlcat.o strlcpy.o unvis.o vis.o -lc
+echo cc -o oksh alloc.o c_ksh.o c_sh.o c_test.o c_ulimit.o edit.o emacs.o eval.o exec.o expr.o history.o io.o jobs.o lex.o mail.o main.o misc.o path.o shf.o syn.o table.o trap.o tree.o tty.o var.o version.o vi.o confstr.o reallocarray.o strtonum.o siglist.o signame.o strlcat.o strlcpy.o unvis.o vis.o -lc
+cc -o oksh alloc.o c_ksh.o c_sh.o c_test.o c_ulimit.o edit.o emacs.o eval.o exec.o expr.o history.o io.o jobs.o lex.o mail.o main.o misc.o path.o shf.o syn.o table.o trap.o tree.o tty.o var.o version.o vi.o confstr.o reallocarray.o strtonum.o siglist.o signame.o strlcat.o strlcpy.o unvis.o vis.o -lc
diff --git a/siglist.c b/siglist.c
@@ -0,0 +1,73 @@
+/*	$OpenBSD: siglist.c,v 1.8 2015/09/19 04:02:21 guenther Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "pconfig.h"
+
+#ifndef HAVE_SIGLIST
+
+#include <signal.h>
+
+const char *const sys_siglist[NSIG] = {
+	"Signal 0",
+	"Hangup",			/* SIGHUP */
+	"Interrupt",			/* SIGINT */
+	"Quit",				/* SIGQUIT */
+	"Illegal instruction",		/* SIGILL */
+	"Trace/BPT trap",		/* SIGTRAP */
+	"Abort trap",			/* SIGABRT */
+	"EMT trap",			/* SIGEMT */
+	"Floating point exception",	/* SIGFPE */
+	"Killed",			/* SIGKILL */
+	"Bus error",			/* SIGBUS */
+	"Segmentation fault",		/* SIGSEGV */
+	"Bad system call",		/* SIGSYS */
+	"Broken pipe",			/* SIGPIPE */
+	"Alarm clock",			/* SIGALRM */
+	"Terminated",			/* SIGTERM */
+	"Urgent I/O condition",		/* SIGURG */
+	"Suspended (signal)",		/* SIGSTOP */
+	"Suspended",			/* SIGTSTP */
+	"Continued",			/* SIGCONT */
+	"Child exited",			/* SIGCHLD */
+	"Stopped (tty input)",		/* SIGTTIN */
+	"Stopped (tty output)",		/* SIGTTOU */
+	"I/O possible",			/* SIGIO */
+	"Cputime limit exceeded",	/* SIGXCPU */
+	"Filesize limit exceeded",	/* SIGXFSZ */
+	"Virtual timer expired",	/* SIGVTALRM */
+	"Profiling timer expired",	/* SIGPROF */
+	"Window size changes",		/* SIGWINCH */
+	"Information request",		/* SIGINFO */
+	"User defined signal 1",	/* SIGUSR1 */
+	"User defined signal 2",	/* SIGUSR2 */
+	"Thread AST",			/* SIGTHR */
+};
+
+#endif /* !HAVE_SIGLIST */
diff --git a/vis.h b/vis.h
@@ -73,8 +73,6 @@
  */
 #define	UNVIS_END	1	/* no more characters */
 
-#include <sys/cdefs.h>
-
 char	*vis(char *, int, int, int);
 int	strvis(char *, const char *, int);
 int	stravis(char **, const char *, int);