Himanshu Gupta wrote:
> Thanks Josh and Micah for your inputs.
In addition to whatever Josh and Micah told you, let me add the information
that follows. More than once I have had to relearn how wget deals with
command line options. The last time I did so, I created the HOWTO that
appears below (comments about this information from those in the know on
this list are welcome). I'm happy to collect any other topics that people
want to submit and add them to the file. Perhaps Micah will even be willing
to add it to the repository. :-)
By the way, if your mail reader throws away line breaks, you will want to
restore them. --Tony
To find out what a command line option does:
Look in src/main.c in the option_data array for the string to corresponds
to
the command line option; the entries are of the form:
{ "option", 'O', TYPE, "data", argtype },
where you're searching for "option".
If TYPE is OPT_BOOLEAN or OPT_VALUE:
Note the value of "data". Then look at init.c at the commands array for
an entry that starts with the same data. These lines are of the form:
{ "data", &opt.variable, cmd_TYPE },
The corresponding line will tell you what variable gets set when that
option
is selected. Now use grep or some other search tool to find out where
the
variable is referenced.
For example, the --accept option sets the value of opt.accepts, which is
referenced in ftp.c and utils.c
If the TYPE is anything else:
Look to see how main.c handles that TYPE.
For example, OPT__APPEND_OUTPUT sets the option named "logfile" and then
sets the variable append_to_log to true. Searching for append_to_log
shows that it is only used in main.c. Checking init.c (as described
above)
for the option "logfile" shows that it sets the value of opt.lfilename,
which is referenced in mswindows.c, progress.c, and utils.c.
To add a new command line option:
The simplest approach is to find an existing option that is close to what
you
want to accomplish and mirror it. You will need to edit the following
files
as described.
src/main.c
Add a line to the option_data array in the following format:
{ "option", 'O', TYPE, "data", argtype },
where:
option is the long name to be accepted from the command line
Ois the short name (one character) to be accepted from the
command or '' if there is no short name; the short name
must only be assigned to one option. Also, there are very
few short names available and the maintainers are not
inclined to give them out unless the option is likely to
be used frequently.
TYPE is one of the following standard options:
OPT_VALUEon the command line, option must be
followed by a value that will be stored
?somewhere?
OPT_BOOLEAN option is a boolean value that may appear
on the command line as --option for true
or --no-option for false
OPT_FUNCALL an internal function will be invoked if the
option is selected on the command line
Note: If one of these choices won't work for your option
you can add a new value of the OPT__XXX to the enum list
and add special code to handle it in src/main.c.
data For OPT_VALUE and OPT_BOOLEAN, the "name" assigned to the
option in the commands array defined in src/init.c (see
below). For OPT_FUNCALL, a pointer to the function to be
invoked.
argtype For OPT_VALUE and OPT_BOOLEAN, use -1. For OPT_FUNCALL use
no_argument.
NOTE: The options *must* appear in alphabetical order because a Boolean
search is used for the list.
src/main.c
Add the help string to function print_help as follows:
N_("\
-O, --optiondoes something nifty.\n"),
If the short name is '', put spaces in place of "-O,".
Select a reasonable place to add the text into the help output in one
of the existing groups of options: Startup, Logging and input file,
Download, Directories, HTTP options, HTTPS (SSL/TLS) options,
FTP options, Recursive download, or Recursive accept/reject.
src/options.h
Define the variable to receive the value of the option in the options
structure.
src/init.c
Add a line to the commands array in the following format:
{ "data", &opt.variable, cmd_TYPE },
where:
data matches the "data" string you entered above in the
options_data array in src/main.c
variable is the