aboutsummaryrefslogtreecommitdiff
path: root/src/repl.c
diff options
context:
space:
mode:
authorChristopher Uhlig2025-01-25 13:01:10 +0100
committerChristopher Uhlig2025-01-25 13:01:10 +0100
commit87b90103930d83d74baa998866b0995cb8887d51 (patch)
tree0eb876341c2794f2165b83c1d339fb3b38e9f711 /src/repl.c
parent18fb7cb8ae69fc3439266a154aa6b0f947d6805d (diff)
downloadminishell-87b90103930d83d74baa998866b0995cb8887d51.tar.gz
minishell-87b90103930d83d74baa998866b0995cb8887d51.zip
fixed leaks in tokenizer and collectargs also fixed seg for < > and improved value add by $ use
Diffstat (limited to 'src/repl.c')
-rw-r--r--src/repl.c43
1 files changed, 5 insertions, 38 deletions
diff --git a/src/repl.c b/src/repl.c
index 3988a42..93874a7 100644
--- a/src/repl.c
+++ b/src/repl.c
@@ -6,48 +6,17 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */
-/* Updated: 2025/01/23 17:42:33 by chuhlig ### ########.fr */
+/* Updated: 2025/01/25 12:41:48 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/minishell.h"
#include "token.h"
-t_token *shallow_copy_token(t_token *token)
-{
- if (token == NULL)
- return (NULL);
-
- if (token->type == STRING_TOKEN)
- return (new_str_token(token->content.string, NULL, NULL));
- else if (token->type == REDIR_TOKEN)
- return (new_redir_token(token->content.redir_type, NULL, NULL));
- else
- return (new_redir_token(token->type, NULL, NULL));
-}
-
-t_token *shallow_copy_tokens(t_token *tokens)
-{
- t_token *result;
- t_token *cur;
-
- result = shallow_copy_token(tokens);
- if (!result)
- return (NULL);
- cur = result;
- while (tokens->next != NULL)
- {
- tokens = tokens->next;
- cur->next = shallow_copy_tokens(tokens);
- cur = cur->next;
- }
- return (result);
-}
-
void free_repl(char *input, t_node *ast)
{
free(input);
- if(ast)
+ if (ast)
free_node(ast);
}
@@ -56,7 +25,6 @@ void repl(const char *prompt, t_env **env, int *promptflag)
char *input;
t_token *token_list;
t_node *ast;
- t_token *tokens_copy;
(*promptflag)++;
while (1)
@@ -70,17 +38,16 @@ void repl(const char *prompt, t_env **env, int *promptflag)
break ;
}
if (input[0] == '\0')
+ {
+ free(input);
continue ;
+ }
add_history(input);
token_list = NULL;
tokenizer(input, &token_list, '\0');
- tokens_copy = shallow_copy_tokens(token_list);
- free_tokens(tokens_copy);
- // print_token_list(token_list);
ast = parse(token_list, env);
if (ast)
set_return_code(eval(ast, env), env);
free_repl(input, ast);
- print_token_list(tokens_copy);
}
}