Deleted Added
full compact
jot.c (77276) jot.c (77287)
1/*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)jot.c 8.1 (Berkeley) 6/6/93";
43#endif
44static const char rcsid[] =
1/*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)jot.c 8.1 (Berkeley) 6/6/93";
43#endif
44static const char rcsid[] =
45 "$FreeBSD: head/usr.bin/jot/jot.c 77276 2001-05-27 21:08:19Z dd $";
45 "$FreeBSD: head/usr.bin/jot/jot.c 77287 2001-05-28 00:55:50Z dd $";
46#endif /* not lint */
47
48/*
49 * jot - print sequential or random data
50 *
51 * Author: John Kunze, Office of Comp. Affairs, UCB
52 */
53

--- 21 unchanged lines hidden (view full) ---

75int infinity;
76int boring;
77int prec;
78int longdata;
79int intdata;
80int chardata;
81int nosign;
82int nofinalnl;
46#endif /* not lint */
47
48/*
49 * jot - print sequential or random data
50 *
51 * Author: John Kunze, Office of Comp. Affairs, UCB
52 */
53

--- 21 unchanged lines hidden (view full) ---

75int infinity;
76int boring;
77int prec;
78int longdata;
79int intdata;
80int chardata;
81int nosign;
82int nofinalnl;
83char *sepstring = "\n";
83const char *sepstring = "\n";
84char format[BUFSIZ];
85
84char format[BUFSIZ];
85
86int main __P((int, char *[]));
86void getformat __P((void));
87int getprec __P((char *));
88int putdata __P((double, long));
89static void usage __P((void));
90
91int
92main(argc, argv)
93 int argc;

--- 177 unchanged lines hidden (view full) ---

271 default:
272 errx(1, "bad mask");
273 }
274 if (reps == 0)
275 infinity = 1;
276 if (randomize) {
277 *x = (ender - begin) * (ender > begin ? 1 : -1);
278 for (*i = 1; *i <= reps || infinity; (*i)++) {
87void getformat __P((void));
88int getprec __P((char *));
89int putdata __P((double, long));
90static void usage __P((void));
91
92int
93main(argc, argv)
94 int argc;

--- 177 unchanged lines hidden (view full) ---

272 default:
273 errx(1, "bad mask");
274 }
275 if (reps == 0)
276 infinity = 1;
277 if (randomize) {
278 *x = (ender - begin) * (ender > begin ? 1 : -1);
279 for (*i = 1; *i <= reps || infinity; (*i)++) {
279 *y = (double) arc4random() / ULONG_MAX;
280 *y = arc4random() / ULONG_MAX;
280 if (putdata(*y * *x + begin, reps - *i))
281 errx(1, "range error in conversion");
282 }
283 } else
284 for (*i = 1, *x = begin; *i <= reps || infinity; (*i)++, *x += s)
285 if (putdata(*x, reps - *i))
286 errx(1, "range error in conversion");
287 if (!nofinalnl)

--- 43 unchanged lines hidden (view full) ---

331{
332 fprintf(stderr, "%s\n%s\n",
333 "usage: jot [-cnr] [-b word] [-w word] [-s string] [-p precision]",
334 " [reps [begin [end [s]]]]");
335 exit(1);
336}
337
338int
281 if (putdata(*y * *x + begin, reps - *i))
282 errx(1, "range error in conversion");
283 }
284 } else
285 for (*i = 1, *x = begin; *i <= reps || infinity; (*i)++, *x += s)
286 if (putdata(*x, reps - *i))
287 errx(1, "range error in conversion");
288 if (!nofinalnl)

--- 43 unchanged lines hidden (view full) ---

