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
|
|
|
|
|
2012-03-24 16:16:34 +01:00
|
|
|
|
int main(int argc, char **argv);
|
2005-08-11 17:17:52 +02:00
|
|
|
|
|
|
|
|
|
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 14:35:17 +02:00
|
|
|
|
len = printf("Remaining: %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("-");
|
2005-08-12 14:35:17 +02:00
|
|
|
|
printf("][K\n");
|
2005-08-12 13:23:33 +02:00
|
|
|
|
} 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]);
|
2005-09-09 18:02:43 +02:00
|
|
|
|
if(count < 0) return 1;
|
2005-08-11 17:17:52 +02:00
|
|
|
|
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)) {
|
2005-08-12 14:35:17 +02:00
|
|
|
|
char *nl;
|
2005-08-11 17:17:52 +02:00
|
|
|
|
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");
|
2005-08-12 14:35:17 +02:00
|
|
|
|
if((nl = strchr(line, '\n'))) *nl = '\0';
|
|
|
|
|
line[78] = '\0';
|
|
|
|
|
printf("\r%s\r", 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;
|
|
|
|
|
}
|