Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 2 | /* |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 3 | * seq implementation for busybox |
| 4 | * |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 5 | * Copyright (C) 2004, Glenn McGrath |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 6 | * |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 7 | * Licensed under the GPL v2, see the file LICENSE in this tarball. |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include "busybox.h" |
| 13 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame^] | 14 | int seq_main(int argc, char **argv) |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 15 | { |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 16 | double last, first, increment, i; |
| 17 | |
| 18 | first = increment = 1; |
| 19 | switch (argc) { |
| 20 | case 4: |
| 21 | increment=atof(argv[2]); |
| 22 | case 3: |
| 23 | first=atof(argv[1]); |
| 24 | case 2: |
| 25 | last=atof(argv[argc -1]); |
| 26 | break; |
| 27 | default: |
| 28 | bb_show_usage(); |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 29 | } |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 30 | |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 31 | /* You should note that this is pos-5.0.91 semantics, -- FK. */ |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 32 | if (first < last ? increment > 0 : increment < 0) { |
| 33 | for (i = first; |
| 34 | (first < last) ? (i <= last) : (i >= last); |
| 35 | i += increment) |
| 36 | { |
| 37 | printf("%g\n", i); |
| 38 | } |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 41 | return EXIT_SUCCESS; |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 42 | } |