demo_number.c 895 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* demo_number.c - Expose atolx() and human_readable() for testing.
  2. *
  3. * Copyright 2015 Rob Landley <rob@landley.net>
  4. USE_DEMO_NUMBER(NEWTOY(demo_number, "D#=3<3M#<0hcdbs", TOYFLAG_BIN))
  5. config DEMO_NUMBER
  6. bool "demo_number"
  7. default n
  8. help
  9. usage: demo_number [-hsbi] [-D LEN] NUMBER...
  10. -D output field is LEN chars
  11. -M input units (index into bkmgtpe)
  12. -c Comma comma down do be do down down
  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. #define FOR_demo_number
  19. #include "toys.h"
  20. GLOBALS(
  21. long M, D;
  22. )
  23. void demo_number_main(void)
  24. {
  25. char **arg;
  26. for (arg = toys.optargs; *arg; arg++) {
  27. long long ll = atolx(*arg);
  28. if (toys.optflags) {
  29. human_readable_long(toybuf, ll, TT.D, TT.M, toys.optflags);
  30. xputs(toybuf);
  31. } else printf("%lld\n", ll);
  32. }
  33. }