2.4.1 Option Argument Types

Mu supports several option types, and more may be added in the future. These types will automatically be processed from the string argument, and the processed argument will be returned in *arg if arg is not NULL (see Option Structure). arg should be a pointer to a value of the type indicated by the arg_type field, which must be one of the values in the table below. However, if arg_type is MU_OPT_SUBOPT, arg must not be used (see Parsing Suboptions). If an error occurs while processing an argument, an error message will be printed to standard error, and mu_parse_opts will return an error code (see Option Parsing Errors).

Unless otherwise specified, *argstr will be set to the unprocessed string argument if argstr is not NULL (see Option Structure). However, if arg_type is MU_OPT_SUBOPT, argstr must not be used.

You can also parse your own types using callbacks (see Option Callbacks).

Enumerated Type: enum MU_OPT_ARG_TYPE
MU_OPT_BOOL

This is a boolean value. The type of *arg should be int and bool_default should be used for the default value (see Option Structure). If MU_OPT_BOOL is given in the arg_type field, the argument can either be ‘yes’ or ‘true’ for a true value, or ‘no’ or ‘false’ for a false value. Matching is case insensitive and allows abbreviation.

If the argument is none of ‘yes’, ‘no’, ‘true’, or ‘false’, it will be parsed as an integer (see below). Zero is false and any other integer is true.

If the argument is not an integer either, that will be an error.

MU_OPT_INT

This is an integer value. The type of *arg should be long and int_default should be used for the default value (see Option Structure). The radix (or base) that the argument is parsed as depends on the first non-whitespace characters after an optional ‘+’ or ‘-’ sign. If these characters are ‘0x’ or ‘0X’, the integer is parsed as hexadecimal. Otherwise, if the first character is ‘0’, and the following character is notx’ or ‘X’, the integer will be parsed as octal. Otherwise, the integer will be parsed as decimal. See (libc)Parsing of Integers for more information on how integers are parsed.

If the parsed integer is outside the bounds specified by the ibound field (see Option Structure), then that will be treated as an error.

MU_OPT_FLOAT

This is a floating-point value. The type of *arg should be double and float_default should be used for the default value (see Option Structure). The radix (or base) that the argument is parsed as depends on the first non-whitespace characters after an optional ‘+’ or ‘-’ sign. If these characters are ‘0x’ or ‘0X’, the number is parsed as hexadecimal. Otherwise, if the first character is ‘0’, and the following character is notx’ or ‘X’, the number will be parsed as octal. Otherwise, the number will be parsed as decimal. See (libc)Parsing of Floats for more information on how floating-point numbers are parsed. See (libc)Parsing of Floats for more information on how floating-point numbers are parsed.

If the parsed floating-point numebr is outside the bounds specified by the fbound field (see Option Structure), then that will be treated as an error.

MU_OPT_STRING

This is a string value. The type of *arg should be const char * and string_default should be used for the default value (see Option Structure) (i.e., the type of arg should be const char **). *argstr (if argstr is not NULL) will be set to the same value as *arg.

MU_OPT_FILE

This is a file argument. The type of *arg should be FILE * (i.e., the type of arg should be FILE **) and file_default should be used for the default value (see Option Structure). file_mode should be used for this type and only for this type (see Option Structure).

file_mode describes the mode to use when opening the file, and how ‘-’ should be handled. If file_mode indicates that the file should be opened in read-only mode, ‘-’ will be handled as standard input. If file_mode indicates that the file should be opened in write-only mode, ‘-’ will be handled as standard output. If file_mode indicates that the file should be opened for both reading and writing, ‘-’ will cause an error.

If argstr is not NULL, *argstr will be set to ‘<stdin>’ if ‘-’ was handled as standard input, ‘<stdout>’ if ‘-’ was handled as standard output, or the file name given as the argument to the option if the argument was not ‘-’.

If an error occurs while opening a file, an error message will be printed to standard error and mu_parse_opts will return an error code (see Option Parsing Errors).

For more information on how files are opened and how file_mode is parsed, see (libc)Opening Streams.

MU_OPT_DIRECTORY

This is a directory argument. The type of *arg should be DIR * (i.e., the type of arg should be DIR **) and dir_default should be used for the default value (see Option Structure). See (libc)Opening a Directory Stream for more information on how directories are opened.

If you’d like to know the name of the directory as given as the argument to the option, you can use the argstr field (see Option Structure).

If an error occurs while opening a directory, an error message will be printed to standard error and mu_parse_opts will return an error code (see Option Parsing Errors).

MU_OPT_ENUM

This is an enumerated argument. The enumeration specification is the enum_values field (see Option Structure).

For more information, See Parsing Enumerated Arguments to Options.

MU_OPT_SUBOPT

This indicates that the option takes suboptions as arguments. Suboptions may not take suboptions as arguments. See Parsing Suboptions for more information.