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

[svn] Only set a flag in the SIGWINCH handler.

This commit is contained in:
hniksic 2003-11-04 05:37:14 -08:00
parent 8b3985dd30
commit f4cbba565e
6 changed files with 85 additions and 31 deletions

View File

@ -1,3 +1,8 @@
2003-11-04 Hrvoje Niksic <hniksic@xemacs.org>
* configure.in: Check whether volatile is supported. Don't check
for gethostname and uname, which are not used.
2003-11-04 Hrvoje Niksic <hniksic@xemacs.org>
* configure.in: Move some checks into aclocal.m4. Check whether

View File

@ -149,14 +149,21 @@ dnl
AM_C_PROTOTYPES
dnl
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for basic compiler characteristics.
dnl
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_C_VOLATILE
AC_C_BIGENDIAN
dnl
dnl Checks for headers
dnl
AC_CHECK_HEADERS(string.h stdarg.h unistd.h sys/time.h utime.h sys/utime.h)
AC_CHECK_HEADERS(termios.h sys/ioctl.h sys/select.h sys/utsname.h)
AC_CHECK_HEADERS(inttypes.h signal.h setjmp.h pwd.h)
AC_HEADER_TIME
dnl
dnl Check integral type sizes.
dnl
@ -164,16 +171,25 @@ AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_HEADERS(inttypes.h)
AC_CHECK_TYPES(uint32_t)
dnl
dnl Checks for headers
dnl Checks for system-specific types.
dnl
AC_CHECK_HEADERS(string.h stdarg.h unistd.h sys/time.h utime.h sys/utime.h pwd.h)
AC_CHECK_HEADERS(termios.h sys/ioctl.h sys/select.h sys/utsname.h)
AC_CHECK_HEADERS(signal.h setjmp.h)
AC_HEADER_TIME
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_CHECK_TYPES(uint32_t)
AC_CHECK_TYPES(sig_atomic_t, [], [], [
#include <stdio.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_SIGNAL_H
# include <signal.h>
#endif
])
dnl
dnl Return type of signal-handlers
@ -187,8 +203,7 @@ AC_FUNC_ALLOCA
AC_FUNC_MMAP
AC_CHECK_FUNCS(strdup strstr strcasecmp strncasecmp strpbrk memmove)
AC_CHECK_FUNCS(gettimeofday mktime strptime strerror snprintf vsnprintf)
AC_CHECK_FUNCS(select sigblock sigsetjmp signal symlink access isatty)
AC_CHECK_FUNCS(uname gethostname usleep)
AC_CHECK_FUNCS(usleep select sigblock sigsetjmp signal symlink access isatty)
dnl
dnl Call Wget's local macros defined in aclocal.

View File

@ -1,5 +1,11 @@
2003-11-04 Hrvoje Niksic <hniksic@xemacs.org>
* progress.c (progress_handle_sigwinch): Don't call
determine_screen_width() from the signal handler. Instead, just
set a volatile variable.
(bar_create): Check whether SIGWINCH was received.
(bar_update): Ditto.
* sysdep.h: Define SYSTEM_FNMATCH only if HAVE_FNMATCH_H is true.
2003-11-03 Hrvoje Niksic <hniksic@xemacs.org>

View File

@ -64,6 +64,9 @@ char *alloca ();
/* Define to empty or __inline__ or __inline. */
#undef inline
/* Define `volatile' to be empty if the compiler doesn't support it. */
#undef volatile
/* Define to `unsigned' if <sys/types.h> doesn't define. */
#undef size_t
@ -116,15 +119,9 @@ char *alloca ();
/* Define if you have struct utimbuf. */
#undef HAVE_STRUCT_UTIMBUF
/* Define if you have the uname function. */
#undef HAVE_UNAME
/* Define if you have a working version of mmap. */
#undef HAVE_MMAP
/* Define if you have the gethostname function. */
#undef HAVE_GETHOSTNAME
/* Define if you have the select function. */
#undef HAVE_SELECT
@ -287,6 +284,9 @@ char *alloca ();
/* Define if you have uint32_t. */
#undef HAVE_UINT32_T
/* Define if you have sig_atomic_t. */
#undef HAVE_SIG_ATOMIC_T
/* Some autoconf-unrelated preprocessor magic that cannot be in
sysdep.h because it must be done before including the system
headers. */

View File

@ -408,7 +408,13 @@ dot_set_params (const char *params)
create_image will overflow the buffer. */
#define MINIMUM_SCREEN_WIDTH 45
static int screen_width = DEFAULT_SCREEN_WIDTH;
/* The last known screen width. This can be updated by the code that
detects that SIGWINCH was received (but it's never updated from the
signal handler). */
static int screen_width;
/* A flag that, when set, means SIGWINCH was received. */
static volatile sig_atomic_t received_sigwinch;
/* Size of the download speed history ring. */
#define DLSPEED_HISTORY_SIZE 20
@ -484,6 +490,18 @@ bar_create (long initial, long total)
bp->initial_length = initial;
bp->total_length = total;
/* Initialize screen_width if this hasn't been done or if it might
have changed, as indicated by receiving SIGWINCH. */
if (!screen_width || received_sigwinch)
{
screen_width = determine_screen_width ();
if (!screen_width)
screen_width = DEFAULT_SCREEN_WIDTH;
else if (screen_width < MINIMUM_SCREEN_WIDTH)
screen_width = MINIMUM_SCREEN_WIDTH;
received_sigwinch = 0;
}
/* - 1 because we don't want to use the last screen column. */
bp->width = screen_width - 1;
/* + 1 for the terminating zero. */
@ -517,12 +535,24 @@ bar_update (void *progress, long howmuch, double dltime)
update_speed_ring (bp, howmuch, dltime);
if (screen_width - 1 != bp->width)
/* If SIGWINCH (the window size change signal) been received,
determine the new screen size and update the screen. */
if (received_sigwinch)
{
int old_width = screen_width;
screen_width = determine_screen_width ();
if (!screen_width)
screen_width = DEFAULT_SCREEN_WIDTH;
else if (screen_width < MINIMUM_SCREEN_WIDTH)
screen_width = MINIMUM_SCREEN_WIDTH;
if (screen_width != old_width)
{
bp->width = screen_width - 1;
bp->buffer = xrealloc (bp->buffer, bp->width + 1);
force_screen_update = 1;
}
received_sigwinch = 0;
}
if (dltime - bp->last_screen_update < 200 && !force_screen_update)
/* Don't update more often than five times per second. */
@ -844,7 +874,6 @@ display_image (char *buf)
static void
bar_set_params (const char *params)
{
int sw;
char *term = getenv ("TERM");
if (params
@ -877,19 +906,13 @@ bar_set_params (const char *params)
set_progress_implementation (FALLBACK_PROGRESS_IMPLEMENTATION);
return;
}
sw = determine_screen_width ();
if (sw && sw >= MINIMUM_SCREEN_WIDTH)
screen_width = sw;
}
#ifdef SIGWINCH
RETSIGTYPE
progress_handle_sigwinch (int sig)
{
int sw = determine_screen_width ();
if (sw && sw >= MINIMUM_SCREEN_WIDTH)
screen_width = sw;
received_sigwinch = 1;
signal (SIGWINCH, progress_handle_sigwinch);
}
#endif

View File

@ -252,6 +252,11 @@ void *memcpy ();
int fnmatch ();
#endif
/* Provide sig_atomic_t if the system doesn't. */
#ifndef HAVE_SIG_ATOMIC_T
typedef int sig_atomic_t;
#endif
/* Provide uint32_t on the platforms that don't define it. Although
most code should be agnostic about integer sizes, some code really
does need a 32-bit integral type. Such code should use uint32_t.