8006be83dc5227481906dd08ce75ac4ef9bab194
[oweals/busybox.git] / seq.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * seq implementation for busybox
4  *
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]);
33         } else if (argc == 3) {
34                 first = atof(argv[1]);
35         } else if (argc != 2) {
36                 bb_show_usage();
37         }
38         last = atof(argv[argc - 1]);
39
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) {
47                 printf("%g\n", i);
48         }
49
50         return EXIT_SUCCESS;
51 }