2006-06-02 20:56:16 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2003-11-14 10:04:33 +00:00
|
|
|
/*
|
|
|
|
* Monitor a pipe with a simple progress display.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 by Rob Landley <rob@landley.net>, Joey Hess
|
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2003-11-14 10:04:33 +00:00
|
|
|
*/
|
2011-04-01 20:56:30 +00:00
|
|
|
|
|
|
|
//usage:#define pipe_progress_trivial_usage NOUSAGE_STR
|
|
|
|
//usage:#define pipe_progress_full_usage ""
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2003-11-14 10:04:33 +00:00
|
|
|
|
|
|
|
#define PIPE_PROGRESS_SIZE 4096
|
|
|
|
|
2006-06-02 20:56:16 +00:00
|
|
|
/* Read a block of data from stdin, write it to stdout.
|
|
|
|
* Activity is indicated by a '.' to stderr
|
2003-11-14 10:04:33 +00:00
|
|
|
*/
|
2007-10-11 10:05:36 +00:00
|
|
|
int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
2003-11-14 10:04:33 +00:00
|
|
|
{
|
2010-06-06 16:19:25 +00:00
|
|
|
char buf[PIPE_PROGRESS_SIZE];
|
2003-11-14 10:04:33 +00:00
|
|
|
time_t t = time(NULL);
|
2010-06-06 16:19:25 +00:00
|
|
|
int len;
|
2003-11-14 10:04:33 +00:00
|
|
|
|
2010-06-06 16:19:25 +00:00
|
|
|
while ((len = safe_read(STDIN_FILENO, buf, PIPE_PROGRESS_SIZE)) > 0) {
|
2003-11-14 10:04:33 +00:00
|
|
|
time_t new_time = time(NULL);
|
|
|
|
if (new_time != t) {
|
|
|
|
t = new_time;
|
2010-06-06 19:53:09 +00:00
|
|
|
bb_putchar_stderr('.');
|
2003-11-14 10:04:33 +00:00
|
|
|
}
|
2010-06-06 16:19:25 +00:00
|
|
|
full_write(STDOUT_FILENO, buf, len);
|
2003-11-14 10:04:33 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 19:53:09 +00:00
|
|
|
bb_putchar_stderr('\n');
|
2003-11-14 10:04:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|