![]() |
BSB Developer Docs
|
Command line argument parsing library. More...
#include <core/string.h>Go to the source code of this file.
Typedefs | |
| typedef void(* | OptionCallback) (char opt, const char *optarg, void *context) |
| Option callback function type. | |
Functions | |
| bool | parse_args (FuriString *args, const char *opts, OptionCallback callback, void *context) |
| Parse command options from an argument string. | |
Command line argument parsing library.
Supports a getopt-like syntax with single-character options and positional arguments. Options may have a required argument or be argument-less.
Strings containing space characters must be enclosed in single or double quotes. If quotes need to be present inside of a quoted string, they must be of opposite type, e.g. "String with 'quotes'" or 'String with "quotes"'.
Escaping is not supported.
| typedef void(* OptionCallback) (char opt, const char *optarg, void *context) |
Option callback function type.
If opt is a zero (NUL) character, the parsed option is a positional argument.
If an option argument was not required, optarg will be NULL.
| [in] | opt | option character from the parsed argument string |
| [in] | optarg | option argument (if required and present, may be NULL) |
| [in,out] | context | pointer to a user-specified object from parse_args invocation |
| bool parse_args | ( | FuriString * | args, |
| const char * | opts, | ||
| OptionCallback | callback, | ||
| void * | context ) |
Parse command options from an argument string.
opts must be a string containing all of the options to be looked for, e.g. "abcDEF".
To make an option require an argument, : must be added after the option character, i.e. "a:b:c" means that -a and -b options require an argument, while -c does not.
If only positional arguments are needed, opts can be NULL or an empty string.
The following situations are treated as a success:
opts option specifier stringopts contentsThe following situations are treated as errors:
| [in,out] | args | pointer to a FuriString containing the argument string |
| [in] | opts | pointer to a zero-terminated string containing option specifiers (may be NULL) |
| [in] | callback | pointer to a function to be called for each option or positional argument |
| [in,out] | context | pointer to a user-specified object (will be passed to the callback) |
true on success, false otherwise