/* Command line parsing.
- Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1996-2005 Free Software Foundation, Inc.
This file is part of GNU Wget.
GNU General Public License for more details.
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.
+along with Wget; if not, write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
In addition, as a special exception, the Free Software Foundation
gives permission to link the code of its release of Wget with the
#endif /* HAVE_UNISTD_H */
#include <string.h>
#include <signal.h>
-#if defined(HAVE_NLS) && defined(HAVE_LOCALE_H)
+#ifdef HAVE_NLS
# include <locale.h>
#endif
#include <assert.h>
#include "url.h"
#include "progress.h" /* for progress_handle_sigwinch */
#include "convert.h"
+#include "http.h" /* for save_cookies */
/* On GNU system this will include system-wide getopt.h. */
#include "getopt.h"
struct options opt;
-extern LARGE_INT total_downloaded_bytes;
extern char *version_string;
-extern struct cookie_jar *wget_cookie_jar;
-
+#if defined(SIGHUP) || defined(SIGUSR1)
static void redirect_output_signal (int);
+#endif
const char *exec_name;
\f
/* HAVE_NLS implies existence of functions invoked here. */
#ifdef HAVE_NLS
/* Set the current locale. */
- /* Where possible, sets only LC_MESSAGES and LC_CTYPE. Other
- categories, such as numeric, time, or collation, break code that
- parses data received from the network and relies on C-locale
- behavior of libc functions. For example, Solaris strptime fails
- to recognize English month names in non-English locales, which
- breaks http_atotm. Some implementations of fnmatch perform
- unwanted case folding in non-C locales. ctype macros, while they
- were used, provided another example against LC_ALL. */
-#if defined(LC_MESSAGES) && defined(LC_CTYPE)
- setlocale (LC_MESSAGES, "");
- setlocale (LC_CTYPE, ""); /* safe because we use safe-ctype */
-#else
setlocale (LC_ALL, "");
-#endif
/* Set the text message domain. */
bindtextdomain ("wget", LOCALEDIR);
textdomain ("wget");
#endif
#ifdef ENABLE_DEBUG
-# define IF_DEBUG(x) x
+# define WHEN_DEBUG(x) x
#else
-# define IF_DEBUG(x) NULL
+# define WHEN_DEBUG(x) NULL
#endif
struct cmdline_option {
int argtype; /* for non-standard options */
};
-struct cmdline_option option_data[] =
+static struct cmdline_option option_data[] =
{
{ "accept", 'A', OPT_VALUE, "accept", -1 },
{ "append-output", 'a', OPT__APPEND_OUTPUT, NULL, required_argument },
{ "convert-links", 'k', OPT_BOOLEAN, "convertlinks", -1 },
{ "cookies", 0, OPT_BOOLEAN, "cookies", -1 },
{ "cut-dirs", 0, OPT_VALUE, "cutdirs", -1 },
- { IF_DEBUG ("debug"), 'd', OPT_BOOLEAN, "debug", -1 },
+ { WHEN_DEBUG ("debug"), 'd', OPT_BOOLEAN, "debug", -1 },
{ "delete-after", 0, OPT_BOOLEAN, "deleteafter", -1 },
{ "directories", 0, OPT_BOOLEAN, "dirstruct", -1 },
{ "directory-prefix", 'P', OPT_VALUE, "dirprefix", -1 },
{ "waitretry", 0, OPT_VALUE, "waitretry", -1 },
};
-#undef IF_DEBUG
+#undef WHEN_DEBUG
#undef IF_SSL
/* Return a string that contains S with "no-" prepended. The string
N_("\
-K, --backup-converted before converting file X, back up as X.orig.\n"),
N_("\
- -m, --mirror shortcut option equivalent to -r -N -l inf -nr.\n"),
+ -m, --mirror shortcut for -N -r -l inf --no-remove-listing.\n"),
N_("\
-p, --page-requisites get all images, etc. needed to display HTML page.\n"),
N_("\
exit (0);
}
+/* Return a human-readable printed representation of INTERVAL,
+ measured in seconds. */
+
+static char *
+secs_to_human_time (double interval)
+{
+ static char buf[32];
+ int secs = (int) (interval + 0.5);
+ int hours, mins, days;
+
+ days = secs / 86400, secs %= 86400;
+ hours = secs / 3600, secs %= 3600;
+ mins = secs / 60, secs %= 60;
+
+ if (days)
+ sprintf (buf, "%dd %dh %dm %ds", days, hours, mins, secs);
+ else if (hours)
+ sprintf (buf, "%dh %dm %ds", hours, mins, secs);
+ else if (mins)
+ sprintf (buf, "%dm %ds", mins, secs);
+ else
+ sprintf (buf, "%ss", print_decimal (interval));
+
+ return buf;
+}
+
static void
print_version (void)
{
char **url, **t;
int i, ret, longindex;
int nurl, status;
- int append_to_log = 0;
+ bool append_to_log = false;
i18n_initialize ();
else
{
/* NEG is true for `--no-FOO' style boolean options. */
- int neg = val & BOOLEAN_NEG_MARKER;
+ bool neg = !!(val & BOOLEAN_NEG_MARKER);
setoptval (opt->data, neg ? "0" : "1", opt->long_name);
}
break;
break;
case OPT__APPEND_OUTPUT:
setoptval ("logfile", optarg, opt->long_name);
- append_to_log = 1;
+ append_to_log = true;
break;
case OPT__EXECUTE:
run_command (optarg);
/* The wgetrc commands are named noparent and noclobber,
so we must revert the meaning of the cmdline options
before passing the value to setoptval. */
- int flag = 1;
+ bool flag = true;
if (optarg)
flag = (*optarg == '1' || TOLOWER (*optarg) == 'y'
|| (TOLOWER (optarg[0]) == 'o'
/* Open the output filename if necessary. */
if (opt.output_document)
{
- extern FILE *output_stream;
- extern int output_stream_regular;
-
if (HYPHENP (opt.output_document))
output_stream = stdout;
else
{
- struct_stat st;
+ struct_fstat st;
output_stream = fopen (opt.output_document,
opt.always_rest ? "ab" : "wb");
if (output_stream == NULL)
exit (1);
}
if (fstat (fileno (output_stream), &st) == 0 && S_ISREG (st.st_mode))
- output_stream_regular = 1;
+ output_stream_regular = true;
}
}
|| (opt.input_filename && total_downloaded_bytes != 0))
{
logprintf (LOG_NOTQUIET,
- _("\nFINISHED --%s--\nDownloaded: %s bytes in %d files\n"),
- time_str (NULL), with_thousand_seps_large (total_downloaded_bytes),
- opt.numurls);
+ _("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"),
+ time_str (NULL),
+ opt.numurls,
+ human_readable (total_downloaded_bytes),
+ secs_to_human_time (total_download_time),
+ retr_rate (total_downloaded_bytes, total_download_time));
/* 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));
+ _("Download quota of %s EXCEEDED!\n"),
+ human_readable (opt.quota));
}
if (opt.cookies_output)
}
\f
#if defined(SIGHUP) || defined(SIGUSR1)
+
+/* So the signal_name check doesn't blow when only one is available. */
+#ifndef SIGHUP
+# define SIGHUP -1
+#endif
+#ifndef SIGUSR1
+# define SIGUSR1 -1
+#endif
+
/* 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. */