On Mon, Nov 10, 2008 at 01:55:22PM +0100, Bernhard Reutner-Fischer wrote:
>On Mon, Nov 10, 2008 at 12:02:12PM +0100, Natanael Copa wrote:
>>attatched is a patch that adds support for the -w option to seq.
>
>Didn't work for 10 -1 8 (missing ^+ in getopt32)
>and forgot to update the usage.
>What about separator support? Would need to suppress printing the sep if
>it was the last occurance..
something like the attached. Quite bloated, though..
function old new delta
seq_main 235 341 +106
packed_usage 13671 13708 +37
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 143/0) Total: 143 bytes
Denys, please install and/or adjust.
Cheers,
>># ./busybox seq -w 001 010
>>001
>>002
>>003
>>004
>>005
>>006
>>007
>>008
>>009
>>010
>>
>># make bloatcheck
>>function old new delta
>>seq_main 268 320 +52
>>.rodata 169558 169564 +6
>>------------------------------------------------------------------------------
>>(add/remove: 0/0 grow/shrink: 2/0 up/down: 58/0) Total: 58
>>bytes
>> text data bss dec hex filename
>> 942990 9145 5288 957423 e9bef busybox_old
>> 943048 9145 5288 957481 e9c29 busybox_unstripped
>>
>>-nc
>
>>Index: coreutils/seq.c
>>===================================================================
>>--- coreutils/seq.c (revision 23942)
>>+++ coreutils/seq.c (working copy)
>>@@ -16,6 +16,10 @@
>> int seq_main(int argc, char **argv)
>> {
>> double last, increment, i;
>>+ int width = getopt32(argv, "w");
>>+
>>+ argc -= optind;
>>+ argv += optind;
>>
>> i = increment = 1;
>> switch (argc) {
>>@@ -29,10 +33,12 @@
>> default:
>> bb_show_usage();
>> }
>>+ if (width)
>>+ width = strlen(argv[argc-1]);
>>
>> /* You should note that this is pos-5.0.91 semantics, -- FK. */
>> while ((increment > 0 && i <= last) || (increment < 0 && i >= last)) {
>>- printf("%g\n", i);
>>+ printf("%0*g\n", width, i);
>> i += increment;
>> }
>>
Index: coreutils/seq.c
===================================================================
--- coreutils/seq.c (revision 23935)
+++ coreutils/seq.c (working copy)
@@ -16,23 +16,35 @@ int seq_main(int argc, char **argv) MAIN
int seq_main(int argc, char **argv)
{
double last, increment, i;
+ enum { OPT_w = 1, OPT_s };
+ const char *sep = "\n";
+ bool is_consecutive = 0;
+ unsigned opt = getopt32(argv, "+ws:", &sep);
+ unsigned width = 0;
+ argc -= optind;
+ argv += optind;
i = increment = 1;
switch (argc) {
- case 4:
- increment = atof(argv[2]);
case 3:
- i = atof(argv[1]);
+ increment = atof(argv[1]);
case 2:
+ i = atof(*argv);
+ case 1:
last = atof(argv[argc-1]);
break;
default:
bb_show_usage();
}
+ if (opt & OPT_w) /* Pad to length of start or last */
+ width = MAX(strlen(*argv), strlen(argv[argc-1]));
/* You should note that this is pos-5.0.91 semantics, -- FK. */
while ((increment > 0 && i <= last) || (increment < 0 && i >= last)) {
- printf("%g\n", i);
+ if (is_consecutive++) {
+ printf("%s", sep);
+ }
+ printf("%0*g", width, i);
i += increment;
}
Index: include/usage.h
===================================================================
--- include/usage.h (revision 23935)
+++ include/usage.h (working copy)
@@ -3508,11 +3508,13 @@
"\nOther options are silently ignored; -oi is implied" \
#define seq_trivial_usage \
- "[first [increment]] last"
+ "[-w] [-s separator] [first [increment]] last"
#define seq_full_usage "\n\n" \
"Print numbers from FIRST to LAST, in steps of INCREMENT.\n" \
"FIRST, INCREMENT default to 1\n" \
"\nArguments:" \
+ "\n -w Pad to last with leading zeros" \
+ "\n -s <string> Use string separator" \
"\n LAST" \
"\n FIRST LAST" \
"\n FIRST INCREMENT LAST" \
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox