From 16c4357f0d0df0ce4f91d424cc57ce571ccf4e91 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 26 Mar 2018 17:36:33 -0500 Subject: Rename demo_human_readable.c->demo_number.c and have it do atolx() too. --- toys/example/demo_human_readable.c | 23 ----------------------- toys/example/demo_number.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 23 deletions(-) delete mode 100644 toys/example/demo_human_readable.c create mode 100644 toys/example/demo_number.c (limited to 'toys/example') diff --git a/toys/example/demo_human_readable.c b/toys/example/demo_human_readable.c deleted file mode 100644 index 9fff2626..00000000 --- a/toys/example/demo_human_readable.c +++ /dev/null @@ -1,23 +0,0 @@ -/* test_human_readable.c - Expose lib/lib.c human_readable() for testing. - * - * Copyright 2015 Rob Landley - -USE_TEST_HUMAN_READABLE(NEWTOY(test_human_readable, "<1>1ibs", TOYFLAG_BIN)) - -config TEST_HUMAN_READABLE - bool "test_human_readable" - default n - help - usage: test_human_readable [-sbi] NUMBER -*/ - -#define FOR_test_human_readable -#include "toys.h" - -void test_human_readable_main(void) -{ - char *c; - - human_readable(toybuf, strtoll(*toys.optargs, &c, 0), toys.optflags); - printf("%s\n", toybuf); -} diff --git a/toys/example/demo_number.c b/toys/example/demo_number.c new file mode 100644 index 00000000..4c7b7327 --- /dev/null +++ b/toys/example/demo_number.c @@ -0,0 +1,33 @@ +/* demo_number.c - Expose atolx() and human_readable() for testing. + * + * Copyright 2015 Rob Landley + +USE_DEMO_NUMBER(NEWTOY(demo_number, "hdbs", TOYFLAG_BIN)) + +config DEMO_NUMBER + bool "demo_number" + default n + help + usage: demo_number [-hsbi] NUMBER... + + -b Use "B" for single byte units (HR_B) + -d Decimal units + -h human readable + -s Space between number and units (HR_SPACE) +*/ + +#include "toys.h" + +void demo_number_main(void) +{ + char **arg; + + for (arg = toys.optargs; *arg; arg++) { + long long ll = atolx(*arg); + + if (toys.optflags) { + human_readable(toybuf, ll, toys.optflags); + xputs(toybuf); + } else printf("%lld\n", ll); + } +} -- cgit v1.2.3