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: 4253ca89387918e0945e980144cbb17a1f3f7d14
parent: f067067da3ddbb5f3a0e9d3f0bec5e3032b5ffa4
author: Brian Callahan <bcallah@openbsd.org>
date:   Sat, 18 Nov 2023 19:31:39 -0500
oksh-7.4
MCVS/Entries8+-
MREADME.md4+-
Mc_sh.c21++--
Mksh.186++++++++--------
Mmain.c2+-
Moksh.1108++++++++------------
6 files changed, 106 insertions(+), 123 deletions(-)
diff --git a/CVS/Entries b/CVS/Entries
@@ -7,13 +7,10 @@
 /misc.c/1.78/Result of merge//
 /CONTRIBUTORS/1.11/Thu Aug  3 22:00:56 2023//
 /LEGAL/1.2/Thu Aug  3 22:00:56 2023//
-/Makefile/1.39/Thu Aug  3 22:25:58 2023//
 /NOTES/1.16/Thu Aug  3 22:00:56 2023//
 /PROJECTS/1.9/Thu Aug  3 22:00:56 2023//
-/README/1.16/Thu Aug  3 22:25:58 2023//
 /alloc.c/1.19/Thu Aug  3 22:00:56 2023//
 /c_ksh.c/1.62/Thu Aug  3 22:00:56 2023//
-/c_sh.c/1.64/Thu Aug  3 22:00:56 2023//
 /c_test.c/1.28/Result of merge//
 /c_test.h/1.4/Thu Aug  3 22:00:56 2023//
 /c_ulimit.c/1.29/Thu Aug  3 22:00:56 2023//
@@ -25,7 +22,6 @@
 /expand.h/1.15/Thu Aug  3 22:00:56 2023//
 /expr.c/1.34/Thu Aug  3 22:00:56 2023//
 /jobs.c/1.62/Thu Aug  3 22:00:56 2023//
-/ksh.1/1.219/Thu Aug  3 22:25:58 2023//
 /lex.c/1.79/Thu Aug  3 22:00:56 2023//
 /lex.h/1.21/Thu Aug  3 22:00:56 2023//
 /mail.c/1.27/Thu Aug  3 22:00:56 2023//
@@ -43,4 +39,8 @@
 /tty.h/1.6/Thu Aug  3 22:00:56 2023//
 /var.c/1.73/Result of merge//
 /version.c/1.12/Thu Aug  3 22:00:56 2023//
+/Makefile/1.39/Sun Nov 19 00:26:55 2023//
+/README/1.16/Sun Nov 19 00:26:55 2023//
+/c_sh.c/1.65/Sun Nov 19 00:26:55 2023//
+/ksh.1/1.220/Sun Nov 19 00:26:55 2023//
 D
diff --git a/README.md b/README.md
@@ -141,5 +141,5 @@ for details.
 
 Get a tarball
 -------------
-See releases tab. The latest release is oksh-7.3, which matches the ksh(1)
-from OpenBSD 7.3, released April 10, 2023.
+See releases tab. The latest release is oksh-7.4, which matches the ksh(1)
+from OpenBSD 7.4, released October 16, 2023.
diff --git a/c_sh.c b/c_sh.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: c_sh.c,v 1.64 2020/05/22 07:50:07 benno Exp $	*/
+/*	$OpenBSD: c_sh.c,v 1.65 2023/09/14 18:32:03 cheloha Exp $	*/
 
 /*
  * built-in Bourne commands
@@ -676,18 +676,21 @@ c_unset(char **wp)
 	return 0;
 }
 
+#ifndef TIMEVAL_TO_TIMESPEC
+#define TIMEVAL_TO_TIMESPEC(tv, ts) do {				\
+	(ts)->tv_sec = (tv)->tv_sec;					\
+	(ts)->tv_nsec = (tv)->tv_usec * 1000;				\
+} while (0)
+#endif
+
 static void
 p_tv(struct shf *shf, int posix, struct timeval *tv, int width, char *prefix,
     char *suffix)
 {
-	if (posix)
-		shf_fprintf(shf, "%s%*lld.%02ld%s", prefix ? prefix : "",
-		    width, (long long)tv->tv_sec, tv->tv_usec / 10000, suffix);
-	else
-		shf_fprintf(shf, "%s%*lldm%02lld.%02lds%s", prefix ? prefix : "",
-		    width, (long long)tv->tv_sec / 60,
-		    (long long)tv->tv_sec % 60,
-		    tv->tv_usec / 10000, suffix);
+	struct timespec ts;
+
+	TIMEVAL_TO_TIMESPEC(tv, &ts);
+	p_ts(shf, posix, &ts, width, prefix, suffix);
 }
 
 static void
diff --git a/ksh.1 b/ksh.1
@@ -1,8 +1,8 @@
-.\"	$OpenBSD: ksh.1,v 1.219 2023/06/10 07:24:21 op Exp $
+.\"	$OpenBSD: ksh.1,v 1.220 2023/10/20 18:51:09 schwarze Exp $
 .\"
 .\"	Public Domain
 .\"
-.Dd $Mdocdate: June 10 2023 $
+.Dd $Mdocdate: October 20 2023 $
 .Dt KSH 1
 .Os
 .Sh NAME
@@ -1188,8 +1188,8 @@ is printed on standard error (preceded by
 .Ar name : )
 and an error occurs (normally causing termination of a shell script, function,
 or script sourced using the
-.Sq \&.
-built-in).
+.Sq Ic \&.
+built-in command).
 If
 .Ar word
 is omitted, the string
@@ -1287,8 +1287,8 @@ keyword (i.e. a Korn shell style function).
 .It Ev 1 No ... Ev 9
 The first nine positional parameters that were supplied to the shell, function,
 or script sourced using the
-.Sq \&.
-built-in.
+.Sq Ic \&.
+built-in command.
 Further positional parameters may be accessed using
 .Pf ${ Ar number Ns } .
 .It Ev *
@@ -1412,10 +1412,10 @@ below for more information.
 .It Ev HISTCONTROL
 A colon separated list of history settings.
 If
-.Li ignoredups
+.Sy ignoredups
 is present, lines identical to the previous history line will not be saved.
 If
-.Li ignorespace
+.Sy ignorespace
 is present, lines starting with a space will not be saved.
 Unknown settings are ignored.
 .It Ev HISTFILE
@@ -1533,7 +1533,7 @@ is (so they know how far it is to the edge of the screen), escape codes in
 the prompt tend to mess things up.
 You can tell the shell not to count certain
 sequences (such as escape codes) by using the
-.Li \e[ Ns Ar ... Ns Li \e]
+.Sy \e[ Ns Ar ... Ns Sy \e]
 substitution (see below) or by prefixing your prompt with a non-printing
 character (such as control-A) followed by a carriage return and then delimiting
 the escape codes with this non-printing character.
@@ -1551,85 +1551,85 @@ The following backslash-escaped special characters can be used
 to customise the prompt:
 .Pp
 .Bl -tag -width "\eD{format}XX" -compact
-.It Li \ea
+.It Sy \ea
 Insert an ASCII bell character.
-.It Li \ed
+.It Sy \ed
 The current date, in the format
 .Dq Day Month Date
 for example
 .Dq Wed Nov 03 .
-.It Li \eD Ns Brq Ar format
+.It Sy \eD Ns Brq Ar format
 The current date, with
 .Ar format
 converted by
 .Xr strftime 3 .
 The braces must be specified.
-.It Li \ee
+.It Sy \ee
 Insert an ASCII escape character.
-.It Li \eh
+.It Sy \eh
 The hostname, minus domain name.
-.It Li \eH
+.It Sy \eH
 The full hostname, including domain name.
-.It Li \ej
+.It Sy \ej
 Current number of jobs running
 (see
 .Sx Job control
 below).
-.It Li \el
+.It Sy \el
 The controlling terminal.
-.It Li \en
+.It Sy \en
 Insert a newline character.
-.It Li \er
+.It Sy \er
 Insert a carriage return character.
-.It Li \es
+.It Sy \es
 The name of the shell.
-.It Li \et
+.It Sy \et
 The current time, in 24-hour HH:MM:SS format.
-.It Li \eT
+.It Sy \eT
 The current time, in 12-hour HH:MM:SS format.
-.It Li \e@
+.It Sy \e@
 The current time, in 12-hour HH:MM:SS AM/PM format.
-.It Li \eA
+.It Sy \eA
 The current time, in 24-hour HH:MM format.
-.It Li \eu
+.It Sy \eu
 The current user's username.
-.It Li \ev
+.It Sy \ev
 The current version of
 .Nm .
-.It Li \eV
+.It Sy \eV
 Like
-.Sq \ev ,
+.Sy \ev ,
 but more verbose.
-.It Li \ew
+.It Sy \ew
 The current working directory.
 .Dv $HOME
 is abbreviated as
 .Sq ~ .
-.It Li \eW
+.It Sy \eW
 The basename of
 the current working directory.
 .Dv $HOME
 is abbreviated as
 .Sq ~ .
-.It Li \e!
+.It Sy \e!
 The current history number.
 An unescaped
-.Ql !\&
+.Sq Sy !\&
 will produce the current history number too,
 as per the POSIX specification.
 A literal
 .Ql \&!
 can be put in the prompt by placing
-.Ql !!
+.Sq Sy !!
 in
 .Ev PS1 .
-.It Li \e#
+.It Sy \e#
 The current command number.
 This could be different to the current history number,
 if
 .Ev HISTFILE
 contains a history list from a previous session.
-.It Li \e$
+.It Sy \e$
 The default prompt character i.e.\&
 .Sq #
 if the effective UID is 0,
@@ -1640,15 +1640,15 @@ Since the shell interprets
 as a special character within double quotes,
 it is safer in this case to escape the backslash
 than to try quoting it.
-.It Li \e Ns Ar nnn
+.It Sy \e Ns Ar nnn
 The octal character
 .Ar nnn .
-.It Li \e\e
+.It Sy \e\e
 Insert a single backslash character.
-.It Li \e[
+.It Sy \e[
 Normally the shell keeps track of the number of characters in the prompt.
 Use of this sequence turns off that count.
-.It Li \e]
+.It Sy \e]
 Use of this sequence turns the count back on.
 .El
 .Pp
@@ -2337,13 +2337,13 @@ syntax or the Bourne/POSIX shell
 .Ar function-name Ns ()
 syntax (see below for the difference between the two forms).
 Functions are like
-.Li .-scripts
+.Ic \&. Ns -scripts
 (i.e. scripts sourced using the
-.Sq \&.
-built-in)
+.Sq Ic \&.
+built-in command)
 in that they are executed in the current environment.
 However, unlike
-.Li .-scripts ,
+.Ic \&. Ns -scripts,
 shell arguments (i.e. positional parameters $1, $2, etc.)\&
 are never visible inside them.
 When the shell is determining the location of a command, functions
diff --git a/main.c b/main.c
@@ -312,7 +312,7 @@ main(int argc, char *argv[])
 #ifndef SMALL
 	/* setstr can't fail here */
 	setstr(global(version_param), ksh_version, KSH_RETURN_ERROR);
-	setstr(global("OKSH_VERSION"), "oksh 7.3", KSH_RETURN_ERROR);
+	setstr(global("OKSH_VERSION"), "oksh 7.4", KSH_RETURN_ERROR);
 #endif /* SMALL */
 
 	/* execute initialization statements */
diff --git a/oksh.1 b/oksh.1
@@ -1,8 +1,8 @@
-.\"	$OpenBSD: ksh.1,v 1.218 2022/12/26 17:45:27 jmc Exp $
+.\"	$OpenBSD: ksh.1,v 1.220 2023/10/20 18:51:09 schwarze Exp $
 .\"
 .\"	Public Domain
 .\"
-.Dd $Mdocdate: December 26 2022 $
+.Dd $Mdocdate: October 20 2023 $
 .Dt OKSH 1
 .Os
 .Sh NAME
@@ -1188,8 +1188,8 @@ is printed on standard error (preceded by
 .Ar name : )
 and an error occurs (normally causing termination of a shell script, function,
 or script sourced using the
-.Sq \&.
-built-in).
+.Sq Ic \&.
+built-in command).
 If
 .Ar word
 is omitted, the string
@@ -1287,8 +1287,8 @@ keyword (i.e. a Korn shell style function).
 .It Ev 1 No ... Ev 9
 The first nine positional parameters that were supplied to the shell, function,
 or script sourced using the
-.Sq \&.
-built-in.
+.Sq Ic \&.
+built-in command.
 Further positional parameters may be accessed using
 .Pf ${ Ar number Ns } .
 .It Ev *
@@ -1412,10 +1412,10 @@ below for more information.
 .It Ev HISTCONTROL
 A colon separated list of history settings.
 If
-.Li ignoredups
+.Sy ignoredups
 is present, lines identical to the previous history line will not be saved.
 If
-.Li ignorespace
+.Sy ignorespace
 is present, lines starting with a space will not be saved.
 Unknown settings are ignored.
 .It Ev HISTFILE
@@ -1533,7 +1533,7 @@ is (so they know how far it is to the edge of the screen), escape codes in
 the prompt tend to mess things up.
 You can tell the shell not to count certain
 sequences (such as escape codes) by using the
-.Li \e[ Ns Ar ... Ns Li \e]
+.Sy \e[ Ns Ar ... Ns Sy \e]
 substitution (see below) or by prefixing your prompt with a non-printing
 character (such as control-A) followed by a carriage return and then delimiting
 the escape codes with this non-printing character.
@@ -1551,85 +1551,85 @@ The following backslash-escaped special characters can be used
 to customise the prompt:
 .Pp
 .Bl -tag -width "\eD{format}XX" -compact
-.It Li \ea
+.It Sy \ea
 Insert an ASCII bell character.
-.It Li \ed
+.It Sy \ed
 The current date, in the format
 .Dq Day Month Date
 for example
 .Dq Wed Nov 03 .
-.It Li \eD Ns Brq Ar format
+.It Sy \eD Ns Brq Ar format
 The current date, with
 .Ar format
 converted by
 .Xr strftime 3 .
 The braces must be specified.
-.It Li \ee
+.It Sy \ee
 Insert an ASCII escape character.
-.It Li \eh
+.It Sy \eh
 The hostname, minus domain name.
-.It Li \eH
+.It Sy \eH
 The full hostname, including domain name.
-.It Li \ej
+.It Sy \ej
 Current number of jobs running
 (see
 .Sx Job control
 below).
-.It Li \el
+.It Sy \el
 The controlling terminal.
-.It Li \en
+.It Sy \en
 Insert a newline character.
-.It Li \er
+.It Sy \er
 Insert a carriage return character.
-.It Li \es
+.It Sy \es
 The name of the shell.
-.It Li \et
+.It Sy \et
 The current time, in 24-hour HH:MM:SS format.
-.It Li \eT
+.It Sy \eT
 The current time, in 12-hour HH:MM:SS format.
-.It Li \e@
+.It Sy \e@
 The current time, in 12-hour HH:MM:SS AM/PM format.
-.It Li \eA
+.It Sy \eA
 The current time, in 24-hour HH:MM format.
-.It Li \eu
+.It Sy \eu
 The current user's username.
-.It Li \ev
+.It Sy \ev
 The current version of
 .Nm .
-.It Li \eV
+.It Sy \eV
 Like
-.Sq \ev ,
+.Sy \ev ,
 but more verbose.
-.It Li \ew
+.It Sy \ew
 The current working directory.
 .Dv $HOME
 is abbreviated as
 .Sq ~ .
-.It Li \eW
+.It Sy \eW
 The basename of
 the current working directory.
 .Dv $HOME
 is abbreviated as
 .Sq ~ .
-.It Li \e!
+.It Sy \e!
 The current history number.
 An unescaped
-.Ql !\&
+.Sq Sy !\&
 will produce the current history number too,
 as per the POSIX specification.
 A literal
 .Ql \&!
 can be put in the prompt by placing
-.Ql !!
+.Sq Sy !!
 in
 .Ev PS1 .
-.It Li \e#
+.It Sy \e#
 The current command number.
 This could be different to the current history number,
 if
 .Ev HISTFILE
 contains a history list from a previous session.
-.It Li \e$
+.It Sy \e$
 The default prompt character i.e.\&
 .Sq #
 if the effective UID is 0,
@@ -1640,15 +1640,15 @@ Since the shell interprets
 as a special character within double quotes,
 it is safer in this case to escape the backslash
 than to try quoting it.
-.It Li \e Ns Ar nnn
+.It Sy \e Ns Ar nnn
 The octal character
 .Ar nnn .
-.It Li \e\e
+.It Sy \e\e
 Insert a single backslash character.
-.It Li \e[
+.It Sy \e[
 Normally the shell keeps track of the number of characters in the prompt.
 Use of this sequence turns off that count.
-.It Li \e]
+.It Sy \e]
 Use of this sequence turns the count back on.
 .El
 .Pp
@@ -2337,13 +2337,13 @@ syntax or the Bourne/POSIX shell
 .Ar function-name Ns ()
 syntax (see below for the difference between the two forms).
 Functions are like
-.Li .-scripts
+.Ic \&. Ns -scripts
 (i.e. scripts sourced using the
-.Sq \&.
-built-in)
+.Sq Ic \&.
+built-in command)
 in that they are executed in the current environment.
 However, unlike
-.Li .-scripts ,
+.Ic \&. Ns -scripts,
 shell arguments (i.e. positional parameters $1, $2, etc.)\&
 are never visible inside them.
 When the shell is determining the location of a command, functions
@@ -2569,20 +2569,6 @@ in non-POSIX mode:
 alias a='for ' i='j'
 a i in 1 2; do echo i=$i j=$j; done
 .Ed
-.It
-.Ic test .
-In POSIX mode, the expression
-.Sq Fl t
-(preceded by some number of
-.Sq \&!
-arguments) is always true as it is a non-zero length string;
-in non-POSIX mode, it tests if file descriptor 1 is a
-.Xr tty 4
-(i.e. the
-.Ar fd
-argument to the
-.Fl t
-test may be left out and defaults to 1).
 .El
 .Ss Strict Bourne shell mode
 When the
@@ -3857,18 +3843,12 @@ socket.
 .It Fl s Ar file
 .Ar file
 is not empty.
-.It Fl t Op Ar fd
+.It Fl t Ar fd
 File descriptor
 .Ar fd
 is a
 .Xr tty 4
 device.
-If the
-.Ic posix
-option is not set,
-.Ar fd
-may be left out, in which case it is taken to be 1 (the behaviour differs due
-to the special POSIX rules described above).
 .It Fl u Ar file
 .Ar file Ns 's
 mode has the setuid bit set.