⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c

📁 wget (command line browser) source code
💻 C
📖 第 1 页 / 共 3 页
字号:
  return 1;}/* Parse VAL as a number and set its value to CLOSURE (which should   point to a long int).   By default, the value is assumed to be in bytes.  If "K", "M", or   "G" are appended, the value is multiplied with 1<<10, 1<<20, or   1<<30, respectively.  Floating point values are allowed and are   cast to integer before use.  The idea is to be able to use things   like 1.5k instead of "1536".   The string "inf" is returned as 0.   In case of error, 0 is returned and memory pointed to by CLOSURE   remains unmodified.  */static intcmd_bytes (const char *com, const char *val, void *closure){  double byte_value;  if (!parse_bytes_helper (val, &byte_value))    {      fprintf (stderr, _("%s: %s: Invalid byte value `%s'\n"),	       exec_name, com, val);      return 0;    }  *(long *)closure = (long)byte_value;  return 1;}/* Like cmd_bytes, but CLOSURE is interpreted as a pointer to   LARGE_INT.  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 intcmd_bytes_large (const char *com, const char *val, void *closure){  double byte_value;  if (!parse_bytes_helper (val, &byte_value))    {      fprintf (stderr, _("%s: %s: Invalid byte value `%s'\n"),	       exec_name, com, val);      return 0;    }  *(LARGE_INT *)closure = (LARGE_INT)byte_value;  return 1;}/* Store the value of VAL to *OUT.  The value is a time period, by   default expressed in seconds, but also accepting suffixes "m", "h",   "d", and "w" for minutes, hours, days, and weeks respectively.  */static intcmd_time (const char *com, const char *val, void *closure){  double number, mult;  const char *end = val + strlen (val);  /* Strip trailing whitespace.  */  while (val < end && ISSPACE (end[-1]))    --end;  if (val == end)    {    err:      fprintf (stderr, _("%s: %s: Invalid time period `%s'\n"),	       exec_name, com, val);      return 0;    }  switch (TOLOWER (end[-1]))    {    case 's':      --end, mult = 1;		/* seconds */      break;    case 'm':      --end, mult = 60;		/* minutes */      break;    case 'h':      --end, mult = 3600;	/* hours */      break;    case 'd':      --end, mult = 86400.0;	/* days */      break;    case 'w':      --end, mult = 604800.0;	/* weeks */      break;    default:      /* Not a recognized suffix: assume it belongs to the number.	 (If not, atof simple_atof will raise an error.)  */      mult = 1;    }  /* Skip leading and trailing whitespace. */  while (val < end && ISSPACE (*val))    ++val;  while (val < end && ISSPACE (end[-1]))    --end;  if (val == end)    goto err;  if (!simple_atof (val, end, &number))    goto err;  *(double *)closure = number * mult;  return 1;}/* Specialized helper functions, used by `commands' to handle some   options specially.  */static int check_user_specified_header PARAMS ((const char *));static intcmd_spec_dirstruct (const char *com, const char *val, void *closure){  if (!cmd_boolean (com, val, &opt.dirstruct))    return 0;  /* Since dirstruct behaviour is explicitly changed, no_dirstruct     must be affected inversely.  */  if (opt.dirstruct)    opt.no_dirstruct = 0;  else    opt.no_dirstruct = 1;  return 1;}static intcmd_spec_header (const char *com, const char *val, void *closure){  if (!*val)    {      /* Empty header means reset headers.  */      FREE_MAYBE (opt.user_header);      opt.user_header = NULL;    }  else    {      int i;      if (!check_user_specified_header (val))	{	  fprintf (stderr, _("%s: %s: Invalid header `%s'.\n"),		   exec_name, com, val);	  return 0;	}      i = opt.user_header ? strlen (opt.user_header) : 0;      opt.user_header = (char *)xrealloc (opt.user_header, i + strlen (val)					  + 2 + 1);      strcpy (opt.user_header + i, val);      i += strlen (val);      opt.user_header[i++] = '\r';      opt.user_header[i++] = '\n';      opt.user_header[i] = '\0';    }  return 1;}static intcmd_spec_htmlify (const char *com, const char *val, void *closure){  int flag = cmd_boolean (com, val, &opt.htmlify);  if (flag && !opt.htmlify)    opt.remove_listing = 0;  return flag;}/* Set the "mirror" mode.  It means: recursive download, timestamping,   no limit on max. recursion depth, and don't remove listings.  */static intcmd_spec_mirror (const char *com, const char *val, void *closure){  int mirror;  if (!cmd_boolean (com, val, &mirror))    return 0;  if (mirror)    {      opt.recursive = 1;      if (!opt.no_dirstruct)	opt.dirstruct = 1;      opt.timestamping = 1;      opt.reclevel = INFINITE_RECURSION;      opt.remove_listing = 0;    }  return 1;}/* Set progress.type to VAL, but verify that it's a valid progress   implementation before that.  */static intcmd_spec_progress (const char *com, const char *val, void *closure){  if (!valid_progress_implementation_p (val))    {      fprintf (stderr, _("%s: %s: Invalid progress type `%s'.\n"),	       exec_name, com, val);      return 0;    }  FREE_MAYBE (opt.progress_type);  /* Don't call set_progress_implementation here.  It will be called     in main() when it becomes clear what the log output is.  */  opt.progress_type = xstrdup (val);  return 1;}/* Set opt.recursive to VAL as with cmd_boolean.  If opt.recursive is   set to true, also set opt.dirstruct to 1, unless opt.no_dirstruct   is specified.  */static intcmd_spec_recursive (const char *com, const char *val, void *closure){  if (!cmd_boolean (com, val, &opt.recursive))    return 0;  else    {      if (opt.recursive && !opt.no_dirstruct)	opt.dirstruct = 1;    }  return 1;}static intcmd_spec_restrict_file_names (const char *com, const char *val, void *closure){  int restrict_os = opt.restrict_files_os;  int restrict_ctrl = opt.restrict_files_ctrl;  const char *end = strchr (val, ',');  if (!end)    end = val + strlen (val);#define VAL_IS(string_literal) BOUNDED_EQUAL (val, end, string_literal)  if (VAL_IS ("unix"))    restrict_os = restrict_unix;  else if (VAL_IS ("windows"))    restrict_os = restrict_windows;  else if (VAL_IS ("nocontrol"))    restrict_ctrl = 0;  else    {    err:      fprintf (stderr,	       _("%s: %s: Invalid restriction `%s', use `unix' or `windows'.\n"),	       exec_name, com, val);      return 0;    }#undef VAL_IS  if (*end)    {      if (!strcmp (end + 1, "nocontrol"))	restrict_ctrl = 0;      else	goto err;    }  opt.restrict_files_os = restrict_os;  opt.restrict_files_ctrl = restrict_ctrl;  return 1;}/* Set all three timeout values. */static intcmd_spec_timeout (const char *com, const char *val, void *closure){  double value;  if (!cmd_time (com, val, &value))    return 0;  opt.read_timeout = value;  opt.connect_timeout = value;  opt.dns_timeout = value;  return 1;}static intcmd_spec_useragent (const char *com, const char *val, void *closure){  /* Just check for empty string and newline, so we don't throw total     junk to the server.  */  if (!*val || strchr (val, '\n'))    {      fprintf (stderr, _("%s: %s: Invalid value `%s'.\n"),	       exec_name, com, val);      return 0;    }  opt.useragent = xstrdup (val);  return 1;}/* Miscellaneous useful routines.  *//* A very simple atoi clone, more portable than strtol and friends,   but reports errors, unlike atoi.  Returns 1 on success, 0 on   failure.  In case of success, stores result to *DEST.  */static intsimple_atoi (const char *beg, const char *end, int *dest){  int result = 0;  const char *p;  if (beg == end)    return 0;  for (p = beg; p < end && ISDIGIT (*p); p++)    result = (10 * result) + (*p - '0');  if (p != end)    return 0;  *dest = result;  return 1;}/* Trivial atof, with error reporting.  Handles "<digits>[.<digits>]",   doesn't handle exponential notation.  Returns 1 on success, 0 on   failure.  In case of success, stores its result to *DEST.  */static intsimple_atof (const char *beg, const char *end, double *dest){  double result = 0;  int seen_dot = 0;  int seen_digit = 0;  double divider = 1;  const char *p;  for (p = beg; p < end; p++)    {      char ch = *p;      if (ISDIGIT (ch))	{	  if (!seen_dot)	    result = (10 * result) + (ch - '0');	  else	    result += (ch - '0') / (divider *= 10);	  seen_digit = 1;	}      else if (ch == '.')	{	  if (!seen_dot)	    seen_dot = 1;	  else	    return 0;	}      else	return 0;    }  if (!seen_digit)    return 0;  *dest = result;  return 1;}static intcheck_user_specified_header (const char *s){  const char *p;  for (p = s; *p && *p != ':' && !ISSPACE (*p); p++);  /* The header MUST contain `:' preceded by at least one     non-whitespace character.  */  if (*p != ':' || p == s)    return 0;  /* The header MUST NOT contain newlines.  */  if (strchr (s, '\n'))    return 0;  return 1;}void cleanup_html_url PARAMS ((void));void res_cleanup PARAMS ((void));void downloaded_files_free PARAMS ((void));void http_cleanup PARAMS ((void));/* Free the memory allocated by global variables.  */voidcleanup (void){  /* Free external resources, close files, etc. */  if (opt.dfp)    fclose (opt.dfp);  /* We're exiting anyway so there's no real need to call free()     hundreds of times.  Skipping the frees will make Wget exit     faster.     However, when detecting leaks, it's crucial to free() everything     because then you can find the real leaks, i.e. the allocated     memory which grows with the size of the program.  */#ifdef DEBUG_MALLOC  convert_cleanup ();  res_cleanup ();  http_cleanup ();  cleanup_html_url ();  downloaded_files_free ();  host_cleanup ();  cookie_jar_delete (wget_cookie_jar);  {    extern acc_t *netrc_list;    free_netrc (netrc_list);  }  FREE_MAYBE (opt.lfilename);  FREE_MAYBE (opt.dir_prefix);  FREE_MAYBE (opt.input_filename);  FREE_MAYBE (opt.output_document);  free_vec (opt.accepts);  free_vec (opt.rejects);  free_vec (opt.excludes);  free_vec (opt.includes);  free_vec (opt.domains);  free_vec (opt.follow_tags);  free_vec (opt.ignore_tags);  FREE_MAYBE (opt.progress_type);  xfree (opt.ftp_acc);  FREE_MAYBE (opt.ftp_pass);  FREE_MAYBE (opt.ftp_proxy);  FREE_MAYBE (opt.https_proxy);  FREE_MAYBE (opt.http_proxy);  free_vec (opt.no_proxy);  FREE_MAYBE (opt.useragent);  FREE_MAYBE (opt.referer);  FREE_MAYBE (opt.http_user);  FREE_MAYBE (opt.http_passwd);  FREE_MAYBE (opt.user_header);#ifdef HAVE_SSL  FREE_MAYBE (opt.sslcertkey);  FREE_MAYBE (opt.sslcertfile);#endif /* HAVE_SSL */  FREE_MAYBE (opt.bind_address);  FREE_MAYBE (opt.cookies_input);  FREE_MAYBE (opt.cookies_output);#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -