unsigned int arg_count;
char** arg_vect;
int current;
- OptionConfig_T* options;
+ opts_cfg_t* options;
} StreamContext_T;
static entry_t* Options = NULL;
static void opts_parse_argument( StreamContext_T* ctx );
static void opts_parse_error(const char* msg, char* opt_name);
-static OptionConfig_T* opts_get_option_config( OptionConfig_T* opts, OptionType_T typ, char* name );
+static opts_cfg_t* opts_get_option_config( opts_cfg_t* opts, OptionType_T typ, char* name );
static char* opts_next_token( StreamContext_T* ctx );
static void opts_consume_ws( StreamContext_T* ctx );
static char opts_next_char( StreamContext_T* ctx );
static void opts_add_option(char* name, char* tag, char* arg);
static void opts_add_argument(char* arg);
-void opts_parse( OptionConfig_T* opts, int argc, char** argv ) {
+void opts_parse( opts_cfg_t* opts, int argc, char** argv ) {
/* Setup the stream */
StreamContext_T ctx;
ctx.line_idx = 0;
static void opts_parse_short_option( StreamContext_T* ctx ) {
char opt[2] = { ctx->current, '\0' };
char* opt_name = strclone(opt);
- OptionConfig_T* config = opts_get_option_config( ctx->options, SHORT, opt_name );
+ opts_cfg_t* config = opts_get_option_config( ctx->options, SHORT, opt_name );
if (config != NULL) {
char* opt_arg = NULL;
(void)opts_next_char( ctx );
static void opts_parse_long_option( StreamContext_T* ctx ) {
char* opt_name = opts_next_token( ctx );
- OptionConfig_T* config = opts_get_option_config( ctx->options, LONG, opt_name );
+ opts_cfg_t* config = opts_get_option_config( ctx->options, LONG, opt_name );
if (config != NULL) {
char* opt_arg = NULL;
if (config->has_arg)
opts_add_argument(arg_val);
}
-static OptionConfig_T* opts_get_option_config( OptionConfig_T* opts, OptionType_T type, char* name ) {
- OptionConfig_T* cfg = NULL;
+static opts_cfg_t* opts_get_option_config( opts_cfg_t* opts, OptionType_T type, char* name ) {
+ opts_cfg_t* cfg = NULL;
int i = 0;
while( opts[i].name != NULL ) {
OptionType_T curr_type = (strlen(opts[i].name) > 1) ? LONG : SHORT;
return (NULL == p_opt) ? NULL : p_opt->value;
}
+bool opts_equal(const char* name, const char* tag, const char* value) {
+ return (0 == strcmp(value, opts_get_value(name,tag)));
+}
+
const char** opts_select(const char* name, const char* tag) {
size_t index = 0;
const char** ret = (const char**)malloc(sizeof(const char*));
#include <stdbool.h>
#include <stddef.h>
-typedef struct OptionConfig_T {
+typedef struct {
char* name;
bool has_arg;
char* tag;
char* desc;
-} OptionConfig_T;
+} opts_cfg_t;
-void opts_parse( OptionConfig_T* opts, int argc, char** argv );
+void opts_parse(opts_cfg_t* opts, int argc, char** argv);
void opts_reset(void);
bool opts_is_set(const char* name, const char* tag);
+bool opts_equal(const char* name, const char* tag, const char* value);
+
const char* opts_get_value(const char* name, const char* tag);
const char** opts_select(const char* name, const char* tag);
//-----------------------------------------------------------------------------
// Sample Option Configuration
//-----------------------------------------------------------------------------
-OptionConfig_T Options_Config[] = {
+opts_cfg_t Options_Config[] = {
{ "a", false, "test_a", "A simple test option" },
{ "b", true, "test_b", "A simple test option" },
{ "c", false, "test_c", "A simple test option" },