/* Download progress.
- Copyright (C) 2001 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU Wget.
You should have received a copy of the GNU General Public License
along with Wget; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+In addition, as a special exception, the Free Software Foundation
+gives permission to link the code of its release of Wget with the
+OpenSSL project's "OpenSSL" library (or with modified versions of it
+that use the same license as the "OpenSSL" library), and distribute
+the linked executables. You must obey the GNU General Public License
+in all respects for all of the code used other than "OpenSSL". If you
+modify this file, you may extend this exception to your version of the
+file, but you are not obligated to do so. If you do not wish to do
+so, delete this exception statement from your version. */
#include <config.h>
struct progress_implementation {
char *name;
- void *(*create) (long, long);
- void (*update) (void *, long, long);
- void (*finish) (void *, long);
- void (*set_params) (const char *);
+ void *(*create) PARAMS ((long, long));
+ void (*update) PARAMS ((void *, long, long));
+ void (*finish) PARAMS ((void *, long));
+ void (*set_params) PARAMS ((const char *));
};
/* Necessary forward declarations. */
memset (bp, 0, sizeof (*bp));
+ /* In theory, our callers should take care of this pathological
+ case, but it can sometimes happen. */
+ if (initial > total)
+ total = initial;
+
bp->initial_length = initial;
bp->total_length = total;
adjust bp->total_length to the new reality, so that the code in
create_image() that depends on total size being smaller or
equal to the expected size doesn't abort. */
- bp->total_length = bp->count + bp->initial_length;
+ bp->total_length = bp->initial_length + bp->count;
/* This code attempts to determine the current download speed. We
measure the speed over the interval of approximately three
{
struct bar_progress *bp = progress;
+ if (bp->total_length > 0
+ && bp->count + bp->initial_length > bp->total_length)
+ /* See bar_update() for explanation. */
+ bp->total_length = bp->initial_length + bp->count;
+
create_image (bp, dltime);
display_image (bp->buffer);
bar_set_params (const char *params)
{
int sw;
+ char *term = getenv ("TERM");
if (params
&& 0 == strcmp (params, "force"))
if ((opt.lfilename
#ifdef HAVE_ISATTY
+ /* The progress bar doesn't make sense if the output is not a
+ TTY -- when logging to file, it is better to review the
+ dots. */
|| !isatty (fileno (stderr))
#else
1
#endif
+ /* Normally we don't depend on terminal type because the
+ progress bar only uses ^M to move the cursor to the
+ beginning of line, which works even on dumb terminals. But
+ Jamie Zawinski reports that ^M and ^H tricks don't work in
+ Emacs shell buffers, and only make a mess. */
+ || (term && 0 == strcmp (term, "emacs"))
)
&& !current_impl_locked)
{