51 #define ECANCELED_NO_OP __einfo_error ( EINFO_ECANCELED_NO_OP ) 52 #define EINFO_ECANCELED_NO_OP \ 53 __einfo_uniqify ( EINFO_ECANCELED, 0x01, "Nothing to do" ) 56 #define EINVAL_INTEGER __einfo_error ( EINFO_EINVAL_INTEGER ) 57 #define EINFO_EINVAL_INTEGER \ 58 __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid integer value" ) 59 #define EINVAL_UNKNOWN_OPTION __einfo_error ( EINFO_EINVAL_UNKNOWN_OPTION ) 60 #define EINFO_EINVAL_UNKNOWN_OPTION \ 61 __einfo_uniqify ( EINFO_EINVAL, 0x02, "Unrecognised option" ) 62 #define EINVAL_MISSING_ARGUMENT __einfo_error ( EINFO_EINVAL_MISSING_ARGUMENT ) 63 #define EINFO_EINVAL_MISSING_ARGUMENT \ 64 __einfo_uniqify ( EINFO_EINVAL, 0x03, "Missing argument" ) 99 if ( *endp || ( ! *text ) ) {
100 printf (
"\"%s\": invalid integer value\n", text );
115 unsigned int value_ms;
143 printf (
"\"%s\": invalid UUID\n", text );
166 printf (
"\"%s\": no such network device\n", text );
188 if ( ! *configurator ) {
189 printf (
"\"%s\": no such configurator\n", text );
209 printf (
"\"%s\": no such user interface\n", text );
211 printf (
"No default user interface\n" );
245 if ( text[0] && ! text[1] ) {
279 printf (
"\"%s\": no such scope\n", text );
306 printf (
"\"%s\": invalid setting\n", text );
354 printf (
"\"%s\": no such parameter list\n", text );
356 printf (
"No default parameter list\n" );
375 printf (
"Usage:\n\n %s", argv[0] );
376 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
381 printf (
" %s<%s>%s", ( is_optional ?
"[" :
"" ),
382 option->longopt, ( is_optional ?
"]" :
"" ) );
403 struct option longopts[
cmd->num_options + 1 + 1 ];
404 char shortopts[
cmd->num_options * 3 + 1
406 unsigned int shortopt_idx = 0;
407 int ( * parse ) (
char *text,
void *
value );
411 unsigned int num_args;
416 memset ( longopts, 0,
sizeof ( longopts ) );
417 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
418 longopts[i].
name =
cmd->options[i].longopt;
419 longopts[i].
has_arg =
cmd->options[i].has_arg;
420 longopts[i].
val =
cmd->options[i].shortopt;
421 shortopts[shortopt_idx++] =
cmd->options[i].shortopt;
423 for ( j =
cmd->options[i].has_arg ; j > 0 ; j-- )
424 shortopts[shortopt_idx++] =
':';
426 longopts[i].
name =
"help";
427 longopts[i].
val =
'h';
428 shortopts[shortopt_idx++] =
'h';
429 shortopts[shortopt_idx++] =
'\0';
430 assert ( shortopt_idx <=
sizeof ( shortopts ) );
431 DBGC (
cmd,
"Command \"%s\" has options \"%s\", %d-%d args, len %d\n",
432 argv[0], shortopts,
cmd->min_args,
cmd->max_args,
cmd->len );
435 while ( (
c =
getopt_long ( argc, argv, shortopts, longopts,
452 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
453 if (
c !=
cmd->options[i].shortopt )
455 parse =
cmd->options[i].parse;
461 assert ( i < cmd->num_options );
466 num_args = ( argc -
optind );
467 if ( ( num_args < cmd->min_args ) || ( num_args >
cmd->max_args ) ) {
#define EINVAL_UNKNOWN_OPTION
int parse_integer(char *text, unsigned int *value)
Parse integer value.
#define EINVAL
Invalid argument.
struct arbelprm_rc_send_wqe rc
static __always_inline void off_t int c
int printf(const char *fmt,...)
Write a formatted string to the console.
int parse_key(char *text, unsigned int *key)
Parse key.
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
int optind
Current option index.
int parse_netdev_configurator(char *text, struct net_device_configurator **configurator)
Parse network device configurator name.
int parse_uuid(char *text, struct uuid_option *uuid)
Parse UUID.
A UUID command-line option.
int parse_dynui(char *text, struct dynamic_ui **dynui)
Parse dynamic user interface name.
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
A request parameter list.
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
struct dynamic_ui * find_dynui(const char *name)
Find dynamic user interface.
#define ENOENT
No such file or directory.
int parse_setting(char *text, struct named_setting *setting, get_child_settings_t get_child)
Parse setting name.
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
static int isascii(int character)
Check if character is ASCII.
struct parameters * find_parameters(const char *name)
Find request parameter list by name.
#define ENOTSUP
Operation not supported.
int uuid_aton(const char *string, union uuid *uuid)
Parse UUID.
#define KEY_MIN
Minimum value for special keypresses.
struct net_device_configurator * find_netdev_configurator(const char *name)
Find network device configurator.
Parse command-line options.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int parse_string(char *text, char **value)
Parse string value.
A long option, as used for getopt_long()
struct settings *(* get_child_settings_t)(struct settings *settings, const char *name)
A child settings block locator function.
pseudo_bit_t value[0x00020]
#define __unused
Declare a variable or data structure as unused.
static struct net_device * netdev
struct settings * autovivify_child_settings(struct settings *parent, const char *name)
Find or create child settings block.
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_flag(char *text __unused, int *flag)
Parse flag.
#define PRODUCT_COMMAND_URI
#define ERANGE
Result too large.
const char * name
Long name of this option.
int parse_parameters(char *text, struct parameters **params)
Parse request parameter list name.
Command line option parsing.
#define ENODEV
No such device.
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Parse command-line options.
void print_usage(struct command_descriptor *cmd, char **argv)
Print command usage message.
Network device management.
A dynamic user interface.
struct net_device * find_netdev(const char *name)
Get network device by name.
A network device configurator.
A command-line option descriptor.
#define EINVAL_MISSING_ARGUMENT
struct settings * find_settings(const char *name)
Find settings block.
char * optarg
Option argument.
#define ECANCELED_NO_OP
Return status code for "--help" option.
uint32_t flag
Flag number.
Option may have an argument.
int parse_settings(char *text, struct settings **value)
Parse settings block name.
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
int has_arg
Option takes an argument.
static union @438 opts
"cert<xxx>" option list
#define NULL
NULL pointer (VOID *)
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define TICKS_PER_MS
Number of ticks per millisecond.
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
void * memset(void *dest, int character, size_t len) __nonnull
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.