[Wget parameter conversion] option_data Conversion

Source: Internet
Author: User

The main function first obtains the program name, which is probably the wget name.

System macro:

# Ifdef target_ OS _mac # endif # ifdef _ Linux _ // identifies a Linux system # endif # ifdef _ Win32 | _ win64 // different operating systems use different macros # endif

Option_data

Long_option

Long_name(Char *)

Name

Short_name(Char)

Optmap indexes short_name

Type(Enum)

Has_argBase on type does not directly use the argtype parameter as the result of has_arg for bool and opt_value.

Data(Void *)

Val-> Option_data Index

Argtype(INT)

Has_argBase on type does not directly use the argtype parameter as the result of has_arg for bool and opt_value.

Optmap maps shortname to long_option Indexes

The method used is optmap [opt-> short_name-32] = longopt-long_options;

Start with the main function:

If the name of the program is run by wgeton windows, the suffix of ".exe" must be removed, and Linux does not need to be used. For Linux, you only need to have the executable permission.

I18n_initialize (); // configure something internationalized, which is related to the system environment. This is to support all language loops. // exec_name = strrchr (argv [0], path_separator ); if (! Exec_name) exec_name = argv [0]; else ++ exec_name; # ifdef Windows/* Drop extension (typically. EXE) from executable filename. */windows_main (char **) & exec_name); # endif

Set the default value of the OPT option and call the configuration file

Initialize (void) {char * file; intok = true; defaults (); // set the default value of OPT in wget for initialization. # Ifdef system_wgetrc if (file_exists_p (system_wgetrc) OK & = run_wgetrc (system_wgetrc); # endif/* override it with your own, if one exists. */file = wgetrc_file_name (); // 'todo: This file does not exist on Linux. If (! File) // return directly if the wgetrc configuration file does not exist in llinux;

The following function converts option_data to long_option and optmap.

Todo: here we use option_data to convert short_option and long_option.

Static voidinit_switches (void) {char * P = short_options; Inti, O = 0; for (I = 0; I <countof (option_data); I ++) {struct explain line_option * opt = & option_data [I]; struct option * longopt; If (! Opt-> long_name)/* the option is disabled. */continue; longopt = & long_options [O ++]; longopt-> name = opt-> long_name;/* long_option option_data name-> long_name; Val-> option_data index. Has_arg-> re_argument, optional_argment, noset the member of flag *****????? * ***** Add by Leok 2011-11-28 */longopt-> val = I; If (opt-> short_name) {* P ++ = opt-> short_name; optmap [opt-> short_name-32] = longopt-long_options;} switch (opt-> type) {Case opt_value: longopt-> has_arg = required_argument; If (opt-> short_name) * P ++ = ':'; break; Case opt_boolean:/* specify an optional argument for long options, so that -- option = off works the same as -- no-option, for compati Bility with pre-1.10 wget. however, don't specify optional arguments short-option booleans because they prevent combining of short options. */longopt-> has_arg = optional_argument; longopt = & long_options [O ++]; longopt-> name = no_prefix (opt-> long_name); longopt-> has_arg = no_argument; longopt-> val = I | boolean_neg_marker; break; default: assert (opt-> argtype! =-1); longopt-> has_arg = opt-> argtype; If (opt-> short_name) {If (longopt-> has_arg = required_argument) * P ++ = ': ';}}* P =' \ 0'; Assert (O <= countof (long_options ));}

Note:

Word: Catalog: Directory, compiling directory bail out: bail parse: parsing, analysis verbose: lengthy fatal: fatal, lethal recursive: recursive, regression span: spanning, traversing porting: porting reside: Directory, residence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.