diff options
author | John-Mark Gurney <jmg@FreeBSD.org> | 1997-02-14 19:08:18 +0000 |
---|---|---|
committer | John-Mark Gurney <jmg@FreeBSD.org> | 1997-02-14 19:08:18 +0000 |
commit | 88e8266d80952d975529dc1a8f451e78100204d6 (patch) | |
tree | bb507265d688210fbf061f7772dbfdcfe0cb2129 /usr.bin/fetch | |
parent | d0390e0570c8bab47d99720f0e5a074ed9937840 (diff) | |
download | src-88e8266d80952d975529dc1a8f451e78100204d6.tar.gz src-88e8266d80952d975529dc1a8f451e78100204d6.zip |
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
Notes
Notes:
svn path=/head/; revision=22720
Diffstat (limited to 'usr.bin/fetch')
-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 2aa7b9eb259c..57f1d408c564 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); } |