Skip to content

Commit

Permalink
Sync from OpenBSD
Browse files Browse the repository at this point in the history
Adds manual page tweak from May 4:
---
CVSROOT:	/cvs
Module name:	src
Changes by:	[email protected]	2021/05/04 15:03:31

Modified files:
	bin/ksh        : ksh.1 sh.1
	usr.bin/getopt : getopt.1

Log message:
shell scripts should use getopts instead of getopt

Add a prominent deprecation notice to getopt.1.
Add examples of the getopts idiom to sh.1 and ksh.1.

Requested by and ok espie@, ok jmc@
--

Also adds today's commit:
---
CVSROOT:	/cvs
Module name:	src
Changes by:	[email protected]	2021/06/27 09:53:33

Modified files:
	bin/ksh        : emacs.c

Log message:
In addition to 2-byte and 3-byte UTF-8 sequences, correctly identify all
4-byte UTF-8 sequences and not just some of them, to keep them together
and avoid passing them on byte by byte, helping tools like tmux(1).

While here, also do all the range tests with < and > rather than &
for uniformity and readability, and add some comments.

Input and OK jca@ and nicm@.

Soeren at Soeren dash Tempel dot net originally reported the bug
and provided an incomplete patch that was used as a starting point,
and he also tested this final patch.
---
  • Loading branch information
