diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-05-05 16:41:36 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-05-05 16:41:36 +0000 |
commit | dda18efbf37e2def7490bb7865d41b1560d8412c (patch) | |
tree | 183e963df6417e3620440e07954cd50a3be45811 /src/skaembutils | |
parent | c7f0abb049cbd58704545ee94ec6e6aa40d00f0a (diff) | |
download | s6-portable-utils-dda18efbf37e2def7490bb7865d41b1560d8412c.tar.gz s6-portable-utils-dda18efbf37e2def7490bb7865d41b1560d8412c.tar.xz s6-portable-utils-dda18efbf37e2def7490bb7865d41b1560d8412c.zip |
- add s6-seq v2.0.5.0
- rc for 2.0.5.0
Diffstat (limited to 'src/skaembutils')
-rw-r--r-- | src/skaembutils/deps-exe/s6-seq | 1 | ||||
-rw-r--r-- | src/skaembutils/s6-seq.c | 61 |
2 files changed, 62 insertions, 0 deletions
diff --git a/src/skaembutils/deps-exe/s6-seq b/src/skaembutils/deps-exe/s6-seq new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/skaembutils/deps-exe/s6-seq @@ -0,0 +1 @@ +-lskarnet diff --git a/src/skaembutils/s6-seq.c b/src/skaembutils/s6-seq.c new file mode 100644 index 0000000..bad4afd --- /dev/null +++ b/src/skaembutils/s6-seq.c @@ -0,0 +1,61 @@ +/* ISC license. */ + +#include <skalibs/uint.h> +#include <skalibs/sgetopt.h> +#include <skalibs/buffer.h> +#include <skalibs/strerr2.h> + +#define USAGE "s6-seq [ -w ] [ -s separator ] limits" +#define dieusage() strerr_dieusage(100, USAGE) + +int main (int argc, char const *const *argv) +{ + char const *sep = "\n" ; + unsigned int fixed = 0, seplen = 1, i = 1, increment = 1 ; + unsigned int last ; + char fmt[UINT_FMT] ; + PROG = "s6-seq" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + register int opt = subgetopt_r(argc, argv, "ws:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'w': fixed = 1 ; break ; + case 's': sep = l.arg ; seplen = str_len(sep) ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + switch (argc) + { + case 1 : + if (!uint0_scan(argv[0], &last)) dieusage() ; + break ; + case 2 : + if (!uint0_scan(argv[0], &i) + || !uint0_scan(argv[1], &last)) dieusage() ; + break ; + case 3 : + if (!uint0_scan(argv[0], &i) + || !uint0_scan(argv[1], &increment) + || !uint0_scan(argv[2], &last)) dieusage() ; + break ; + default : dieusage() ; + } + if (!seplen) seplen = 1 ; + if (fixed) fixed = uint_fmt(0, i + increment * ((last - i) / increment)) ; + for (; i <= last ; i += increment) + { + if (buffer_put(buffer_1, fmt, fixed ? (uint0_fmt(fmt, i, fixed), fixed) : uint_fmt(fmt, i)) < 0) goto err ; + if (buffer_put(buffer_1, sep, seplen) < 0) goto err ; + } + if (!buffer_flush(buffer_1)) goto err ; + return 0 ; + +err: + strerr_diefu1sys(111, "write to stdout") ; +} |