| tnew seq from plan 9 (Anthony Martin) - plan9port - [fork] Plan 9 from user spa… | |
| git clone git://src.adamsgaard.dk/plan9port | |
| Log | |
| Files | |
| Refs | |
| README | |
| LICENSE | |
| --- | |
| commit 470dce9dee60ad1c38721a8ad24247c2fd59191f | |
| parent 729e53b9e55756f1b0475195489cf7309a2b80ac | |
| Author: rsc <devnull@localhost> | |
| Date: Thu, 12 Oct 2006 01:42:11 +0000 | |
| new seq from plan 9 (Anthony Martin) | |
| Diffstat: | |
| M src/cmd/seq.c | 32 ++++++++++++++++++++---------… | |
| 1 file changed, 21 insertions(+), 11 deletions(-) | |
| --- | |
| diff --git a/src/cmd/seq.c b/src/cmd/seq.c | |
| t@@ -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,'.'); | |
| t@@ -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': | |
| t@@ -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); | |
| } |