CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
optarg.h File Reference

The declarations in this header file correspond to the definitions in optarg.c. More...

#include <stdbool.h>
#include "cdi_core_api.h"

Go to the source code of this file.

Data Structures

struct  OptDef
 A structure that is used by the user to define a single option. An array of these option structs is passed to GetOpt() for command line parsing. More...
 
struct  OptArg
 A structure that describes a single command line option and its associated arguments. More...
 

Macros

#define OPTARG_MAX_OPTION_ARGS   (20)
 The maximum number of arguments allowed for any command line option.
 
#define OPTARG_MAX_OPTION_LENGTH   (16)
 The maximum length of any option string.
 
#define OPTARG_MAX_SHORT_OPTION_LENGTH   (5)
 The maximum length of any short option string.
 
#define OPTARG_MAX_ARG_STR_LENGTH   (16)
 The maximum length of any option argument string.
 
#define OPTARG_MAX_DESCRIPTION_STRING_LEN   (800)
 The maximum length of any option description string.
 
#define OPTARG_MAX_IP_STRING_LEN   (20)
 The maximum length of an IP address string.
 
#define OPTARG_OPTION_ARRAY_MAX_CHAR_LEN   (400)
 The maximum number of chars in an array containing command line choices (i.e. platforms_array).
 
#define OPTARG_USAGE_DESCRIPTION_INDENT   (1 + OPTARG_MAX_SHORT_OPTION_LENGTH + 5 + OPTARG_MAX_OPTION_LENGTH + 1 + OPTARG_MAX_ARG_STR_LENGTH + 3)
 The number of chars to indent the description field in the main usage message.
 
#define OPTARG_AVM_USAGE_LIST_INDENT   (29)
 The number of chars to indent the options list in the audio and video usage messages.
 

Functions

void PrintKeyArrayNames (const CdiEnumStringKey *key_array, const int indent)
 
void PrintOption (const OptDef *option_ptr)
 
void PrintUsage (const OptDef *opt_array_ptr, bool has_error)
 
bool GetOpt (int argc, const char *argv_ptr[], int *index_ptr, OptDef *opt_array_ptr, OptArg *this_opt_ptr)
 

Detailed Description

The declarations in this header file correspond to the definitions in optarg.c.

Function Documentation

◆ GetOpt()

bool GetOpt ( int argc,
const char * argv_ptr[],
int * index_ptr,
OptDef * opt_array_ptr,
OptArg * this_opt_ptr )

A user-facing function that takes in the argv system command line args array and an index and finds the next option and its associated arguments, incrementing the index accordingly. Returns false for any error condition or if the end of the arguments array has been reached. The contents of index_ptr are incremented as options and arguments are processed and will be equal to argc on a normal exit after processing all options and arguments. However, if we hit the end of the argv array and are still expecting arguments to the last option, we will increment the contents of index_ptr beyond argc so that the calling routine can detect that it was not a normal exit.

Parameters
argcThe system command line argument count variable.
argv_ptrThe pointer to the system command line arguments array.
index_ptrThe pointer to the current argv index, which gets incremented by the function as options and arguments are retrieved. Should match argc after all argv elements have been processed.
opt_array_ptrPointer to array of user-defined options.
this_opt_ptrA structure describing the single option (and arguments) retrieved.
Returns
True for success; false for failure or if we are at the end of argv.

◆ PrintKeyArrayNames()

void PrintKeyArrayNames ( const CdiEnumStringKey * key_array,
const int indent )

Print all the name_str elements of a key-value array in the format: <key_array[0].name_str, key_array[1].name_str ... >

Parameters
key_arrayA key-value array to search for name_str.
indentThe number of space to indent before printing the array of names from the name_str member of each key-value pair.

◆ PrintOption()

void PrintOption ( const OptDef * option_ptr)

Print the usage message of a single option based on the user-defined usage options.

Parameters
option_ptrPointer to a single user-defined option.

◆ PrintUsage()

void PrintUsage ( const OptDef * opt_array_ptr,
bool has_error )

Print the usage message based on the user-defined usage options.

Parameters
opt_array_ptrPointer to array of user-defined options.
has_errorTrue if we got an error and wish to print an error statement after printing usage.