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 -0000      1.23
+++ jot.1       13 Aug 2021 06:50:42 -0000
@@ -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 -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:


Reply via email to