+2005-06-25 Hrvoje Niksic <hniksic@xemacs.org>
+
+ * utils.c (with_thousand_seps_sum): Now defined only if
+ SUM_SIZE_INT is double.
+
+ * wget.h (SUM_SIZE_INT): Instead of bothering with long, long
+ long, __int64, and friends, simply either use wgint or double, end
+ of story. Since we know how to print either, we no longer need
+ LARGE_INT_FMT.
+
+ * sysdeps.h (LARGE_INT): Renamed to SUM_SIZE_INT to better reflect
+ its intent, and moved to wget.h.
+
2005-06-25 Hrvoje Niksic <hniksic@xemacs.org>
* Makefile.in: No need to clean .libs.
#include "convert.h" /* for downloaded_file */
#include "recur.h" /* for INFINITE_RECURSION */
-extern LARGE_INT total_downloaded_bytes;
+extern SUM_SIZE_INT total_downloaded_bytes;
/* File where the "ls -al" listing will be saved. */
#define LIST_FILENAME ".listing"
#include "convert.h"
extern char *version_string;
-extern LARGE_INT total_downloaded_bytes;
+extern SUM_SIZE_INT total_downloaded_bytes;
extern FILE *output_stream;
extern bool output_stream_regular;
CMD_DECLARE (cmd_boolean);
CMD_DECLARE (cmd_bytes);
-CMD_DECLARE (cmd_bytes_large);
+CMD_DECLARE (cmd_bytes_sum);
#ifdef HAVE_SSL
CMD_DECLARE (cmd_cert_type);
#endif
{ "proxypassword", &opt.proxy_passwd, cmd_string },
{ "proxyuser", &opt.proxy_user, cmd_string },
{ "quiet", &opt.quiet, cmd_boolean },
- { "quota", &opt.quota, cmd_bytes_large },
+ { "quota", &opt.quota, cmd_bytes_sum },
#ifdef HAVE_SSL
{ "randomfile", &opt.random_file, cmd_file },
#endif
return true;
}
-/* Engine for cmd_bytes and cmd_bytes_large: converts a string such as
+/* Engine for cmd_bytes and cmd_bytes_sum: converts a string such as
"100k" or "2.5G" to a floating point number. */
static bool
}
/* Like cmd_bytes, but PLACE is interpreted as a pointer to
- LARGE_INT. It works by converting the string to double, therefore
+ SIZE_SUM. It works by converting the string to double, therefore
working with values up to 2^53-1 without loss of precision. This
value (8192 TB) is large enough to serve for a while. */
static bool
-cmd_bytes_large (const char *com, const char *val, void *place)
+cmd_bytes_sum (const char *com, const char *val, void *place)
{
double byte_value;
if (!parse_bytes_helper (val, &byte_value))
exec_name, com, val);
return false;
}
- *(LARGE_INT *)place = (LARGE_INT)byte_value;
+ *(SUM_SIZE_INT *) place = (SUM_SIZE_INT) byte_value;
return true;
}
struct options opt;
-extern LARGE_INT total_downloaded_bytes;
+extern SUM_SIZE_INT total_downloaded_bytes;
extern char *version_string;
extern struct cookie_jar *wget_cookie_jar;
{
logprintf (LOG_NOTQUIET,
_("\nFINISHED --%s--\nDownloaded: %s bytes in %d files\n"),
- time_str (NULL), with_thousand_seps_large (total_downloaded_bytes),
+ time_str (NULL),
+ with_thousand_seps_sum (total_downloaded_bytes),
opt.numurls);
/* Print quota warning, if exceeded. */
if (opt.quota && total_downloaded_bytes > opt.quota)
logprintf (LOG_NOTQUIET,
_("Download quota (%s bytes) EXCEEDED!\n"),
- with_thousand_seps_large (opt.quota));
+ with_thousand_seps_sum (opt.quota));
}
if (opt.cookies_output)
wgint limit_rate; /* Limit the download rate to this
many bps. */
- LARGE_INT quota; /* Maximum file size to download and
+ SUM_SIZE_INT quota; /* Maximum file size to download and
store. */
int numurls; /* Number of successfully downloaded
#include "convert.h"
extern char *version_string;
-extern LARGE_INT total_downloaded_bytes;
+extern SUM_SIZE_INT total_downloaded_bytes;
extern struct hash_table *dl_url_file_map;
extern struct hash_table *downloaded_html_set;
#include "ptimer.h"
/* Total size of downloaded files. Used to enforce quota. */
-LARGE_INT total_downloaded_bytes;
+SUM_SIZE_INT total_downloaded_bytes;
/* If non-NULL, the stream to which output should be written. This
stream is initialized when `-O' is used. */
# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
#endif
-/* Define a large integral type useful for storing large sizes that
- exceed sizes of one download, such as when printing the sum of all
- downloads. Note that this has nothing to do with large file
- support, which determines the wgint type. This should be as large
- as possible even on systems where when wgint is 32-bit; also,
- unlike wgint, this can be a floating point type.
-
- We use a 64-bit integral type where available, `double' otherwise.
- It's hard to print LARGE_INT's portably, but fortunately it's
- rarely needed. */
-
-#if SIZEOF_LONG >= 8
-/* Long is large enough: use it. */
-typedef long LARGE_INT;
-# define LARGE_INT_FMT "%ld"
-#elif SIZEOF_LONG_LONG >= 8
-/* Long long is large enough: use it. */
-typedef long long LARGE_INT;
-# define LARGE_INT_FMT "%lld"
-#elif WINDOWS
-/* Use __int64 under Windows. */
-typedef __int64 LARGE_INT;
-# define LARGE_INT_FMT "%I64"
-#else
-/* Large integer type unavailable; fake it with `double'. */
-typedef double LARGE_INT;
-# define LARGE_INT_FMT "%.0f"
-#endif
-
/* These are needed so we can #define struct_stat to struct _stati64
under Windows. */
#ifndef struct_stat
\f
/* Add thousand separators to a number already in string form. Used
- by with_thousand_seps and with_thousand_seps_large. */
+ by with_thousand_seps and with_thousand_seps_sum. */
static char *
add_thousand_seps (const char *repr)
return add_thousand_seps (inbuf);
}
-/* Write a string representation of LARGE_INT NUMBER into the provided
- buffer.
-
- It would be dangerous to use sprintf, because the code wouldn't
- work on a machine with gcc-provided long long support, but without
- libc support for "%lld". However, such old systems platforms
- typically lack snprintf and will end up using our version, which
- does support "%lld" whereever long longs are available. */
-
-static void
-large_int_to_string (char *buffer, int bufsize, LARGE_INT number)
-{
- snprintf (buffer, bufsize, LARGE_INT_FMT, number);
-}
-
-/* The same as with_thousand_seps, but works on LARGE_INT. */
+/* When SUM_SIZE_INT is wgint, with_thousand_seps_large is #defined to
+ with_thousand_seps. The function below is used on non-LFS systems
+ where SUM_SIZE_INT typedeffed to double. */
+#ifndef with_thousand_seps_sum
char *
-with_thousand_seps_large (LARGE_INT l)
+with_thousand_seps_sum (SUM_SIZE_INT l)
{
- char inbuf[48];
- large_int_to_string (inbuf, sizeof (inbuf), l);
+ char inbuf[64];
+ snprintf (inbuf, sizeof (inbuf), "%.0f", l);
return add_thousand_seps (inbuf);
}
+#endif /* not with_thousand_seps_sum */
/* N, a byte quantity, is converted to a human-readable abberviated
form a la sizes printed by `ls -lh'. The result is written to a
void free_keys_and_values (struct hash_table *);
char *with_thousand_seps (wgint);
-char *with_thousand_seps_large (LARGE_INT);
+#ifndef with_thousand_seps_sum
+char *with_thousand_seps_sum (SUM_SIZE_INT);
+#endif
char *human_readable (wgint);
int numdigit (wgint);
char *number_to_string (char *, wgint);
# endif
#endif
+/* Now define a large integral type useful for storing sizes of *sums*
+ of downloads, such as the value of the --quota option. This should
+ be a type able to hold 2G+ values even on systems without large
+ file support. (It is useful to limit Wget's download quota to say
+ 10G even if a single file cannot be that large.)
+
+ To make sure we get the largest size possible, we use `double' on
+ systems without a 64-bit integral type. (Since it is used in very
+ few places in Wget, this is acceptable.) */
+
+#if SIZEOF_WGINT >= 8
+/* just use wgint, which we already know how to print */
+typedef wgint SUM_SIZE_INT;
+# define with_thousand_seps_sum with_thousand_seps
+#else
+/* On systems without LFS, use double, which buys us integers up to 2^53. */
+typedef double SUM_SIZE_INT;
+#endif
+
#include "options.h"
/* Everything uses this, so include them here directly. */