Skip to content

Commit

Permalink
Callback function now takes a pointer to t_tokenline_parsed.
Browse files Browse the repository at this point in the history
  • Loading branch information
biot committed Nov 22, 2014
1 parent 2d5b0da commit 2d8ae20
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void tl_set_prompt(t_tokenline *tl, char *prompt)
Change the prompt tokenline uses. The pointer is used from then on,
so dynamic prompt changes can be done there as well.

typedef void (*tl_callback)(void *user, t_tokenline_parsed p);
typedef void (*tl_callback)(void *user, t_tokenline_parsed *p);
void tl_set_callback(t_tokenline *tl, tl_callback callback)

Set the function that will be called when a command is entered. The
Expand Down
18 changes: 9 additions & 9 deletions demo/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,34 @@ void print(void *user, const char *str)
printf("%s", str);
}

static void dump_parsed(void *user, t_tokenline_parsed p)
static void dump_parsed(void *user, t_tokenline_parsed *p)
{
float arg_float;
int arg_int, i;

(void)user;

for (i = 0; p.tokens[i]; i++) {
for (i = 0; p->tokens[i]; i++) {
printf("%d: ", i);
switch (p.tokens[i]) {
switch (p->tokens[i]) {
case TARG_INT:
memcpy(&arg_int, p.buf + p.tokens[++i], sizeof(int));
memcpy(&arg_int, p->buf + p->tokens[++i], sizeof(int));
printf("integer %d\n", arg_int);
break;
case TARG_FLOAT:
memcpy(&arg_float, p.buf + p.tokens[++i], sizeof(float));
memcpy(&arg_float, p->buf + p->tokens[++i], sizeof(float));
printf("float %f\n", arg_float);
break;
case TARG_FREQ:
memcpy(&arg_float, p.buf + p.tokens[++i], sizeof(float));
memcpy(&arg_float, p->buf + p->tokens[++i], sizeof(float));
printf("frequency %f\n", arg_float);
break;
case TARG_STRING:
printf("string '%s'\n", p.buf + p.tokens[++i]);
printf("string '%s'\n", p->buf + p->tokens[++i]);
break;
default:
printf("token %d (%s)\n", p.tokens[i],
dict[p.tokens[i]].tokenstr);
printf("token %d (%s)\n", p->tokens[i],
dict[p->tokens[i]].tokenstr);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tokenline.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ static void process_line(t_tokenline *tl)
if (!tokenize(tl, words, num_words, NULL, NULL))
break;
if (tl->callback)
tl->callback(tl->user, tl->parsed);
tl->callback(tl->user, &tl->parsed);
}
} while (FALSE);

Expand Down
2 changes: 1 addition & 1 deletion tokenline.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct tokenline_parsed {
} t_tokenline_parsed;

typedef void (*tl_printfunc)(void *user, const char *str);
typedef void (*tl_callback)(void *user, t_tokenline_parsed p);
typedef void (*tl_callback)(void *user, t_tokenline_parsed *p);
typedef struct tokenline {
t_token *token_levels[TL_MAX_TOKEN_LEVELS];
int token_level;
Expand Down

0 comments on commit 2d8ae20

Please sign in to comment.