Skip to content

Commit

Permalink
Add T_FLAG_SUFFIX_TOKEN_DELIM_INT instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
biot committed Nov 25, 2014
1 parent 8269e6f commit c829344
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions demo/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ t_token_dict dict[] = {
{ T_FREQUENCY, "frequency" },
{ T_MKDIR, "mkdir" },
{ T_LS, "ls" },
{ T_TAP, "tap" },
{ T_EXIT, "exit" },
{ }
};
Expand Down Expand Up @@ -85,6 +86,9 @@ t_token tokens[] = {
.help = "Set things" },
{ T_DEVICE,
.help = "Device mode" },
{ T_TAP,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Tap" },
{ T_HELP,
.arg_type = T_ARG_HELP,
.help = "Available commands" },
Expand Down
1 change: 1 addition & 0 deletions demo/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum {
T_FREQUENCY,
T_MKDIR,
T_LS,
T_TAP,
T_EXIT,
};

5 changes: 5 additions & 0 deletions demo/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static void dump_parsed(void *user, t_tokenline_parsed *p)
{
struct demo_context *ctx;
float arg_float;
uint32_t arg_uint;
int arg_int, i;

ctx = user;
Expand All @@ -69,6 +70,10 @@ static void dump_parsed(void *user, t_tokenline_parsed *p)
case T_ARG_STRING:
printf("string '%s'\n", p->buf + p->tokens[++i]);
break;
case T_ARG_TOKEN_SUFFIX_INT:
memcpy(&arg_uint, p->buf + p->tokens[++i], sizeof(uint32_t));
printf("token-suffixed integer %d\n", arg_uint);
break;
default:
printf("token %d (%s)\n", p->tokens[i],
dict[p->tokens[i]].tokenstr);
Expand Down

0 comments on commit c829344

Please sign in to comment.