diff options
Diffstat (limited to 'arg.c')
-rw-r--r-- | arg.c | 40 |
1 files changed, 24 insertions, 16 deletions
@@ -2,10 +2,15 @@ //for local usage only? int __search_arg( char *in, def_arg *arg ); +/*from s_arg_[TYPE] create type arg_[TYPE]*/ void* __create_arg( int type, void *val ); -int __add_arg( arg_t *arg, int type,void *val ); +/*add to argument list new parsed/recognized argument*/ +int __add_arg( arg_t *arg, int type, void *val ); +/* +check if command line argument ARG[NUM<argc] +*/ #define CHK_ARG(ARG,NUM) if ((ARG+NUM)>=argc) {\ printf("not enought arguments for %s ",argv[ARG]);break;} @@ -25,6 +30,10 @@ arg_t* arg_load( int argc, char **argv, def_arg *argl ) used = malloc(sizeof(uint8_t)*argc); memset( used, 0, sizeof(uint8_t)*argc ); + /*************************************************************************** + Go troght all define arguments and try to parse and match all found arguments. + Prepare list of all recognized arguments + ***************************************************************************/ i = 1; //we can ignore first as first arg is name of programm while ( i < argc ) { @@ -89,9 +98,9 @@ arg_t* arg_load( int argc, char **argv, def_arg *argl ) arg_val *val = __create_arg( argl[pos].type, argl[pos].def ); - if (((s_arg_val*)argl[pos].def)->ptr != NULL) - val->def = 0; - val->used = 1; + //if (((s_arg_val*)argl[pos].def)->ptr != NULL) + // val->def = 0; + //val->used = 1; val->ptr = argv[i+1]; __add_arg( ret, ARGT_VAL, val ); @@ -121,7 +130,7 @@ arg_t* arg_load( int argc, char **argv, def_arg *argl ) flg = __create_arg( argl[pos].type, argl[pos].def ); - flg->used = 1; + //flg->used = 1; flg->flag = 1; __add_arg( ret, ARGT_FLAG, flg ); @@ -198,8 +207,8 @@ arg_ip* arg_c_ip( uint32_t ip, uint16_t port ) ret = malloc( sizeof(arg_ip) ); memset(ret,0,sizeof(arg_ip)); - ret->default_ip = ip; - ret->default_port = port; + ret->ip = ip; + ret->port = port; return ret; } @@ -212,9 +221,9 @@ arg_range* arg_c_range( uint32_t start, uint32_t end, uint32_t step ) ret = malloc( sizeof(arg_range) ); memset( ret, 0, sizeof(arg_range) ); - ret->default_start = start; - ret->default_end = end; - ret->default_step = step; + ret->start = start; + ret->end = end; + ret->step = step; return ret; } @@ -227,13 +236,13 @@ arg_float* arg_c_float( float val ) ret = malloc( sizeof(arg_float) ); memset( ret, 0, sizeof(arg_float) ); - ret->default_val = val; + ret->val = val; return ret; } -arg_list* arg_c_list( uint32_t num, void **vals, void *def ) +arg_list* arg_c_list( uint32_t num, void **vals) { arg_list *ret = NULL; @@ -242,7 +251,6 @@ arg_list* arg_c_list( uint32_t num, void **vals, void *def ) ret->num = num; ret->vals = vals; - ret->default_val = def; return ret; } @@ -255,7 +263,7 @@ arg_file* arg_c_file( char *name ) ret = malloc( sizeof(arg_file) ); memset( ret, 0, sizeof(arg_file) ); - ret->default_name = name; + ret->name = name; return ret; } @@ -268,7 +276,7 @@ arg_val* arg_c_val( char *ptr ) ret = malloc( sizeof(arg_val) ); memset( ret, 0, sizeof(arg_val) ); - ret->default_ptr = ptr; + ret->ptr = ptr; return ret; } @@ -412,7 +420,7 @@ void* __create_arg( int type, void *val ) arg_list *list = NULL; s_arg_list *s_list = NULL; - list = arg_c_list( s_list->num, s_list->vals, s_list->default_val ); + list = arg_c_list( s_list->num, s_list->vals ); ret = list; break; |