Skip to content

Commit

Permalink
Optionally restrict input to one command per line.
Browse files Browse the repository at this point in the history
  • Loading branch information
biot committed Nov 28, 2014
1 parent 1296306 commit 0fe64e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tokenline.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,12 @@ static int tokenize(t_tokenline *tl, int *words, int num_words,
/* Argument is one of these subtokens. */
arg_tokens = token_stack[cur_tsp][t_idx].subtokens;
} else if (token_stack[cur_tsp][t_idx].subtokens) {
/* Switch to a new token set. */
token_stack[cur_tsp + 1] = token_stack[cur_tsp][t_idx].subtokens;
cur_tsp++;
} else {
/* Not expecting any more arguments or tokens. */
done = TRUE;
done = tl->one_command_per_line;
}
} else {
if (!complete_tokens)
Expand Down Expand Up @@ -496,6 +497,7 @@ static int tokenize(t_tokenline *tl, int *words, int num_words,
break;
}
arg_needed = 0;
done = tl->one_command_per_line;
}
}
if (arg_needed && !complete_tokens) {
Expand Down Expand Up @@ -812,6 +814,7 @@ void tl_init(t_tokenline *tl, t_token *tokens_top, t_token_dict *token_dict,
tl->token_dict = token_dict;
tl->print = printfunc;
tl->user = user;
tl->one_command_per_line = TL_ONE_COMMAND_PER_LINE;
tl->hist_step = -1;
}

Expand Down
2 changes: 2 additions & 0 deletions tokenline.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define TL_MAX_TOKEN_LEVELS 8
#define TL_MAX_HISTORY_SIZE 512
#define TL_TOKEN_DELIMITER ':'
#define TL_ONE_COMMAND_PER_LINE FALSE

enum {
/* Token can be optionally suffixed by delimiter and integer. */
Expand Down Expand Up @@ -66,6 +67,7 @@ typedef struct tokenline {
char *prompt;
tl_callback callback;
int pos;
int one_command_per_line;
t_tokenline_parsed parsed;
int hist_step;
int hist_begin;
Expand Down

0 comments on commit 0fe64e9

Please sign in to comment.