view toys/other/count.c @ 818:264b9da809df

Simplify license text, as mentioned on the mailing list. Reasoning: it was never my intent to require anybody to copy license text into another project if they cut and pasted something out of toybox. The "permission for any purpose" is as close to public domain as you can get in our current screwed up legal system without making people uncomfortable the _other_ way. (Besides, my initial reading of that was "all copies of the source code" but that's not what it says, and somebody pointed out that Android has "show license text" options because paranoid lawyers think that sort of thing applies to the BINARY version, which is nuts.)
author Rob Landley <rob@landley.net>
date Thu, 14 Mar 2013 09:02:37 -0500
parents 786841fdb1e0
children
line wrap: on
line source

/* count.c - Progress indicator from stdin to stdout
 *
 * Copyright 2002 Rob Landley <rob@landley.net>

USE_COUNT(NEWTOY(count, NULL, TOYFLAG_USR|TOYFLAG_BIN))

config COUNT
  bool "count"
  default y
  help
    usage: count

    Copy stdin to stdout, displaying simple progress indicator to stderr.
*/

#include "toys.h"

void count_main(void)
{
  uint64_t size = 0;
  int len;
  char buf[32];

  for (;;) {
    len = xread(0, toybuf, sizeof(toybuf));
    if (!len) break;
    size += len;
    xwrite(1, toybuf, len);
    xwrite(2, buf, sprintf(buf, "%"PRIu64" bytes\r", size));
  }
  xwrite(2, "\n", 1);
}