Next: , Previous: libefi-string, Up: libefi


5.1.4 Parsing of Options

The `efi' library contains functionality for parsing options. The parsing framework is modeled after argp from the gnu C library. The application defines a list of valid options, and pass them together with a parse hook to the efi_argp_parse method. The hook will get invoked during the parsing with information about what option was just parsed. Definitions and prototypes is available in gnu/efi/util/argp.h.

The options is defined as a NULL terminated array of efi_argp_option_t structures. The efi_argp_option_t structure has the following members:

— argp Option: efi_char16_t* longarg

Long argument name of the option, if any. Long arguments are argumnets that start with `--'. For example --output.

— argp Option: int shortarg

Short argument name of the option, if any. Short argument are arguments that start with `-'. For example -o.

— argp Option: int flags

Option flags. The only flag currently available is EFI_ARGP_ARG_OPTIONAL which defines that the option takes an optional argument.

— argp Option: int key

A key that can be used by the parser hook to identify the option.

— argp Option: efi_char16_t* doc

A documentation string that describes the option. Mandatory.

— argp Option: efi_char16_t* arg

Name of the argument that the option takes. Should be in uppercase.

FIXME: If neither longarg nor shortarg is specified in the option is treated as an mandatory argument to the program. If no option is defined for the program argument, the hook will be invoked with opt as NULL but a valid arg argument.

FIXME: When all options has been parsed the parser will invoke the hook with opt and arg set to NULL to signal that all options has been parsed.

The signature of the hook:

— Function: efi_status_t efi_argp_parse_hook_t (void *data, efi_argp_option_t *opt, efi_char16_t *arg)

Parse hook invoked from the option parser. DATA is a user defined pointer that was provided to efi_argp_parse. opt is the option that was pased, and arg is an optional argument to the option. The hook should return EFI_SUCCESS if it could handle the option.

Caution: The option parser uses the first argument passed to efi_argp_parse as the program name.

— Function: efi_status_t efi_argp_parse (int argc, efi_char16_t **argv, efi_argp_option_t *options, efi_argp_parse_hook_t hook, void *data)

Parse options and invoke hook hook with the parsed option. options is a list of options that should be parsed. argc is the number of arguments passed to the program. argv is an array of all arguments. data is a user defined pointer that will be passed to the hook.