2005-08-11 17:17:52 +02:00
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <time.h>
|
2005-08-11 18:18:53 +02:00
|
|
|
|
#include <unistd.h>
|
2005-08-12 13:23:33 +02:00
|
|
|
|
#include <string.h>
|
2005-08-11 17:17:52 +02:00
|
|
|
|
|
|
|
|
|
_PROTOTYPE(int main, (int argc, char **argv));
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
prettyprogress(long b, long maxb, time_t starttime)
|
|
|
|
|
{
|
|
|
|
|
/* print progress indication */
|
|
|
|
|
time_t spent, now;
|
2005-08-11 18:18:53 +02:00
|
|
|
|
double bpsec;
|
2005-08-11 17:17:52 +02:00
|
|
|
|
time(&now);
|
|
|
|
|
spent = now - starttime;
|
2005-08-12 13:23:33 +02:00
|
|
|
|
printf("\r"); /* Make sure progress bar starts at beginning of line */
|
2005-08-11 18:18:53 +02:00
|
|
|
|
if(spent > 0 && (bpsec = (double)b / spent) > 0) {
|
2005-08-11 17:17:52 +02:00
|
|
|
|
int len, i;
|
|
|
|
|
long secremain, minremain, hremain;
|
|
|
|
|
secremain = (maxb - b) / bpsec;
|
|
|
|
|
minremain = (secremain / 60) % 60;
|
|
|
|
|
hremain = secremain / 3600;
|
2005-08-12 13:23:33 +02:00
|
|
|
|
len = printf("Remainining: %ld files. ", maxb-b);
|
2005-08-11 18:18:53 +02:00
|
|
|
|
|
|
|
|
|
#if 0
|
2005-08-12 13:23:33 +02:00
|
|
|
|
len += printf("ETA: %d:%02d:%02d ",
|
2005-08-11 17:17:52 +02:00
|
|
|
|
hremain, minremain, secremain % 60);
|
2005-08-11 18:18:53 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2005-08-12 13:23:33 +02:00
|
|
|
|
len += printf(" [");
|
2005-08-11 18:18:53 +02:00
|
|
|
|
|
2005-08-11 17:17:52 +02:00
|
|
|
|
#define WIDTH 77
|
|
|
|
|
len = WIDTH - len;
|
|
|
|
|
for(i = 0; i < (b * (len-1) / maxb); i++)
|
2005-08-12 13:23:33 +02:00
|
|
|
|
printf("=");
|
|
|
|
|
printf("|");
|
2005-08-11 17:17:52 +02:00
|
|
|
|
for(; i < len-2; i++)
|
2005-08-12 13:23:33 +02:00
|
|
|
|
printf("-");
|
|
|
|
|
printf("]\n");
|
|
|
|
|
} else printf("\n");
|
2005-08-11 17:17:52 +02:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(argc, argv)
|
|
|
|
|
int argc;
|
|
|
|
|
char *argv[];
|
|
|
|
|
{
|
|
|
|
|
long i = 0, count = 0;
|
2005-08-12 13:23:33 +02:00
|
|
|
|
int l;
|
2005-08-11 17:17:52 +02:00
|
|
|
|
char line[2000];
|
|
|
|
|
time_t start;
|
|
|
|
|
if(argc < 2) return 1;
|
|
|
|
|
count = atol(argv[1]);
|
|
|
|
|
if(count < 1) return 1;
|
|
|
|
|
time(&start);
|
|
|
|
|
printf("\n");
|
2005-08-12 13:23:33 +02:00
|
|
|
|
#define LINES 5
|
|
|
|
|
for(l = 1; l <= LINES+1; l++) printf("\n");
|
|
|
|
|
printf("[A");
|
2005-08-11 17:17:52 +02:00
|
|
|
|
while(fgets(line, sizeof(line), stdin)) {
|
|
|
|
|
i++;
|
2005-08-12 13:23:33 +02:00
|
|
|
|
for(l = 0; l <= LINES; l++) printf("[A");
|
2005-08-11 17:17:52 +02:00
|
|
|
|
if(i <= count) prettyprogress(i, count, start);
|
2005-08-12 13:23:33 +02:00
|
|
|
|
else printf("\n");
|
|
|
|
|
printf("[M");
|
|
|
|
|
for(l = 0; l < LINES; l++) printf("[B");
|
|
|
|
|
printf("\r%s[A", line);
|
2005-08-11 17:17:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-12 13:23:33 +02:00
|
|
|
|
printf("\nDone.[K\n");
|
2005-08-11 17:17:52 +02:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|