about summary refs log tree commit diff
path: root/src/usr.bin/jot
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-10-14 17:34:52 +0200
committerLeah Neukirchen <leah@vuxu.org>2021-10-14 17:34:52 +0200
commitad03f8de9c5b50f4877e3a0c2ed8ac3e13ac0059 (patch)
treef9942320bdc02998e30af2f48d0f1db1a2220961 /src/usr.bin/jot
parentdf04b70be3237e61d568e1b416e8cf9efe2abfb3 (diff)
downloadoutils-ad03f8de9c5b50f4877e3a0c2ed8ac3e13ac0059.tar.gz
outils-ad03f8de9c5b50f4877e3a0c2ed8ac3e13ac0059.tar.xz
outils-ad03f8de9c5b50f4877e3a0c2ed8ac3e13ac0059.zip
cvs update v0.10
Diffstat (limited to 'src/usr.bin/jot')
-rw-r--r--src/usr.bin/jot/jot.126
-rw-r--r--src/usr.bin/jot/jot.c59
2 files changed, 49 insertions, 36 deletions
diff --git a/src/usr.bin/jot/jot.1 b/src/usr.bin/jot/jot.1
index c82553e..69c7c64 100644
--- a/src/usr.bin/jot/jot.1
+++ b/src/usr.bin/jot/jot.1
@@ -1,4 +1,4 @@
-.\"	$OpenBSD: jot.1,v 1.23 2016/08/12 21:49:31 tb Exp $
+.\"	$OpenBSD: jot.1,v 1.25 2021/08/13 11:27:33 martijn Exp $
 .\"	$NetBSD: jot.1,v 1.2 1994/11/14 20:27:36 jtc Exp $
 .\"
 .\" Copyright (c) 1993
@@ -30,7 +30,7 @@
 .\"
 .\"	@(#)jot.1	8.1 (Berkeley) 6/6/93
 .\"
-.Dd $Mdocdate: August 12 2016 $
+.Dd $Mdocdate: August 13 2021 $
 .Dt JOT 1
 .Os
 .Sh NAME
@@ -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
@@ -58,9 +58,18 @@ The options are as follows:
 Just print
 .Ar word
 repetitively.
+Overrides earlier
+.Fl b ,
+.Fl c ,
+and
+.Fl w .
 .It Fl c
 This is an abbreviation for
 .Fl w Ic %c .
+Overrides earlier
+.Fl b
+and
+.Fl w .
 .It Fl n
 Do not print the final newline normally appended to the output.
 .It Fl p Ar precision
@@ -99,6 +108,11 @@ are possible by using the appropriate
 conversion specification inside
 .Ar word ,
 in which case the data is inserted rather than appended.
+Overrides earlier
+.Fl b ,
+.Fl c ,
+and
+.Fl w .
 .El
 .Pp
 The last four arguments specify the length of the output sequence,
@@ -115,7 +129,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 +142,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 +163,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
diff --git a/src/usr.bin/jot/jot.c b/src/usr.bin/jot/jot.c
index b2e4a05..a0b3de8 100644
--- a/src/usr.bin/jot/jot.c
+++ b/src/usr.bin/jot/jot.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: jot.c,v 1.49 2019/06/27 18:03:36 deraadt Exp $	*/
+/*	$OpenBSD: jot.c,v 1.56 2021/08/13 12:37:28 jmc Exp $	*/
 /*	$NetBSD: jot.c,v 1.3 1994/12/02 20:29:43 pk Exp $	*/
 
 /*-
@@ -70,6 +70,7 @@ static bool	intdata;
 static bool	longdata;
 static bool	nosign;
 static bool	randomize;
+static bool	word;
 
 static void	getformat(void);
 static int	getprec(char *);
@@ -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:
@@ -160,8 +166,6 @@ main(int argc, char *argv[])
 			mask |= REPS;
 			if (reps == 0)
 				infinity = true;
-			if (prec == -1)
-				prec = 0;
 		}
 	case 0:
 		if (prec == -1)
@@ -246,7 +250,7 @@ main(int argc, char *argv[])
 			if (putdata(x, reps == i && !infinity))
 				errx(1, "range error in conversion: %f", x);
 	} else { /* Random output: use defaults for omitted values. */
-		bool		use_unif;
+		bool		use_unif = 0;
 		uint32_t	pow10 = 1;
 		uint32_t	uintx = 0; /* Initialized to make gcc happy. */
 
@@ -260,21 +264,20 @@ main(int argc, char *argv[])
 		}
 		x = ender - begin;
 
-		if (prec == 0 && (fmod(ender, 1) != 0 || fmod(begin, 1) != 0))
-			use_unif = 0;
-		else {
+		if (prec > 0 || (fmod(ender, 1) == 0 && fmod(begin, 1) == 0)) {
+			double range;
+
 			while (prec-- > 0)
 				pow10 *= 10;
-			/*
-			 * If pow10 * (ender - begin) is an integer, use
-			 * arc4random_uniform().
-			 */
-			use_unif = fmod(pow10 * (ender - begin), 1) == 0;
-			if (use_unif) {
-				uintx = pow10 * (ender - begin);
-				if (uintx >= UINT32_MAX)
+
+			range = pow10 * (ender - begin);
+
+			/* If range is an integer, use arc4random_uniform(). */
+			if (fmod(range, 1) == 0) {
+				if (range >= UINT32_MAX)
 					errx(1, "requested range too large");
-				uintx++;
+				use_unif = 1;
+				uintx = range + 1;
 			}
 		}
 
@@ -305,25 +308,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)
@@ -337,7 +336,7 @@ usage(void)
 {
 	(void)fprintf(stderr, "usage: jot [-cnr] [-b word] [-p precision] "
 	    "[-s string] [-w word]\n"
-	    "	   [reps [begin [end [s]]]]\n");
+	    "	   [reps [begin [end [step]]]]\n");
 	exit(1);
 }
 
@@ -444,7 +443,7 @@ fmt_broken:
 
 		while ((p = strchr(p, '%')) != NULL && p[1] == '%')
 			p += 2;
-		
+
 		if (p != NULL) {
 			if (p[1] != '\0')
 				errx(1, "too many conversions");