On Mon, 2008-11-10 at 13:55 +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.

thanks!

> What about separator support? 

i didnt have need for it so i didnt implement it.

> Would need to suppress printing the sep if
> it was the last occurance..

attatched


Index: coreutils/seq.c
===================================================================
--- coreutils/seq.c	(revision 23989)
+++ coreutils/seq.c	(working copy)
@@ -16,23 +16,32 @@
 int seq_main(int argc, char **argv)
 {
 	double last, increment, i;
+	enum { OPT_w = 1, OPT_s };
+	const char *sep = "\n";
+	unsigned opt = getopt32(argv, "+ws:", &sep);
 
+	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 */
+		opt = 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 (i >= last)
+			sep = "\n";
+		printf("%0*g%s", opt, i, sep);
 		i += increment;
 	}
 
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to