X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=config%2Ftthsum.c;h=dd20521e6473519374c47ffd6df89624b97fd958;hb=e194f2fdfdde54a19e3e94a63f70580b6da0854a;hp=236cbfe4ba2c5ace283df4eb8755f4e26246528f;hpb=2fba954a2ff66ea881f90bde4b3d29ed0cc5d23a;p=doldaconnect.git diff --git a/config/tthsum.c b/config/tthsum.c index 236cbfe..dd20521 100644 --- a/config/tthsum.c +++ b/config/tthsum.c @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -47,7 +48,7 @@ struct tigertreehash { int depth; }; -char buf[32768], dbuf[512]; +char buf[32768], dbuf[8192]; static char *base64set = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static int base64rev[] = { @@ -534,18 +535,24 @@ int main(int argc, char **argv) char res[24]; char *statefile; FILE *state; + int progress, bytes; + struct stat sb; filter = 0; output = 4; outfd = 3; + progress = 0; statefile = NULL; - while((c = getopt(argc, argv, "hf456F:s:")) != -1) { + while((c = getopt(argc, argv, "phf456F:s:")) != -1) { switch(c) { case '4': case '5': case '6': output = c - '0'; break; + case 'p': + progress = 1; + break; case 'f': filter = 1; break; @@ -611,6 +618,7 @@ int main(int argc, char **argv) } memcpy(&tth.block, dbuf, tth.offset); fclose(state); + unlink(statefile); } } while(1) { @@ -672,6 +680,12 @@ int main(int argc, char **argv) exit(1); } } + if(progress) { + fstat(fd, &sb); + if(!S_ISREG(sb.st_mode)) + sb.st_size = -1; + bytes = 0; + } inittigertree(&tth); while(1) { ret = read(fd, buf, sizeof(buf)); @@ -679,10 +693,29 @@ int main(int argc, char **argv) perror("tigersum: read"); exit(1); } + if(progress) { + if((bytes == 0) || ((bytes & ~0xFFFFF) != ((bytes + ret) & ~0xFFFFF))) { + bytes += ret; + fprintf(stderr, "\033[1G"); + if(argc - optind > 1) + fprintf(stderr, "%s: ", argv[i]); + if(sb.st_size < 0) { + fprintf(stderr, "%i", bytes); + } else { + fprintf(stderr, "%i%%", (int)(((float)bytes / (float)sb.st_size) * 100.0)); + } + fprintf(stderr, "\033[K"); + fflush(stderr); + } else { + bytes += ret; + } + } if(ret == 0) break; dotigertree(&tth, buf, ret); } + if(progress) + fprintf(stderr, "\n"); synctigertree(&tth); restigertree(&tth, res); if(output == 4) @@ -695,6 +728,7 @@ int main(int argc, char **argv) printf("%s %s\n", dbuf, argv[i]); else printf("%s\n", dbuf); + fflush(stdout); close(fd); } }