iPXE
Data Structures | Macros | Functions
parseopt.h File Reference

Command line option parsing. More...

#include <stdint.h>
#include <stddef.h>
#include <ipxe/uuid.h>
#include <ipxe/settings.h>

Go to the source code of this file.

Data Structures

struct  option_descriptor
 A command-line option descriptor. More...
 
struct  command_descriptor
 A command descriptor. More...
 
struct  named_setting
 A parsed named setting. More...
 
struct  uuid_option
 A UUID command-line option. More...
 

Macros

#define OPTION_PARSER(_struct, _field, _parse)
 Construct option parser. More...
 
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
 Construct option descriptor. More...
 
#define MAX_ARGUMENTS   0xff
 No maximum number of arguments. More...
 
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
 Construct command descriptor. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int parse_string (char *text, char **value)
 Parse string value. More...
 
int parse_integer (char *text, unsigned int *value)
 Parse integer value. More...
 
int parse_timeout (char *text, unsigned long *value)
 Parse timeout value (in ms) More...
 
int parse_uuid (char *text, struct uuid_option *uuid)
 Parse UUID. More...
 
int parse_netdev (char *text, struct net_device **netdev)
 Parse network device name. More...
 
int parse_netdev_configurator (char *text, struct net_device_configurator **configurator)
 Parse network device configurator name. More...
 
int parse_menu (char *text, struct menu **menu)
 Parse menu name. More...
 
int parse_flag (char *text __unused, int *flag)
 Parse flag. More...
 
int parse_key (char *text, unsigned int *key)
 Parse key. More...
 
int parse_settings (char *text, struct settings **settings)
 Parse settings block name. More...
 
int parse_setting (char *text, struct named_setting *setting, get_child_settings_t get_child)
 Parse setting name. More...
 
int parse_existing_setting (char *text, struct named_setting *setting)
 Parse existing setting name. More...
 
int parse_autovivified_setting (char *text, struct named_setting *setting)
 Parse and autovivify setting name. More...
 
int parse_parameters (char *text, struct parameters **params)
 Parse request parameter list name. More...
 
void print_usage (struct command_descriptor *cmd, char **argv)
 Print command usage message. More...
 
int reparse_options (int argc, char **argv, struct command_descriptor *cmd, void *opts)
 Reparse command-line options. More...
 
int parse_options (int argc, char **argv, struct command_descriptor *cmd, void *opts)
 Parse command-line options. More...
 

Detailed Description

Command line option parsing.

Definition in file parseopt.h.

Macro Definition Documentation

◆ OPTION_PARSER

#define OPTION_PARSER (   _struct,
  _field,
  _parse 
)
Value:
( ( int ( * ) ( char *text, void *value ) ) \
( ( ( ( typeof ( _parse ) * ) NULL ) == \
( ( int ( * ) ( char *text, \
typeof ( ( ( _struct * ) NULL )->_field ) * ) ) \
NULL ) ) ? _parse : _parse ) )
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

Construct option parser.

Parameters
_structOptions structure type
_fieldField within options structure
_parseField type-specific option parser
Return values
_parseGeneric option parser

Definition at line 49 of file parseopt.h.

◆ OPTION_DESC

#define OPTION_DESC (   _longopt,
  _shortopt,
  _has_arg,
  _struct,
  _field,
  _parse 
)
Value:
{ \
.longopt = _longopt, \
.shortopt = _shortopt, \
.has_arg = _has_arg, \
.offset = offsetof ( _struct, _field ), \
.parse = OPTION_PARSER ( _struct, _field, _parse ), \
}
#define OPTION_PARSER(_struct, _field, _parse)
Construct option parser.
Definition: parseopt.h:49
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24

Construct option descriptor.

Parameters
_longoptLong option name, if any
_shortoptShort option name, if any
_has_argArgument requirement
_structOptions structure type
_fieldField within options structure
_parseField type-specific option parser
Return values
_optionOption descriptor

Definition at line 67 of file parseopt.h.

◆ MAX_ARGUMENTS

#define MAX_ARGUMENTS   0xff

No maximum number of arguments.

Definition at line 97 of file parseopt.h.

◆ COMMAND_DESC

#define COMMAND_DESC (   _struct,
  _options,
  _min_args,
  _max_args,
  _usage 
)
Value:
{ \
.options = ( ( ( ( typeof ( _options[0] ) * ) NULL ) == \
( ( struct option_descriptor * ) NULL ) ) ? \
_options : _options ), \
.num_options = ( sizeof ( _options ) / \
sizeof ( _options[0] ) ), \
.len = sizeof ( _struct ), \
.min_args = _min_args, \
.max_args = _max_args, \
.usage = _usage, \
}
uint32_t len
Length.
Definition: ena.h:14
A command-line option descriptor.
Definition: parseopt.h:23
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

