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 | * |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include "busybox.h" |
| 22 | |
| 23 | extern int seq_main(int argc, char **argv) |
| 24 | { |
| 25 | double last; |
| 26 | double first = 1; |
| 27 | double increment = 1; |
| 28 | double i; |
| 29 | |
| 30 | if (argc == 4) { |
| 31 | first = atof(argv[1]); |
| 32 | increment = atof(argv[2]); |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 33 | } else if (argc == 3) { |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 34 | first = atof(argv[1]); |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 35 | } else if (argc != 2) { |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 36 | bb_show_usage(); |
| 37 | } |
| 38 | last = atof(argv[argc - 1]); |
| 39 | |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 40 | /* You should note that this is pos-5.0.91 semantics, -- FK. */ |
| 41 | if ((first > last) && (increment > 0)) { |
| 42 | return EXIT_SUCCESS; |
| 43 | } |
| 44 | |
| 45 | for (i = first; ((first <= last) ? (i <= last) : (i >= last)); |
| 46 | i += increment) { |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 47 | printf("%g\n", i); |
| 48 | } |
| 49 | |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 50 | return EXIT_SUCCESS; |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 51 | } |