52#define ECANCELED_NO_OP __einfo_error ( EINFO_ECANCELED_NO_OP )
53#define EINFO_ECANCELED_NO_OP \
54 __einfo_uniqify ( EINFO_ECANCELED, 0x01, "Nothing to do" )
57#define EINVAL_INTEGER __einfo_error ( EINFO_EINVAL_INTEGER )
58#define EINFO_EINVAL_INTEGER \
59 __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid integer value" )
60#define EINVAL_UNKNOWN_OPTION __einfo_error ( EINFO_EINVAL_UNKNOWN_OPTION )
61#define EINFO_EINVAL_UNKNOWN_OPTION \
62 __einfo_uniqify ( EINFO_EINVAL, 0x02, "Unrecognised option" )
63#define EINVAL_MISSING_ARGUMENT __einfo_error ( EINFO_EINVAL_MISSING_ARGUMENT )
64#define EINFO_EINVAL_MISSING_ARGUMENT \
65 __einfo_uniqify ( EINFO_EINVAL, 0x03, "Missing argument" )
100 if ( *endp || ( ! *text ) ) {
101 printf (
"\"%s\": invalid integer value\n", text );
116 unsigned int value_ms;
144 printf (
"\"%s\": invalid UUID\n", text );
167 printf (
"\"%s\": no such network device\n", text );
189 if ( ! *configurator ) {
190 printf (
"\"%s\": no such configurator\n", text );
210 printf (
"\"%s\": no such user interface\n", text );
212 printf (
"No default user interface\n" );
246 if ( text[0] && ! text[1] ) {
280 printf (
"\"%s\": no such scope\n", text );
307 printf (
"\"%s\": invalid setting\n", text );
355 printf (
"\"%s\": no such parameter list\n", text );
357 printf (
"No default parameter list\n" );
376 printf (
"Usage:\n\n %s", argv[0] );
377 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
382 printf (
" %s<%s>%s", ( is_optional ?
"[" :
"" ),
383 option->longopt, ( is_optional ?
"]" :
"" ) );
404 struct option longopts[
cmd->num_options + 1 + 1 ];
405 char shortopts[
cmd->num_options * 3 + 1
407 unsigned int shortopt_idx = 0;
408 int ( * parse ) (
char *text,
void *
value );
412 unsigned int num_args;
417 memset ( longopts, 0,
sizeof ( longopts ) );
418 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
419 longopts[i].
name =
cmd->options[i].longopt;
420 longopts[i].
has_arg =
cmd->options[i].has_arg;
421 longopts[i].
val =
cmd->options[i].shortopt;
422 shortopts[shortopt_idx++] =
cmd->options[i].shortopt;
424 for ( j =
cmd->options[i].has_arg ; j > 0 ; j-- )
425 shortopts[shortopt_idx++] =
':';
427 longopts[i].
name =
"help";
428 longopts[i].
val =
'h';
429 shortopts[shortopt_idx++] =
'h';
430 shortopts[shortopt_idx++] =
'\0';
431 assert ( shortopt_idx <=
sizeof ( shortopts ) );
432 DBGC (
cmd,
"Command \"%s\" has options \"%s\", %d-%d args, len %d\n",
433 argv[0], shortopts,
cmd->min_args,
cmd->max_args,
cmd->len );
436 while ( ( c =
getopt_long ( argc, argv, shortopts, longopts,
453 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
454 if ( c !=
cmd->options[i].shortopt )
456 parse =
cmd->options[i].parse;
462 assert ( i < cmd->num_options );
467 num_args = ( argc -
optind );
468 if ( ( num_args < cmd->min_args ) || ( num_args >
cmd->max_args ) ) {
#define NULL
NULL pointer (VOID *)
union @162305117151260234136356364136041353210355154177 key
Sense key.
uint32_t flag
Flag number.
struct arbelprm_rc_send_wqe rc
pseudo_bit_t value[0x00020]
#define assert(condition)
Assert a condition at run-time.
#define PRODUCT_COMMAND_URI
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
static int isascii(int character)
Check if character is ASCII.
struct dynamic_ui * find_dynui(const char *name)
Find dynamic user interface.
static struct net_device * netdev
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Parse command-line options.
int optind
Current option index.
char * optarg
Option argument.
Parse command-line options.
@ optional_argument
Option may have an argument.
#define __unused
Declare a variable or data structure as unused.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define ENOENT
No such file or directory.
#define EINVAL
Invalid argument.
#define ENOTSUP
Operation not supported.
#define ERANGE
Result too large.
#define ENODEV
No such device.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
struct settings *(* get_child_settings_t)(struct settings *settings, const char *name)
A child settings block locator function.
#define TICKS_PER_MS
Number of ticks per millisecond.
void * memset(void *dest, int character, size_t len) __nonnull
#define KEY_MIN
Minimum value for special keypresses.
struct net_device_configurator * find_netdev_configurator(const char *name)
Find network device configurator.
struct net_device * find_netdev(const char *name)
Get network device by name.
Network device management.
struct parameters * find_parameters(const char *name)
Find request parameter list by name.
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.
int parse_key(char *text, unsigned int *key)
Parse key.
int parse_flag(char *text __unused, int *flag)
Parse flag.
#define ECANCELED_NO_OP
Return status code for "--help" option.
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
int parse_existing_setting(char *text, struct named_setting *setting)
Parse existing setting name.
int parse_netdev_configurator(char *text, struct net_device_configurator **configurator)
Parse network device configurator name.
int parse_dynui(char *text, struct dynamic_ui **dynui)
Parse dynamic user interface name.
int parse_string(char *text, char **value)
Parse string value.
#define EINVAL_UNKNOWN_OPTION
int parse_uuid(char *text, struct uuid_option *uuid)
Parse UUID.
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
int parse_setting(char *text, struct named_setting *setting, get_child_settings_t get_child)
Parse setting name.
void print_usage(struct command_descriptor *cmd, char **argv)
Print command usage message.
#define EINVAL_MISSING_ARGUMENT
int parse_settings(char *text, struct settings **value)
Parse settings block name.
int parse_integer(char *text, unsigned int *value)
Parse integer value.
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
int parse_parameters(char *text, struct parameters **params)
Parse request parameter list name.
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Command line option parsing.
struct settings * autovivify_child_settings(struct settings *parent, const char *name)
Find or create child settings block.
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
struct settings * find_settings(const char *name)
Find settings block.
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
A dynamic user interface.
A network device configurator.
A command-line option descriptor.
A long option, as used for getopt_long()
int has_arg
Option takes an argument.
const char * name
Long name of this option.
A request parameter list.
A UUID command-line option.
int uuid_aton(const char *string, union uuid *uuid)
Parse UUID.
int printf(const char *fmt,...)
Write a formatted string to the console.