Commit 0b559dff authored by Romain Bignon's avatar Romain Bignon

beautifull progressbar

parent f952c2a5
......@@ -222,11 +222,9 @@ int start_job(const char *filename, const char **nicks, int* hsock, fd_set *fdse
/* child */
close(notify_pipe[0]);
parse_file(notify_pipe[1], nicks, filename);
printf("Finished %s\n", filename);
close(notify_pipe[1]);
exit(127);
}
printf("Started a new job on %s\n", filename);
close(notify_pipe[1]);
if (notify_pipe[0] > *hsock)
*hsock = notify_pipe[0];
......@@ -359,6 +357,31 @@ static void process_data(struct data* data, time_t start, time_t end)
}
}
void print_progress(float x, float tot)
{
static char progress[51];
static char b[65];
size_t i;
size_t state = x / tot * 50 - 1;
if (b[0] == '\0')
for (i = 0; i < sizeof(b) - 1; ++i)
b[i] = '\b';
else
fputs(b, stdout);
for (i = 0; i < 50; ++i)
if (i < state)
progress[i] = '=';
else if (i == state)
progress[i] = '>';
else
progress[i] = ' ';
printf("Extracting: [%s]", progress);
fflush(stdout);
}
int main(int argc, char **argv)
{
static struct option long_options[] =
......@@ -371,7 +394,7 @@ int main(int argc, char **argv)
int nprocess = 1;
int hsock = 0;
fd_set fdset;
struct data data;
struct data data = {0};
const char *nicks[] = {"romain", "Progs", "vaginus", NULL};
while((i = getopt_long(argc, argv, "j:h", long_options, &option_index)) != -1)
......@@ -405,7 +428,7 @@ int main(int argc, char **argv)
for (i = 0; i < nprocess && optind < argc; ++i)
if (start_job(argv[optind++], nicks, &hsock, &fdset) != 0)
{
fprintf(stderr, "Error: %s\n", strerror(errno));
fprintf(stderr, "Error in start_job(): %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
......@@ -433,13 +456,17 @@ int main(int argc, char **argv)
r = read(i, &ts, sizeof(ts));
if (r > 0 && r < (ssize_t)sizeof(ts))
printf("Pas content (%ld < %ld)\n", r, sizeof(ts));
{
fprintf(stderr, "Received malformated data (%ld < %ld)\n", r, sizeof(ts));
exit(EXIT_FAILURE);
}
if (r <= 0)
{
if (errno)
fprintf(stderr, "Close[%d/%d]: %s\n", i, hsock, strerror(errno));
close(i);
print_progress(optind, argc);
FD_CLR(i, &fdset);
if (optind < argc)
......@@ -461,9 +488,9 @@ int main(int argc, char **argv)
}
}
struct period* p;
/* struct period* p;
for (p = data.periods; p; p = p->next)
printf("From %ld to %ld\n", p->start, p->end);
printf("From %ld to %ld\n", p->start, p->end);*/
exit(EXIT_SUCCESS);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment