48 #define ECANCELED_NO_OP __einfo_error ( EINFO_ECANCELED_NO_OP ) 49 #define EINFO_ECANCELED_NO_OP \ 50 __einfo_uniqify ( EINFO_ECANCELED, 0x01, "Nothing to do" ) 53 #define EINVAL_INTEGER __einfo_error ( EINFO_EINVAL_INTEGER ) 54 #define EINFO_EINVAL_INTEGER \ 55 __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid integer value" ) 56 #define EINVAL_UNKNOWN_OPTION __einfo_error ( EINFO_EINVAL_UNKNOWN_OPTION ) 57 #define EINFO_EINVAL_UNKNOWN_OPTION \ 58 __einfo_uniqify ( EINFO_EINVAL, 0x02, "Unrecognised option" ) 59 #define EINVAL_MISSING_ARGUMENT __einfo_error ( EINFO_EINVAL_MISSING_ARGUMENT ) 60 #define EINFO_EINVAL_MISSING_ARGUMENT \ 61 __einfo_uniqify ( EINFO_EINVAL, 0x03, "Missing argument" ) 96 if ( *endp || ( ! *text ) ) {
97 printf (
"\"%s\": invalid integer value\n", text );
112 unsigned int value_ms;
140 printf (
"\"%s\": no such network device\n", text );
162 if ( ! *configurator ) {
163 printf (
"\"%s\": no such configurator\n", text );
183 printf (
"\"%s\": no such menu\n", text );
185 printf (
"No default menu\n" );
218 if ( text[0] && ! text[1] ) {
242 printf (
"\"%s\": no such scope\n", text );
269 printf (
"\"%s\": invalid setting\n", text );
317 printf (
"\"%s\": no such parameter list\n", text );
319 printf (
"No default parameter list\n" );
338 printf (
"Usage:\n\n %s", argv[0] );
339 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
344 printf (
" %s<%s>%s", ( is_optional ?
"[" :
"" ),
345 option->longopt, ( is_optional ?
"]" :
"" ) );
366 struct option longopts[
cmd->num_options + 1 + 1 ];
367 char shortopts[
cmd->num_options * 3 + 1
369 unsigned int shortopt_idx = 0;
370 int ( * parse ) (
char *text,
void *
value );
374 unsigned int num_args;
379 memset ( longopts, 0,
sizeof ( longopts ) );
380 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
381 longopts[i].
name =
cmd->options[i].longopt;
382 longopts[i].
has_arg =
cmd->options[i].has_arg;
383 longopts[i].
val =
cmd->options[i].shortopt;
384 shortopts[shortopt_idx++] =
cmd->options[i].shortopt;
386 for ( j =
cmd->options[i].has_arg ; j > 0 ; j-- )
387 shortopts[shortopt_idx++] =
':';
389 longopts[i].
name =
"help";
390 longopts[i].
val =
'h';
391 shortopts[shortopt_idx++] =
'h';
392 shortopts[shortopt_idx++] =
'\0';
393 assert ( shortopt_idx <=
sizeof ( shortopts ) );
394 DBGC (
cmd,
"Command \"%s\" has options \"%s\", %d-%d args, len %d\n",
395 argv[0], shortopts,
cmd->min_args,
cmd->max_args,
cmd->len );
398 while ( (
c =
getopt_long ( argc, argv, shortopts, longopts,
415 for ( i = 0 ; i <
cmd->num_options ; i++ ) {
416 if (
c !=
cmd->options[i].shortopt )
418 parse =
cmd->options[i].parse;
424 assert ( i < cmd->num_options );
429 num_args = ( argc -
optind );
430 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
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_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.
#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.
struct parameters * find_parameters(const char *name)
Find request parameter list by name.
#define ENOTSUP
Operation not supported.
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.
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.
pseudo_bit_t value[0x00020]
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.
#define __unused
Declare a variable or data structure as unused.
static union @432 opts
"cert<xxx>" option list
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.
int parse_menu(char *text, struct menu **menu)
Parse menu name.
char * optarg
Option argument.
#define ECANCELED_NO_OP
Return status code for "--help" option.
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.
#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.
uint16_t flag
Flag number.
void * memset(void *dest, int character, size_t len) __nonnull
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.