332{
333 fprintf(stderr, "%s\n%s\n",
334 "usage: jot [-cnr] [-b word] [-w word] [-s string] [-p precision]",
335 " [reps [begin [end [s]]]]");
336 exit(1);
337}
338
339int
339getprec(s)
340 char *s;
340getprec(str)
341 char *str;
341{
342 char *p;
343 char *q;
344
342{
343 char *p;
344 char *q;
345
345 for (p = s; *p; p++)
346 for (p = str; *p; p++)
346 if (*p == '.')
347 break;
348 if (!*p)
349 return (0);
350 for (q = ++p; *p; p++)
351 if (!isdigit(*p))
352 break;
353 return (p - q);
354}
355
356void
357getformat()
358{
347 if (*p == '.')
348 break;
349 if (!*p)
350 return (0);
351 for (q = ++p; *p; p++)
352 if (!isdigit(*p))
353 break;
354 return (p - q);
355}
356
357void
358getformat()
359{
359 char *p;
360 char *p, *p2;
360 int dot, hash, space, sign, numbers = 0;
361 size_t sz;
361 int dot, hash, space, sign, numbers = 0;
362 size_t sz;
362 char *s;
363
364 if (boring) /* no need to bother */
365 return;
366 for (p = format; *p; p++) /* look for '%' */
367 if (*p == '%' && *(p+1) != '%') /* leave %% alone */
368 break;
369 sz = sizeof(format) - strlen(format) - 1;
370 if (!*p && !chardata) {

--- 8 unchanged lines hidden (view full) ---

379 errx(1, "-w word too long");
380 strcat(format, "%"); /* cannot end in single '%' */
381 } else {
382 /*
383 * Allow conversion format specifiers of the form
384 * %[#][ ][{+,-}][0-9]*[.[0-9]*]? where ? must be one of
385 * [l]{d,i,o,u,x} or {f,e,g,E,G,d,o,x,D,O,U,X,c,u}
386 */
363
364 if (boring) /* no need to bother */
365 return;
366 for (p = format; *p; p++) /* look for '%' */
367 if (*p == '%' && *(p+1) != '%') /* leave %% alone */
368 break;
369 sz = sizeof(format) - strlen(format) - 1;
370 if (!*p && !chardata) {

--- 8 unchanged lines hidden (view full) ---

379 errx(1, "-w word too long");
380 strcat(format, "%"); /* cannot end in single '%' */
381 } else {
382 /*
383 * Allow conversion format specifiers of the form
384 * %[#][ ][{+,-}][0-9]*[.[0-9]*]? where ? must be one of
385 * [l]{d,i,o,u,x} or {f,e,g,E,G,d,o,x,D,O,U,X,c,u}
386 */
387 s = p++;
387 p2 = p++;
388 dot = hash = space = sign = numbers = 0;
389 while (!isalpha(*p)) {
390 if (isdigit(*p)) {
391 numbers++;
392 p++;
393 } else if ((*p == '#' && !(numbers|dot|sign|space|
394 hash++)) ||
395 (*p == ' ' && !(numbers|dot|space++)) ||

--- 38 unchanged lines hidden (view full) ---

434 goto fmt_broken;
435 case 'f': case 'e': case 'g': case 'E': case 'G':
436 if (!longdata)
437 break;
438 /* FALLTHROUGH */
439 default:
440fmt_broken:
441 *++p = '\0';
388 dot = hash = space = sign = numbers = 0;
389 while (!isalpha(*p)) {
390 if (isdigit(*p)) {
391 numbers++;
392 p++;
393 } else if ((*p == '#' && !(numbers|dot|sign|space|
394 hash++)) ||
395 (*p == ' ' && !(numbers|dot|space++)) ||

--- 38 unchanged lines hidden (view full) ---

434 goto fmt_broken;
435 case 'f': case 'e': case 'g': case 'E': case 'G':
436 if (!longdata)
437 break;
438 /* FALLTHROUGH */
439 default:
440fmt_broken:
441 *++p = '\0';
442 errx(1, "illegal or unsupported format '%s'", s);
442 errx(1, "illegal or unsupported format '%s'", p2);
443 /* NOTREACHED */
444 }
445 while (*++p)
446 if (*p == '%' && *(p+1) && *(p+1) != '%')
447 errx(1, "too many conversions");
448 else if (*p == '%' && *(p+1) == '%')
449 p++;
450 else if (*p == '%' && !*(p+1)) {
451 strcat(format, "%");
452 break;
453 }
454 }
455}
443 /* NOTREACHED */
444 }
445 while (*++p)
446 if (*p == '%' && *(p+1) && *(p+1) != '%')
447 errx(1, "too many conversions");
448 else if (*p == '%' && *(p+1) == '%')
449 p++;
450 else if (*p == '%' && !*(p+1)) {
451 strcat(format, "%");
452 break;
453 }
454 }
455}