fix: compiling but not working -- need debug

This commit is contained in:
Matteo Flebus 2026-01-15 20:42:28 +01:00
parent 1eecb1bd42
commit 04529f858c
4 changed files with 11 additions and 3 deletions

View file

@ -96,7 +96,9 @@ ssize_t stream_read(char **stream)
else if (context.mode == IOB_MODE_CMD) else if (context.mode == IOB_MODE_CMD)
{ {
*stream = context.args; *stream = context.args;
return strlen(context.args); size_t len = strlen(context.args);
context.args[len] = EOF;
return len;
} }
else else
{ {

View file

@ -12,6 +12,7 @@
static char *end_last_token; static char *end_last_token;
static ssize_t remaining_chars; static ssize_t remaining_chars;
static bool at_beginning = true;
/* @brief: saves state for the next call the the lexer. /* @brief: saves state for the next call the the lexer.
* *
@ -20,6 +21,7 @@ static void save_state(char *stream, ssize_t i)
{ {
remaining_chars -= i; remaining_chars -= i;
end_last_token = stream + i; end_last_token = stream + i;
at_beginning = false;
return; return;
} }
@ -43,6 +45,7 @@ static void set_token_spechar(struct token *tok, char *begin, ssize_t size)
if (begin[0] == EOF) if (begin[0] == EOF)
{ {
tok->type = TOKEN_EOF; tok->type = TOKEN_EOF;
remaining_chars = 0;
} }
else if (begin[0] == ';') else if (begin[0] == ';')
{ {
@ -100,6 +103,7 @@ static void set_token_word(struct token *tok, char *begin, ssize_t size)
{ {
if (tok->type == TOKEN_NULL) if (tok->type == TOKEN_NULL)
{ {
tok->type = TOKEN_WORD;
tok->data = calloc(size + 1, sizeof(char)); tok->data = calloc(size + 1, sizeof(char));
if (tok->data == NULL) if (tok->data == NULL)
return; return;
@ -133,9 +137,10 @@ char *stream_init(void)
{ {
char *stream; char *stream;
if (remaining_chars == 0) if (at_beginning)
{ {
remaining_chars = stream_read(&stream); remaining_chars = stream_read(&stream);
// at_beginning = true;
} }
else else
{ {

View file

@ -35,6 +35,7 @@ struct ast *get_ast()
token = pop_token(); token = pop_token();
break; break;
} }
token = peek_token();
} }
if (token == NULL) if (token == NULL)

View file

@ -54,7 +54,7 @@ static bool isterminator(struct token *token)
struct ast *parse_simple_command(void) struct ast *parse_simple_command(void)
{ {
struct list *command_elements = NULL; struct list *command_elements = NULL;
struct token *token = POP_TOKEN(); struct token *token = PEEK_TOKEN();
while (!isterminator(token)) while (!isterminator(token))
{ {