From nobody Sat Aug 20 11:30:10 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M8xHk6dQmz4Z4RC; Sat, 20 Aug 2022 11:30:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4M8xHk67lSz44Hr; Sat, 20 Aug 2022 11:30:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660995010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MymYZLXqwV00B5LZq/8Wa4V2lkzTF1wANc3qcziGJbA=; b=E6RWhz/tj/PZiVBOTwrBqPoRN1LVEZixI7AxldebTu3fjLlbJ8ioiYD34/LswxvuCYMexE KHgnoSsSQsEON5bTzcfIJD0jQUaMrtrs4IWj8i5sbHagbtOzIeY9EjTiduqeFHWRVDYHRT RHhft6dr1CUB4XiA2L7qN7787F6n+lQ+9H1P3wP9yT5LZ1+c611tVeFlKPz5MEyJc70JbR WSNvej01MHcQEbnMA7CUBMK2MAgtH9Rmgp6Danpp5yFRkDjbDu1Uxo+k4Zlbngzu4slYM6 XWXi89dkC5coHCztBr6zWDQ1QlqAlb6lIyLp9Ubqniu6cz6itoegs1MR/0GU2A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4M8xHk55GDzVwg; Sat, 20 Aug 2022 11:30:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27KBUACg076479; Sat, 20 Aug 2022 11:30:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27KBUAOM076476; Sat, 20 Aug 2022 11:30:10 GMT (envelope-from git) Date: Sat, 20 Aug 2022 11:30:10 GMT Message-Id: <202208201130.27KBUAOM076476@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: 755a1be6d015 - main - sh: accept fc options grouped behind one '-' List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 755a1be6d015287763b0f336d4e9b8179615f511 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660995010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=MymYZLXqwV00B5LZq/8Wa4V2lkzTF1wANc3qcziGJbA=; b=ul7V6CvGXqRWt3FzpQc+ThB6Uoo/J7sWlPZroTWFbLEl/quuM/HX5Wa4BQ2vfLV2J98NRi vdKJvpFmtj7gUoNbFSdCt/VxX8TOQn2P0d/pH2WuPw6l3OuBTrUgGRHlCuKBpnltNQnm71 p+6osGSHuYRonkqpKYF5kf4GQCVNVsnFYqF9w81Qwl8227vxUsRUqUeSQcQB/qy68CUHax hGDSoxEi/pT5DT4Fg7A0LjVe65EgxYfByJlVoqSmNCuxBxLubBTYYkA7Rc0LrMUPoMNkp1 ORFoW0tlHemkjynE3bMy/WqWwTHzmJTqwyjG7CqpQp986A1SXZt1hFfXhtZoqQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660995010; a=rsa-sha256; cv=none; b=xKtsr2BTyWweQ4ElDQg8Kg2ZA6oymxC2mgXUYXAwtQHT/6acgo++/QmF8ehr749c6nQKzp Hx63kGvHeruvXpQejbn5pCRKUj9vCe2+ApVs3asp8BjyA8JckSYpTcD3qULFRvtmij4Mpw VDlwLdKLYtXhcmqj1rvPJ4MLkX304rbJQbp3wItizsrWRo2XoCYtYlbO99+sAgBwM4yKjz VUrJRgka0DyxwDwh4hPcIyApXh7TfeDNDlkOpo8Wzc/meVGklOlfBJmVDfIk01YdpaArPD XNNITlgiCQOOrLzHKmUqbuZEPgrH449lCtv1qWVBQxvI/6FiEb3qZyIpOwiv9Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=755a1be6d015287763b0f336d4e9b8179615f511 commit 755a1be6d015287763b0f336d4e9b8179615f511 Author: Piotr Pawel Stefaniak AuthorDate: 2022-08-20 10:15:05 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2022-08-20 11:26:05 +0000 sh: accept fc options grouped behind one '-' As per Utility Syntax Guidelines, accept both forms: -l -n and -ln. To do that, anticipate the source string for the next option that will be parsed by nextopt(). It's not always *argptr, sometimes it is nextopt_optptr. To simplify the check for not_fcnumber, slightly modify nextopt() to always nullify nextopt_optptr in cases where it would have been set to point to a NUL character. Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D35836 --- bin/sh/histedit.c | 43 ++++++++++++++++++++------------------ bin/sh/options.c | 5 ++++- bin/sh/tests/builtins/Makefile | 1 + bin/sh/tests/builtins/fc3.0 | 9 ++++++++ bin/sh/tests/builtins/fc3.0.stderr | 1 + bin/sh/tests/builtins/fc3.0.stdout | 3 +++ 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index 453260a27e54..8812200279f0 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -255,7 +255,6 @@ setterm(const char *term) int histcmd(int argc, char **argv __unused) { - int ch; const char *editor = NULL; HistEvent he; int lflg = 0, nflg = 0, rflg = 0, sflg = 0; @@ -277,25 +276,29 @@ histcmd(int argc, char **argv __unused) if (argc == 1) error("missing history argument"); - while (not_fcnumber(*argptr) && (ch = nextopt("e:lnrs")) != '\0') - switch ((char)ch) { - case 'e': - editor = shoptarg; - break; - case 'l': - lflg = 1; - break; - case 'n': - nflg = 1; - break; - case 'r': - rflg = 1; - break; - case 's': - sflg = 1; - break; - } - + while (not_fcnumber(*argptr)) + do { + switch (nextopt("e:lnrs")) { + case 'e': + editor = shoptarg; + break; + case 'l': + lflg = 1; + break; + case 'n': + nflg = 1; + break; + case 'r': + rflg = 1; + break; + case 's': + sflg = 1; + break; + case '\0': + goto operands; + } + } while (nextopt_optptr != NULL); +operands: savehandler = handler; /* * If executing... diff --git a/bin/sh/options.c b/bin/sh/options.c index 97171d32bff1..55bfd9d483b7 100644 --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -589,6 +589,9 @@ nextopt(const char *optstring) shoptarg = p; p = NULL; } - nextopt_optptr = p; + if (p != NULL && *p != '\0') + nextopt_optptr = p; + else + nextopt_optptr = NULL; return c; } diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile index f9b464a6da4b..727a7bc6c848 100644 --- a/bin/sh/tests/builtins/Makefile +++ b/bin/sh/tests/builtins/Makefile @@ -94,6 +94,7 @@ ${PACKAGE}FILES+= exit3.0 ${PACKAGE}FILES+= export1.0 ${PACKAGE}FILES+= fc1.0 ${PACKAGE}FILES+= fc2.0 +${PACKAGE}FILES+= fc3.0 fc3.0.stdout fc3.0.stderr ${PACKAGE}FILES+= for1.0 ${PACKAGE}FILES+= for2.0 ${PACKAGE}FILES+= for3.0 diff --git a/bin/sh/tests/builtins/fc3.0 b/bin/sh/tests/builtins/fc3.0 new file mode 100644 index 000000000000..daa615bcc3ca --- /dev/null +++ b/bin/sh/tests/builtins/fc3.0 @@ -0,0 +1,9 @@ +export PS1='_ ' # cannot predict whether ran by root or not + +echo ': command1 +: command2 +: command3 +: command4 +fc -l -n -1 +fc -ln 2 3 +' | ENV= HISTFILE=/dev/null ${SH} +m -i diff --git a/bin/sh/tests/builtins/fc3.0.stderr b/bin/sh/tests/builtins/fc3.0.stderr new file mode 100644 index 000000000000..e05147fb8209 --- /dev/null +++ b/bin/sh/tests/builtins/fc3.0.stderr @@ -0,0 +1 @@ +_ _ _ _ _ _ _ _ diff --git a/bin/sh/tests/builtins/fc3.0.stdout b/bin/sh/tests/builtins/fc3.0.stdout new file mode 100644 index 000000000000..8c23c913635d --- /dev/null +++ b/bin/sh/tests/builtins/fc3.0.stdout @@ -0,0 +1,3 @@ +: command4 +: command2 +: command3