toybox/toys/example/demo_number.c
<<
>>
Prefs
   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, "hdbs", TOYFLAG_BIN))
   6
   7config 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#include "toys.h"
  20
  21void demo_number_main(void)
  22{
  23  char **arg;
  24
  25  for (arg = toys.optargs; *arg; arg++) {
  26    long long ll = atolx(*arg);
  27
  28    if (toys.optflags) {
  29      human_readable(toybuf, ll, toys.optflags);
  30      xputs(toybuf);
  31    } else printf("%lld\n", ll);
  32  }
  33}
  34