1/* demo_number.c - Expose atolx() and human_readable() for testing.
2 *
3 * Copyright 2015 Rob Landley <rob@landley.net>
4
5USE_DEMO_NUMBER(NEWTOY(demo_number, "D#=3<3M#<0hcdbs", TOYFLAG_BIN))
6
7config DEMO_NUMBER
8  bool "demo_number"
9  default n
10  help
11    usage: demo_number [-hsbi] [-D LEN] NUMBER...
12
13    -D	output field is LEN chars
14    -M	input units (index into bkmgtpe)
15    -c	Comma comma down do be do down down
16    -b	Use "B" for single byte units (HR_B)
17    -d	Decimal units
18    -h	Human readable
19    -s	Space between number and units (HR_SPACE)
20*/
21
22#define FOR_demo_number
23#include "toys.h"
24
25GLOBALS(
26  long M, D;
27)
28
29void demo_number_main(void)
30{
31  char **arg;
32
33  for (arg = toys.optargs; *arg; arg++) {
34    long long ll = atolx(*arg);
35
36    if (toys.optflags) {
37      human_readable_long(toybuf, ll, TT.D, TT.M, toys.optflags);
38      xputs(toybuf);
39    } else printf("%lld\n", ll);
40  }
41}
42