diff options
author | nthnluu <nate1299@me.com> | 2024-01-28 21:20:27 -0500 |
---|---|---|
committer | nthnluu <nate1299@me.com> | 2024-01-28 21:20:27 -0500 |
commit | c63f340d90800895f007de64b7d2d14624263331 (patch) | |
tree | 2c0849fa597dd6da831c8707b6f2603403778d7b /kernel/test/kshell/tokenizer.h |
Created student weenix repository
Diffstat (limited to 'kernel/test/kshell/tokenizer.h')
-rw-r--r-- | kernel/test/kshell/tokenizer.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/kernel/test/kshell/tokenizer.h b/kernel/test/kshell/tokenizer.h new file mode 100644 index 0000000..9c49026 --- /dev/null +++ b/kernel/test/kshell/tokenizer.h @@ -0,0 +1,39 @@ +#pragma once + +#include "types.h" + +#include "test/kshell/kshell.h" + +typedef enum kshell_token_type +{ + KTT_WORD, + KTT_REDIRECT_IN, /* '<' */ + KTT_REDIRECT_OUT, /* '>' */ + KTT_REDIRECT_OUT_APPEND, /* '>>' */ + KTT_EOL, + + KTT_MAX /* Number of token types */ +} kshell_token_type_t; + +typedef struct kshell_token +{ + kshell_token_type_t kt_type; + char *kt_text; + size_t kt_textlen; +} kshell_token_t; + +/** + * Finds the next token in the input line. + * + * Note: To find multiple tokens from the same line, you increment the + * line pointer by the number of bytes processed before the next call + * to kshell_next token. + * + * @param ksh the kshell + * @param line the input line to tokenize + * @param token out parameter containing the next token found + * @return 0 if no more tokens, otherwise, number of bytes processed + */ +long kshell_next_token(kshell_t *ksh, char *line, kshell_token_t *token); + +const char *kshell_token_type_str(kshell_token_type_t type); |