Only in oksh-7.0: README diff -ur oksh-7.0/README.md oksh-7.3/README.md --- oksh-7.0/README.md 2021-10-10 01:37:49 +++ oksh-7.3/README.md 2023-04-17 02:04:12 @@ -57,6 +57,8 @@ * [CompCert](https://compcert.org/) * [Nils Weller's C compiler](http://nwcc.sourceforge.net/) * [cproc](https://sr.ht/~mcf/cproc/) (Currently requires a small tweak to ignore a volatile store error) +* [vbcc](http://www.compilers.de/vbcc.html) (Only tested on OpenBSD/i386) +* [chibicc](https://github.com/rui314/chibicc) Building with a compiler not listed here? Add it and send a pull request! @@ -88,6 +90,13 @@ $ make && sudo make install ``` +Out-of-tree builds +------------------ +The `configure` script will detect out-of-tree builds if you prefer to +build out-of-tree. In order for this to work, the `VPATH` make extension +is used. While not POSIX, `VPATH` is known to work with BSD make and GNU +make. In-tree builds create a fully POSIX `Makefile`. + Cross compiling --------------- Cross compiling can be achieved by running `configure` as follows: @@ -130,5 +139,5 @@ Get a tarball ------------- -See releases tab. The latest release is oksh-7.0, which matches the ksh(1) -from OpenBSD 7.0, released October 14, 2021. +See releases tab. The latest release is oksh-7.3, which matches the ksh(1) +from OpenBSD 7.3, released April 10, 2023. diff -ur oksh-7.0/configure oksh-7.3/configure --- oksh-7.0/configure 2021-08-20 22:32:00 +++ oksh-7.3/configure 2023-04-17 02:03:22 @@ -24,8 +24,15 @@ EOF fi +if [ ! -z "$vpath" ] ; then cat << EOF >> Makefile +VPATH = $vpath +EOF +fi + +cat << EOF >> Makefile + PREFIX = $prefix BINDIR = $bindir MANDIR = $mandir @@ -119,6 +126,22 @@ fi } +c11noreturncheck() { + cat << EOF > conftest.c +#include +_Noreturn void usage(void){exit(1);}int main(void){usage();return 0;} +EOF + $cc $cflags -o conftest.o -c conftest.c > /dev/null 2>&1 + $cc $ldflags -o conftest conftest.o > /dev/null 2>&1 + if [ $? -eq 0 ] ; then + rm -f conftest conftest.o conftest.c + return 0 + else + rm -f conftest conftest.o conftest.c + return 1 + fi +} + c99check() { cat << EOF > conftest.c #include @@ -274,7 +297,7 @@ deadcheck() { cat << EOF > conftest.c #include -__dead usage(void){exit(1);}int main(void){usage();return 0;} +__dead void usage(void){exit(1);}int main(void){usage();return 0;} EOF $cc $cflags -o conftest.o -c conftest.c > /dev/null 2>&1 $cc $ldflags -o conftest conftest.o > /dev/null 2>&1 @@ -290,7 +313,7 @@ dead2check() { cat << EOF > conftest.c #include -__dead2 usage(void){exit(1);}int main(void){usage();return 0;} +__dead2 void usage(void){exit(1);}int main(void){usage();return 0;} EOF $cc $cflags -o conftest.o -c conftest.c > /dev/null 2>&1 $cc $ldflags -o conftest conftest.o > /dev/null 2>&1 @@ -431,7 +454,7 @@ noreturncheck() { cat << EOF > conftest.c #include -__attribute__((__noreturn__)) usage(void){exit(1);}int main(void){usage();return 0;} +__attribute__((__noreturn__)) void usage(void){exit(1);}int main(void){usage();return 0;} EOF $cc $cflags -o conftest.o -c conftest.c > /dev/null 2>&1 $cc $ldflags -o conftest conftest.o > /dev/null 2>&1 @@ -487,7 +510,7 @@ cat << EOF > conftest.c #include #include -int main(void){setresgid(NULL, NULL, NULL);return 0;} +int main(void){setresgid(0, 0, 0);return 0;} EOF $cc $cflags -o conftest.o -c conftest.c > /dev/null 2>&1 $cc $ldflags -o conftest conftest.o > /dev/null 2>&1 @@ -504,7 +527,7 @@ cat << EOF > conftest.c #include #include -int main(void){setresuid(NULL, NULL, NULL);return 0;} +int main(void){setresuid(0, 0, 0);return 0;} EOF $cc $cflags -o conftest.o -c conftest.c > /dev/null 2>&1 $cc $ldflags -o conftest conftest.o > /dev/null 2>&1 @@ -781,6 +804,7 @@ instsh=0 static=0 lto=0 +small=0 strip=1 # Options @@ -804,6 +828,12 @@ mandir=${opt#*=} mandirset=1 ;; + --cc=*) + CC=${opt#*=} + ;; + --cflags=*) + CFLAGS=${opt#*=} + ;; --disable-curses|--enable-curses) if [ "x$opt" = "x--disable-curses" ] ; then curses=0 @@ -825,6 +855,14 @@ instsh=0 fi ;; + --disable-small|--enable-small) + if [ "x$opt" = "x--enable-small" ] ; then + small=1 + curses=0 + else + small=0 + fi + ;; --disable-static|--enable-static) if [ "x$opt" = "x--enable-static" ] ; then static=1 @@ -860,6 +898,10 @@ echo "Install executable to BINDIR [$bindir]" printf " --mandir=MANDIR " echo "Install manual pages to MANDIR [$mandir]" + printf " --cc=CC " + echo "Use specified C compiler [default=cc]" + printf " --cflags=CFLAGS " + echo "Use specified CFLAGS [default=\"-g -O2\"]" printf " --enable-curses " echo "Use curses library for screen clear [default=yes]" printf " --enable-ksh " @@ -868,6 +910,8 @@ echo "Enable link-time optimization [default=no]" printf " --enable-sh " echo "Install additional sh executable [default=no]" + printf " --enable-small " + echo "Disable curses and extended history [default=no]" printf " --enable-static " echo "Statically link executables [default=no]" printf " --no-thanks " @@ -963,6 +1007,11 @@ echo "$cc" fi +if [ "x$cc" = "xvc" ] ; then + echo "using vbcc, setting CFLAGS to -g -O=990" + cflags="-g -O=990 -DEMACS -DVI" +fi + if [ "x$cflags" = "x-DEMACS -DVI" ] ; then printf "checking if the compiler accepts -g -O2... " defaultcflagscheck @@ -1027,9 +1076,15 @@ cflags="$cflags -D_ANSI_LIBRARY" ldflags="$ldflags -Wl,-nopie" ;; + "xchibicc") + cflags="$cflags -D_ANSI_LIBRARY" + ;; "xnwcc") ldflags="$ldflags -Wl,-nopie" ;; + "xvc") + cflags="$cflags -D_ANSI_LIBRARY" + ;; esac ;; "xAIX"|"xOS400") @@ -1052,6 +1107,10 @@ fi fi +if [ $small -ne 0 ] ; then + cflags="$cflags -DSMALL" +fi + cat << EOF > pconfig.h /* This file automatically generated by configure. */ @@ -1076,9 +1135,21 @@ echo "#define __dead __attribute__((__noreturn__))" >> pconfig.h echo "yes" else - echo "#define __dead" >> pconfig.h - echo "#define __attribute__(x)" >> pconfig.h echo "no" + printf "checking for _Noreturn... " + c11noreturncheck + if [ $? -eq 0 ] ; then + echo "#ifdef __dead" >> pconfig.h + echo "#undef __dead" >> pconfig.h + echo "#endif" >> pconfig.h + echo "#define __dead _Noreturn" >> pconfig.h + echo "#define __attribute__(x)" >> pconfig.h + echo "yes" + else + echo "#define __dead" >> pconfig.h + echo "#define __attribute__(x)" >> pconfig.h + echo "no" + fi fi fi fi @@ -1334,6 +1405,17 @@ echo "yes" else echo "no" +fi + +printf "checking for out-of-tree build... " +if [ "x$(dirname $0)" = "x." ] ; then + echo "no" +elif [ "x$(dirname $0)" = "x$(pwd)" ] ; then + echo "no" +else + echo "yes" + vpath="$(dirname $0)" + cflags="$cflags -I$(pwd)" fi printf "creating Makefile... " diff -ur oksh-7.0/confstr.c oksh-7.3/confstr.c --- oksh-7.0/confstr.c 2021-08-20 22:32:00 +++ oksh-7.3/confstr.c 2023-04-17 02:03:22 @@ -28,7 +28,7 @@ * SUCH DAMAGE. */ -#include "portable.h" +#include "pconfig.h" #ifndef HAVE_CONFSTR diff -ur oksh-7.0/emacs.c oksh-7.3/emacs.c --- oksh-7.0/emacs.c 2021-08-20 22:32:00 +++ oksh-7.3/emacs.c 2023-04-17 02:03:22 @@ -1,4 +1,4 @@ -/* $OpenBSD: emacs.c,v 1.88 2021/06/27 15:53:33 schwarze Exp $ */ +/* $OpenBSD: emacs.c,v 1.89 2021/10/09 21:38:00 halex Exp $ */ /* * Emacs-like command line editing and history @@ -277,7 +277,7 @@ { 0, 0, 0 }, }; -int +static int isu8cont(unsigned char c) { return (c & (0x80 | 0x40)) == 0x80; @@ -905,7 +905,7 @@ if ((c = x_e_getc()) < 0) return KSTD; f = kb_find_hist_func(c); - if (c == CTRL('[')) { + if (c == CTRL('[') || c == CTRL('@')) { x_e_ungetc(c); break; } else if (f == x_search_hist) diff -ur oksh-7.0/exec.c oksh-7.3/exec.c --- oksh-7.0/exec.c 2021-08-20 22:32:00 +++ oksh-7.3/exec.c 2023-04-17 02:03:22 @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.c,v 1.74 2019/06/28 13:34:59 deraadt Exp $ */ +/* $OpenBSD: exec.c,v 1.76 2022/10/10 14:57:48 kn Exp $ */ /* * execute command tree @@ -114,10 +114,12 @@ for (iowp = t->ioact; *iowp != NULL; iowp++) { if (iosetup(*iowp, tp) < 0) { exstat = rv = 1; - /* Redirection failures for special commands + /* Except in the permanent case (exec 2>afile), + * redirection failures for special commands * cause (non-interactive) shell to exit. */ - if (tp && tp->type == CSHELL && + if (tp && tp->val.f != c_exec && + tp->type == CSHELL && (tp->flag & SPEC_BI)) errorf(NULL); /* Deal with FERREXIT, quitenv(), etc. */ @@ -1197,7 +1199,7 @@ * doesn't get removed too soon). */ h = maketemp(ATEMP, TT_HEREDOC_EXP, &genv->temps); - if (!(shf = h->shf) || (fd = open(h->name, O_RDONLY, 0)) == -1) { + if (!(shf = h->shf) || (fd = open(h->name, O_RDONLY)) == -1) { warningf(true, "can't %s temporary file %s: %s", !shf ? "create" : "open", h->name, strerror(errno)); diff -ur oksh-7.0/ksh.1 oksh-7.3/ksh.1 --- oksh-7.0/ksh.1 2021-08-20 22:32:00 +++ oksh-7.3/ksh.1 2023-04-17 02:03:22 @@ -1,8 +1,8 @@ -.\" $OpenBSD: ksh.1,v 1.215 2021/05/04 21:03:30 naddy Exp $ +.\" $OpenBSD: ksh.1,v 1.218 2022/12/26 17:45:27 jmc Exp $ .\" .\" Public Domain .\" -.Dd $Mdocdate: May 4 2021 $ +.Dd $Mdocdate: December 26 2022 $ .Dt KSH 1 .Os .Sh NAME @@ -745,9 +745,10 @@ must be unquoted. .It The second operand of the -.Sq != +.Sq = , +.Sq == and -.Sq = +.Sq != expressions are patterns (e.g. the comparison .Ic [[ foobar = f*r ]] succeeds). @@ -2712,9 +2713,7 @@ .Cm +-x Oc .Op Fl p .Op Cm + -.Oo Ar name -.Op Ns = Ns Ar value -.Ar ... Oc +.Op Ar name Ns Oo = Ns Ar value Oc Ar ... .Xc Without arguments, .Ic alias @@ -3453,9 +3452,7 @@ .It Xo .Ic readonly .Op Fl p -.Oo Ar parameter -.Op Ns = Ns Ar value -.Ar ... Oc +.Op Ar parameter Ns Oo = Ns Ar value Oc Ar ... .Xc Sets the read-only attribute of the named parameters. If values are given, @@ -4012,7 +4009,7 @@ .Pp If the .Fl p -option is given the output is slightly longer: +option is given, the output is slightly longer: .Bd -literal -offset indent real 0.00 user 0.00 @@ -4124,11 +4121,7 @@ .Op Fl i Ns Op Ar n .No \&| Fl f Op Fl tux .Oc -.Oo -.Ar name -.Op Ns = Ns Ar value -.Ar ... -.Oc +.Op Ar name Ns Oo = Ns Ar value Oc Ar ... .Xc Display or set parameter attributes. With no diff -ur oksh-7.0/lex.c oksh-7.3/lex.c --- oksh-7.0/lex.c 2021-08-20 22:32:00 +++ oksh-7.3/lex.c 2023-04-17 02:03:22 @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.78 2018/01/15 14:58:05 jca Exp $ */ +/* $OpenBSD: lex.c,v 1.79 2023/02/08 17:22:10 kn Exp $ */ /* * lexical analysis and source input @@ -1335,6 +1335,7 @@ case 'u': /* '\' 'u' username */ strlcpy(strbuf, username, sizeof strbuf); break; +#ifndef SMALL case 'v': /* '\' 'v' version (short) */ p = strchr(ksh_version, ' '); if (p) @@ -1350,6 +1351,7 @@ case 'V': /* '\' 'V' version (long) */ strlcpy(strbuf, ksh_version, sizeof strbuf); break; +#endif /* SMALL */ case 'w': /* '\' 'w' cwd */ p = str_val(global("PWD")); n = strlen(str_val(global("HOME"))); diff -ur oksh-7.0/main.c oksh-7.3/main.c --- oksh-7.0/main.c 2021-10-10 00:41:31 +++ oksh-7.3/main.c 2023-04-17 02:04:21 @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.98 2019/06/28 13:34:59 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.99 2023/02/08 17:22:10 kn Exp $ */ /* * startup, main loop, environments and error handling @@ -81,8 +81,10 @@ static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }"; static const char *initcoms [] = { +#ifndef SMALL "typeset", "-r", "KSH_VERSION", NULL, "typeset", "-r", "OKSH_VERSION", NULL, +#endif /* SMALL */ "typeset", "-x", "SHELL", "PATH", "HOME", "PWD", "OLDPWD", NULL, "typeset", "-ir", "PPID", NULL, "typeset", "-i", "OPTIND=1", NULL, @@ -111,7 +113,9 @@ char username[_PW_NAME_LEN + 1]; +#ifndef SMALL #define version_param (initcoms[2]) +#endif /* SMALL */ /* The shell uses its own variation on argv, to build variables like * $0 and $@. @@ -250,7 +254,9 @@ (strlen(kshname) >= 3 && !strcmp(&kshname[strlen(kshname) - 3], "/sh"))) { Flag(FSH) = 1; +#ifndef SMALL version_param = "SH_VERSION"; +#endif /* SMALL */ } /* Set edit mode to emacs by default, may be overridden @@ -299,9 +305,11 @@ } ppid = getppid(); setint(global("PPID"), (int64_t) ppid); +#ifndef SMALL /* setstr can't fail here */ setstr(global(version_param), ksh_version, KSH_RETURN_ERROR); - setstr(global("OKSH_VERSION"), "oksh 7.0", KSH_RETURN_ERROR); + setstr(global("OKSH_VERSION"), "oksh 7.3", KSH_RETURN_ERROR); +#endif /* SMALL */ /* execute initialization statements */ for (wp = (char**) initcoms; *wp != NULL; wp++) { diff -ur oksh-7.0/misc.c oksh-7.3/misc.c --- oksh-7.0/misc.c 2021-08-20 22:32:00 +++ oksh-7.3/misc.c 2023-04-17 02:03:22 @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.76 2020/10/26 18:16:51 tb Exp $ */ +/* $OpenBSD: misc.c,v 1.78 2021/12/24 22:08:37 deraadt Exp $ */ /* * Miscellaneous functions @@ -908,7 +908,7 @@ go->buf[0] = c; go->optarg = go->buf; } else { - warningf(true, "%s%s-%c: unknown option", + warningf(false, "%s%s-%c: unknown option", (go->flags & GF_NONAME) ? "" : argv[0], (go->flags & GF_NONAME) ? "" : ": ", c); if (go->flags & GF_ERROR) @@ -934,7 +934,7 @@ go->optarg = go->buf; return ':'; } - warningf(true, "%s%s-`%c' requires argument", + warningf(false, "%s%s-`%c' requires argument", (go->flags & GF_NONAME) ? "" : argv[0], (go->flags & GF_NONAME) ? "" : ": ", c); if (go->flags & GF_ERROR) @@ -1138,7 +1138,7 @@ /* Assume getcwd() available */ if (!buf) { bsize = PATH_MAX; - b = alloc(PATH_MAX + 1, ATEMP); + b = alloc(bsize, ATEMP); } else b = buf; diff -ur oksh-7.0/oksh.1 oksh-7.3/oksh.1 --- oksh-7.0/oksh.1 2021-08-20 22:32:00 +++ oksh-7.3/oksh.1 2023-04-17 02:03:22 @@ -1,8 +1,8 @@ -.\" $OpenBSD: ksh.1,v 1.215 2021/05/04 21:03:30 naddy Exp $ +.\" $OpenBSD: ksh.1,v 1.218 2022/12/26 17:45:27 jmc Exp $ .\" .\" Public Domain .\" -.Dd $Mdocdate: May 4 2021 $ +.Dd $Mdocdate: December 26 2022 $ .Dt OKSH 1 .Os .Sh NAME @@ -745,9 +745,10 @@ must be unquoted. .It The second operand of the -.Sq != +.Sq = , +.Sq == and -.Sq = +.Sq != expressions are patterns (e.g. the comparison .Ic [[ foobar = f*r ]] succeeds). @@ -2712,9 +2713,7 @@ .Cm +-x Oc .Op Fl p .Op Cm + -.Oo Ar name -.Op Ns = Ns Ar value -.Ar ... Oc +.Op Ar name Ns Oo = Ns Ar value Oc Ar ... .Xc Without arguments, .Ic alias @@ -3453,9 +3452,7 @@ .It Xo .Ic readonly .Op Fl p -.Oo Ar parameter -.Op Ns = Ns Ar value -.Ar ... Oc +.Op Ar parameter Ns Oo = Ns Ar value Oc Ar ... .Xc Sets the read-only attribute of the named parameters. If values are given, @@ -4012,7 +4009,7 @@ .Pp If the .Fl p -option is given the output is slightly longer: +option is given, the output is slightly longer: .Bd -literal -offset indent real 0.00 user 0.00 @@ -4124,11 +4121,7 @@ .Op Fl i Ns Op Ar n .No \&| Fl f Op Fl tux .Oc -.Oo -.Ar name -.Op Ns = Ns Ar value -.Ar ... -.Oc +.Op Ar name Ns Oo = Ns Ar value Oc Ar ... .Xc Display or set parameter attributes. With no diff -ur oksh-7.0/sh.1 oksh-7.3/sh.1 --- oksh-7.0/sh.1 2021-08-20 22:32:00 +++ oksh-7.3/sh.1 2023-04-17 02:03:22 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sh.1,v 1.153 2021/05/04 21:03:31 naddy Exp $ +.\" $OpenBSD: sh.1,v 1.156 2022/12/19 08:19:50 sdk Exp $ .\" .\" Copyright (c) 2015 Jason McIntyre .\" @@ -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: May 4 2021 $ +.Dd $Mdocdate: December 19 2022 $ .Dt SH 1 .Os .Sh NAME @@ -752,9 +752,9 @@ and so on. Parameters .Sq # -to +down to .Sq Po #\(mi Ns Ar n Pc Ns +1 -and downwards are unset and +are unset and .Sq # is updated to the new number of positional parameters. If @@ -1052,9 +1052,9 @@ .Ic 0 , ^ , $ , and .Ic c . -If the motion moves towards the beginning of the line +If the motion moves towards the beginning of the line, the character under the cursor is not deleted; -if it moves towards the end of the line +if it moves towards the end of the line, it is deleted. .It Ic C Delete the characters between the cursor and the line end, @@ -1089,7 +1089,7 @@ A special motion command, .Ic d , may be used to delete the entire line. -If the motion moves towards the beginning of the line +If the motion moves towards the beginning of the line, the character under the cursor is not deleted. .It Oo Ar count Oc Ns Ic D Delete the characters between the cursor and the line end, @@ -1100,7 +1100,7 @@ A special motion command, .Ic y , may be used to yank the entire line. -If the motion moves towards the beginning of the line +If the motion moves towards the beginning of the line, the character under the cursor is not yanked. .It Oo Ar count Oc Ns Ic Y Yank (copy) the characters between the cursor and the line end, @@ -1390,7 +1390,7 @@ .Pp Where .Ar expression -is an integer, parameter name, or array reference, +is an integer or parameter name, optionally combined with any of the operators described below, listed and grouped according to precedence: .Bl -tag -width Ds diff -ur oksh-7.0/tty.c oksh-7.3/tty.c --- oksh-7.0/tty.c 2021-08-20 22:32:00 +++ oksh-7.3/tty.c 2023-04-17 02:03:22 @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.18 2019/06/28 13:34:59 deraadt Exp $ */ +/* $OpenBSD: tty.c,v 1.19 2021/10/24 21:24:21 deraadt Exp $ */ #include #include @@ -33,7 +33,7 @@ tty_close(); tty_devtty = 1; - tfd = open("/dev/tty", O_RDWR, 0); + tfd = open("/dev/tty", O_RDWR); if (tfd == -1) { tty_devtty = 0; warningf(false, "No controlling tty (open /dev/tty: %s)", diff -ur oksh-7.0/vi.c oksh-7.3/vi.c --- oksh-7.0/vi.c 2021-08-20 22:32:00 +++ oksh-7.3/vi.c 2023-04-17 02:03:22 @@ -15,8 +15,16 @@ #include #include #if !defined(SMALL) && !defined(NO_CURSES) +#ifdef HAVE_CURSES # include # include +#elif defined(HAVE_NCURSES) +# include +# include +#elif defined(HAVE_NCURSESNCURSES) +# include +# include +#endif #endif #include "sh.h"