diff options
author | jmg <jmg@FreeBSD.org> | 1997-02-14 19:08:18 +0000 |
---|---|---|
committer | jmg <jmg@FreeBSD.org> | 1997-02-14 19:08:18 +0000 |
commit | 5a03931ab59c699dc77bb35946d102f53e43c6ad (patch) | |
tree | bb507265d688210fbf061f7772dbfdcfe0cb2129 /usr.bin | |
parent | 731964886006c63acb149497e458d29a68368332 (diff) | |
download | FreeBSD-src-5a03931ab59c699dc77bb35946d102f53e43c6ad.zip FreeBSD-src-5a03931ab59c699dc77bb35946d102f53e43c6ad.tar.gz |
Modified the display() function to recognize when the output it going to a
file. When it is don't do the percentage update, but still display the file
size and rate.
Closes PR#2725
Reviewed by: wollman
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/fetch/main.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/usr.bin/fetch/main.c b/usr.bin/fetch/main.c index 2aa7b9e..57f1d40 100644 --- a/usr.bin/fetch/main.c +++ b/usr.bin/fetch/main.c @@ -287,7 +287,7 @@ display(struct fetch_state *fs, off_t size, ssize_t n) { static off_t bytes; static off_t bytestart; - static int pr, init = 0; + static int pr, stdoutatty, init = 0; static struct timeval t0, t_start; static char *s; struct timezone tz; @@ -301,13 +301,13 @@ display(struct fetch_state *fs, off_t size, ssize_t n) gettimeofday(&t0, &tz); t_start = t0; bytes = pr = 0; - s = safe_malloc(strlen(fs->fs_outputfile) + 50); + stdoutatty = isatty(STDOUT_FILENO); if (size > 0) - sprintf (s, "Receiving %s (%qd bytes)%s", fs->fs_outputfile, + asprintf (&s, "Receiving %s (%qd bytes)%s", fs->fs_outputfile, (quad_t)size, size ? "" : " [appending]"); else - sprintf (s, "Receiving %s", fs->fs_outputfile); + asprintf (&s, "Receiving %s", fs->fs_outputfile); printf ("%s", s); fflush (stdout); bytestart = bytes = n; @@ -315,10 +315,12 @@ display(struct fetch_state *fs, off_t size, ssize_t n) } gettimeofday(&t, &tz); if (n == -1) { - if (size > 0) - printf ("\r%s: 100%%", s); - else - printf ("\r%s: %qd Kbytes", s, (quad_t)bytes/1024); + if(stdoutatty) { + if (size > 0) + printf ("\r%s: 100%%", s); + else + printf ("\r%s: %qd Kbytes", s, (quad_t)bytes/1024); + } bytes -= bytestart; d = t.tv_sec + t.tv_usec/1.e6 - t_start.tv_sec - t_start.tv_usec/1.e6; printf ("\n%qd bytes transfered in %.1f seconds", (quad_t)bytes, d); @@ -339,12 +341,14 @@ display(struct fetch_state *fs, off_t size, ssize_t n) return; t0 = t; pr++; - if (size > 1000000) - printf ("\r%s: %2qd%%", s, (quad_t)bytes/(size/100)); - else if (size > 0) - printf ("\r%s: %2qd%%", s, (quad_t)100*bytes/size); - else - printf ("\r%s: %qd kB", s, (quad_t)bytes/1024); + if(stdoutatty) { + if (size > 1000000) + printf ("\r%s: %2qd%%", s, (quad_t)bytes/(size/100)); + else if (size > 0) + printf ("\r%s: %2qd%%", s, (quad_t)100*bytes/size); + else + printf ("\r%s: %qd kB", s, (quad_t)bytes/1024); + } fflush (stdout); } |