ibara committed Jun 27, 2021
1 parent b9b207c commit 7a5f8be
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 43 deletions.
62 changes: 31 additions & 31 deletions CVS/Entries
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,40 @@
/io.c/1.38/Result of merge//
/history.c/1.84/Result of merge//
/trap.c/1.33/Tue Dec 17 00:39:35 2019//
/emacs.c/1.87/Result of merge//
/sh.h/1.76/Result of merge//
/eval.c/1.66/Result of merge//
/misc.c/1.76/Result of merge//
/var.c/1.72/Result of merge//
/vi.c/1.60/Result of merge+Fri Mar 12 03:48:27 2021//
/CONTRIBUTORS/1.11/Fri Apr 16 21:43:40 2021//
/LEGAL/1.2/Fri Apr 16 21:43:40 2021//
/Makefile/1.39/Fri Apr 30 23:20:22 2021//
/NOTES/1.16/Fri Apr 16 21:43:40 2021//
/PROJECTS/1.9/Fri Apr 16 21:43:40 2021//
/README/1.16/Fri Apr 30 23:20:22 2021//
/alloc.c/1.19/Fri Apr 16 21:43:40 2021//
/c_ksh.c/1.62/Fri Apr 16 21:43:40 2021//
/c_sh.c/1.64/Fri Apr 16 21:43:40 2021//
/c_test.h/1.4/Fri Apr 16 21:43:40 2021//
/c_ulimit.c/1.29/Fri Apr 16 21:43:40 2021//
/edit.h/1.12/Fri Apr 16 21:43:40 2021//
/expand.h/1.15/Fri Apr 16 21:43:40 2021//
/expr.c/1.34/Fri Apr 16 21:43:40 2021//
/jobs.c/1.62/Fri Apr 16 21:43:40 2021//
/ksh.1/1.214/Fri Apr 16 21:43:40 2021//
/lex.c/1.78/Fri Apr 16 21:43:40 2021//
/lex.h/1.21/Fri Apr 16 21:43:40 2021//
/mail.c/1.27/Fri Apr 16 21:43:40 2021//
/path.c/1.23/Fri Apr 16 21:43:40 2021//
/sh.1/1.152/Fri Apr 16 21:43:40 2021//
/shf.c/1.34/Fri Apr 16 21:43:40 2021//
/shf.h/1.8/Fri Apr 16 21:43:40 2021//
/syn.c/1.39/Fri Apr 16 21:43:40 2021//
/table.c/1.25/Fri Apr 16 21:43:40 2021//
/table.h/1.15/Fri Apr 16 21:43:40 2021//
/tree.c/1.34/Fri Apr 16 21:43:40 2021//
/tree.h/1.12/Fri Apr 16 21:43:40 2021//
/tty.h/1.6/Fri Apr 16 21:43:40 2021//
/version.c/1.12/Fri Apr 16 21:43:40 2021//
/CONTRIBUTORS/1.11/Thu Jun 3 17:46:02 2021//
/LEGAL/1.2/Thu Jun 3 17:46:02 2021//
/Makefile/1.39/Sun Jun 27 18:11:13 2021//
/NOTES/1.16/Thu Jun 3 17:46:02 2021//
/PROJECTS/1.9/Thu Jun 3 17:46:02 2021//
/README/1.16/Sun Jun 27 18:11:13 2021//
/alloc.c/1.19/Thu Jun 3 17:46:02 2021//
/c_ksh.c/1.62/Thu Jun 3 17:46:02 2021//
/c_sh.c/1.64/Thu Jun 3 17:46:02 2021//
/c_test.h/1.4/Thu Jun 3 17:46:02 2021//
/c_ulimit.c/1.29/Thu Jun 3 17:46:02 2021//
/edit.h/1.12/Thu Jun 3 17:46:02 2021//
/emacs.c/1.88/Result of merge//
/expand.h/1.15/Thu Jun 3 17:46:02 2021//
/expr.c/1.34/Thu Jun 3 17:46:02 2021//
/jobs.c/1.62/Thu Jun 3 17:46:02 2021//
/ksh.1/1.215/Sun Jun 27 18:11:13 2021//
/lex.c/1.78/Thu Jun 3 17:46:02 2021//
/lex.h/1.21/Thu Jun 3 17:46:02 2021//
/mail.c/1.27/Thu Jun 3 17:46:02 2021//
/path.c/1.23/Thu Jun 3 17:46:02 2021//
/sh.1/1.153/Sun Jun 27 18:11:13 2021//
/shf.c/1.34/Thu Jun 3 17:46:02 2021//
/shf.h/1.8/Thu Jun 3 17:46:02 2021//
/syn.c/1.39/Thu Jun 3 17:46:02 2021//
/table.c/1.25/Thu Jun 3 17:46:02 2021//
/table.h/1.15/Thu Jun 3 17:46:02 2021//
/tree.c/1.34/Thu Jun 3 17:46:02 2021//
/tree.h/1.12/Thu Jun 3 17:46:02 2021//
/tty.h/1.6/Thu Jun 3 17:46:02 2021//
/version.c/1.12/Thu Jun 3 17:46:02 2021//
D
19 changes: 13 additions & 6 deletions emacs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: emacs.c,v 1.87 2020/05/08 14:30:42 jca Exp $ */
/* $OpenBSD: emacs.c,v 1.88 2021/06/27 15:53:33 schwarze Exp $ */

/*
* Emacs-like command line editing and history
Expand Down Expand Up @@ -1859,11 +1859,17 @@ x_e_getu8(char *buf, int off)
return -1;
buf[off++] = c;

if (c == 0xf4)
/*
* In the following, comments refer to violations of
* the inequality tests at the ends of the lines.
* See the utf8(7) manual page for details.
*/