Construct command descriptor.

Parameters
_structOptions structure type
_optionsOption descriptor array
_check_argsRemaining argument checker
_usageCommand usage
Return values
_commandCommand descriptor

Definition at line 108 of file parseopt.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ parse_string()

int parse_string ( char *  text,
char **  value 
)

Parse string value.

Parameters
textText
Return values
valueString value
rcReturn status code

Definition at line 73 of file parseopt.c.

73  {
74 
75  /* Sanity check */
76  assert ( text != NULL );
77 
78  /* Parse string */
79  *value = text;
80 
81  return 0;
82 }
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), NULL, and value.

◆ parse_integer()

int parse_integer ( char *  text,
unsigned int *  value 
)

Parse integer value.

Parameters
textText
Return values
valueInteger value
rcReturn status code

Definition at line 91 of file parseopt.c.

91  {
92  char *endp;
93 
94  /* Sanity check */
95  assert ( text != NULL );
96 
97  /* Parse integer */
98  *value = strtoul ( text, &endp, 0 );
99  if ( *endp || ( ! *text ) ) {
100  printf ( "\"%s\": invalid integer value\n", text );
101  return -EINVAL_INTEGER;
102  }
103 
104  return 0;
105 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:484
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define EINVAL_INTEGER
Definition: parseopt.c:56
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), EINVAL_INTEGER, NULL, printf(), strtoul(), and value.

Referenced by colour_exec(), cpair_exec(), cpuid_exec(), exit_exec(), imgmem_exec(), inc_exec(), parse_key(), parse_timeout(), pxebs_exec(), and sleep_exec().

◆ parse_timeout()

int parse_timeout ( char *  text,
unsigned long *  value 
)

Parse timeout value (in ms)

Parameters
textText
Return values
valueInteger value
rcReturn status code

Definition at line 114 of file parseopt.c.

