Skip to content

Commit

Permalink
add cmdl_parse_ints()
Browse files Browse the repository at this point in the history
  • Loading branch information
jfzheng committed Jan 12, 2016
1 parent 9f4cd84 commit 21df0a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions libsim/sim_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,31 @@ int cmdl_parse_int (cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *
return 0;
}

int cmdl_parse_ints (cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *opt)
{
int i = 0;
if (act == CMDL_ACT_PARSE)
{
for (i=0; i<opt->narg; ++i) {
char *arg = cmdl_iter_next(iter);
if (!arg || /*b_err=*/str_2_int(arg, &((int*)dst)[i])) {
xerr(arg ? "str2i() failed\n" : "noarg\n");
cmdl_iter_dbg (iter);
return CMDL_RET_ERROR;
}
}
return opt->narg + 1;
}
else if (act == CMDL_ACT_RESULT)
{
for (i=0; i<opt->narg; ++i) {
xprint("%s'%d'", i?"":",", *((int*)dst));
}
}

return 0;
}

int cmdl_parse_xlevel(cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *opt)
{
if (act == CMDL_ACT_PARSE)
Expand Down Expand Up @@ -830,6 +855,14 @@ void cmdl_layer_prefix(int layer)
}
}

void cmdl_iter_dbg (cmdl_iter_t *_iter)
{
cmdl_iter_t iter = *_iter;
for (cmdl_iter_1st(&iter); cmdl_iter_curr(&iter); cmdl_iter_next(&iter)) {
xdbg("%s\n", cmdl_iter_curr(&iter));
}
}

/**
* @param iter just for layer trace
*/
Expand Down
2 changes: 2 additions & 0 deletions libsim/sim_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ char* cmdl_peek_next(cmdl_iter_t *iter); /** argv[1 + iter->idx]
char* cmdl_peek_ith (cmdl_iter_t *iter, int ith); /** argv[ith + iter->idx] */
char* cmdl_iter_pop (cmdl_iter_t *iter, int b_opt);
void cmdl_layer_prefix(int layer);
void cmdl_iter_dbg (cmdl_iter_t *iter);

typedef enum {
CMDL_ACT_PARSE = 0,
Expand Down Expand Up @@ -136,6 +137,7 @@ int cmdl_parse_range (cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *
int cmdl_parse_str (cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *opt);
int cmdl_parse_strcpy(cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *opt);
int cmdl_parse_int (cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *opt);
int cmdl_parse_ints (cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *opt);
int cmdl_parse_xlevel(cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *opt);
int cmdl_parse_help (cmdl_iter_t *iter, void* dst, cmdl_act_t act, cmdl_opt_t *opt);

Expand Down

0 comments on commit 21df0a7

Please sign in to comment.