Commit d0d29bf1 authored by Kevin Wolf's avatar Kevin Wolf

shell: Erst in Syntaxtree parsen, dann ausführen

* shell: Dieser Commit spendiert der Shell Ansätze von einem richtigen
  Parser anstatt nur Dateiumleitungen aus der Tokensuppe herauszufischen
  und den Rest als Argumente zu nehmen.
Signed-off-by: Kevin Wolf's avatarKevin Wolf <kevin@tyndur.org>
parent fc447b48
This diff is collapsed.
......@@ -43,6 +43,7 @@
/* Tokenizer */
enum token_type {
TT_END_OF_INPUT,
TT_WORD,
TT_OPERATOR,
};
......@@ -60,8 +61,6 @@ struct tokenizer* tokenizer_create(const char *str);
int tokenizer_get(struct tokenizer* tok, struct token* token);
void tokenizer_free(struct tokenizer* tok);
int tokenize_cmdline(const char* str, char** output, struct token* tokens);
/** Array mit den Befehlen */
typedef struct shell_command_t {
const char* name;
......
......@@ -96,7 +96,11 @@ int tokenizer_get(struct tokenizer* tok, struct token* token)
enum token_type type = TT_WORD;
if (!str || !*str) {
return -1;
*token = (struct token) {
.type = TT_END_OF_INPUT,
.value = NULL,
};
return 0;
}
restart:
......@@ -216,12 +220,10 @@ restart:
abort();
accept:
if (token) {
*token = (struct token) {
.type = type,
.value = strndup(tok->input, str - tok->input),
};
}
*token = (struct token) {
.type = type,
.value = strndup(tok->input, str - tok->input),
};
tok->input = str;
return 0;
......@@ -231,25 +233,3 @@ void tokenizer_free(struct tokenizer* tok)
{
free(tok);
}
int tokenize_cmdline(const char* str, char** output, struct token* tokens)
{
struct tokenizer* tok;
int num_tokens = 0;
if (output) {
*output = NULL;
}
tok = tokenizer_create(str);
while (tokenizer_get(tok, tokens) == 0) {
num_tokens++;
if (tokens) {
tokens++;
}
}
tokenizer_free(tok);
return num_tokens;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment