Hi Martijn,
Martijn van Duren wrote on Fri, Aug 13, 2021 at 08:51:42AM +0200:
> So here's the first one:
> - When -b is set, but followed by -w it doesn't remove the boring flag
> and the -w is interpreted as a -b string
I agree that can't be quite right.
> - -c is defined as "This is an abbreviation for -w %c.", but adding a
> -w option itself results in:
> $ jot -cw"bla " 5 97
> bla a
> bla b
> bla c
> bla d
> bla e
>
> instead of
>
> $ jot -w"bla " 5 97
> bla 97
> bla 98
> bla 99
> bla 100
> bla 101
I agree that cannot be right either.
It was even listed in my personal BUGS.txt file for the utility.
> - -b always overwrites -c.
That isnt necessarily wrong, ...
> tb already agrees that these options should be mutually exlusive, so
> here's the accompanying code. I choose to go for the last option wins
> appraoch, similar to ls, df, du, ...
... but i agree "mutually exclusive, overriding" is potentially
more useful.
In this case, even though this is not a POSIX command, POSIX utility
convention 12.2.11 is pertinent:
The order of different options relative to one another should not
matter, unless the options are documented as mutually-exclusive
and such an option is documented to override any incompatible
options preceding it. If an option that has option-arguments is
repeated, the option and option-argument combinations should be
interpreted in the order specified on the command line.
In its current state, the program violates that. With your patch,
it conforms.
> Regress seems to pass.
>
> OK?
OK schwarze@.
Consider putting the declaration of "bool word" alongside the other
"static bool" in file scope. I admit this one is only used in main,
but so are finalnl, infinity, and randomize, and physicists like
symmetry.
I would prefer to keep the documentation of overriding together
with each option, making it harder to overlook and even reducing
the total amount of text.
That is, append
* "Overrides earlier -b, -c, and -w." to the -b and -w list entries
* "Overrides earlier -b and -w." to the -c list entry.
OK either way, though.
Yours,
Ingo
> Index: jot.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/jot/jot.c,v
> retrieving revision 1.51
> diff -u -p -r1.51 jot.c
> --- jot.c 30 Jul 2021 02:47:37 -0000 1.51
> +++ jot.c 13 Aug 2021 06:50:42 -0000
> @@ -86,6 +86,7 @@ main(int argc, char *argv[])
> int n = 0;
> int ch;
> const char *errstr;
> + bool word;
>
> if (pledge("stdio", NULL) == -1)
> err(1, "pledge");
> @@ -94,10 +95,13 @@ main(int argc, char *argv[])
> switch (ch) {
> case 'b':
> boring = true;
> + chardata = word = false;
> format = optarg;
> break;
> case 'c':
> chardata = true;
> + boring = word = false;
> + format = "";
> break;
> case 'n':
> finalnl = false;
> @@ -115,6 +119,8 @@ main(int argc, char *argv[])
> sepstring = optarg;
> break;
> case 'w':
> + word = true;
> + boring = chardata = false;
> format = optarg;
> break;
> default: