From 8905d3bdbb8474274ed788791c50ed8107ba07a5 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 28 Jun 2024 22:04:12 +0200 Subject: updated makefile for tokenizer --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 41551ec..4ac27f7 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ HEADERS = -I include -I $(LIB_DIR)/libft VPATH := src SRC := main.c debug_tools.c init.c signal_handling.c repl.c new_token.c \ - free_token.c new_node.c free_node.c + free_token.c new_node.c free_node.c tokenizer.c OBJ_DIR := _obj OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o)) -- cgit v1.2.3 From 16ca09f57525cd9a4e7eb82ce70e4c1e0cb85a31 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 9 Jul 2024 12:56:09 +0200 Subject: Remove redundant funcs and add parse funcs to header and Makefile --- Makefile | 2 +- include/minishell.h | 6 +++++- src/free_node.c | 8 +------- src/parser.c | 15 +-------------- 4 files changed, 8 insertions(+), 23 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 41551ec..8896ded 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ HEADERS = -I include -I $(LIB_DIR)/libft VPATH := src SRC := main.c debug_tools.c init.c signal_handling.c repl.c new_token.c \ - free_token.c new_node.c free_node.c + free_token.c new_node.c free_node.c parser.c parse_cmd.c OBJ_DIR := _obj OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o)) diff --git a/include/minishell.h b/include/minishell.h index a528e4a..2411cc5 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -6,7 +6,7 @@ /* By: dkaiser content.assign.var); - free(node->content.assign.value); -} - static void free_pipe_node(t_node *node) { free_node(node->content.pipe.left); diff --git a/src/parser.c b/src/parser.c index 5bf82f6..66c6785 100644 --- a/src/parser.c +++ b/src/parser.c @@ -6,7 +6,7 @@ /* By: dkaiser type == CMD_NODE) + print_cmd_node(ast, indent); + else if (ast->type == PIPE_NODE) + { + printf("%*s%s", indent, "", "* PIPE"); + print_ast_rec(ast->content.pipe.left, indent + 2); + print_ast_rec(ast->content.pipe.right, indent + 2); + } +} + +static void print_cmd_node(t_node *ast, int indent) +{ + int i; + + printf("\n%*s%s", indent, "", "* CMD"); + i = 0; + printf("\n%*sARGS:", indent + 2, ""); + while (ast->content.cmd.args[i] != NULL) + { + printf(" %s", ast->content.cmd.args[i]); + i++; + } + i = 0; + printf("\n%*sASSIGNS:", indent + 2, ""); + while (ast->content.cmd.assigns[i] != NULL) + { + printf(" %s=%s", ast->content.cmd.assigns[i]->var, + ast->content.cmd.assigns[i]->value); + i++; + } + printf("\n%*sREDIRS:", indent + 2, ""); + printf("\n%*sIN: %d %s", indent + 4, "", ast->content.cmd.redirs[0].type, + ast->content.cmd.redirs[0].specifier); + printf("\n%*sOUT: %d %s", indent + 4, "", ast->content.cmd.redirs[1].type, + ast->content.cmd.redirs[1].specifier); +} -- cgit v1.2.3 From b7569587bbd57c56d4b5dbc9116e681e5175e772 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:20:11 +0200 Subject: added -g flagg for compile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 4ac27f7..1eaae01 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ NAME := minishell CC = cc -CFLAGS = -Wall -Wextra -Werror +CFLAGS = -Wall -Wextra -Werror -g LIB_DIR = lib LIBS = -L $(LIB_DIR)/libft -lft -lreadline HEADERS = -I include -I $(LIB_DIR)/libft -- cgit v1.2.3 From 0451d68ddc3b945ae0c3c30d14061ff9f523c0c8 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:53:50 +0200 Subject: added strncpy in make and removed -g out of main makefile --- Makefile | 2 +- lib/libft/Makefile | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 1eaae01..4ac27f7 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ NAME := minishell CC = cc -CFLAGS = -Wall -Wextra -Werror -g +CFLAGS = -Wall -Wextra -Werror LIB_DIR = lib LIBS = -L $(LIB_DIR)/libft -lft -lreadline HEADERS = -I include -I $(LIB_DIR)/libft diff --git a/lib/libft/Makefile b/lib/libft/Makefile index 3c2fb91..6951c43 100644 --- a/lib/libft/Makefile +++ b/lib/libft/Makefile @@ -30,6 +30,7 @@ SRC = ft_atoi.c \ ft_strlen.c \ ft_strmapi.c \ ft_strncmp.c \ + ft_strncpy.c \ ft_strnstr.c \ ft_strrchr.c \ ft_strtrim.c \ -- cgit v1.2.3 From f53acc629b1b3e7f4097eef1e26841ef0b9b24c6 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Sun, 11 Aug 2024 12:15:40 +0200 Subject: Fix parser bugs --- Makefile | 2 +- src/collect_redirs.c | 13 +++++++++---- src/parse_cmd.c | 10 ++++------ src/tokenizer.c | 4 +++- 4 files changed, 17 insertions(+), 12 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 3450e3c..d4778bf 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ HEADERS = -I include -I $(LIB_DIR)/libft VPATH := src SRC := main.c debug_tools.c init.c signal_handling.c repl.c new_token.c \ free_token.c new_node.c free_node.c tokenizer.c parser.c \ - parse_cmd.c print_ast.c + parse_cmd.c collect_assigns.c collect_redirs.c print_ast.c OBJ_DIR := _obj OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o)) diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 76b08da..d50bec4 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,13 +6,13 @@ /* By: dkaiser next != NULL) { if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) - collect_redir(tokens, result, cur); + cur = collect_redir(tokens, result, cur); else if (cur->type == REDIR_TOKEN) { dbg("TODO: Add parsing errmsg"); @@ -43,7 +43,8 @@ t_redirection *collect_redirs(t_token **tokens) return (result); } -static void collect_redir(t_token **tokens, t_redirection *result, t_token *cur) +static t_token *collect_redir(t_token **tokens, t_redirection *result, + t_token *cur) { set_redir(&result[is_output_redir(cur->content.redir_type)], cur->content.redir_type, cur->next->content.string); @@ -57,7 +58,11 @@ static void collect_redir(t_token **tokens, t_redirection *result, t_token *cur) free_token_and_connect(cur->previous); } else + { free_token(cur); + return (NULL); + } + return (cur); } static void set_redir(t_redirection *redir, int type, char *specifier) diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 068a4c1..eb70f0d 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,7 +6,7 @@ /* By: dkaiser next; - } result = malloc(sizeof(char *) * (i + 1)); if (result == NULL) return (free_tokens(*tokens), NULL); @@ -46,10 +43,11 @@ static char **collect_args(t_token **tokens) i = 0; while (cur != NULL && cur->type == STRING_TOKEN) { + if (cur->previous) + free_token(cur->previous); result[i] = cur->content.string; i++; cur = cur->next; - free_token(cur->previous); } result[i] = NULL; return (result); diff --git a/src/tokenizer.c b/src/tokenizer.c index 34685ac..efbf723 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */ -/* Updated: 2024/08/09 15:40:00 by chuhlig ### ########.fr */ +/* Updated: 2024/08/11 11:40:35 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -110,4 +110,6 @@ void tokenizer(char *s, t_token **token_list) pos = i + 1; } } + while ((*token_list)->previous) + *token_list = (*token_list)->previous; } -- cgit v1.2.3 From 99e8655aaf9827c7d5248c7f3d0913fcb1377cfb Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Sun, 11 Aug 2024 12:27:02 +0200 Subject: Remove assigns I found out that there's a difference between shell variables and env variables. We don't have to implement shell variables, so I removed all code that handles them. --- Makefile | 2 +- include/ast.h | 12 ++------ include/minishell.h | 3 +- src/collect_assigns.c | 84 --------------------------------------------------- src/free_node.c | 20 +----------- src/new_node.c | 5 ++- src/parse_cmd.c | 6 ++-- src/print_ast.c | 10 +----- 8 files changed, 10 insertions(+), 132 deletions(-) delete mode 100644 src/collect_assigns.c (limited to 'Makefile') diff --git a/Makefile b/Makefile index d4778bf..827c317 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ HEADERS = -I include -I $(LIB_DIR)/libft VPATH := src SRC := main.c debug_tools.c init.c signal_handling.c repl.c new_token.c \ free_token.c new_node.c free_node.c tokenizer.c parser.c \ - parse_cmd.c collect_assigns.c collect_redirs.c print_ast.c + parse_cmd.c collect_redirs.c print_ast.c OBJ_DIR := _obj OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o)) diff --git a/include/ast.h b/include/ast.h index bf19083..cd2f9c9 100644 --- a/include/ast.h +++ b/include/ast.h @@ -6,7 +6,7 @@ /* By: dkaiser type == STRING_TOKEN - && !is_quote(cur->content.string[0]) && ft_strchr(cur->content.string, - '=') != NULL) - { - result[i++] = to_assign(cur->content.string); - if (cur->next != NULL) - { - cur = cur->next; - free_token(cur->previous); - } - else - free_token(cur); - } - *tokens = cur; - result[i] = NULL; - return (result); -} - -static t_assign *to_assign(char *str) -{ - t_assign *result; - char *split_pos; - - split_pos = ft_strchr(str, '='); - *split_pos = '\0'; - result = malloc(sizeof(t_assign)); - if (result == NULL) - { - return (NULL); - } - result->var = str; - result->value = split_pos + 1; - return (result); -} - -static int count_tokens(t_token *tokens) -{ - int len; - - len = 0; - while (tokens != NULL && tokens->type == STRING_TOKEN - && !is_quote(tokens->content.string[0]) - && ft_strchr(tokens->content.string, '=') != NULL) - { - len++; - tokens = tokens->next; - } - return (len); -} - -static int is_quote(char c) -{ - return (c == '"' || c == '\''); -} diff --git a/src/free_node.c b/src/free_node.c index f387c0a..6eae059 100644 --- a/src/free_node.c +++ b/src/free_node.c @@ -6,7 +6,7 @@ /* By: dkaiser content.cmd.args); - free_assigns(node->content.cmd.assigns); if (node->content.cmd.redirs[0].type != 0 && node->content.cmd.redirs[0].specifier != NULL) free(node->content.cmd.redirs[0].specifier); @@ -54,19 +52,3 @@ static void free_cmd_node(t_node *node) && node->content.cmd.redirs[0].specifier != NULL) free(node->content.cmd.redirs[1].specifier); } - -static void free_assigns(t_assign **assigns) -{ - int i; - - i = 0; - if (assigns == 0) - return ; - while (assigns[i] != NULL) - { - free(assigns[i]->var); - free(assigns[i]); - i++; - } - free(assigns); -} diff --git a/src/new_node.c b/src/new_node.c index c2458d0..6da9f9e 100644 --- a/src/new_node.c +++ b/src/new_node.c @@ -6,7 +6,7 @@ /* By: dkaiser content.cmd.args = args; - node->content.cmd.assigns = assigns; node->content.cmd.redirs[0] = redirs[0]; node->content.cmd.redirs[1] = redirs[1]; free(redirs); diff --git a/src/parse_cmd.c b/src/parse_cmd.c index eb70f0d..2755cae 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,7 +6,7 @@ /* By: dkaiser content.cmd.args[i]); i++; } - i = 0; - printf("\n%*sASSIGNS:", indent + 2, ""); - while (ast->content.cmd.assigns[i] != NULL) - { - printf(" %s=%s", ast->content.cmd.assigns[i]->var, - ast->content.cmd.assigns[i]->value); - i++; - } printf("\n%*sREDIRS:", indent + 2, ""); printf("\n%*sIN: %d %s", indent + 4, "", ast->content.cmd.redirs[0].type, ast->content.cmd.redirs[0].specifier); -- cgit v1.2.3