Re: fresh prompt after Ctrl-C in cdio(1)
Ingo Schwarze wrote: > Any user of this program with a sufficient knowledge of signal > handling is welcome to design, implement, and test signal handling > that remains active during other parts of the execution of the > cdio(1) program. The committed patch provides a starting point. Pepole with sufficient knowledge of signal handling are too rare for that to happen.
Re: fresh prompt after Ctrl-C in cdio(1)
Hi, Christian Weisgerber wrote on Thu, Aug 12, 2021 at 06:31:56PM +0200: > Ingo Schwarze: >> deraadt@ recently pointed out to me in private mail that it is good >> for usability if interactive programs providing line editing >> functionality are consistent what they do with Ctrl-C, ideally >> discard the current input line and provide a fresh prompt. >> >> So i propose to do the same in cdio(1), which currently just exits >> on Ctrl-C. >> >> OK? > That looks correct and works fine for me. ok naddy@ Committed for now, thanks for checking. > (I still have a USB CD drive and I use it from time to time to play > audio CDs with cdio. I had completely forgotten that cdio supports > editline, though. The cdio interactive mode is pretty useless since > interrupting a running command aborts the program.) Any user of this program with a sufficient knowledge of signal handling is welcome to design, implement, and test signal handling that remains active during other parts of the execution of the cdio(1) program. The committed patch provides a starting point. Yours, Ingo
Re: jot(1): make -b -c and -w mutually exclusive
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 - 1.51 > +++ jot.c 13 Aug 2021 06:50:42 - > @@ -86,6 +86,7 @@ main(int argc, char *argv[]) > int n = 0; > int ch; > const char *errstr; > + boolword; > > 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:
Re: jot(1): putdata de Morgan's rule
On Fri, Aug 13, 2021 at 09:10:57AM +0200, Martijn van Duren wrote: > Similar to tb's de Morgan's rule send last night. > > Shaves of 4 LoC of putdata and reads easier to me. Agreed. > regress passes > > OK? ok tb > > martijn@ > > 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 - 1.51 > +++ jot.c 13 Aug 2021 07:09:41 - > @@ -304,25 +304,21 @@ putdata(double x, bool last) > if (boring) > printf("%s", format); > else if (longdata && nosign) { > - if (x <= (double)ULONG_MAX && x >= 0.0) > - printf(format, (unsigned long)x); > - else > + if (x < 0.0 || x > (double)ULONG_MAX) > return 1; > + printf(format, (unsigned long)x); > } else if (longdata) { > - if (x <= (double)LONG_MAX && x >= (double)LONG_MIN) > - printf(format, (long)x); > - else > + if (x < (double)LONG_MIN || x > (double)LONG_MAX) > return 1; > + printf(format, (long)x); > } else if (chardata || (intdata && !nosign)) { > - if (x <= (double)INT_MAX && x >= (double)INT_MIN) > - printf(format, (int)x); > - else > + if (x < (double)INT_MIN || x > (double)INT_MAX) > return 1; > + printf(format, (int)x); > } else if (intdata) { > - if (x <= (double)UINT_MAX && x >= 0.0) > - printf(format, (unsigned int)x); > - else > + if (x < 0.0 || x > (double)UINT_MAX) > return 1; > + printf(format, (unsigned int)x); > } else > printf(format, x); > if (!last) > >
jot(1): putdata de Morgan's rule
Similar to tb's de Morgan's rule send last night. Shaves of 4 LoC of putdata and reads easier to me. regress passes OK? martijn@ 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 - 1.51 +++ jot.c 13 Aug 2021 07:09:41 - @@ -304,25 +304,21 @@ putdata(double x, bool last) if (boring) printf("%s", format); else if (longdata && nosign) { - if (x <= (double)ULONG_MAX && x >= 0.0) - printf(format, (unsigned long)x); - else + if (x < 0.0 || x > (double)ULONG_MAX) return 1; + printf(format, (unsigned long)x); } else if (longdata) { - if (x <= (double)LONG_MAX && x >= (double)LONG_MIN) - printf(format, (long)x); - else + if (x < (double)LONG_MIN || x > (double)LONG_MAX) return 1; + printf(format, (long)x); } else if (chardata || (intdata && !nosign)) { - if (x <= (double)INT_MAX && x >= (double)INT_MIN) - printf(format, (int)x); - else + if (x < (double)INT_MIN || x > (double)INT_MAX) return 1; + printf(format, (int)x); } else if (intdata) { - if (x <= (double)UINT_MAX && x >= 0.0) - printf(format, (unsigned int)x); - else + if (x < 0.0 || x > (double)UINT_MAX) return 1; + printf(format, (unsigned int)x); } else printf(format, x); if (!last)
Re: jot(1): rename 's' to 'step'
On Fri, Aug 13, 2021 at 08:58:42AM +0200, Martijn van Duren wrote: > Historically 's' presumably stood both for step and seed, but since we > don't support seed anymore I think it's wise to make things a little > more readable and just rename 's' to 'step'. > > tb@ already agrees with the concept. > > OK? Yes, please! It also makes matching the manual to the code easier. ok tb > > martijn@ > > Index: jot.1 > === > RCS file: /cvs/src/usr.bin/jot/jot.1,v > retrieving revision 1.23 > diff -u -p -r1.23 jot.1 > --- jot.1 12 Aug 2016 21:49:31 - 1.23 > +++ jot.1 13 Aug 2021 06:57:56 - > @@ -45,7 +45,7 @@ > .Op Fl s Ar string > .Op Fl w Ar word > .Oo Ar reps Oo Ar begin Oo Ar end > -.Oo Ar s Oc Oc Oc Oc > +.Oo Ar step Oc Oc Oc Oc > .Ek > .Sh DESCRIPTION > .Nm > @@ -115,7 +115,7 @@ The default values for > .Ar begin , > .Ar end , > and > -.Ar s > +.Ar step > are 100, 1, 100, and 1, respectively. > Omitted values are computed if possible or assume the default. > A special case arises if only > @@ -128,7 +128,7 @@ if > is greater than > .Ar end > then > -.Ar s > +.Ar step > is set to \(mi1, otherwise it is set to 1; > afterwards > .Ar reps > @@ -149,7 +149,7 @@ Random numbers are obtained through > Historical versions of > .Nm > used > -.Ar s > +.Ar step > to seed the random number generator. > This is no longer supported. > The name > >
jot(1): rename 's' to 'step'
Historically 's' presumably stood both for step and seed, but since we don't support seed anymore I think it's wise to make things a little more readable and just rename 's' to 'step'. tb@ already agrees with the concept. OK? martijn@ Index: jot.1 === RCS file: /cvs/src/usr.bin/jot/jot.1,v retrieving revision 1.23 diff -u -p -r1.23 jot.1 --- jot.1 12 Aug 2016 21:49:31 - 1.23 +++ jot.1 13 Aug 2021 06:57:56 - @@ -45,7 +45,7 @@ .Op Fl s Ar string .Op Fl w Ar word .Oo Ar reps Oo Ar begin Oo Ar end -.Oo Ar s Oc Oc Oc Oc +.Oo Ar step Oc Oc Oc Oc .Ek .Sh DESCRIPTION .Nm @@ -115,7 +115,7 @@ The default values for .Ar begin , .Ar end , and -.Ar s +.Ar step are 100, 1, 100, and 1, respectively. Omitted values are computed if possible or assume the default. A special case arises if only @@ -128,7 +128,7 @@ if is greater than .Ar end then -.Ar s +.Ar step is set to \(mi1, otherwise it is set to 1; afterwards .Ar reps @@ -149,7 +149,7 @@ Random numbers are obtained through Historical versions of .Nm used -.Ar s +.Ar step to seed the random number generator. This is no longer supported. The name
jot(1): make -b -c and -w mutually exclusive
Looking at tb's diff I fell in the trap of looking at other parts of the code. Now he's conning me into writing diffs... 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 - -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 - -b always overwrites -c. 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, ... Regress seems to pass. OK? martijn@ Index: jot.1 === RCS file: /cvs/src/usr.bin/jot/jot.1,v retrieving revision 1.23 diff -u -p -r1.23 jot.1 --- jot.1 12 Aug 2016 21:49:31 - 1.23 +++ jot.1 13 Aug 2021 06:50:42 - @@ -101,6 +101,15 @@ conversion specification inside in which case the data is inserted rather than appended. .El .Pp +It is not an error to specify more than one of +the mutually exclusive options +.Fl b , +.Fl c +and +.Fl w . +Where more than one of these options is specified, +the last option given overrides the others. +.Pp The last four arguments specify the length of the output sequence, its start and end points, and the step size. Any three of these arguments determine the fourth. 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 - 1.51 +++ jot.c 13 Aug 2021 06:50:42 - @@ -86,6 +86,7 @@ main(int argc, char *argv[]) int n = 0; int ch; const char *errstr; + boolword; 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: