iPXE
Macros | Functions
parseopt.c File Reference

Command line option parsing. More...

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/uuid.h>
#include <ipxe/netdevice.h>
#include <ipxe/dynui.h>
#include <ipxe/settings.h>
#include <ipxe/params.h>
#include <ipxe/timer.h>
#include <ipxe/keys.h>
#include <ipxe/parseopt.h>
#include <config/branding.h>

Go to the source code of this file.

Macros

#define ECANCELED_NO_OP   __einfo_error ( EINFO_ECANCELED_NO_OP )
 Return status code for "--help" option. More...
 
#define EINFO_ECANCELED_NO_OP   __einfo_uniqify ( EINFO_ECANCELED, 0x01, "Nothing to do" )
 
#define EINVAL_INTEGER   __einfo_error ( EINFO_EINVAL_INTEGER )
 
#define EINFO_EINVAL_INTEGER   __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid integer value" )
 
#define EINVAL_UNKNOWN_OPTION   __einfo_error ( EINFO_EINVAL_UNKNOWN_OPTION )
 
#define EINFO_EINVAL_UNKNOWN_OPTION   __einfo_uniqify ( EINFO_EINVAL, 0x02, "Unrecognised option" )
 
#define EINVAL_MISSING_ARGUMENT   __einfo_error ( EINFO_EINVAL_MISSING_ARGUMENT )
 
#define EINFO_EINVAL_MISSING_ARGUMENT   __einfo_uniqify ( EINFO_EINVAL, 0x03, "Missing argument" )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
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_dynui (char *text, struct dynamic_ui **dynui)
 Parse dynamic user interface 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 **value)
 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.c.

Macro Definition Documentation

◆ ECANCELED_NO_OP

#define ECANCELED_NO_OP   __einfo_error ( EINFO_ECANCELED_NO_OP )

Return status code for "--help" option.

Definition at line 52 of file parseopt.c.

◆ EINFO_ECANCELED_NO_OP

#define EINFO_ECANCELED_NO_OP   __einfo_uniqify ( EINFO_ECANCELED, 0x01, "Nothing to do" )

Definition at line 53 of file parseopt.c.

◆ EINVAL_INTEGER

#define EINVAL_INTEGER   __einfo_error ( EINFO_EINVAL_INTEGER )

Definition at line 57 of file parseopt.c.

◆ EINFO_EINVAL_INTEGER

#define EINFO_EINVAL_INTEGER   __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid integer value" )

Definition at line 58 of file parseopt.c.

◆ EINVAL_UNKNOWN_OPTION

#define EINVAL_UNKNOWN_OPTION   __einfo_error ( EINFO_EINVAL_UNKNOWN_OPTION )

Definition at line 60 of file parseopt.c.

◆ EINFO_EINVAL_UNKNOWN_OPTION

#define EINFO_EINVAL_UNKNOWN_OPTION   __einfo_uniqify ( EINFO_EINVAL, 0x02, "Unrecognised option" )

Definition at line 61 of file parseopt.c.

◆ EINVAL_MISSING_ARGUMENT

#define EINVAL_MISSING_ARGUMENT   __einfo_error ( EINFO_EINVAL_MISSING_ARGUMENT )

Definition at line 63 of file parseopt.c.

◆ EINFO_EINVAL_MISSING_ARGUMENT

#define EINFO_EINVAL_MISSING_ARGUMENT   __einfo_uniqify ( EINFO_EINVAL, 0x03, "Missing argument" )

Definition at line 64 of file parseopt.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ parse_string()

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

Parse string value.

Parameters
textText
Return values
valueString value
rcReturn status code

Definition at line 74 of file parseopt.c.

74  {
75 
76  /* Sanity check */
77  assert ( text != NULL );
78 
79  /* Parse string */
80  *value = text;
81 
82  return 0;
83 }
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:322

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 92 of file parseopt.c.

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

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 115 of file parseopt.c.

