1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "libbb.h"
19
20
21
22int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
23int seq_main(int argc, char **argv)
24{
25 enum {
26 OPT_w = (1 << 0),
27 OPT_s = (1 << 1),
28 };
29 double first, last, increment, v;
30 unsigned n;
31 unsigned width;
32 unsigned frac_part;
33 const char *sep, *opt_s = "\n";
34 unsigned opt;
35
36#if ENABLE_LOCALE_SUPPORT
37
38
39 setlocale(LC_NUMERIC, "C");
40#endif
41
42 opt = getopt32(argv, "+ws:", &opt_s);
43 argc -= optind;
44 argv += optind;
45 first = increment = 1;
46 errno = 0;
47 switch (argc) {
48 char *pp;
49 case 3:
50 increment = strtod(argv[1], &pp);
51 errno |= *pp;
52 case 2:
53 first = strtod(argv[0], &pp);
54 errno |= *pp;
55 case 1:
56 last = strtod(argv[argc-1], &pp);
57 if (!errno && *pp == '\0')
58 break;
59 default:
60 bb_show_usage();
61 }
62
63#if ENABLE_LOCALE_SUPPORT
64 setlocale(LC_NUMERIC, "");
65#endif
66
67
68 width = 0;
69 frac_part = 0;
70 while (1) {
71 char *dot = strchrnul(*argv, '.');
72 int w = (dot - *argv);
73 int f = strlen(dot);
74 if (width < w)
75 width = w;
76 argv++;
77 if (!*argv)
78 break;
79
80
81
82
83 if (frac_part < f)
84 frac_part = f;
85 }
86 if (frac_part) {
87 frac_part--;
88 if (frac_part)
89 width += frac_part + 1;
90 }
91 if (!(opt & OPT_w))
92 width = 0;
93
94 sep = "";
95 v = first;
96 n = 0;
97 while (increment >= 0 ? v <= last : v >= last) {
98 if (printf("%s%0*.*f", sep, width, frac_part, v) < 0)
99 break;
100 sep = opt_s;
101
102 n++;
103 v = first + n * increment;
104 }
105 if (n)
106 bb_putchar('\n');
107
108 return fflush_all();
109}
110