new seq from plan 9 (Anthony Martin)
This commit is contained in:
parent
729e53b9e5
commit
470dce9dee
1 changed files with 21 additions and 11 deletions
|
|
@ -18,19 +18,19 @@ usage(void)
|
||||||
void
|
void
|
||||||
buildfmt(void)
|
buildfmt(void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
char *dp;
|
char *dp;
|
||||||
int w, p, maxw, maxp;
|
int w, p, maxw, maxp;
|
||||||
static char fmt[16];
|
static char fmt[16];
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
double val;
|
||||||
|
|
||||||
format = "%g\n";
|
format = "%g\n";
|
||||||
if(!constant)
|
if(!constant)
|
||||||
return;
|
return;
|
||||||
maxw = 0;
|
maxw = 0;
|
||||||
maxp = 0;
|
maxp = 0;
|
||||||
for(i=0; i<=nsteps; i++){
|
for(val = min; val <= max; val += incr){
|
||||||
sprint(buf, "%g", min+i*incr);
|
sprint(buf, "%g", val);
|
||||||
if(strchr(buf, 'e')!=0)
|
if(strchr(buf, 'e')!=0)
|
||||||
return;
|
return;
|
||||||
dp = strchr(buf,'.');
|
dp = strchr(buf,'.');
|
||||||
|
|
@ -49,8 +49,9 @@ buildfmt(void)
|
||||||
|
|
||||||
void
|
void
|
||||||
main(int argc, char *argv[]){
|
main(int argc, char *argv[]){
|
||||||
int i, j, n;
|
int j, n;
|
||||||
char buf[256], ffmt[4096];
|
char buf[256], ffmt[4096];
|
||||||
|
double val;
|
||||||
|
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'w':
|
case 'w':
|
||||||
|
|
@ -78,15 +79,24 @@ main(int argc, char *argv[]){
|
||||||
fprint(2, "seq: zero increment\n");
|
fprint(2, "seq: zero increment\n");
|
||||||
exits("zero increment");
|
exits("zero increment");
|
||||||
}
|
}
|
||||||
nsteps = (max-min)/incr+.5;
|
|
||||||
if(!format)
|
if(!format)
|
||||||
buildfmt();
|
buildfmt();
|
||||||
for(i=0; i<=nsteps; i++){
|
if(incr > 0){
|
||||||
n = sprint(buf, format, min+i*incr);
|
for(val = min; val <= max; val += incr){
|
||||||
if(constant)
|
n = sprint(buf, format, val);
|
||||||
for(j=0; buf[j]==' '; j++)
|
if(constant)
|
||||||
buf[j] ='0';
|
for(j=0; buf[j]==' '; j++)
|
||||||
write(1, buf, n);
|
buf[j] ='0';
|
||||||
|
write(1, buf, n);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
for(val = min; val >= max; val += incr){
|
||||||
|
n = sprint(buf, format, val);
|
||||||
|
if(constant)
|
||||||
|
for(j=0; buf[j]==' '; j++)
|
||||||
|
buf[j] ='0';
|
||||||
|
write(1, buf, n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exits(0);
|
exits(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue