aboutsummaryrefslogtreecommitdiff
path: root/coreutils/seq.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/seq.c')
-rw-r--r--coreutils/seq.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/coreutils/seq.c b/coreutils/seq.c
index beb339d1e..77a8aba8a 100644
--- a/coreutils/seq.c
+++ b/coreutils/seq.c
@@ -22,7 +22,7 @@
22//usage:#define seq_full_usage "\n\n" 22//usage:#define seq_full_usage "\n\n"
23//usage: "Print numbers from FIRST to LAST, in steps of INC.\n" 23//usage: "Print numbers from FIRST to LAST, in steps of INC.\n"
24//usage: "FIRST, INC default to 1.\n" 24//usage: "FIRST, INC default to 1.\n"
25//usage: "\n -w Pad to last with leading zeros" 25//usage: "\n -w Pad with leading zeros"
26//usage: "\n -s SEP String separator" 26//usage: "\n -s SEP String separator"
27 27
28#include "libbb.h" 28#include "libbb.h"
@@ -41,6 +41,7 @@ int seq_main(int argc, char **argv)
41 unsigned width; 41 unsigned width;
42 unsigned frac_part; 42 unsigned frac_part;
43 const char *sep, *opt_s = "\n"; 43 const char *sep, *opt_s = "\n";
44 char *saved;
44 unsigned opt; 45 unsigned opt;
45 46
46#if ENABLE_LOCALE_SUPPORT 47#if ENABLE_LOCALE_SUPPORT
@@ -49,7 +50,29 @@ int seq_main(int argc, char **argv)
49 setlocale(LC_NUMERIC, "C"); 50 setlocale(LC_NUMERIC, "C");
50#endif 51#endif
51 52
52 opt = getopt32(argv, "+ws:", &opt_s); 53 /* Cater for negative arguments: if we see one, truncate argv[] on it */
54 n = 0;
55 for (;;) {
56 char c;
57 saved = argv[++n];
58 if (!saved)
59 break;
60 if (saved[0] != '-') {
61 // break; // "seq -s : -1 1" won't be treated correctly
62 continue;
63 }
64// "seq -s -1 1 9" is not treated correctly, but such usage
65// (delimiter string which looks like negative number) is very unlikely
66 c = saved[1];
67 if (c == '.' || (c >= '0' && c <= '9')) {
68 argv[n] = NULL;
69 break;
70 }
71 }
72 opt = getopt32(argv, "+ws:", &opt_s); /* "+": stop at first non-option */
73 /* Restore possibly truncated argv[] */
74 argv[n] = saved;
75
53 argc -= optind; 76 argc -= optind;
54 argv += optind; 77 argv += optind;
55 first = increment = 1; 78 first = increment = 1;