![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
Standard command-line options options and parsing. More...
Go to the source code of this file.
Classes | |
| struct | OptsInfo_T |
| Short and Long Options Info. More... | |
| struct | OptsPgmInfo_T |
| Program Description Strings Info Structure. More... | |
Macros | |
| #define | OPTS_NO_SHORT 0 |
| no short option equivalent | |
| #define | OPTS_RVAL_ERROR '?' |
| options error | |
| #define | OPTS_RVAL_LOG 'l' |
| -l, –log return value | |
| #define | OPTS_RVAL_LONG (CHAR_MAX + 1) |
| long return value start | |
| #define | OPTS_RVAL_HELP (OPTS_RVAL_LONG) |
| –help return value | |
| #define | OPTS_RVAL_VERSION (OPTS_RVAL_LONG + 1) |
| –version return value | |
| #define | OPTS_RVAL_LOGFILE (OPTS_RVAL_LONG + 2) |
| –logfile return value | |
| #define | OPTS_RVAL_LOGNOCOLOR (OPTS_RVAL_LONG + 3) |
| –log-no-color rval | |
| #define | OPTS_RVAL_LOGNOTIME (OPTS_RVAL_LONG + 4) |
| –log-no-timestamp rval | |
| #define | OPTS_RVAL_USER (OPTS_RVAL_LONG + 5) |
| start of user available | |
| #define | OPTSBADARG(argv0, opt, arg) OptsInvalid(argv0, "Invalid '%s' argument to '%s' option.", arg, opt) |
| Standard bad option error message reporter. More... | |
Typedefs | |
| typedef int(* | OptsCvtFunc_T) (const char *argv0, const char *sOptName, char *optarg, void *pOptVal) |
| Option Argument Conversion Function Type. | |
| typedef char *(* | OptsFmtFunc_T) (char *buf, size_t buflen, void *pOptVal) |
| Option Value String Formatter Type. | |
Functions | |
| char ** | OptsGet (const char *argv0, const PkgInfo_T *pPkgInfo, OptsPgmInfo_T *pPgmInfo, OptsInfo_T *pOptsInfo, bool_t bHasLogging, int *pargc, char *argv[]) |
| Gets, validates, and sets all command line options. More... | |
| int | OptsCvtArgStr (const char *argv0, const char *sOptName, char *optarg, void *pOptVal) |
| Convert options string argument to string. More... | |
| int | OptsCvtArgBool (const char *argv0, const char *sOptName, char *optarg, void *pOptVal) |
| Convert options boolean argument to bool_t. More... | |
| int | OptsCvtArgInt (const char *argv0, const char *sOptName, char *optarg, void *pOptVal) |
| Convert options integer argument to integer. More... | |
| int | OptsCvtArgFloat (const char *argv0, const char *sOptName, char *optarg, void *pOptVal) |
| Convert options float argument to double. More... | |
| int | OptsCvtArgLogLevel (const char *argv0, const char *sOptName, char *optarg, void *pOptVal) |
| Convert options string argument to log threshold level. More... | |
| char * | OptsFmtStr (char *buf, size_t buflen, void *pOptVal) |
| String option value string formatter. More... | |
| char * | OptsFmtInt (char *buf, size_t buflen, void *pOptVal) |
| Integer option value string formatter. More... | |
| char * | OptsFmtFloat (char *buf, size_t buflen, void *pOptVal) |
| Float option value string formatter. More... | |
| char * | OptsFmtBool (char *buf, size_t buflen, void *pOptVal) |
| Boolean option value string formatter. More... | |
| char * | OptsFmtChar (char *buf, size_t buflen, void *pOptVal) |
| Character option value string formatter. More... | |
| char * | OptsFmtLogLevel (char *buf, size_t buflen, void *pOptVal) |
| Log Level option value string formatter. More... | |
| void | OptsInvalid (const char *argv0, const char *sFmt,...) |
| Invalid option or option argument print and exit. More... | |
Standard command-line options options and parsing.
Every application that uses librnr options facilities are provided with a set of built-in options (described below) to standardize RoadNarrows application interfaces.
Set logging threshold level. All logging events with priority ≤ level will be logged. All others will be ignored. The level argument is one of:
'off' or 0 | Disable all logging. |
'error' or 1 | Enable error and warning logging. |
'diag1' or 2 | Enable diagnostics 1 logging. |
'diag2' or 3 | Enable diagnostics 2 logging. |
'diag3' or 4 | Enable diagnostics 3 logging. |
'diag4' or 5 | Enable diagnostics 4 logging. |
'diag5' or 6 | Enable diagnostics 5 logging. |
> 6 | Enable user-defined logging. |
DEFAULT: off
Set log file file. Special file names:
'stderr' | log to standard error. |
'stdout' | log to standard output. |
DEFAULT: stderr
Disable logging with compiled ANSI color strings.
DEFAULT: false
Disable logging with timestamps.
DEFAULT: false
Display this help and exit.
Output version information and exit.
—
Definition in file opts.h.
| #define OPTSBADARG | ( | argv0, | |
| opt, | |||
| arg | |||
| ) | OptsInvalid(argv0, "Invalid '%s' argument to '%s' option.", arg, opt) |
Standard bad option error message reporter.
| argv0 | Command name string. |
| opt | Option name string. |
| arg | Option argument name string. |
Definition at line 263 of file opts.h.
Referenced by OptsCvtArgBool(), OptsCvtArgFloat(), and OptsCvtArgInt().
| int OptsCvtArgBool | ( | const char * | argv0, |
| const char * | sOptName, | ||
| char * | optarg, | ||
| void * | pOptVal | ||
| ) |
Convert options boolean argument to bool_t.
1 or "true" converts to true.
0 or "false" converts to false.
| argv0 | Command name. | |
| sOptName | Option name. | |
| optarg | Parsed option argument to convert (optional). | |
| [out] | pOptVal | Pointer to converted option value. |
true | OPTSBADARG() |
Definition at line 1018 of file opts.c.
References OK, and OPTSBADARG.
| int OptsCvtArgFloat | ( | const char * | argv0, |
| const char * | sOptName, | ||
| char * | optarg, | ||
| void * | pOptVal | ||
| ) |
Convert options float argument to double.
Accepted format: optionally signed floating-point number.
| argv0 | Command name. | |
| sOptName | Option name. | |
| optarg | Parsed option argument to convert (optional). | |
| [out] | pOptVal | Pointer to converted option value. |
1.0 | OPTSBADARG() |
Definition at line 1109 of file opts.c.
References OK, and OPTSBADARG.
| int OptsCvtArgInt | ( | const char * | argv0, |
| const char * | sOptName, | ||
| char * | optarg, | ||
| void * | pOptVal | ||
| ) |
Convert options integer argument to integer.
Accepted formats: decimal hexidecimal(0x<hexdigits>) octal(0<octaldigits>).
| argv0 | Command name. | |
| sOptName | Option name. | |
| optarg | Parsed option argument to convert (optional). | |
| [out] | pOptVal | Pointer to converted option value. |
1 | OPTSBADARG() |
Definition at line 1065 of file opts.c.
References OK, and OPTSBADARG.
Referenced by OptsCvtArgLogLevel().
| int OptsCvtArgLogLevel | ( | const char * | argv0, |
| const char * | sOptName, | ||
| char * | optarg, | ||
| void * | pOptVal | ||
| ) |
Convert options string argument to log threshold level.
Format: "off", "error", "diag1", "diag2", "diag3", "diag4", "diag5", or >= 0
| argv0 | Command name. | |
| sOptName | Option name. | |
| optarg | Parsed option argument to convert (optional). | |
| [out] | pOptVal | Pointer to converted option value. |
LOG_LEVEL_DFT | OPTSBADARG() |
Definition at line 1151 of file opts.c.
References arraysize, LOG_LEVEL_DFT, LOG_LEVEL_OFF, NvpName2Val(), OK, and OptsCvtArgInt().
Referenced by OptsLogSetLevel().
| int OptsCvtArgStr | ( | const char * | argv0, |
| const char * | sOptName, | ||
| char * | optarg, | ||
| void * | pOptVal | ||
| ) |
Convert options string argument to string.
| argv0 | Command name. | |
| sOptName | Option name. | |
| optarg | Parsed option argument to convert (optional). | |
| [out] | pOptVal | Pointer to converted option value. |
"" (zero-length string)Definition at line 987 of file opts.c.
References new_strdup(), and OK.
Referenced by OptsGet(), and OptsLogSetFile().
| char* OptsFmtBool | ( | char * | buf, |
| size_t | buflen, | ||
| void * | pOptVal | ||
| ) |
Boolean option value string formatter.
| [out] | buf | Output buffer. |
| buflen | Buffer length. | |
| pOptVal | Option value. |
| char* OptsFmtChar | ( | char * | buf, |
| size_t | buflen, | ||
| void * | pOptVal | ||
| ) |
| char* OptsFmtFloat | ( | char * | buf, |
| size_t | buflen, | ||
| void * | pOptVal | ||
| ) |
| char* OptsFmtInt | ( | char * | buf, |
| size_t | buflen, | ||
| void * | pOptVal | ||
| ) |
Integer option value string formatter.
| [out] | buf | Output buffer. |
| buflen | Buffer length. | |
| pOptVal | Option value. |
Definition at line 1215 of file opts.c.
Referenced by OptsFmtLogLevel().
| char* OptsFmtLogLevel | ( | char * | buf, |
| size_t | buflen, | ||
| void * | pOptVal | ||
| ) |
Log Level option value string formatter.
| [out] | buf | Output buffer. |
| buflen | Buffer length. | |
| pOptVal | Option value. |
Definition at line 1289 of file opts.c.
References LOG_LEVEL_OFF, OptsFmtInt(), and OptsFmtStr().
| char* OptsFmtStr | ( | char * | buf, |
| size_t | buflen, | ||
| void * | pOptVal | ||
| ) |
String option value string formatter.
| [out] | buf | Output buffer. |
| buflen | Buffer length. | |
| pOptVal | Option value. |
Definition at line 1191 of file opts.c.
References NULL.
Referenced by OptsFmtLogLevel().
| char** OptsGet | ( | const char * | argv0, |
| const PkgInfo_T * | pPkgInfo, | ||
| OptsPgmInfo_T * | pPgmInfo, | ||
| OptsInfo_T * | pOptsInfo, | ||
| bool_t | bHasLogging, | ||
| int * | pargc, | ||
| char * | argv[] | ||
| ) |
Gets, validates, and sets all command line options.
| argv0 | (Massaged) program name. | |
| pPkgInfo | Package info. | |
| pPgmInfo | Program info. | |
| pOptsInfo | Program options info. | |
| bHasLogging | Do [not] include logging options. | |
| [out] | pargc | New non-option argument count. |
| argv | Command-line options and arguments. arguments. |
Definition at line 861 of file opts.c.
References EC_BAD_OPT, OptsInfo_T::fn_cvt, OptsInfo_T::has_arg, OptsInfo_T::long_opt, OptsCtl_T::m_pLongOpts, OptsCtl_T::m_sShortOpts, NULL, OK, OptsInfo_T::opt_addr, OPTS_LONGOPT_LOG, OPTS_LONGOPT_LOGFILE, OPTS_RESET_ARGCV, OPTS_RVAL_ERROR, OPTS_RVAL_HELP, OPTS_RVAL_LOG, OPTS_RVAL_LOGFILE, OPTS_RVAL_LOGNOCOLOR, OPTS_RVAL_LOGNOTIME, OPTS_RVAL_VERSION, OptsCvtArgStr(), OptsDelete(), OptsHelp(), OptsInvalid(), OptsLogDisableColor(), OptsLogDisableTimestamp(), OptsLogSetFile(), OptsLogSetLevel(), OptsNew(), OptsVersion(), and OptsInfo_T::pvt_retval.
Referenced by init().
| void OptsInvalid | ( | const char * | argv0, |
| const char * | sFmt, | ||
| ... | |||
| ) |
Invalid option or option argument print and exit.
| argv0 | Program name. |
| sFmt | Error format string. |
| ... | Variable arguments to format string. |
EC_BAD_OPT(2). Definition at line 1313 of file opts.c.
References EC_BAD_OPT, MAX_FMT_BUF, and NULL.
Referenced by OptsGet().