1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Fall back to dot progress when forced to background.

Published in <sxs1yi8n7lx.fsf@florida.arsdigita.de>.
This commit is contained in:
hniksic 2001-12-05 23:14:35 -08:00
parent 00407b0762
commit 39b2248bde
4 changed files with 45 additions and 3 deletions

View File

@ -1,3 +1,18 @@
2001-12-06 Hrvoje Niksic <hniksic@arsdigita.com>
* progress.c (progress_create): Make sure that, when the output is
redirected, the progress implementation gets changed to the
fallback one.
(bar_set_params): Set current_impl_locked to 1 when "force" is
specified.
(progress_create): Don't change the progress implementation if
current_impl_locked is non-zero.
* main.c (redirect_output_signal): Call
progress_schedule_redirect.
* progress.c (progress_schedule_redirect): New function.
2001-12-06 Hrvoje Niksic <hniksic@arsdigita.com>
* log.c (logvprintf): Restructure to allow being called multiple

View File

@ -880,7 +880,11 @@ Can't timestamp and not clobber old files at the same time.\n"));
#ifdef HAVE_SIGNAL
/* Hangup signal handler. When wget receives SIGHUP or SIGUSR1, it
will proceed operation as usual, trying to write into a log file.
If that is impossible, the output will be turned off. */
If that is impossible, the output will be turned off.
#### It is unsafe to do call libc functions from a signal handler.
What we should do is, set a global variable, and have the code in
log.c pick it up. */
static RETSIGTYPE
redirect_output_signal (int sig)
@ -894,5 +898,6 @@ redirect_output_signal (int sig)
(sig == SIGUSR1 ? "SIGUSR1" :
"WTF?!")));
redirect_output (tmp);
progress_schedule_redirect ();
}
#endif /* HAVE_SIGNAL */

View File

@ -61,6 +61,7 @@ static struct progress_implementation implementations[] = {
{ "bar", bar_create, bar_update, bar_finish, bar_set_params }
};
static struct progress_implementation *current_impl;
int current_impl_locked;
/* Progress implementation used by default. Can be overriden in
wgetrc or by the fallback one. */
@ -111,6 +112,7 @@ set_progress_implementation (const char *name)
if (!strncmp (pi->name, name, namelen))
{
current_impl = pi;
current_impl_locked = 0;
if (colon)
/* We call pi->set_params even if colon is NULL because we
@ -125,6 +127,14 @@ set_progress_implementation (const char *name)
abort ();
}
static int output_redirected;
void
progress_schedule_redirect (void)
{
output_redirected = 1;
}
/* Create a progress gauge. INITIAL is the number of bytes the
download starts from (zero if the download starts from scratch).
TOTAL is the expected total number of bytes in this download. If
@ -134,6 +144,14 @@ set_progress_implementation (const char *name)
void *
progress_create (long initial, long total)
{
/* Check if the log status has changed under our feet. */
if (output_redirected)
{
if (!current_impl_locked)
set_progress_implementation (FALLBACK_PROGRESS_IMPLEMENTATION);
output_redirected = 0;
}
return current_impl->create (initial, total);
}
@ -653,6 +671,10 @@ bar_set_params (const char *params)
{
int sw;
if (params
&& 0 == strcmp (params, "force"))
current_impl_locked = 1;
if ((opt.lfilename
#ifdef HAVE_ISATTY
|| !isatty (fileno (stderr))
@ -660,8 +682,7 @@ bar_set_params (const char *params)
1
#endif
)
&& !(params != NULL
&& 0 == strcmp (params, "force")))
&& !current_impl_locked)
{
/* We're not printing to a TTY, so revert to the fallback
display. #### We're recursively calling

View File

@ -22,6 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
int valid_progress_implementation_p PARAMS ((const char *));
void set_progress_implementation PARAMS ((const char *));
void progress_schedule_redirect PARAMS ((void));
void *progress_create PARAMS ((long, long));
void progress_update PARAMS ((void *, long, long));