Initial public busybox maemo commit, 3:1.10.2.legal-1osso12
[busybox4maemo] / coreutils / seq.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * seq implementation for busybox
4  *
5  * Copyright (C) 2004, Glenn McGrath
6  *
7  * Licensed under the GPL v2, see the file LICENSE in this tarball.
8  */
9
10 #include "libbb.h"
11
12 /* This is a NOFORK applet. Be very careful! */
13
14
15 int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16 int seq_main(int argc, char **argv)
17 {
18         double last, increment, i;
19
20         i = increment = 1;
21         switch (argc) {
22                 case 4:
23                         increment = atof(argv[2]);
24                 case 3:
25                         i = atof(argv[1]);
26                 case 2:
27                         last = atof(argv[argc-1]);
28                         break;
29                 default:
30                         bb_show_usage();
31         }
32
33         /* You should note that this is pos-5.0.91 semantics, -- FK. */
34         while ((increment > 0 && i <= last) || (increment < 0 && i >= last)) {
35                 printf("%g\n", i);
36                 i += increment;
37         }
38
39         return fflush(stdout);
40 }