* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char copyright
[] =
"@(#) Copyright (c) 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)jot.c 8.1 (Berkeley) 6/6/93";
* jot - print sequential or random data
* Author: John Kunze, Office of Comp. Affairs, UCB
#define isdefault(s) (strcmp((s), "-") == 0)
void error
__P((char *, char *));
void getargs
__P((int, char *[]));
void getformat
__P((void));
int getprec
__P((char *));
void putdata
__P((double, long));
register double *x
= &xd
;
register double *y
= &yd
;
*x
= (ender
- begin
) * (ender
> begin
? 1 : -1);
for (*i
= 1; *i
<= reps
|| infinity
; (*i
)++) {
*y
= (double) random() / INT_MAX
;
putdata(*y
* *x
+ begin
, reps
- *i
);
for (*i
= 1, *x
= begin
; *i
<= reps
|| infinity
; (*i
)++, *x
+= s
)
register unsigned int mask
= 0;
while (--ac
&& **++av
== '-' && !isdefault(*av
))
error("Need context word after -w or -b", "");
strcpy(sepstring
, *av
+ 2);
error("Need string after -s", "");
strcpy(sepstring
, *++av
);
error("Need number after -p", "");
error("Bad precision value", "");
error("Unknown option %s", *av
);
switch (ac
) { /* examine args right to left, falling thru cases */
if (!sscanf(av
[3], "%lf", &s
))
error("Bad s value: %s", av
[3]);
if (!sscanf(av
[2], "%lf", &ender
))
ender
= av
[2][strlen(av
[2])-1];
if (!sscanf(av
[1], "%lf", &begin
))
begin
= av
[1][strlen(av
[1])-1];
if (n
> prec
) /* maximum precision */
if (!sscanf(av
[0], "%ld", &reps
))
error("Bad reps value: %s", av
[0]);
error("jot - print sequential or random data", "");
error("Too many arguments. What do you mean by %s?", av
[4]);
while (mask
) /* 4 bit mask has 1's where last 4 args were given */
switch (mask
) { /* fill in the 0's by default or computation */
reps
= (ender
- begin
+ s
) / s
;
error("Impossible stepsize", "");
s
= (randomize
? time(0) : STEP_DEF
);
error("Must specify begin if reps == 0", "");
begin
= ender
- reps
* s
+ s
;
s
= (randomize
? time(0) : STEP_DEF
);
ender
= begin
+ reps
* s
- s
;
error("Infinite sequences cannot be bounded",
s
= (ender
- begin
) / (reps
- 1);
case 017: /* if reps given and implied, */
if (!randomize
&& s
!= 0.0) {
long t
= (ender
- begin
+ s
) / s
;
error("Impossible stepsize", "");
if (t
< reps
) /* take lesser */
if (boring
) /* repeated word */
else if (dox
) /* scalar */
fputs(sepstring
, stdout
);
fprintf(stderr
, "jot: ");
"\nusage: jot [ options ] [ reps [ begin [ end [ s ] ] ] ]\n");
if (strncmp("jot - ", msg
, 6) == 0)
fprintf(stderr
, "Options:\n\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
"-b word repeated word\n",
"-w word context word\n",
"-s string data separator\n",
"-p precision number of characters\n");
if (boring
) /* no need to bother */
for (p
= format
; *p
; p
++) /* look for '%' */
if (*p
== '%' && *(p
+1) != '%') /* leave %% alone */
sprintf(p
, "%%.%df", prec
);
else if (!*p
&& chardata
) {
strcat(format
, "%"); /* cannot end in single '%' */
case 'f': case 'e': case 'g': case '%':
error("Cannot convert numeric data to strings", "");
/* case 'd': case 'o': case 'x': case 'D': case 'O': case 'X':