if ((c & 0xf8) == 0xf0 && c < 0xf5) /* beyond Unicode */
len = 4;
else if ((c & 0xf0) == 0xe0)
len = 3;
else if ((c & 0xe0) == 0xc0 && c > 0xc1)
else if ((c & 0xe0) == 0xc0 && c > 0xc1) /* use single byte */
len = 2;
else
len = 1;
Expand All @@ -1873,9 +1879,10 @@ x_e_getu8(char *buf, int off)
if (cc == -1)
break;
if (isu8cont(cc) == 0 ||
(c == 0xe0 && len == 3 && cc < 0xa0) ||
(c == 0xed && len == 3 && cc & 0x20) ||
(c == 0xf4 && len == 4 && cc & 0x30)) {
(c == 0xe0 && len == 3 && cc < 0xa0) || /* use 2 bytes */
(c == 0xed && len == 3 && cc > 0x9f) || /* surrogates */
(c == 0xf0 && len == 4 && cc < 0x90) || /* use 3 bytes */
(c == 0xf4 && len == 4 && cc > 0x8f)) { /* beyond Uni. */
x_e_ungetc(cc);
break;
}
Expand Down
23 changes: 21 additions & 2 deletions ksh.1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.\" $OpenBSD: ksh.1,v 1.214 2021/03/11 07:04:12 jmc Exp $
.\" $OpenBSD: ksh.1,v 1.215 2021/05/04 21:03:30 naddy Exp $
.\"
.\" Public Domain
.\"
.Dd $Mdocdate: March 11 2021 $
.Dd $Mdocdate: May 4 2021 $
.Dt KSH 1
.Os
.Sh NAME
Expand Down Expand Up @@ -3219,6 +3219,25 @@ resetting
.Ev OPTIND ,
may lead to unexpected results.
.Pp
The following code fragment shows how one might process the arguments
for a command that can take the option
.Fl a
and the option
.Fl o ,
which requires an argument.
.Bd -literal -offset indent
while getopts ao: name
do
case $name in
a) flag=1 ;;
o) oarg=$OPTARG ;;
?) echo "Usage: ..."; exit 2 ;;
esac
done
shift $(($OPTIND - 1))
echo "Non-option arguments: " "$@"
.Ed
.Pp
.It Xo
.Ic hash
.Op Fl r
Expand Down
23 changes: 21 additions & 2 deletions oksh.1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.\" $OpenBSD: ksh.1,v 1.214 2021/03/11 07:04:12 jmc Exp $
.\" $OpenBSD: ksh.1,v 1.215 2021/05/04 21:03:30 naddy Exp $
.\"
.\" Public Domain
.\"
.Dd $Mdocdate: March 11 2021 $
.Dd $Mdocdate: May 4 2021 $
.Dt OKSH 1
.Os
.Sh NAME
Expand Down Expand Up @@ -3219,6 +3219,25 @@ resetting
.Ev OPTIND ,
may lead to unexpected results.
.Pp
The following code fragment shows how one might process the arguments
for a command that can take the option
.Fl a
and the option
.Fl o ,
which requires an argument.
.Bd -literal -offset indent
while getopts ao: name
do
case $name in
a) flag=1 ;;
o) oarg=$OPTARG ;;
?) echo "Usage: ..."; exit 2 ;;
esac
done
shift $(($OPTIND - 1))
echo "Non-option arguments: " "$@"
.Ed
.Pp
.It Xo
.Ic hash
.Op Fl r
Expand Down
23 changes: 21 additions & 2 deletions sh.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" $OpenBSD: sh.1,v 1.152 2019/05/22 15:23:23 schwarze Exp $
.\" $OpenBSD: sh.1,v 1.153 2021/05/04 21:03:31 naddy Exp $
.\"
.\" Copyright (c) 2015 Jason McIntyre <[email protected]>
.\"
Expand All @@ -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 22 2019 $
.Dd $Mdocdate: May 4 2021 $
.Dt SH 1
.Os
.Sh NAME
Expand Down Expand Up @@ -508,6 +508,25 @@ is a colon,
.Ev OPTARG
is set to the unsupported option,
otherwise an error message is displayed.
.Pp
The following code fragment shows how one might process the arguments
for a command that can take the option
.Fl a
and the option
.Fl o ,
which requires an argument.
.Bd -literal -offset indent
while getopts ao: name
do
case $name in
a) flag=1 ;;
o) oarg=$OPTARG ;;
?) echo "Usage: ..."; exit 2 ;;
esac
done
shift $(($OPTIND - 1))
echo "Non-option arguments: " "$@"
.Ed
.It Ic hash Op Fl r | Ar utility
Add
.Ar utility
Expand Down

0 comments on commit 7a5f8be

Please sign in to comment.