114  {
115  unsigned int value_ms;
116  int rc;
117 
118  /* Parse raw integer value */
119  if ( ( rc = parse_integer ( text, &value_ms ) ) != 0 )
120  return rc;
121 
122  /* Convert to a number of timer ticks */
123  *value = ( value_ms * TICKS_PER_MS );
124 
125  return 0;
126 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define TICKS_PER_MS
Number of ticks per millisecond.
Definition: timer.h:25

References parse_integer(), rc, TICKS_PER_MS, and value.

◆ parse_uuid()

int parse_uuid ( char *  text,
struct uuid_option uuid 
)

Parse UUID.

Parameters
textText
Return values
uuidUUID value
rcReturn status code

Definition at line 135 of file parseopt.c.

135  {
136  int rc;
137 
138  /* Sanity check */
139  assert ( text != NULL );
140 
141  /* Parse UUID */
142  if ( ( rc = uuid_aton ( text, &uuid->buf ) ) != 0 ) {
143  printf ( "\"%s\": invalid UUID\n", text );
144  return rc;
145  }
146  uuid->value = &uuid->buf;
147 
148  return 0;
149 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
A universally unique ID.
Definition: uuid.h:15
int uuid_aton(const char *string, union uuid *uuid)
Parse UUID.
Definition: uuid.c:66
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), NULL, printf(), rc, and uuid_aton().

◆ parse_netdev()

int parse_netdev ( char *  text,
struct net_device **  netdev 
)

Parse network device name.

Parameters
textText
Return values
netdevNetwork device
rcReturn status code

Definition at line 158 of file parseopt.c.

158  {
159 
160  /* Sanity check */
161  assert ( text != NULL );
162 
163  /* Find network device */
164  *netdev = find_netdev ( text );
165  if ( ! *netdev ) {
166  printf ( "\"%s\": no such network device\n", text );
167  return -ENODEV;
168  }
169 
170  return 0;
171 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct net_device * netdev
Definition: gdbudp.c:52
#define ENODEV
No such device.
Definition: errno.h:509
struct net_device * find_netdev(const char *name)
Get network device by name.
Definition: netdevice.c:988
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), ENODEV, find_netdev(), netdev, NULL, and printf().

Referenced by ifcommon_exec(), lotest_exec(), pxebs_exec(), vcreate_exec(), and vdestroy_exec().

◆ parse_netdev_configurator()

int parse_netdev_configurator ( char *  text,
struct net_device_configurator **  configurator 
)

Parse network device configurator name.

Parameters
textText
Return values
configuratorNetwork device configurator
rcReturn status code

Definition at line 180 of file parseopt.c.

181  {
182 
183  /* Sanity check */
184  assert ( text != NULL );
185 
186  /* Find network device configurator */
187  *configurator = find_netdev_configurator ( text );
188  if ( ! *configurator ) {
189  printf ( "\"%s\": no such configurator\n", text );
190  return -ENOTSUP;
191  }
192 
193  return 0;
194 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
struct net_device_configurator * find_netdev_configurator(const char *name)
Find network device configurator.
Definition: netdevice.c:1278
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), ENOTSUP, find_netdev_configurator(), NULL, and printf().

◆ parse_menu()

int parse_menu ( char *  text,
struct menu **  menu 
)

Parse menu name.

Parameters
textText
Return values
menuMenu
rcReturn status code

Definition at line 203 of file parseopt.c.

203  {
204 
205  /* Find menu */
206  *menu = find_menu ( text );
207  if ( ! *menu ) {
208  if ( text ) {
209  printf ( "\"%s\": no such menu\n", text );
210  } else {
211  printf ( "No default menu\n" );
212  }
213  return -ENOENT;
214  }
215 
216  return 0;
217 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define ENOENT
No such file or directory.
Definition: errno.h:514
A menu.
Definition: menu.h:15

References ENOENT, find_menu(), and printf().

Referenced by choose_exec(), and item_exec().

◆ parse_flag()

int parse_flag ( char *text  __unused,
int *  flag 
)

Parse flag.

Parameters
textText (ignored)
Return values
flagFlag to set
rcReturn status code

Definition at line 226 of file parseopt.c.

226  {
227 
228  /* Set flag */
229  *flag = 1;
230 
231  return 0;
232 }
uint16_t flag
Flag number.
Definition: hyperv.h:14

References flag.

◆ parse_key()

int parse_key ( char *  text,
unsigned int *  key 
)

Parse key.

Parameters
textText
Return values
keyKey
rcReturn status code

Definition at line 241 of file parseopt.c.

241  {
242  int rc;
243 
244  /* Interpret single characters as being a literal key character */
245  if ( text[0] && ! text[1] ) {
246  *key = text[0];
247  return 0;
248  }
249 
250  /* Otherwise, interpret as an integer */
251  if ( ( rc = parse_integer ( text, key ) ) < 0 )
252  return rc;
253 
254  /* For backwards compatibility with existing scripts, treat
255  * integers between the ASCII range and special key range as
256  * being relative special key values.
257  */
258  if ( ( ! isascii ( *key ) ) && ( *key < KEY_MIN ) )
259  *key += KEY_MIN;
260 
261  return 0;
262 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int isascii(int character)
Check if character is ASCII.
Definition: ctype.h:18
#define KEY_MIN
Minimum value for special keypresses.
Definition: keys.h:68
union @382 key
Sense key.
Definition: crypto.h:284

References isascii(), key, KEY_MIN, parse_integer(), and rc.

◆ parse_settings()

int parse_settings ( char *  text,
struct settings **  value 
)

Parse settings block name.

Parameters
textText
Return values
valueInteger value
rcReturn status code

Definition at line 271 of file parseopt.c.

271  {
272 
273  /* Sanity check */
274  assert ( text != NULL );
275 
276  /* Parse scope name */
277  *value = find_settings ( text );
278  if ( ! *value ) {
279  printf ( "\"%s\": no such scope\n", text );
280  return -EINVAL;
281  }
282 
283  return 0;
284 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct settings * find_settings(const char *name)
Find settings block.
Definition: settings.c:406
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), EINVAL, find_settings(), NULL, printf(), and value.

Referenced by config_exec().

◆ parse_setting()

int parse_setting ( char *  text,
struct named_setting setting,
get_child_settings_t  get_child 
)

Parse setting name.

Parameters
textText
settingNamed setting to fill in
get_childFunction to find or create child settings block
Return values
rcReturn status code

Note that this function modifies the original text.

Definition at line 296 of file parseopt.c.

297  {
298  int rc;
299 
300  /* Sanity check */
301  assert ( text != NULL );
302 
303  /* Parse setting name */
304  if ( ( rc = parse_setting_name ( text, get_child, &setting->settings,
305  &setting->setting ) ) != 0 ) {
306  printf ( "\"%s\": invalid setting\n", text );
307  return rc;
308  }
309 
310  return 0;
311 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
A setting.
Definition: settings.h:23
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
Definition: settings.c:1528

References assert(), NULL, parse_setting_name(), printf(), and rc.

Referenced by parse_autovivified_setting(), and parse_existing_setting().

◆ parse_existing_setting()

int parse_existing_setting ( char *  text,
struct named_setting setting 
)

Parse existing setting name.

Parameters
textText
settingNamed setting to fill in
Return values
rcReturn status code

Note that this function modifies the original text.

Definition at line 322 of file parseopt.c.

322  {
323 
324  return parse_setting ( text, setting, find_child_settings );
325 }
int parse_setting(char *text, struct named_setting *setting, get_child_settings_t get_child)
Parse setting name.
Definition: parseopt.c:296
A setting.
Definition: settings.h:23
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:279

References find_child_settings(), and parse_setting().

Referenced by inc_exec(), and show_exec().

◆ parse_autovivified_setting()

int parse_autovivified_setting ( char *  text,
struct named_setting setting 
)

Parse and autovivify setting name.

Parameters
textText
settingNamed setting to fill in
Return values
rcReturn status code

Note that this function modifies the original text.

Definition at line 336 of file parseopt.c.

336  {
337 
339 }
int parse_setting(char *text, struct named_setting *setting, get_child_settings_t get_child)
Parse setting name.
Definition: parseopt.c:296
struct settings * autovivify_child_settings(struct settings *parent, const char *name)
Find or create child settings block.
Definition: settings.c:306
A setting.
Definition: settings.h:23

References autovivify_child_settings(), and parse_setting().

Referenced by choose_exec(), pciscan_exec(), and set_core_exec().

◆ parse_parameters()

int parse_parameters ( char *  text,
struct parameters **  params 
)

Parse request parameter list name.

Parameters
textText
Return values
paramsParameter list
rcReturn status code

Definition at line 348 of file parseopt.c.

348  {
349 
350  /* Find parameter list */
351  *params = find_parameters ( text );
352  if ( ! *params ) {
353  if ( text ) {
354  printf ( "\"%s\": no such parameter list\n", text );
355  } else {
356  printf ( "No default parameter list\n" );
357  }
358  return -ENOENT;
359  }
360 
361  return 0;
362 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define ENOENT
No such file or directory.
Definition: errno.h:514
struct parameters * find_parameters(const char *name)
Find request parameter list by name.
Definition: params.c:68

References ENOENT, find_parameters(), and printf().

Referenced by param_exec().

◆ print_usage()

void print_usage ( struct command_descriptor cmd,
char **  argv 
)

Print command usage message.

Parameters
cmdCommand descriptor
argvArgument list

Definition at line 370 of file parseopt.c.

370  {
371  struct option_descriptor *option;
372  unsigned int i;
373  int is_optional;
374 
375  printf ( "Usage:\n\n %s", argv[0] );
376  for ( i = 0 ; i < cmd->num_options ; i++ ) {
377  option = &cmd->options[i];
378  printf ( " [-%c|--%s", option->shortopt, option->longopt );
379  if ( option->has_arg ) {
380  is_optional = ( option->has_arg == optional_argument );
381  printf ( " %s<%s>%s", ( is_optional ? "[" : "" ),
382  option->longopt, ( is_optional ? "]" : "" ) );
383  }
384  printf ( "]" );
385  }
386  if ( cmd->usage )
387  printf ( " %s", cmd->usage );
388  printf ( "\n\nSee " PRODUCT_COMMAND_URI " for further information\n",
389  argv[0] );
390 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
A long option, as used for getopt_long()
Definition: getopt.h:24
#define PRODUCT_COMMAND_URI
Definition: branding.h:127
A command-line option descriptor.
Definition: parseopt.h:23
Option may have an argument.
Definition: getopt.h:20
int has_arg
Option takes an argument.
Definition: getopt.h:32
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29

References cmd, option::has_arg, optional_argument, printf(), and PRODUCT_COMMAND_URI.

Referenced by reparse_options().

◆ reparse_options()

int reparse_options ( int  argc,
char **  argv,
struct command_descriptor cmd,
void *  opts 
)

Reparse command-line options.

Parameters
argcArgument count
argvArgument list
cmdCommand descriptor
optsOptions (already initialised with default values)
Return values
rcReturn status code

Definition at line 401 of file parseopt.c.

402  {
403  struct option longopts[ cmd->num_options + 1 /* help */ + 1 /* end */ ];
404  char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
405  + 1 /* NUL */ ];
406  unsigned int shortopt_idx = 0;
407  int ( * parse ) ( char *text, void *value );
408  void *value;
409  unsigned int i;
410  unsigned int j;
411  unsigned int num_args;
412  int c;
413  int rc;
414 
415  /* Construct long and short option lists for getopt_long() */
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;
422  assert ( cmd->options[i].has_arg <= optional_argument );
423  for ( j = cmd->options[i].has_arg ; j > 0 ; j-- )
424  shortopts[shortopt_idx++] = ':';
425  }
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 );
433 
434  /* Parse options */
435  while ( ( c = getopt_long ( argc, argv, shortopts, longopts,
436  NULL ) ) >= 0 ) {
437  switch ( c ) {
438  case 'h' :
439  /* Print help */
440  print_usage ( cmd, argv );
441  return -ECANCELED_NO_OP;
442  case '?' :
443  /* Print usage message */
444  print_usage ( cmd, argv );
445  return -EINVAL_UNKNOWN_OPTION;
446  case ':' :
447  /* Print usage message */
448  print_usage ( cmd, argv );
449  return -EINVAL_MISSING_ARGUMENT;
450  default:
451  /* Search for an option to parse */
452  for ( i = 0 ; i < cmd->num_options ; i++ ) {
453  if ( c != cmd->options[i].shortopt )
454  continue;
455  parse = cmd->options[i].parse;
456  value = ( opts + cmd->options[i].offset );
457  if ( ( rc = parse ( optarg, value ) ) != 0 )
458  return rc;
459  break;
460  }
461  assert ( i < cmd->num_options );
462  }
463  }
464 
465  /* Check remaining arguments */
466  num_args = ( argc - optind );
467  if ( ( num_args < cmd->min_args ) || ( num_args > cmd->max_args ) ) {
468  print_usage ( cmd, argv );
469  return -ERANGE;
470  }
471 
472  return 0;
473 }
#define EINVAL_UNKNOWN_OPTION
Definition: parseopt.c:59
uint32_t c
Definition: md4.c:30
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int optind
Current option index.
Definition: getopt.c:51
#define DBGC(...)
Definition: compiler.h:505
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
A long option, as used for getopt_long()
Definition: getopt.h:24
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define ERANGE
Result too large.
Definition: errno.h:639
static union @437 opts
"cert<xxx>" option list
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
Parse command-line options.
Definition: getopt.c:229
void print_usage(struct command_descriptor *cmd, char **argv)
Print command usage message.
Definition: parseopt.c:370
#define EINVAL_MISSING_ARGUMENT
Definition: parseopt.c:62
char * optarg
Option argument.
Definition: getopt.c:43
#define ECANCELED_NO_OP
Return status code for "--help" option.
Definition: parseopt.c:51
Option may have an argument.
Definition: getopt.h:20
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), c, cmd, DBGC, ECANCELED_NO_OP, EINVAL_MISSING_ARGUMENT, EINVAL_UNKNOWN_OPTION, ERANGE, getopt_long(), option::has_arg, memset(), option::name, NULL, optarg, optind, optional_argument, opts, print_usage(), rc, option::val, and value.

Referenced by colour_exec(), cpair_exec(), parse_options(), ping_exec(), and sanboot_core_exec().

◆ parse_options()

int parse_options ( int  argc,
char **  argv,
struct command_descriptor cmd,
void *  opts 
)

Parse command-line options.

Parameters
argcArgument count
argvArgument list
cmdCommand descriptor
optsOptions (may be uninitialised)
Return values
rcReturn status code

Definition at line 484 of file parseopt.c.

485  {
486 
487  /* Clear options */
488  memset ( opts, 0, cmd->len );
489 
490  return reparse_options ( argc, argv, cmd, opts );
491 }
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition: parseopt.c:401
static union @437 opts
"cert<xxx>" option list
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
void * memset(void *dest, int character, size_t len) __nonnull

References cmd, memset(), opts, and reparse_options().

Referenced by cert_exec(), choose_exec(), config_exec(), console_exec(), cpuid_exec(), digest_exec(), echo_exec(), exit_exec(), fcels_exec(), fcstat_exec(), gdbstub_exec(), goto_exec(), ibstat_exec(), ifcommon_exec(), imgextract_exec(), imgmem_exec(), imgmulti_exec(), imgsingle_exec(), imgtrust_exec(), imgverify_exec(), inc_exec(), ipstat_exec(), iseq_exec(), isset_exec(), item_exec(), login_exec(), lotest_exec(), menu_exec(), nslookup_exec(), nstat_exec(), ntp_exec(), param_exec(), params_exec(), pciscan_exec(), poweroff_exec(), profstat_exec(), prompt_exec(), pxebs_exec(), reboot_exec(), route_exec(), set_core_exec(), shell_exec(), shim_exec(), show_exec(), sleep_exec(), stoppxe_exec(), sync_exec(), time_exec(), vcreate_exec(), and vdestroy_exec().