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