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