Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/seq.c23
-rwxr-xr-xtestsuite/seq.tests3
2 files changed, 24 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 @@
//usage:#define seq_full_usage "\n\n"
//usage: "Print numbers from FIRST to LAST, in steps of INC.\n"
//usage: "FIRST, INC default to 1.\n"
-//usage: "\n -w Pad to last with leading zeros"
+//usage: "\n -w Pad with leading zeros"
//usage: "\n -s SEP String separator"
#include "libbb.h"
@@ -41,6 +41,7 @@ int seq_main(int argc, char **argv)
unsigned width;
unsigned frac_part;
const char *sep, *opt_s = "\n";
+ char *saved;
unsigned opt;
#if ENABLE_LOCALE_SUPPORT
@@ -49,7 +50,25 @@ int seq_main(int argc, char **argv)
setlocale(LC_NUMERIC, "C");
#endif
- opt = getopt32(argv, "+ws:", &opt_s);
+ /* Cater for negative arguments: if we see one, truncate argv[] on it */
+ n = 0;
+ for (;;) {
+ char c;
+ saved = argv[++n];
+ if (!saved)
+ break;
+ if (saved[0] != '-')
+ break;
+ c = saved[1];
+ if (c == '.' || (c >= '0' && c <= '9')) {
+ argv[n] = NULL;
+ break;
+ }
+ }
+ opt = getopt32(argv, "+ws:", &opt_s); /* "+": stop at first non-option */
+ /* Restore possibly truncated argv[] */
+ argv[n] = saved;
+
argc -= optind;
argv += optind;
first = increment = 1;
diff --git a/testsuite/seq.tests b/testsuite/seq.tests
index 1e1116c7d..d414169c9 100755
--- a/testsuite/seq.tests
+++ b/testsuite/seq.tests
@@ -43,4 +43,7 @@ testing "seq count down by 3 with padding" "seq -w 8 -3 04" "08\n05\n" "" ""
testing "seq count by .3 with padding 1" "seq -w 09 .3 11" "09.0\n09.3\n09.6\n09.9\n10.2\n10.5\n10.8\n" "" ""
testing "seq count by .3 with padding 2" "seq -w 03 .3 0004" "0003.0\n0003.3\n0003.6\n0003.9\n" "" ""
+testing "seq from -4 count down by 2" "seq -4 -2 -8" "-4\n-6\n-8\n" "" ""
+testing "seq from -.0 count down by .25" "seq -.0 -.25 -.9" "-0.00\n-0.25\n-0.50\n-0.75\n" "" ""
+
exit $FAILCOUNT