dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] exec: type: ignore first --, per POSIX
@ 2022-12-13 21:13 наб
  2022-12-13 21:13 ` [PATCH 2/2] options: getopts: " наб
  2023-01-02  9:19 ` [PATCH 1/2] exec: type: " Herbert Xu
  0 siblings, 2 replies; 11+ messages in thread
From: наб @ 2022-12-13 21:13 UTC (permalink / raw)
  To: dash

[-- Attachment #1: Type: text/plain, Size: 1182 bytes --]

Issue 7, XCU, type, OPTIONS reads "None.",
and type isn't a special built-in listed in sexion 2.14 ‒
this means that XCU, 1. Introduction, 1.4 Utility Description Defaults,
OPTIONS, Default Behavior applies:
  Default Behavior: When this section is listed as "None.", it means
  that the implementation need not support any options. Standard
  utilities that do not accept options, but that do accept operands,
  shall recognize "--" as a first argument to be discarded.

Test with: type -- ls --
Correct output lists ls=/bin/ls, then --=ENOENT
Wrong output lists --=ENOENT, ls=/bin/ls, --=ENOENT

Fixes: https://bugs.debian.org/870317
---
 src/exec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/exec.c b/src/exec.c
index 87354d4..d61881d 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -760,11 +760,11 @@ unsetfunc(const char *name)
 int
 typecmd(int argc, char **argv)
 {
-	int i;
 	int err = 0;
 
-	for (i = 1; i < argc; i++) {
-		err |= describe_command(out1, argv[i], NULL, 1);
+	nextopt(nullstr);
+	while (*argptr) {
+		err |= describe_command(out1, *argptr++, NULL, 1);
 	}
 	return err;
 }
-- 
2.30.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/2] options: getopts: ignore first --, per POSIX
  2022-12-13 21:13 [PATCH 1/2] exec: type: ignore first --, per POSIX наб
@ 2022-12-13 21:13 ` наб
  2023-01-02  9:19 ` [PATCH 1/2] exec: type: " Herbert Xu
  1 sibling, 0 replies; 11+ messages in thread
From: наб @ 2022-12-13 21:13 UTC (permalink / raw)
  To: dash

[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]

Issue 7, XCU, getopts, OPTIONS reads "None.",
and getopts isn't a special built-in listed in sexion 2.14 ‒
this means that XCU, 1. Introduction, 1.4 Utility Description Defaults,
OPTIONS, Default Behavior applies:
  Default Behavior: When this section is listed as "None.", it means
  that the implementation need not support any options. Standard
  utilities that do not accept options, but that do accept operands,
  shall recognize "--" as a first argument to be discarded.

Test with: getopts -- d: a
Correct output is no output, exit 1
Wrong output errors out with d: being an invalid argument name
---
 src/options.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/options.c b/src/options.c
index a46c23b..337a8ee 100644
--- a/src/options.c
+++ b/src/options.c
@@ -409,6 +409,9 @@ getoptscmd(int argc, char **argv)
 {
 	char **optbase;
 
+	nextopt(nullstr);
+	argc -= argptr - argv - 1;
+	argv = argptr - 1;
 	if (argc < 3)
 		sh_error("Usage: getopts optstring var [arg]");
 	else if (argc == 3) {
-- 
2.30.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] exec: type: ignore first --, per POSIX
  2022-12-13 21:13 [PATCH 1/2] exec: type: ignore first --, per POSIX наб
  2022-12-13 21:13 ` [PATCH 2/2] options: getopts: " наб
@ 2023-01-02  9:19 ` Herbert Xu
  2023-01-02 12:46   ` наб
  1 sibling, 1 reply; 11+ messages in thread
From: Herbert Xu @ 2023-01-02  9:19 UTC (permalink / raw)
  To: наб; +Cc: dash

наб <nabijaczleweli@nabijaczleweli.xyz> wrote:
> [-- text/plain, encoding quoted-printable, charset: utf-8, 41 lines --]
> 
> Issue 7, XCU, type, OPTIONS reads "None.",

type is marked XSI.  dash does claim conformance with respect
to XSI.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] exec: type: ignore first --, per POSIX
  2023-01-02  9:19 ` [PATCH 1/2] exec: type: " Herbert Xu
@ 2023-01-02 12:46   ` наб
  2023-01-02 13:34     ` Harald van Dijk
  2023-01-03  1:39     ` Herbert Xu
  0 siblings, 2 replies; 11+ messages in thread
From: наб @ 2023-01-02 12:46 UTC (permalink / raw)
  To: Herbert Xu; +Cc: dash

[-- Attachment #1: Type: text/plain, Size: 417 bytes --]

On Mon, Jan 02, 2023 at 05:19:17PM +0800, Herbert Xu wrote:
> наб <nabijaczleweli@nabijaczleweli.xyz> wrote:
> > Issue 7, XCU, type, OPTIONS reads "None.",
> type is marked XSI.  dash does claim conformance with respect
> to XSI.
Which means it ought to abide by "None." in the OPTIONS sexion,
as out-lined in the subsequent lines, i.e. discard an initial --, yes.

Good to see we agree, I guess?
наб

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] exec: type: ignore first --, per POSIX
  2023-01-02 12:46   ` наб
@ 2023-01-02 13:34     ` Harald van Dijk
  2023-01-03  1:39     ` Herbert Xu
  1 sibling, 0 replies; 11+ messages in thread
From: Harald van Dijk @ 2023-01-02 13:34 UTC (permalink / raw)
  To: наб, Herbert Xu; +Cc: dash

On 02/01/2023 12:46, наб wrote:
> On Mon, Jan 02, 2023 at 05:19:17PM +0800, Herbert Xu wrote:
>> наб <nabijaczleweli@nabijaczleweli.xyz> wrote:
>>> Issue 7, XCU, type, OPTIONS reads "None.",
>> type is marked XSI.  dash does claim conformance with respect
>> to XSI.
> Which means it ought to abide by "None." in the OPTIONS sexion,
> as out-lined in the subsequent lines, i.e. discard an initial --, yes.
> 
> Good to see we agree, I guess?

I'm pretty sure that was a pretty bad typo and meant to say "dash does 
*not* claim conformance with respect to XSI." See e.g. 
<https://lore.kernel.org/dash/20130904032000.GA19583@gondor.apana.org.au/>, 
"In any case, dash does not claim XSI conformance, [...]"

Cheers,
Harald van Dijk

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] exec: type: ignore first --, per POSIX
  2023-01-02 12:46   ` наб
  2023-01-02 13:34     ` Harald van Dijk
@ 2023-01-03  1:39     ` Herbert Xu
  2023-01-03 12:40       ` наб
  1 sibling, 1 reply; 11+ messages in thread
From: Herbert Xu @ 2023-01-03  1:39 UTC (permalink / raw)
  To: наб; +Cc: dash

On Mon, Jan 02, 2023 at 01:46:28PM +0100, наб wrote:
> On Mon, Jan 02, 2023 at 05:19:17PM +0800, Herbert Xu wrote:
> > наб <nabijaczleweli@nabijaczleweli.xyz> wrote:
> > > Issue 7, XCU, type, OPTIONS reads "None.",
> > type is marked XSI.  dash does claim conformance with respect
> > to XSI.
> Which means it ought to abide by "None." in the OPTIONS sexion,
> as out-lined in the subsequent lines, i.e. discard an initial --, yes.
> 
> Good to see we agree, I guess?

Sorry, I meant that dash does not claim conformance.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] exec: type: ignore first --, per POSIX
  2023-01-03  1:39     ` Herbert Xu
@ 2023-01-03 12:40       ` наб
  2023-01-04  2:10         ` Herbert Xu
  0 siblings, 1 reply; 11+ messages in thread
From: наб @ 2023-01-03 12:40 UTC (permalink / raw)
  To: Herbert Xu; +Cc: dash

[-- Attachment #1: Type: text/plain, Size: 901 bytes --]

Hi!

On Tue, Jan 03, 2023 at 09:39:17AM +0800, Herbert Xu wrote:
> On Mon, Jan 02, 2023 at 01:46:28PM +0100, наб wrote:
> > On Mon, Jan 02, 2023 at 05:19:17PM +0800, Herbert Xu wrote:
> > > наб <nabijaczleweli@nabijaczleweli.xyz> wrote:
> > > > Issue 7, XCU, type, OPTIONS reads "None.",
> > > type is marked XSI.  dash does claim conformance with respect
> > > to XSI.
> > Which means it ought to abide by "None." in the OPTIONS sexion,
> > as out-lined in the subsequent lines, i.e. discard an initial --, yes.
> > Good to see we agree, I guess?
> Sorry, I meant that dash does not claim conformance.

If I can't convince you to apply this with the consistency argument of
"all built-ins that could, would parse their arguments with nextopt()",
then do consider the 2/2 that does the same for getopts,
which isn't shaded XSI and therefore must support this.

Best,
наб

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] exec: type: ignore first --, per POSIX
  2023-01-03 12:40       ` наб
@ 2023-01-04  2:10         ` Herbert Xu
  2023-01-04 11:33           ` [PATCH v2 1/2] options: getopts: " наб
  2023-01-04 11:35           ` [PATCH v2 2/2] exec: type: ignore first -- for consistency наб
  0 siblings, 2 replies; 11+ messages in thread
From: Herbert Xu @ 2023-01-04  2:10 UTC (permalink / raw)
  To: наб; +Cc: dash

On Tue, Jan 03, 2023 at 01:40:52PM +0100, наб wrote:
>
> If I can't convince you to apply this with the consistency argument of

If you can rephrase the patch description to not refer to
POSIX then I'm happy with your patch for type(1).

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/2] options: getopts: ignore first --, per POSIX
  2023-01-04  2:10         ` Herbert Xu
@ 2023-01-04 11:33           ` наб
  2023-01-08 12:06             ` Herbert Xu
  2023-01-04 11:35           ` [PATCH v2 2/2] exec: type: ignore first -- for consistency наб
  1 sibling, 1 reply; 11+ messages in thread
From: наб @ 2023-01-04 11:33 UTC (permalink / raw)
  To: Herbert Xu; +Cc: dash

[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]

Issue 7, XCU, getopts, OPTIONS reads "None.",
and getopts isn't a special built-in listed in sexion 2.14 ‒
this means that XCU, 1. Introduction, 1.4 Utility Description Defaults,
OPTIONS, Default Behavior applies:
  Default Behavior: When this section is listed as "None.", it means
  that the implementation need not support any options. Standard
  utilities that do not accept options, but that do accept operands,
  shall recognize "--" as a first argument to be discarded.

Test with: getopts -- d: a
Correct output is no output, exit 1
Wrong output errors out with d: being an invalid argument name
---
 src/options.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/options.c b/src/options.c
index a46c23b..337a8ee 100644
--- a/src/options.c
+++ b/src/options.c
@@ -409,6 +409,9 @@ getoptscmd(int argc, char **argv)
 {
 	char **optbase;
 
+	nextopt(nullstr);
+	argc -= argptr - argv - 1;
+	argv = argptr - 1;
 	if (argc < 3)
 		sh_error("Usage: getopts optstring var [arg]");
 	else if (argc == 3) {
-- 
2.30.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/2] exec: type: ignore first -- for consistency
  2023-01-04  2:10         ` Herbert Xu
  2023-01-04 11:33           ` [PATCH v2 1/2] options: getopts: " наб
@ 2023-01-04 11:35           ` наб
  1 sibling, 0 replies; 11+ messages in thread
