aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/seq.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-10-12 01:42:11 +0000
committerrsc <devnull@localhost>2006-10-12 01:42:11 +0000
commit470dce9dee60ad1c38721a8ad24247c2fd59191f (patch)
treeb7b26bab7e04d23e8d7569ca9d820c110706c70e /src/cmd/seq.c
parent729e53b9e55756f1b0475195489cf7309a2b80ac (diff)
downloadplan9port-470dce9dee60ad1c38721a8ad24247c2fd59191f.tar.gz
plan9port-470dce9dee60ad1c38721a8ad24247c2fd59191f.tar.bz2
plan9port-470dce9dee60ad1c38721a8ad24247c2fd59191f.zip
new seq from plan 9 (Anthony Martin)
Diffstat (limited to 'src/cmd/seq.c')
-rw-r--r--src/cmd/seq.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/cmd/seq.c b/src/cmd/seq.c
index 062bb8a4..9fde9ef5 100644
--- a/src/cmd/seq.c
+++ b/src/cmd/seq.c
@@ -18,19 +18,19 @@ usage(void)
void
buildfmt(void)
{
- int i;
char *dp;
int w, p, maxw, maxp;
static char fmt[16];
char buf[32];
+ double val;
format = "%g\n";
if(!constant)
return;
maxw = 0;
maxp = 0;
- for(i=0; i<=nsteps; i++){
- sprint(buf, "%g", min+i*incr);
+ for(val = min; val <= max; val += incr){
+ sprint(buf, "%g", val);
if(strchr(buf, 'e')!=0)
return;
dp = strchr(buf,'.');
@@ -49,8 +49,9 @@ buildfmt(void)
void
main(int argc, char *argv[]){
- int i, j, n;
+ int j, n;
char buf[256], ffmt[4096];
+ double val;
ARGBEGIN{
case 'w':
@@ -78,15 +79,24 @@ main(int argc, char *argv[]){
fprint(2, "seq: zero increment\n");
exits("zero increment");
}
- nsteps = (max-min)/incr+.5;
if(!format)
buildfmt();
- for(i=0; i<=nsteps; i++){
- n = sprint(buf, format, min+i*incr);
- if(constant)
- for(j=0; buf[j]==' '; j++)
- buf[j] ='0';
- write(1, buf, n);
+ if(incr > 0){
+ 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);
+ }
+ }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);
}