📄 main.c
字号:
exit (2); } /* Find the short option character in the mapping. */ longindex = optmap[ret - 32]; } val = long_options[longindex].val; /* Use the retrieved value to locate the option in the option_data array, and to see if we're dealing with the negated "--no-FOO" variant of the boolean option "--foo". */ opt = &option_data[val & ~BOOLEAN_NEG_MARKER]; switch (opt->type) { case OPT_VALUE: setoptval (opt->data, optarg, opt->long_name); break; case OPT_BOOLEAN: if (optarg) /* The user has specified a value -- use it. */ setoptval (opt->data, optarg, opt->long_name); else { /* NEG is true for `--no-FOO' style boolean options. */ bool neg = !!(val & BOOLEAN_NEG_MARKER); setoptval (opt->data, neg ? "0" : "1", opt->long_name); } break; case OPT_FUNCALL: { void (*func) (void) = (void (*) (void)) opt->data; func (); } break; case OPT__APPEND_OUTPUT: setoptval ("logfile", optarg, opt->long_name); append_to_log = true; break; case OPT__EXECUTE: run_command (optarg); break; case OPT__NO: { /* We support real --no-FOO flags now, but keep these short options for convenience and backward compatibility. */ char *p; for (p = optarg; *p; p++) switch (*p) { case 'v': setoptval ("verbose", "0", opt->long_name); break; case 'H': setoptval ("addhostdir", "0", opt->long_name); break; case 'd': setoptval ("dirstruct", "0", opt->long_name); break; case 'c': setoptval ("noclobber", "1", opt->long_name); break; case 'p': setoptval ("noparent", "1", opt->long_name); break; default: printf (_("%s: illegal option -- `-n%c'\n"), exec_name, *p); print_usage (); printf ("\n"); printf (_("Try `%s --help' for more options.\n"), exec_name); exit (1); } break; } case OPT__PARENT: case OPT__CLOBBER: { /* The wgetrc commands are named noparent and noclobber, so we must revert the meaning of the cmdline options before passing the value to setoptval. */ bool flag = true; if (optarg) flag = (*optarg == '1' || TOLOWER (*optarg) == 'y' || (TOLOWER (optarg[0]) == 'o' && TOLOWER (optarg[1]) == 'n')); setoptval (opt->type == OPT__PARENT ? "noparent" : "noclobber", flag ? "0" : "1", opt->long_name); break; } case OPT__DONT_REMOVE_LISTING: setoptval ("removelisting", "0", opt->long_name); break; } longindex = -1; } nurl = argc - optind; /* All user options have now been processed, so it's now safe to do interoption dependency checks. */ if (opt.reclevel == 0) opt.reclevel = INFINITE_RECURSION; /* see recur.h for commentary on this */ if (opt.page_requisites && !opt.recursive) { /* Don't set opt.recursive here because it would confuse the FTP code. Instead, call retrieve_tree below when either page_requisites or recursive is requested. */ opt.reclevel = 0; if (!opt.no_dirstruct) opt.dirstruct = 1; /* normally handled by cmd_spec_recursive() */ } if (opt.verbose == -1) opt.verbose = !opt.quiet; /* Sanity checks. */ if (opt.verbose && opt.quiet) { printf (_("Can't be verbose and quiet at the same time.\n")); print_usage (); exit (1); } if (opt.timestamping && opt.noclobber) { printf (_("\Can't timestamp and not clobber old files at the same time.\n")); print_usage (); exit (1); }#ifdef ENABLE_IPV6 if (opt.ipv4_only && opt.ipv6_only) { printf (_("Cannot specify both --inet4-only and --inet6-only.\n")); print_usage (); exit (1); }#endif if (opt.output_document && (opt.page_requisites || opt.recursive || opt.timestamping)) { printf (_("Cannot specify -r, -p or -N if -O is given.\n")); print_usage (); exit (1); } if (opt.output_document && opt.convert_links && nurl > 1) { printf (_("Cannot specify both -k and -O if multiple URLs are given.\n")); print_usage (); exit (1); } if (!nurl && !opt.input_filename) { /* No URL specified. */ printf (_("%s: missing URL\n"), exec_name); print_usage (); printf ("\n"); /* #### Something nicer should be printed here -- similar to the pre-1.5 `--help' page. */ printf (_("Try `%s --help' for more options.\n"), exec_name); exit (1); }#ifdef MSDOS if (opt.wdebug) dbug_init(); sock_init();#else if (opt.background) fork_to_background ();#endif /* Initialize progress. Have to do this after the options are processed so we know where the log file is. */ if (opt.verbose) set_progress_implementation (opt.progress_type); /* Fill in the arguments. */ url = alloca_array (char *, nurl + 1); for (i = 0; i < nurl; i++, optind++) { char *rewritten = rewrite_shorthand_url (argv[optind]); if (rewritten) url[i] = rewritten; else url[i] = xstrdup (argv[optind]); } url[i] = NULL; /* Initialize logging. */ log_init (opt.lfilename, append_to_log); DEBUGP (("DEBUG output created by Wget %s on %s.\n\n", version_string, OS_TYPE)); /* Open the output filename if necessary. */ if (opt.output_document) { if (HYPHENP (opt.output_document)) output_stream = stdout; else { struct_fstat st; output_stream = fopen (opt.output_document, opt.always_rest ? "ab" : "wb"); if (output_stream == NULL) { perror (opt.output_document); exit (1); } if (fstat (fileno (output_stream), &st) == 0 && S_ISREG (st.st_mode)) output_stream_regular = true; } }#ifdef WINDOWS ws_startup ();#endif#ifdef SIGHUP /* Setup the signal handler to redirect output when hangup is received. */ if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, redirect_output_signal);#endif /* ...and do the same for SIGUSR1. */#ifdef SIGUSR1 signal (SIGUSR1, redirect_output_signal);#endif#ifdef SIGPIPE /* Writing to a closed socket normally signals SIGPIPE, and the process exits. What we want is to ignore SIGPIPE and just check for the return value of write(). */ signal (SIGPIPE, SIG_IGN);#endif#ifdef SIGWINCH signal (SIGWINCH, progress_handle_sigwinch);#endif status = RETROK; /* initialize it, just-in-case */ /* Retrieve the URLs from argument list. */ for (t = url; *t; t++) { char *filename = NULL, *redirected_URL = NULL; int dt; if ((opt.recursive || opt.page_requisites) && (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (*t))) { int old_follow_ftp = opt.follow_ftp; /* Turn opt.follow_ftp on in case of recursive FTP retrieval */ if (url_scheme (*t) == SCHEME_FTP) opt.follow_ftp = 1; status = retrieve_tree (*t); opt.follow_ftp = old_follow_ftp; } else status = retrieve_url (*t, &filename, &redirected_URL, NULL, &dt, opt.recursive); if (opt.delete_after && file_exists_p(filename)) { DEBUGP (("Removing file due to --delete-after in main():\n")); logprintf (LOG_VERBOSE, _("Removing %s.\n"), filename); if (unlink (filename)) logprintf (LOG_NOTQUIET, "unlink: %s\n", strerror (errno)); } xfree_null (redirected_URL); xfree_null (filename); } /* And then from the input file, if any. */ if (opt.input_filename) { int count; status = retrieve_from_file (opt.input_filename, opt.force_html, &count); if (!count) logprintf (LOG_NOTQUIET, _("No URLs found in %s.\n"), opt.input_filename); } /* Print broken links. */ if (opt.recursive && opt.spider) { print_broken_links(); } /* Print the downloaded sum. */ if ((opt.recursive || opt.page_requisites || nurl > 1 || (opt.input_filename && total_downloaded_bytes != 0)) && total_downloaded_bytes != 0) { logprintf (LOG_NOTQUIET, _("FINISHED --%s--\nDownloaded: %d files, %s in %s (%s)\n"), datetime_str (time (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 of %s EXCEEDED!\n"), human_readable (opt.quota)); } if (opt.cookies_output) save_cookies (); if (opt.convert_links && !opt.delete_after) convert_all_links (); log_close (); for (i = 0; i < nurl; i++) xfree (url[i]); cleanup ();#ifdef DEBUG_MALLOC print_malloc_debug_stats ();#endif if (status == RETROK) return 0; else return 1;}#endif /* TESTING */#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. */static voidredirect_output_signal (int sig){ const char *signal_name = (sig == SIGHUP ? "SIGHUP" : (sig == SIGUSR1 ? "SIGUSR1" : "WTF?!")); log_request_redirect_output (signal_name); progress_schedule_redirect (); signal (sig, redirect_output_signal);}#endif/* * vim: et ts=2 sw=2 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -