From: Urban Wallasch Date: Thu, 20 May 2021 10:03:40 +0000 (+0200) Subject: * Improved kaoupload progress ETA formatting. X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=395e22c5fd633baa8dfc3c4f3369266e378edaa6;p=kaotools.git * Improved kaoupload progress ETA formatting. --- diff --git a/kaoupload.c b/kaoupload.c index 8e24433..dde33b2 100644 --- a/kaoupload.c +++ b/kaoupload.c @@ -104,14 +104,20 @@ static curl_off_t str_to_bwl( const char *s ) { } static const char *eta_fmt(int s) { - static char tbuf[10]; - int h, m, n = 0; - h = s / 3600; - m = (s / 60) % 60; - s = s % 60; - if ( h ) - n = snprintf(tbuf, sizeof tbuf, "%02d:", h); - snprintf(tbuf + n, sizeof tbuf - n, "%02d:%02d", m, s); + static char tbuf[20]; + int d, h, m, n = 0; + + d = s / 86400; s %= 86400; + h = s / 3600; s %= 3600; + m = s / 60; s %= 60; + if ( d ) + n = snprintf(tbuf, sizeof tbuf, "%dd ", d); + if ( d || h ) + n += snprintf(tbuf + n, sizeof tbuf - n, "%dh ", h); + if ( !d && ( h || m ) ) + n += snprintf(tbuf + n, sizeof tbuf - n, "%dm ", m); + if ( !d && !h ) + n += snprintf(tbuf + n, sizeof tbuf - n, "%ds", s); return tbuf; } @@ -351,7 +357,7 @@ static int upload_file( const char *fn ) { csize = CSIZE_HARDLIMIT; fprintf( stderr, "\r%3.f%% (%5.1f KiB/s) ", (double)fi.coff * 100 / fi.size, (double)fi.speed / 1024 ); eta = (double)fi.remn / (fi.speed ? fi.speed : 1); - fprintf( stderr, " ETA: %s ", eta_fmt(eta)); + fprintf( stderr, " ETA: %-20s ", eta_fmt(eta)); // fprintf( stderr, "[csize: %ld] {offset: %ld} ", (long)csize, (long)fi.coff ); fflush( stderr ); }