diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-04-10 14:33:20 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-04-10 14:33:20 +0200 |
commit | 9bc2b6e88474a8ebb50c94f29320d343bd374928 (patch) | |
tree | 0af73191b3842822d9d1bf7e8729ea49a4df1a2d /coreutils | |
parent | a26711a2d1464167be4ebc990fe21a3809a2da34 (diff) | |
download | busybox-w32-9bc2b6e88474a8ebb50c94f29320d343bd374928.tar.gz busybox-w32-9bc2b6e88474a8ebb50c94f29320d343bd374928.tar.bz2 busybox-w32-9bc2b6e88474a8ebb50c94f29320d343bd374928.zip |
seq: accept negative parameters
function old new delta
seq_main 429 476 +47
packed_usage 34557 34538 -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 47/-19) Total: 28 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/seq.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/coreutils/seq.c b/coreutils/seq.c index beb339d1e..c0e2d1e06 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,25 @@ 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; | ||
62 | c = saved[1]; | ||
63 | if (c == '.' || (c >= '0' && c <= '9')) { | ||
64 | argv[n] = NULL; | ||
65 | break; | ||
66 | } | ||
67 | } | ||
68 | opt = getopt32(argv, "+ws:", &opt_s); /* "+": stop at first non-option */ | ||
69 | /* Restore possibly truncated argv[] */ | ||
70 | argv[n] = saved; | ||
71 | |||
53 | argc -= optind; | 72 | argc -= optind; |
54 | argv += optind; | 73 | argv += optind; |
55 | first = increment = 1; | 74 | first = increment = 1; |