115  {
116  unsigned int value_ms;
117  int rc;
118 
119  /* Parse raw integer value */
120  if ( ( rc = parse_integer ( text, &value_ms ) ) != 0 )
121  return rc;
122 
123  /* Convert to a number of timer ticks */
124  *value = ( value_ms * TICKS_PER_MS );
125 
126  return 0;
127 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
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:26

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 136 of file parseopt.c.

136  {
137  int rc;
138 
139  /* Sanity check */
140  assert ( text != NULL );
141 
142  /* Parse UUID */
143  if ( ( rc = uuid_aton ( text, &uuid->buf ) ) != 0 ) {
144  printf ( "\"%s\": invalid UUID\n", text );
145  return rc;
146  }
147  uuid->value = &uuid->buf;
148 
149  return 0;
150 }
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:465
A universally unique ID.
Definition: uuid.h:16
int uuid_aton(const char *string, union uuid *uuid)
Parse UUID.
Definition: uuid.c:67
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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 159 of file parseopt.c.

159  {
160 
161  /* Sanity check */
162  assert ( text != NULL );
163 
164  /* Find network device */
165  *netdev = find_netdev ( text );
166  if ( ! *netdev ) {
167  printf ( "\"%s\": no such network device\n", text );
168  return -ENODEV;
169  }
170 
171  return 0;
172 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
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:510
struct net_device * find_netdev(const char *name)
Get network device by name.
Definition: netdevice.c:989
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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 181 of file parseopt.c.

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

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

◆ parse_dynui()

int parse_dynui ( char *  text,
struct dynamic_ui **  dynui 
)

Parse dynamic user interface name.

Parameters
textText
Return values
dynuiDynamic user interface
rcReturn status code

Definition at line 204 of file parseopt.c.

204  {
205 
206  /* Find user interface */
207  *dynui = find_dynui ( text );
208  if ( ! *dynui ) {
209  if ( text ) {
210  printf ( "\"%s\": no such user interface\n", text );
211  } else {
212  printf ( "No default user interface\n" );
213  }
214  return -ENOENT;
215  }
216 
217  return 0;
218 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
struct dynamic_ui * find_dynui(const char *name)
Find dynamic user interface.
Definition: dynui.c:173
#define ENOENT
No such file or directory.
Definition: errno.h:515

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

Referenced by choose_exec(), item_exec(), and present_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 227 of file parseopt.c.

227  {
228 
229  /* Set flag */
230  *flag = 1;
231 
232  return 0;
233 }
uint32_t flag
Flag number.
Definition: aqc1xx.h:37

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 242 of file parseopt.c.

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

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 272 of file parseopt.c.

272  {
273 
274  /* Sanity check */
275  assert ( text != NULL );
276 
277  /* Parse scope name */
278  *value = find_settings ( text );
279  if ( ! *value ) {
280  printf ( "\"%s\": no such scope\n", text );
281  return -EINVAL;
282  }
283 
284  return 0;
285 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
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:407
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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 297 of file parseopt.c.

298  {
299  int rc;
300 
301  /* Sanity check */
302  assert ( text != NULL );
303 
304  /* Parse setting name */
305  if ( ( rc = parse_setting_name ( text, get_child, &setting->settings,
306  &setting->setting ) ) != 0 ) {
307  printf ( "\"%s\": invalid setting\n", text );
308  return rc;
309  }
310 
311  return 0;
312 }
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:465
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
A setting.
Definition: settings.h:24
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
Definition: settings.c:1529

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 323 of file parseopt.c.

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

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 337 of file parseopt.c.

337  {
338 
340 }
int parse_setting(char *text, struct named_setting *setting, get_child_settings_t get_child)
Parse setting name.
Definition: parseopt.c:297
struct settings * autovivify_child_settings(struct settings *parent, const char *name)
Find or create child settings block.
Definition: settings.c:307
A setting.
Definition: settings.h:24

References autovivify_child_settings(), and parse_setting().

Referenced by choose_exec(), pciscan_exec(), set_core_exec(), and usbscan_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 349 of file parseopt.c.

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

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 371 of file parseopt.c.

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

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

References assert(), 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 485 of file parseopt.c.

486  {
487 
488  /* Clear options */
489  memset ( opts, 0, cmd->len );
490 
491  return reparse_options ( argc, argv, cmd, opts );
492 }
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition: parseopt.c:402
static union @447 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(), dynui_exec(), echo_exec(), exit_exec(), fcels_exec(), fcstat_exec(), fdt_exec(), gdbstub_exec(), goto_exec(), ibstat_exec(), ifcommon_exec(), imgdecrypt_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(), nslookup_exec(), nstat_exec(), ntp_exec(), param_exec(), params_exec(), pciscan_exec(), poweroff_exec(), present_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(), usbscan_exec(), vcreate_exec(), and vdestroy_exec().