Re: getopt.3 bugs section

2021-01-09 Thread edgar
On Jan 9, 2021 7:07 AM, Christian Weisgerber  wrote:

  Edgar Pettijohn:

  > In the BUGS section for the getopt(3) manual it mentions not using
  > single digits for options. I know spamd uses -4 and -6 there are
  > probably others. Should they be changed? Or is the manual mistaken?

  You misunderstand.  The manual warns against the use of digits to
  pass numerical arguments.  This usage exists in some historical
  cases, e.g. "nice -10" where <10> is the number 10.

  The use of digits as flags characters, like -4 or -6 to indicate
  IPv4 or IPv6, is perfectly fine.

  --
  Christian "naddy" Weisgerber 
  na...@mips.inka.de

Makes sense. I think it would have been clearer if it just had an example
of what not to do instead of how to do the wrong thing right.
Thanks,
Edgar 


Re: getopt.3 bugs section

2021-01-09 Thread Joerg Sonnenberger
On Sat, Jan 09, 2021 at 02:07:32PM +0100, Christian Weisgerber wrote:
> Edgar Pettijohn:
> 
> > In the BUGS section for the getopt(3) manual it mentions not using
> > single digits for options. I know spamd uses -4 and -6 there are
> > probably others. Should they be changed? Or is the manual mistaken?
> 
> You misunderstand.  The manual warns against the use of digits to
> pass numerical arguments.  This usage exists in some historical
> cases, e.g. "nice -10" where <10> is the number 10.
> 
> The use of digits as flags characters, like -4 or -6 to indicate
> IPv4 or IPv6, is perfectly fine.

If you want to change this, it seems best to point to existing good and
bad examples.

Good:
- using digits as flags, e.g. for IPv4 vs IPv6 support

Bad:
- using digits as numbers, e.g. nice(1), tail(1) historic use.

Recommendation to avoid bad use: -n 

Joerg



Re: getopt.3 bugs section

2021-01-09 Thread Jeremie Courreges-Anglas
On Sat, Jan 09 2021, Christian Weisgerber  wrote:
> Edgar Pettijohn:
>
>> In the BUGS section for the getopt(3) manual it mentions not using
>> single digits for options. I know spamd uses -4 and -6 there are
>> probably others. Should they be changed? Or is the manual mistaken?
>
> You misunderstand.  The manual warns against the use of digits to
> pass numerical arguments.  This usage exists in some historical
> cases, e.g. "nice -10" where <10> is the number 10.

IMO giving a *number* as an example would make things clearer.

Index: getopt.3
===
RCS file: /d/cvs/src/lib/libc/stdlib/getopt.3,v
retrieving revision 1.46
diff -u -p -p -u -r1.46 getopt.3
--- getopt.34 Jan 2016 19:43:13 -   1.46
+++ getopt.39 Jan 2021 13:39:06 -
@@ -326,7 +326,7 @@ It is possible to handle digits as optio
 This allows
 .Fn getopt
 to be used with programs that expect a number
-.Pq Dq Li \-3
+.Pq Dq Li \-389
 as an option.
 This practice is wrong, and should not be used in any current development.
 It is provided for backward compatibility


Other ideas for improvement:
- give a real life example

Index: getopt.3
===
RCS file: /d/cvs/src/lib/libc/stdlib/getopt.3,v
retrieving revision 1.46
diff -u -p -p -u -r1.46 getopt.3
--- getopt.34 Jan 2016 19:43:13 -   1.46
+++ getopt.39 Jan 2021 13:44:29 -
@@ -326,7 +326,7 @@ It is possible to handle digits as optio
 This allows
 .Fn getopt
 to be used with programs that expect a number
-.Pq Dq Li \-3
+.Pq Dq Li nice \-10 program
 as an option.
 This practice is wrong, and should not be used in any current development.
 It is provided for backward compatibility

- move this warning to CAVEATS, since it's not a bug

Index: getopt.3
===
RCS file: /d/cvs/src/lib/libc/stdlib/getopt.3,v
retrieving revision 1.46
diff -u -p -p -u -r1.46 getopt.3
--- getopt.34 Jan 2016 19:43:13 -   1.46
+++ getopt.39 Jan 2021 13:47:08 -
@@ -309,24 +309,12 @@ The
 .Fn getopt
 function appeared in
 .Bx 4.3 .
-.Sh BUGS
-The
-.Fn getopt
-function was once specified to return
-.Dv EOF
-instead of \-1.
-This was changed by
-.St -p1003.2-92
-to decouple
-.Fn getopt
-from
-.In stdio.h .
-.Pp
+.Sh CAVEATS
 It is possible to handle digits as option letters.
 This allows
 .Fn getopt
 to be used with programs that expect a number
-.Pq Dq Li \-3
+.Pq Dq Li nice \-10 program
 as an option.
 This practice is wrong, and should not be used in any current development.
 It is provided for backward compatibility
@@ -361,3 +349,15 @@ while ((ch = getopt(argc, argv, "0123456
prevoptind = optind;
 }
 .Ed
+.Sh BUGS
+The
+.Fn getopt
+function was once specified to return
+.Dv EOF
+instead of \-1.
+This was changed by
+.St -p1003.2-92
+to decouple
+.Fn getopt
+from
+.In stdio.h .


Would the mention of EOF vs -1 fit better in HISTORY or CAVEATS too?

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: getopt.3 bugs section

2021-01-09 Thread Christian Weisgerber
Edgar Pettijohn:

> In the BUGS section for the getopt(3) manual it mentions not using
> single digits for options. I know spamd uses -4 and -6 there are
> probably others. Should they be changed? Or is the manual mistaken?

You misunderstand.  The manual warns against the use of digits to
pass numerical arguments.  This usage exists in some historical
cases, e.g. "nice -10" where <10> is the number 10.

The use of digits as flags characters, like -4 or -6 to indicate
IPv4 or IPv6, is perfectly fine.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: getopt.3 bugs section

2021-01-08 Thread William Ahern
On Fri, Jan 08, 2021 at 05:29:31PM -0600, Edgar Pettijohn wrote:
> In the BUGS section for the getopt(3) manual it mentions not using
> single digits for options. I know spamd uses -4 and -6 there are
> probably others. Should they be changed? Or is the manual mistaken?
> 

That section seems ambiguous (especially in light of your post) on whether
using digits is wrong, or abusing digit support for multi-digit number
option support is wrong. But I think the intention is the latter.

FWIW, POSIX explicitly permits digits:

  Guideline 3:
Each option name should be a single alphanumeric character (the alnum
character classification) from the portable character set. The -W
(capital-W) option shall be reserved for vendor options.

Multi-digit options should not be allowed.

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02

Guideline 3 applies to getopt(3) because,

  The getopt() function... shall follow Utility Syntax Guidelines 3, 4, 5,
  6, 7, 9, and 10 in XBD Utility Syntax Guidelines.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html



getopt.3 bugs section

2021-01-08 Thread Edgar Pettijohn
In the BUGS section for the getopt(3) manual it mentions not using
single digits for options. I know spamd uses -4 and -6 there are
probably others. Should they be changed? Or is the manual mistaken?

Edgar