From: наб @ 2023-01-04 11:35 UTC (permalink / raw)
  To: Herbert Xu; +Cc: dash

[-- Attachment #1: Type: text/plain, Size: 912 bytes --]

This appears to be the only remaining built-in that doesn't use
nextopt() to parse its arguments (and isn't forbidden from doing so) ‒
users expect to be able to do this, and it's nice to be consistent here.

Test with: type -- ls --
Correct output lists ls=/bin/ls, then --=ENOENT
Wrong output lists --=ENOENT, ls=/bin/ls, --=ENOENT

Fixes: https://bugs.debian.org/870317
---
 src/exec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/exec.c b/src/exec.c
index 87354d4..d61881d 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -760,11 +760,11 @@ unsetfunc(const char *name)
 int
 typecmd(int argc, char **argv)
 {
-	int i;
 	int err = 0;
 
-	for (i = 1; i < argc; i++) {
-		err |= describe_command(out1, argv[i], NULL, 1);
+	nextopt(nullstr);
+	while (*argptr) {
+		err |= describe_command(out1, *argptr++, NULL, 1);
 	}
 	return err;
 }
-- 
2.30.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/2] options: getopts: ignore first --, per POSIX
  2023-01-04 11:33           ` [PATCH v2 1/2] options: getopts: " наб
@ 2023-01-08 12:06             ` Herbert Xu
  0 siblings, 0 replies; 11+ messages in thread
From: Herbert Xu @ 2023-01-08 12:06 UTC (permalink / raw)
  To: наб; +Cc: dash

On Wed, Jan 04, 2023 at 12:33:45PM +0100, наб wrote:
> Issue 7, XCU, getopts, OPTIONS reads "None.",
> and getopts isn't a special built-in listed in sexion 2.14 ‒
> this means that XCU, 1. Introduction, 1.4 Utility Description Defaults,
> OPTIONS, Default Behavior applies:
>   Default Behavior: When this section is listed as "None.", it means
>   that the implementation need not support any options. Standard
>   utilities that do not accept options, but that do accept operands,
>   shall recognize "--" as a first argument to be discarded.
> 
> Test with: getopts -- d: a
> Correct output is no output, exit 1
> Wrong output errors out with d: being an invalid argument name
> ---
>  src/options.c | 3 +++
>  1 file changed, 3 insertions(+)

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-01-08 12:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 21:13 [PATCH 1/2] exec: type: ignore first --, per POSIX наб
2022-12-13 21:13 ` [PATCH 2/2] options: getopts: " наб
2023-01-02  9:19 ` [PATCH 1/2] exec: type: " Herbert Xu
2023-01-02 12:46   ` наб
2023-01-02 13:34     ` Harald van Dijk
2023-01-03  1:39     ` Herbert Xu
2023-01-03 12:40       ` наб
2023-01-04  2:10         ` Herbert Xu
2023-01-04 11:33           ` [PATCH v2 1/2] options: getopts: " наб
2023-01-08 12:06             ` Herbert Xu
2023-01-04 11:35           ` [PATCH v2 2/2] exec: type: ignore first -- for consistency наб

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).