Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 2 | /* |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 3 | * seq implementation for busybox |
| 4 | * |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 5 | * Copyright (C) 2004, Glenn McGrath |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 6 | * |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 7 | * Licensed under the GPL v2, see the file LICENSE in this tarball. |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 10 | #include "libbb.h" |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 11 | |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 12 | /* This is a NOFORK applet. Be very careful! */ |
| 13 | |
| 14 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 15 | int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 16 | int seq_main(int argc, char **argv) |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 17 | { |
Denis Vlasenko | 7753ea4 | 2008-11-12 21:37:19 +0000 | [diff] [blame] | 18 | enum { |
| 19 | OPT_w = (1 << 0), |
| 20 | OPT_s = (1 << 1), |
| 21 | }; |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 22 | double last, increment, i; |
Denis Vlasenko | 7753ea4 | 2008-11-12 21:37:19 +0000 | [diff] [blame] | 23 | const char *sep, *opt_s = "\n"; |
| 24 | unsigned opt = getopt32(argv, "+ws:", &opt_s); |
Bernhard Reutner-Fischer | 2598f76 | 2008-11-12 12:59:56 +0000 | [diff] [blame] | 25 | unsigned width = 0; |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 26 | |
Bernhard Reutner-Fischer | 2598f76 | 2008-11-12 12:59:56 +0000 | [diff] [blame] | 27 | argc -= optind; |
| 28 | argv += optind; |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 29 | i = increment = 1; |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 30 | switch (argc) { |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 31 | case 3: |
Bernhard Reutner-Fischer | 2598f76 | 2008-11-12 12:59:56 +0000 | [diff] [blame] | 32 | increment = atof(argv[1]); |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 33 | case 2: |
Bernhard Reutner-Fischer | 2598f76 | 2008-11-12 12:59:56 +0000 | [diff] [blame] | 34 | i = atof(*argv); |
| 35 | case 1: |
Denis Vlasenko | ce97960 | 2006-09-27 23:31:08 +0000 | [diff] [blame] | 36 | last = atof(argv[argc-1]); |
Rob Landley | 73a20f3 | 2006-02-23 19:54:48 +0000 | [diff] [blame] | 37 | break; |
| 38 | default: |
| 39 | bb_show_usage(); |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 40 | } |
Bernhard Reutner-Fischer | 2598f76 | 2008-11-12 12:59:56 +0000 | [diff] [blame] | 41 | if (opt & OPT_w) /* Pad to length of start or last */ |
| 42 | width = MAX(strlen(*argv), strlen(argv[argc-1])); |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 43 | |
Glenn L McGrath | efc6bf6 | 2004-07-23 06:43:29 +0000 | [diff] [blame] | 44 | /* You should note that this is pos-5.0.91 semantics, -- FK. */ |
Denis Vlasenko | 7753ea4 | 2008-11-12 21:37:19 +0000 | [diff] [blame] | 45 | sep = ""; |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 46 | while ((increment > 0 && i <= last) || (increment < 0 && i >= last)) { |
Denis Vlasenko | 7753ea4 | 2008-11-12 21:37:19 +0000 | [diff] [blame] | 47 | printf("%s%0*g", sep, width, i); |
| 48 | sep = opt_s; |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 49 | i += increment; |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 50 | } |
Bernhard Reutner-Fischer | c021cb0 | 2008-11-12 13:22:24 +0000 | [diff] [blame] | 51 | bb_putchar('\n'); |
Denis Vlasenko | 99912ca | 2007-04-10 15:43:37 +0000 | [diff] [blame] | 52 | return fflush(stdout); |
Glenn L McGrath | 82364bb | 2004-01-27 09:22:20 +0000 | [diff] [blame] | 53 | } |