From 2c6101645b681a81d83b9f1dda5276ef851dacc0 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 28 Jun 2024 22:01:20 +0200 Subject: updated the prototyps for the tokenizer --- include/token.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/token.h b/include/token.h index 38e758f..6dd44c9 100644 --- a/include/token.h +++ b/include/token.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* token.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: dkaiser +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 13:27:18 by dkaiser #+# #+# */ -/* Updated: 2024/06/28 14:59:19 by dkaiser ### ########.fr */ +/* Updated: 2024/06/28 21:49:55 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,4 +46,10 @@ t_token *new_redir_token(int type, t_token *previous, void free_token(t_token *token); -#endif +void print_token(t_token *token); +void conditional_print(char *string, int start_of_string, int i, int offset, t_token **token_list); +void tokenizer(char *s, t_token **token_list); +void print_token(t_token *token); + + +#endif \ No newline at end of file -- cgit v1.2.3 From c89e8359a41cb82b52e6b80ae76488c9e274425c Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 28 Jun 2024 22:03:41 +0200 Subject: added tokenizer funktion with connection to struct the test with the printable function didnt worked have to update main as well added currently strncpy in tokenizer test reason later needs to be move also need to add the token part for pipe --- src/tokenizer.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 src/tokenizer.c diff --git a/src/tokenizer.c b/src/tokenizer.c new file mode 100644 index 0000000..086d4b0 --- /dev/null +++ b/src/tokenizer.c @@ -0,0 +1,158 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* tokenizer.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: chuhlig +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */ +/* Updated: 2024/06/28 21:58:38 by chuhlig ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" +#include "token.h" + +char *ft_strncpy(char *dst, char *src, size_t n) +{ + char *start; + + start = dst; + while (n-- > 0 && *src) + *dst++ = *src++; + if (n > 0) + ft_memset(dst, '\0', n); + return (start); +} + +void print_token(t_token *token) +{ + if (token->type == STRING_TOKEN) + { + printf("STRING_TOKEN: %s\n", token->content.string); + } + else if (token->type == REDIR_TOKEN) + { + printf("REDIR_TOKEN: %d\n", token->content.redir_type); + } + else if (token->type == PIPE_TOKEN) + { + printf("PIPE_TOKEN\n"); + } +} + + + +void conditional_print(char *string, int start_of_string, int i, int offset, t_token **token_list) +{ + char *trimmed_line; + char *line; + int len; + + len = i + offset - start_of_string; + if (len > 0) + { + line = (char *)malloc(len + 1); + if (!line) + { + exit(EXIT_FAILURE); + } + ft_strncpy(line, string + start_of_string, len); + line[len] = '\0'; + trimmed_line = line; + while (*trimmed_line == ' ' || *trimmed_line == '\t') + { + trimmed_line++; + } + if (*trimmed_line != '\0') + { + *token_list = new_str_token(trimmed_line, *token_list, NULL); + print_token(*token_list); + } + free(line); + } +} + +void tokenizer(char *s, t_token **token_list) +{ + char *quotes; + char quote_check; + char c; + int start_of_string; + int ignore_space; + int flag; + int i; + int skip; + + quotes = "\"\'"; + quote_check = '\0'; + start_of_string = 0; + ignore_space = 0; + flag = 0; + i = 0; + skip = 0; + while (s[i]) + { + c = s[i]; + if (skip) + { + skip = 0; + i++; + continue ; + } + if (!ignore_space && (c == '|' || c == ';' || c == '<' || c == '>')) + { + conditional_print(s, start_of_string, i, 0, token_list); + if ((c == '<' || c == '>') && s[i + 1] == c) + { + if (c == '<') + { + *token_list = new_redir_token(INPUT_FILE, + *token_list, NULL); + print_token(*token_list); + } + else + { + *token_list = new_redir_token(OUTPUT_APPEND, + *token_list, NULL); + print_token(*token_list); + } + i++; + } + else + { + if (c == '<') + { + *token_list = new_redir_token(INPUT_FILE, + *token_list, NULL); + } + else + { + *token_list = new_redir_token(OUTPUT_OVERRIDE, + *token_list, NULL); + } + print_token(*token_list); + } + start_of_string = i + 1; + } + else if (ignore_space && c == quote_check) + { + quote_check = '\0'; + ignore_space = 0; + } + else if (!ignore_space && ft_strchr(quotes, c)) + { + quote_check = c; + ignore_space = 1; + } + else if ((!ignore_space && (s[i] != ' ' || s[i] != '\t')) || s[i + 1] == '\0') + { + if (s[i + 1]) + conditional_print(s, start_of_string, i, 1, token_list); + else + conditional_print(s, start_of_string, i, 0, token_list); + start_of_string = i + 1; + } + i++; + } +} \ No newline at end of file -- cgit v1.2.3 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(-) 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 42c693f70ff375ce15b5783c251bfa723ac528ce Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Mon, 1 Jul 2024 11:44:06 +0200 Subject: Remove unneeded struct s_sequence --- include/ast.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/ast.h b/include/ast.h index e6ad25d..356ccdd 100644 --- a/include/ast.h +++ b/include/ast.h @@ -6,18 +6,13 @@ /* By: dkaiser next->previous = NULL; free(token); } + +void free_token_and_connect(t_token *token) +{ + if (token->type == STRING_TOKEN) + free(token->content.string); + if (token->previous != NULL) + token->previous->next = token->next; + if (token->next != NULL) + token->next->previous = token->previous; + free(token); +} -- cgit v1.2.3 From 5316c9880416b77b4b97b07fd6ae47f171a0ba23 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Mon, 8 Jul 2024 16:15:32 +0200 Subject: Move assign into cmd node --- include/ast.h | 8 +++----- src/free_node.c | 24 +++++++++++++++++++----- src/new_node.c | 17 +++-------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/ast.h b/include/ast.h index 356ccdd..6479272 100644 --- a/include/ast.h +++ b/include/ast.h @@ -6,7 +6,7 @@ /* By: dkaiser type == ASSIGN_NODE) - free_assign_node(node); - else if (node->type == PIPE_NODE) + if (node->type == PIPE_NODE) free_pipe_node(node); else if (node->type == CMD_NODE) free_cmd_node(node); @@ -54,6 +52,22 @@ static void free_cmd_node(t_node *node) i++; } free(node->content.cmd.args); + free_assigns(node->content.cmd.assigns); free(node->content.cmd.redirs[0].specifier); free(node->content.cmd.redirs[1].specifier); } + +static void free_assigns(t_assign **assigns) +{ + int i; + + i = 0; + while (assigns[i] != NULL) + { + free(assigns[i]->var); + free(assigns[i]->value); + free(assigns[i]); + i++; + } + free(assigns); +} diff --git a/src/new_node.c b/src/new_node.c index 4cdbf9a..c334eb6 100644 --- a/src/new_node.c +++ b/src/new_node.c @@ -6,7 +6,7 @@ /* By: dkaiser content.assign.var = var; - node->content.assign.value = value; - return (node); -} - t_node *new_pipe_node(t_node *left, t_node *right) { t_node *node; @@ -47,7 +35,7 @@ t_node *new_pipe_node(t_node *left, t_node *right) return (node); } -t_node *new_cmd_node(char **args, t_redirection redirs[2]) +t_node *new_cmd_node(char **args, t_assign **assigns, t_redirection redirs[2]) { t_node *node; @@ -55,6 +43,7 @@ t_node *new_cmd_node(char **args, t_redirection redirs[2]) if (node == NULL) return (NULL); node->content.cmd.args = args; + node->content.cmd.assigns = assigns; node->content.cmd.redirs[0] = redirs[0]; node->content.cmd.redirs[1] = redirs[1]; return (node); -- cgit v1.2.3 From 3b2efe45ce23f51e97a54b820b41f230b99bbab2 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Mon, 8 Jul 2024 16:35:30 +0200 Subject: Add most of the parser --- src/parser.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/parser.c diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..5bf82f6 --- /dev/null +++ b/src/parser.c @@ -0,0 +1,106 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parser.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser next = ft_lstnew(parse_statement(current_tokens)); + current = current->next; + } + if (current == NULL) + { + // Free: ft_lstclear(&result, free_node); + return (NULL); + } + current_tokens = split_at_first(&tokens, NEWLINE_TOKEN); + } + return (result); +} + +static t_node *parse_statement(t_token *tokens) +{ + t_token *left_side_tokens; + + left_side_tokens = split_at_first(&tokens, PIPE_TOKEN); + if (tokens != NULL) + { + return (new_pipe_node(parse_cmd(left_side_tokens), + parse_statement(tokens))); + } + else + { + return (parse_cmd(left_side_tokens)); + } +} + +static t_node *parse_cmd(t_token *tokens) +{ + char **args; + t_assign **assigns; + t_redirection **redirs; + + redirs = collect_redirs(&tokens); + assigns = collect_assigns(&tokens); + args = collect_args(&tokens); + return (new_cmd_node(args, assigns, redirs)); +} + +t_token *split_at_first(t_token **tokens, int type) +{ + t_token *split; + t_token *result; + + split = find_token_by_type(*tokens, type); + if (split == NULL) + { + result = *tokens; + *tokens = NULL; + return (result); + } + result = *tokens; + *tokens = split->next; + free_token(split); + return (result); +} + +static t_token *find_token_by_type(t_token *tokens, int type) +{ + while (tokens != NULL) + { + if (tokens->type == type) + return (tokens); + tokens = tokens->next; + } + return (NULL); +} -- cgit v1.2.3 From a5dd924bea37a0786dcf2b95690452f7714043f6 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Mon, 8 Jul 2024 17:30:58 +0200 Subject: Add most of parse_cmd --- src/free_token.c | 4 +- src/parse_cmd.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 src/parse_cmd.c diff --git a/src/free_token.c b/src/free_token.c index 7be6b0e..083484c 100644 --- a/src/free_token.c +++ b/src/free_token.c @@ -6,7 +6,7 @@ /* By: dkaiser type == STRING_TOKEN) - free(token->content.string); if (token->previous != NULL) token->previous->next = NULL; if (token->next != NULL) diff --git a/src/parse_cmd.c b/src/parse_cmd.c new file mode 100644 index 0000000..981bbbb --- /dev/null +++ b/src/parse_cmd.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser +#include + +static t_redirection **collect_redirs(t_token **tokens); +static t_assign **collect_assigns(t_token **tokens); +static char **collect_args(t_token **tokens); +static t_assign *to_assign(char *str); + +t_node *parse_cmd(t_token *tokens) +{ + char **args; + t_assign **assigns; + t_redirection redirs[2]; + + redirs = collect_redirs(&tokens); + assigns = collect_assigns(&tokens); + args = collect_args(&tokens); + return (new_cmd_node(args, assigns, redirs)); +} + +static t_redirection **collect_redirs(t_token **tokens) +{ + return (NULL); +} + +static t_assign **collect_assigns(t_token **tokens) +{ + int i; + t_assign **result; + + i = 0; + while (ft_strchr(tokens[i]->content.string, '=') != NULL) + { + i++; + } + result = malloc(sizeof(t_assign *) * (i + 1)); + if (result == NULL) + { + // free everything + return (NULL); + } + result[i] = NULL; + i--; + while (i >= 0) + { + result[i] = to_assign(tokens[i]->content.string); + i--; + } + return (result); +} + +static char **collect_args(t_token **tokens) +{ + int i; + char **result; + + i = 0; + while (tokens[i] != NULL) + { + i++; + } + result = malloc(sizeof(char *) * (i + 1)); + if (result == NULL) + { + // free everything in the token + return (NULL); + } + i = 0; + while (tokens[i] != NULL) + { + result[i] = tokens[i]->content.string; + free_token(tokens[i]); + i++; + } + result[i] = NULL; + return (result); +} + +static t_assign *to_assign(char *str) +{ + t_assign *result; + char *split; + + result = malloc(sizeof(t_assign)); + if (result == NULL) + return (NULL); + split = ft_strchr(str, '='); + if (split == NULL) + return (NULL); + *split = '\0'; + result->var = str; + result->value = split + 1; + return (result); +} -- cgit v1.2.3 From 389f7c91f0ebd59c80b457fce63ad383dfd27f85 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 9 Jul 2024 12:54:35 +0200 Subject: Get colllect_args() to work properly --- src/parse_cmd.c | 57 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 981bbbb..739c022 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -64,33 +64,6 @@ static t_assign **collect_assigns(t_token **tokens) return (result); } -static char **collect_args(t_token **tokens) -{ - int i; - char **result; - - i = 0; - while (tokens[i] != NULL) - { - i++; - } - result = malloc(sizeof(char *) * (i + 1)); - if (result == NULL) - { - // free everything in the token - return (NULL); - } - i = 0; - while (tokens[i] != NULL) - { - result[i] = tokens[i]->content.string; - free_token(tokens[i]); - i++; - } - result[i] = NULL; - return (result); -} - static t_assign *to_assign(char *str) { t_assign *result; @@ -107,3 +80,33 @@ static t_assign *to_assign(char *str) result->value = split + 1; return (result); } + +static char **collect_args(t_token **tokens) +{ + t_token *cur; + char **result; + int i; + + cur = *tokens; + i = 0; + while (cur != NULL) { + i++; + cur = cur->next; + } + result = malloc(sizeof(char*) * (i + 1)); + if (!result) + { + //free all tokens; + return (NULL); + } + cur = *tokens; + i = 0; + while(cur != NULL) + { + result[i] = cur->content.string; + // free token + i++; + cur = cur->next; + } + return (result); +} -- 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(-) 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 == STRING_TOKEN) - free(token->content.string); if (token->previous != NULL) token->previous->next = token->next; if (token->next != NULL) diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 739c022..4fa2bc2 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,17 +6,13 @@ /* By: dkaiser -#include -static t_redirection **collect_redirs(t_token **tokens); +static t_redirection *collect_redirs(t_token **tokens); static t_assign **collect_assigns(t_token **tokens); static char **collect_args(t_token **tokens); static t_assign *to_assign(char *str); @@ -25,7 +21,7 @@ t_node *parse_cmd(t_token *tokens) { char **args; t_assign **assigns; - t_redirection redirs[2]; + t_redirection *redirs; redirs = collect_redirs(&tokens); assigns = collect_assigns(&tokens); @@ -33,80 +29,144 @@ t_node *parse_cmd(t_token *tokens) return (new_cmd_node(args, assigns, redirs)); } -static t_redirection **collect_redirs(t_token **tokens) +static t_redirection *collect_redirs(t_token **tokens) { - return (NULL); + t_redirection *result; + t_token *cur; + + cur = *tokens; + result = malloc(sizeof(t_redirection) * 2); + if (result == NULL) + { + // free all tokens + return (NULL); + } + result[0].specifier = NULL; + result[0].type = 0; + result[1].specifier = NULL; + result[1].type = 0; + while (cur != NULL && cur->next != NULL) + { + if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) + { + if (cur->content.redir_type & (INPUT_FILE | INPUT_LIMITER)) + { + result[0].type = cur->content.redir_type; + result[0].specifier = cur->next->content.string; + } + else if (cur->content.redir_type & (OUTPUT_APPEND | OUTPUT_OVERRIDE)) + { + result[1].type = cur->content.redir_type; + result[1].specifier = cur->next->content.string; + } + cur = cur->next; + free_token_and_connect(cur->previous); + if (cur->next != NULL) + { + cur = cur->next; + free_token_and_connect(cur->previous); + } + else + { + free_token(cur); + } + } + else if (cur->type == REDIR_TOKEN) + { + // err Parsing error + free(result); + return (NULL); + } + else + { + cur = cur->next; + } + } + return (result); } static t_assign **collect_assigns(t_token **tokens) { - int i; + t_token *cur; t_assign **result; + int i; + cur = *tokens; i = 0; - while (ft_strchr(tokens[i]->content.string, '=') != NULL) + while (cur != NULL && cur->type == STRING_TOKEN + && cur->content.string[0] != '"' && cur->content.string[0] != '\'' + && ft_strchr(cur->content.string, '=') != NULL) { i++; + cur = cur->next; } result = malloc(sizeof(t_assign *) * (i + 1)); - if (result == NULL) + if (!result) { - // free everything + // free all tokens return (NULL); } - result[i] = NULL; - i--; - while (i >= 0) + cur = *tokens; + i = 0; + while (cur != NULL && cur->type == STRING_TOKEN + && cur->content.string[0] != '"' && cur->content.string[0] != '\'' + && ft_strchr(cur->content.string, '=') != NULL) { - result[i] = to_assign(tokens[i]->content.string); - i--; + result[i] = to_assign(cur->content.string); + i++; + cur = cur->next; + free_token(cur->previous); } + *tokens = cur; + result[i] = NULL; return (result); } static t_assign *to_assign(char *str) { t_assign *result; - char *split; + char *split_pos; + split_pos = ft_strchr(str, '='); + *split_pos = '\0'; result = malloc(sizeof(t_assign)); if (result == NULL) + { return (NULL); - split = ft_strchr(str, '='); - if (split == NULL) - return (NULL); - *split = '\0'; + } result->var = str; - result->value = split + 1; + result->value = split_pos + 1; return (result); } static char **collect_args(t_token **tokens) { - t_token *cur; - char **result; - int i; + t_token *cur; + char **result; + int i; cur = *tokens; i = 0; - while (cur != NULL) { + while (cur != NULL) + { i++; cur = cur->next; } - result = malloc(sizeof(char*) * (i + 1)); + result = malloc(sizeof(char *) * (i + 1)); if (!result) { - //free all tokens; + // free all tokens; return (NULL); } cur = *tokens; i = 0; - while(cur != NULL) + while (cur != NULL) { result[i] = cur->content.string; // free token i++; cur = cur->next; } + result[i] = NULL; return (result); } -- cgit v1.2.3 From f10ae66023d98d0f6ce43b8cbf80a769d464d472 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 22 Jul 2024 14:32:22 +0200 Subject: debugger minishell --- .vscode/c_cpp_properties.json | 18 +++++++++++++ .vscode/launch.json | 13 +++++++++ .vscode/settings.json | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..97c1779 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "macos-clang-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "macos-clang-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ecd0fa2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "lldb", + "request": "launch", + "args": [], + "cwd": "/Users/chuhlig/Desktop/minishell/", + "program": "/Users/chuhlig/Desktop/minishell/minishell" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ae14d75 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,62 @@ +{ + "C_Cpp_Runner.cCompilerPath": "clang", + "C_Cpp_Runner.cppCompilerPath": "clang++", + "C_Cpp_Runner.debuggerPath": "lldb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false, + "files.associations": { + "minishell.h": "c" + } +} \ No newline at end of file -- cgit v1.2.3 From e0be5c1a5f65107468781b8dd84f2b32d5f12bec Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 22 Jul 2024 14:33:24 +0200 Subject: some testcases and changes --- src/tokenizer.c | 381 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 321 insertions(+), 60 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index 086d4b0..ddc33da 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -6,23 +6,32 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */ -/* Updated: 2024/06/28 21:58:38 by chuhlig ### ########.fr */ +/* Updated: 2024/07/22 14:18:02 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include "token.h" -char *ft_strncpy(char *dst, char *src, size_t n) +// char *ft_strncpy(char *dst, const char *src, size_t n) +// { +// char *start; + +// start = dst; +// while (n-- > 0 && *src) +// *dst++ = *src++; +// while (n-- > 0) +// *dst++ = '\0'; +// return (start); +// } +char *ft_strncpy(char *s1, char *s2, int n) { - char *start; - - start = dst; - while (n-- > 0 && *src) - *dst++ = *src++; - if (n > 0) - ft_memset(dst, '\0', n); - return (start); + int i = -1; + + while (++i < n && s2[i]) + s1[i] = s2[i]; + s1[i] = '\0'; + return (s1); } void print_token(t_token *token) @@ -39,37 +48,36 @@ void print_token(t_token *token) { printf("PIPE_TOKEN\n"); } + else if (token->type == NEWLINE_TOKEN) + { + printf("NEWLINE_TOKEN\n"); + } } - - +//s[i] should be right bc i wanna start at specific pos void conditional_print(char *string, int start_of_string, int i, int offset, t_token **token_list) { - char *trimmed_line; char *line; int len; - len = i + offset - start_of_string; + len = i + offset - start_of_string + 1; if (len > 0) { - line = (char *)malloc(len + 1); + line = (char *)malloc(len); if (!line) { exit(EXIT_FAILURE); } ft_strncpy(line, string + start_of_string, len); line[len] = '\0'; - trimmed_line = line; - while (*trimmed_line == ' ' || *trimmed_line == '\t') + while (*line == ' ' || *line == '\t' || *line == '\0') + line++; + if (*line != '\0') { - trimmed_line++; - } - if (*trimmed_line != '\0') - { - *token_list = new_str_token(trimmed_line, *token_list, NULL); + *token_list = new_str_token(line, *token_list, NULL); print_token(*token_list); } - free(line); + // free(line); } } @@ -77,82 +85,335 @@ void tokenizer(char *s, t_token **token_list) { char *quotes; char quote_check; - char c; + // char c; int start_of_string; int ignore_space; - int flag; int i; - int skip; quotes = "\"\'"; quote_check = '\0'; start_of_string = 0; ignore_space = 0; - flag = 0; i = 0; - skip = 0; - while (s[i]) + if (!s || !*s) + return ; + while (s[i] && s) { - c = s[i]; - if (skip) - { - skip = 0; - i++; - continue ; - } - if (!ignore_space && (c == '|' || c == ';' || c == '<' || c == '>')) + // c = s[i]; + // if (!ignore_space && (c == '|' || c == '\n' || c == '<' || c == '>')) + if (!ignore_space && (s[i] == '|' || s[i] == '\n' || s[i] == '<' || s[i] == '>')) { conditional_print(s, start_of_string, i, 0, token_list); - if ((c == '<' || c == '>') && s[i + 1] == c) + // if ((c == '<' || c == '>') && s[i + 1] == c) + if ((s[i] == '<' || s[i] == '>') && s[i + 1] == s[i]) { - if (c == '<') - { - *token_list = new_redir_token(INPUT_FILE, + // if (c == '<') + if (s[i] == '<') + *token_list = new_redir_token(INPUT_LIMITER, *token_list, NULL); - print_token(*token_list); - } else - { *token_list = new_redir_token(OUTPUT_APPEND, *token_list, NULL); - print_token(*token_list); - } + print_token(*token_list); i++; } else { - if (c == '<') - { + // if (c == '<') + if (s[i] == '<') *token_list = new_redir_token(INPUT_FILE, *token_list, NULL); - } + // else if (c == '|') + else if (s[i] == '|') + *token_list = new_token(PIPE_TOKEN, *token_list, NULL); + // else if (c == '\n') + else if (s[i] == '\n') + *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); else - { *token_list = new_redir_token(OUTPUT_OVERRIDE, *token_list, NULL); - } print_token(*token_list); + // i++; } start_of_string = i + 1; } - else if (ignore_space && c == quote_check) + // else if (ignore_space && c == quote_check) + // mew update for the sting part 18.07 + else if (ignore_space && s[i] == quote_check) { quote_check = '\0'; ignore_space = 0; } - else if (!ignore_space && ft_strchr(quotes, c)) + // else if (!ignore_space && ft_strchr(quotes, c)) + else if (!ignore_space && ft_strchr(quotes, s[i])) { - quote_check = c; + quote_check = s[i]; ignore_space = 1; } - else if ((!ignore_space && (s[i] != ' ' || s[i] != '\t')) || s[i + 1] == '\0') + // else if ((!ignore_space && (c == '\0' || c == ' ' || c == '\t')) || i == ft_strlen(s) - 1) + if ((!ignore_space && (s[i] == '\0' || s[i] == ' ' || s[i] == '\t')) || i == ft_strlen(s) - 1) { - if (s[i + 1]) - conditional_print(s, start_of_string, i, 1, token_list); - else - conditional_print(s, start_of_string, i, 0, token_list); + if (s[i + 1] == '\0') + i++; + conditional_print(s, start_of_string, i, 0, token_list); start_of_string = i + 1; } + // else if (!ignore_space && ft_strchr(quotes, c)) + // else if (!ignore_space) + // { + // if(ft_strchr(quotes, s[i])) + // { + // quote_check = s[i]; + // ignore_space = 1; + // } + // else if (s[i] == '\0' || s[i] == ' ' || s[i] == '\t' || i == ft_strlen(s) - 1) + // { + // if (s[i + 1] == '\0') + // i++; + // conditional_print(s, start_of_string, i, 0, token_list); + // start_of_string = i + 1; + // } + // } + // else if (ignore_space && (s[i] == quote_check || s[i + 1] == '\0'))// secon part out of while loop? + // { + // quote_check = '\0'; + // ignore_space = 0; + // conditional_print(s, start_of_string, i, 0, token_list); + // start_of_string = i + 1; + // } i++; } -} \ No newline at end of file +} + +///s[i] != ' ' +//mazbe remove c +// why handle space? +//readline delete mazbe? + +// errors today if i change the con print cond removing *line == '\0' +// ./minishell +// Minishell $ test +// Minishell $ idk +// Minishell $ why you idiot a re doing nothing +// zsh: segmentation fault ./minishell +// chuhlig@1-E-9 minishell % ./minishell +// Minishell $ a +// Minishell $ aaa +// Minishell $ aaaaaaaaaaaaaa +// Minishell $ aa aa +// zsh: segmentation fault ./minishell + +// also some space reconizing is wrong +//also the part with cond &s[i] or just s seem f up +//tested different strncpy still errors +// removed anoying brackets to short it +//added pipe and \n token +// string still not works fine mazybe readline and input understanding + +// error with extra condition: +// ./minishell +// Minishell $ test +// STRING_TOKEN: � +// ================================================================= +// ==66482==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000002835 at pc 0x00010bb02c68 bp 0x7ffee41034b0 sp 0x7ffee41034a8 +// READ of size 1 at 0x602000002835 thread T0 +// #0 0x10bb02c67 in tokenizer tokenizer.c:91 +// #1 0x10bb00c66 in repl repl.c:30 +// #2 0x10bb00684 in main main.c:19 +// #3 0x7fff733a7cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8) + +// 0x602000002835 is located 0 bytes to the right of 5-byte region [0x602000002830,0x602000002835) +// allocated by thread T0 here: +// #0 0x10bba517d in wrap_malloc+0x9d (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4917d) +// #1 0x10bb38c44 in xmalloc+0x8 (libreadline.8.dylib:x86_64+0x25c44) +// #2 0x10bb16096 in readline_internal_teardown+0xfa (libreadline.8.dylib:x86_64+0x3096) +// #3 0x10bb15bb4 in readline+0x5b (libreadline.8.dylib:x86_64+0x2bb4) +// #4 0x10bb00ba3 in repl repl.c:25 +// #5 0x10bb00684 in main main.c:19 +// #6 0x7fff733a7cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8) + +// SUMMARY: AddressSanitizer: heap-buffer-overflow tokenizer.c:91 in tokenizer +// Shadow bytes around the buggy address: +// 0x1c04000004b0: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa +// 0x1c04000004c0: fa fa fd fa fa fa fd fa fa fa fd fd fa fa fd fd +// 0x1c04000004d0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd +// 0x1c04000004e0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd +// 0x1c04000004f0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd +// =>0x1c0400000500: fa fa 00 00 fa fa[05]fa fa fa 00 04 fa fa 05 fa +// 0x1c0400000510: fa fa 05 fa fa fa fa fa fa fa fa fa fa fa fa fa +// 0x1c0400000520: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa +// 0x1c0400000530: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa +// 0x1c0400000540: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa +// 0x1c0400000550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa +// Shadow byte legend (one shadow byte represents 8 application bytes): +// Addressable: 00 +// Partially addressable: 01 02 03 04 05 06 07 +// Heap left redzone: fa +// Freed heap region: fd +// Stack left redzone: f1 +// Stack mid redzone: f2 +// Stack right redzone: f3 +// Stack after return: f5 +// Stack use after scope: f8 +// Global redzone: f9 +// Global init order: f6 +// Poisoned by user: f7 +// Container overflow: fc +// Array cookie: ac +// Intra object redzone: bb +// ASan internal: fe +// Left alloca redzone: ca +// Right alloca redzone: cb +// Shadow gap: cc +// ==66482==ABORTING + +// othere error currently +// test +// STRING_TOKEN: +// minishell(86892,0x111ae2dc0) malloc: *** error for object 0x7fedf3200014: pointer being freed was not allocated +// minishell(86892,0x111ae2dc0) malloc: *** set a breakpoint in malloc_error_break to debug +// zsh: abort ./minishell +// chuhlig@1-E-9 minishell % ./minishell +// Minishell $ "test" +// Minishell $ "testtest" +// Minishell $ "test test" +// Minishell $ te +// STRING_TOKEN: ` +// minishell(86928,0x114a76dc0) malloc: *** error for object 0x7fcaa8d04f27: pointer being freed was not allocated +// minishell(86928,0x114a76dc0) malloc: *** set a breakpoint in malloc_error_break to debug +// zsh: abort ./minishell +// chuhlig@1-E-9 minishell % ./minishell +// Minishell $ a +// STRING_TOKEN: +// Minishell $ a +// zsh: segmentation fault ./minishell +// chuhlig@1-E-9 minishell % ./minishell +// Minishell $ a +// STRING_TOKEN: ^ +// minishell(86958,0x11c50adc0) malloc: *** error for object 0x7fb24a800011: pointer being freed was not allocated +// minishell(86958,0x11c50adc0) malloc: *** set a breakpoint in malloc_error_break to debug +// zsh: abort ./minishell +// chuhlig@1-E-9 minishell % ./minishell +// Minishell $ a +// zsh: segmentation fault ./minishell + +///do i need to update after cont print i? +// end quote not works atm and have to check the lenth +// how to handle not in quote text command +// space generell need to be fixed + +/// 1425 2207 +// Minishell $ test test "ters" +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters" +// Minishell $ test test "ters +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters +// Minishell $ test test "ters " "a +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters " +// STRING_TOKEN: "a +// Minishell $ |||| <><> <><> <<< >>>> ||| +// STRING_TOKEN: | +// PIPE_TOKEN +// STRING_TOKEN: | +// PIPE_TOKEN +// STRING_TOKEN: | +// PIPE_TOKEN +// STRING_TOKEN: | +// PIPE_TOKEN +// STRING_TOKEN: +// STRING_TOKEN: < +// REDIR_TOKEN: 0 +// STRING_TOKEN: > +// REDIR_TOKEN: 2 +// STRING_TOKEN: < +// REDIR_TOKEN: 0 +// STRING_TOKEN: > +// REDIR_TOKEN: 2 +// STRING_TOKEN: ^ +// STRING_TOKEN: < +// REDIR_TOKEN: 0 +// STRING_TOKEN: > +// REDIR_TOKEN: 2 +// STRING_TOKEN: < +// REDIR_TOKEN: 0 +// STRING_TOKEN: > +// REDIR_TOKEN: 2 +// STRING_TOKEN: ^ +// STRING_TOKEN: < +// REDIR_TOKEN: 1 +// STRING_TOKEN: < +// REDIR_TOKEN: 0 +// STRING_TOKEN: � +// STRING_TOKEN: > +// REDIR_TOKEN: 3 +// STRING_TOKEN: > +// REDIR_TOKEN: 3 +// STRING_TOKEN: +// STRING_TOKEN: | +// PIPE_TOKEN +// STRING_TOKEN: | +// PIPE_TOKEN +// STRING_TOKEN: | +// PIPE_TOKEN +// STRING_TOKEN: +// Minishell $ test test "ters " "a asddddsa asdss +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters " +// STRING_TOKEN: "a asddddsa asdss +// Minishell $ test test "ters " "a asddddsa asdss ' test +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters " +// STRING_TOKEN: "a asddddsa asdss ' test +// Minishell $ test test "ters " "a asddddsa asdss ' test" +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters " +// STRING_TOKEN: "a asddddsa asdss ' test" +// Minishell $ test test "ters " "a asddddsa asdss ' test +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters " +// STRING_TOKEN: "a asddddsa asdss ' test +// Minishell $ test test "ters " "a asddddsa asdss ' te' +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters " +// STRING_TOKEN: "a asddddsa asdss ' te' +// Minishell $ test test "ters " "a asddddsa asdss ' te'" 'tes +// STRING_TOKEN: test +// STRING_TOKEN: test +// STRING_TOKEN: "ters " +// STRING_TOKEN: "a asddddsa asdss ' te'" +// STRING_TOKEN: 'tes +// Minishell $ +// STRING_TOKEN: � +// STRING_TOKEN: ��D� +// minishell(95695,0x10c1addc0) malloc: *** error for object 0x7f844c004407: pointer being freed was not allocated +// minishell(95695,0x10c1addc0) malloc: *** set a breakpoint in malloc_error_break to debug +// zsh: abort ./minishell +// chuhlig@1-E-11 minishell % ./minishell +// Minishell $ +// STRING_TOKEN: � +// STRING_TOKEN: � +// minishell(95853,0x118e33dc0) malloc: *** error for object 0x7fe72b405977: pointer being freed was not allocated +// minishell(95853,0x118e33dc0) malloc: *** set a breakpoint in malloc_error_break to debug +// zsh: abort ./minishell +// chuhlig@1-E-11 minishell % test +// chuhlig@1-E-11 minishell % pwd +// /Users/chuhlig/Desktop/minishell +// chuhlig@1-E-11 minishell % ./minishell +// Minishell $ test +// STRING_TOKEN: +// STRING_TOKEN: test +// Minishell $ test +// STRING_TOKEN: ` +// STRING_TOKEN: +// STRING_TOKEN: test +// Minishell $ \ No newline at end of file -- cgit v1.2.3 From f7df3a73f9d97ae09e9f3e3cd04eafd7824191ce Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 22 Jul 2024 14:39:25 +0200 Subject: added in repl.c tokenizer + visual and free --- src/repl.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/repl.c b/src/repl.c index 85d227f..99293e2 100644 --- a/src/repl.c +++ b/src/repl.c @@ -3,18 +3,22 @@ /* ::: :::::::: */ /* repl.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: dkaiser +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2024/06/25 15:03:00 by dkaiser ### ########.fr */ +/* Updated: 2024/07/15 19:53:52 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ -#include "minishell.h" +#include "../include/minishell.h" +#include "token.h" void repl(const char *prompt) { char *input; + t_token *token_list; + t_token *current; + t_token *next; while (1) { @@ -22,6 +26,15 @@ void repl(const char *prompt) if (input == NULL) return ; add_history(input); + token_list = NULL; + tokenizer(input, &token_list); + current = token_list; + while (current != NULL) + { + next = current->next; + free_token(current); + current = next; + } free(input); } } -- cgit v1.2.3 From 47a68b82e0463f5dfd4bd8a9c4b32b4c5fbcb610 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Mon, 22 Jul 2024 15:07:59 +0200 Subject: Fix errors and make the parser work --- include/ast.h | 9 ++++++--- src/free_node.c | 13 ++++++++----- src/new_node.c | 3 ++- src/parse_cmd.c | 29 ++++++++++++++++------------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/include/ast.h b/include/ast.h index b0ed996..bf19083 100644 --- a/include/ast.h +++ b/include/ast.h @@ -6,12 +6,12 @@ /* By: dkaiser content.cmd.args[i] != NULL) + while (node->content.cmd.args != NULL && node->content.cmd.args[i] != NULL) { free(node->content.cmd.args[i]); i++; } free(node->content.cmd.args); free_assigns(node->content.cmd.assigns); - free(node->content.cmd.redirs[0].specifier); - free(node->content.cmd.redirs[1].specifier); + if (node->content.cmd.redirs[0].type != 0 && node->content.cmd.redirs[0].specifier != NULL) + free(node->content.cmd.redirs[0].specifier); + if (node->content.cmd.redirs[1].type != 0 && node->content.cmd.redirs[0].specifier != NULL) + free(node->content.cmd.redirs[1].specifier); } static void free_assigns(t_assign **assigns) @@ -56,10 +58,11 @@ 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]->value); free(assigns[i]); i++; } diff --git a/src/new_node.c b/src/new_node.c index c334eb6..c2458d0 100644 --- a/src/new_node.c +++ b/src/new_node.c @@ -6,7 +6,7 @@ /* By: dkaiser content.cmd.assigns = assigns; node->content.cmd.redirs[0] = redirs[0]; node->content.cmd.redirs[1] = redirs[1]; + free(redirs); return (node); } diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 4fa2bc2..0173caa 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,7 +6,7 @@ /* By: dkaiser next != NULL) { if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) { if (cur->content.redir_type & (INPUT_FILE | INPUT_LIMITER)) - { - result[0].type = cur->content.redir_type; - result[0].specifier = cur->next->content.string; - } + idx = 0; else if (cur->content.redir_type & (OUTPUT_APPEND | OUTPUT_OVERRIDE)) - { - result[1].type = cur->content.redir_type; - result[1].specifier = cur->next->content.string; - } + idx = 1; + set_redir(&result[idx], cur->content.redir_type, + cur->next->content.string); cur = cur->next; free_token_and_connect(cur->previous); if (cur->next != NULL) @@ -170,3 +167,9 @@ static char **collect_args(t_token **tokens) result[i] = NULL; return (result); } + +static void set_redir(t_redirection *redir, int type, char *specifier) +{ + redir->type = type; + redir->specifier = specifier; +} -- cgit v1.2.3 From c16b4655f77db2f152625f226dc66ccc922671b4 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Mon, 22 Jul 2024 16:33:08 +0200 Subject: Add print_ast function --- Makefile | 3 ++- include/minishell.h | 4 ++-- src/print_ast.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/print_ast.c diff --git a/Makefile b/Makefile index 8896ded..a56ada3 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ 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 parser.c parse_cmd.c + free_token.c new_node.c free_node.c parser.c parse_cmd.c \ + print_ast.c OBJ_DIR := _obj OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o)) diff --git a/include/minishell.h b/include/minishell.h index 2411cc5..d980d42 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -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 2252eac3c49fa373d295d485e4f04ea41a475efb Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 2 Aug 2024 13:23:49 +0200 Subject: Fix print_ast --- src/print_ast.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/print_ast.c b/src/print_ast.c index d1f5095..94f813f 100644 --- a/src/print_ast.c +++ b/src/print_ast.c @@ -6,7 +6,7 @@ /* By: dkaiser type == PIPE_NODE) { - printf("%*s%s", indent, "", "* PIPE"); + printf("\n%*s%s", indent, "", "* PIPE"); print_ast_rec(ast->content.pipe.left, indent + 2); print_ast_rec(ast->content.pipe.right, indent + 2); } @@ -44,9 +44,9 @@ static void print_cmd_node(t_node *ast, int indent) printf("\n%*s%s", indent, "", "* CMD"); i = 0; printf("\n%*sARGS:", indent + 2, ""); - while (ast->content.cmd.args[i] != NULL) + while (ast->content.cmd.args != NULL && ast->content.cmd.args[i] != NULL) { - printf(" %s", ast->content.cmd.args[i]); + printf(" '%s'", ast->content.cmd.args[i]); i++; } i = 0; -- cgit v1.2.3 From d59a405311553dbe568ed79a5449f3222f8495ad Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 2 Aug 2024 13:24:48 +0200 Subject: Fix some issues in parse_cmd.c --- src/parse_cmd.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 0173caa..8ed9785 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,7 +6,7 @@ /* By: dkaiser previous); if (cur->next != NULL) { + if (cur->previous == NULL) + *tokens = cur->next; cur = cur->next; free_token_and_connect(cur->previous); } @@ -111,8 +113,15 @@ static t_assign **collect_assigns(t_token **tokens) { result[i] = to_assign(cur->content.string); i++; - cur = cur->next; - free_token(cur->previous); + if (cur->next != NULL) + { + cur = cur->next; + free_token(cur->previous); + } + else + { + free_token(cur); + } } *tokens = cur; result[i] = NULL; @@ -157,7 +166,7 @@ static char **collect_args(t_token **tokens) } cur = *tokens; i = 0; - while (cur != NULL) + while (cur != NULL && cur->type == STRING_TOKEN) { result[i] = cur->content.string; // free token -- cgit v1.2.3 From 82c1eed4f7795ef135a586af2fb334145b64b2f6 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 2 Aug 2024 14:14:42 +0200 Subject: Add function free_tokens() --- include/token.h | 3 ++- src/free_token.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/token.h b/include/token.h index d61195d..72ca5e5 100644 --- a/include/token.h +++ b/include/token.h @@ -6,7 +6,7 @@ /* By: dkaiser next->previous = token->previous; free(token); } + +void free_tokens(t_token *tokens) +{ + while (tokens->next != NULL) + { + tokens = tokens->next; + free_token(tokens->previous); + } + free_token(tokens); +} -- cgit v1.2.3 From c7a4494fd97b7e80665cbd47ed96bc37bf5800e5 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 2 Aug 2024 15:29:00 +0200 Subject: Refactor parser * Fix norme for free_node.c * Uglify parser.c * Merge parser updates into refactor-parser * Outsource collect_assigns and collect_redirs * Make parse_cmd.c norme conform * Make free_tokens() norme conform * Make collect_assigns.c norme conform * Some refactoring of collect_redirs * Refactor collect_redirs--- include/minishell.h | 16 +++--- src/collect_assigns.c | 84 ++++++++++++++++++++++++++++++ src/collect_redirs.c | 80 +++++++++++++++++++++++++++++ src/free_node.c | 8 +-- src/free_token.c | 4 +- src/parse_cmd.c | 138 ++------------------------------------------------ src/parser.c | 14 ++--- 7 files changed, 193 insertions(+), 151 deletions(-) create mode 100644 src/collect_assigns.c create mode 100644 src/collect_redirs.c diff --git a/include/minishell.h b/include/minishell.h index d980d42..b21acbc 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -6,7 +6,7 @@ /* By: dkaiser # include -int init(void); -int init_signal_handling(void); +int init(void); +int init_signal_handling(void); -void repl(const char *prompt); +void repl(const char *prompt); -t_list *parse(t_token *tokens); -t_node *parse_cmd(t_token *tokens); +t_list *parse(t_token *tokens); +t_node *parse_cmd(t_token *tokens); +t_redirection *collect_redirs(t_token **tokens); +t_assign **collect_assigns(t_token **tokens); -void print_ast(t_node *ast); +void print_ast(t_node *ast); #endif diff --git a/src/collect_assigns.c b/src/collect_assigns.c new file mode 100644 index 0000000..da43503 --- /dev/null +++ b/src/collect_assigns.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* collect_assigns.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* 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/collect_redirs.c b/src/collect_redirs.c new file mode 100644 index 0000000..76b08da --- /dev/null +++ b/src/collect_redirs.c @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* collect_redirs.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser next != NULL) + { + if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) + collect_redir(tokens, result, cur); + else if (cur->type == REDIR_TOKEN) + { + dbg("TODO: Add parsing errmsg"); + return (free(result), NULL); + } + else + cur = cur->next; + } + return (result); +} + +static void 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); + cur = cur->next; + free_token_and_connect(cur->previous); + if (cur->next != NULL) + { + if (cur->previous == NULL) + *tokens = cur->next; + cur = cur->next; + free_token_and_connect(cur->previous); + } + else + free_token(cur); +} + +static void set_redir(t_redirection *redir, int type, char *specifier) +{ + redir->type = type; + redir->specifier = specifier; +} + +static int is_output_redir(int i) +{ + if (i & (INPUT_FILE | INPUT_LIMITER)) + return (0); + else if (i & (OUTPUT_APPEND | OUTPUT_OVERRIDE)) + return (1); + else + { + panic(UNREACHABLE); + return (-1); + } +} diff --git a/src/free_node.c b/src/free_node.c index f8677d5..f387c0a 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) + if (node->content.cmd.redirs[0].type != 0 + && node->content.cmd.redirs[0].specifier != NULL) free(node->content.cmd.redirs[0].specifier); - if (node->content.cmd.redirs[1].type != 0 && node->content.cmd.redirs[0].specifier != NULL) + if (node->content.cmd.redirs[1].type != 0 + && node->content.cmd.redirs[0].specifier != NULL) free(node->content.cmd.redirs[1].specifier); } diff --git a/src/free_token.c b/src/free_token.c index 3c8ce1a..9b035ac 100644 --- a/src/free_token.c +++ b/src/free_token.c @@ -6,7 +6,7 @@ /* By: dkaiser next != NULL) { diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 8ed9785..068a4c1 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,18 +6,13 @@ /* By: dkaiser next != NULL) - { - if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) - { - if (cur->content.redir_type & (INPUT_FILE | INPUT_LIMITER)) - idx = 0; - else if (cur->content.redir_type & (OUTPUT_APPEND | OUTPUT_OVERRIDE)) - idx = 1; - set_redir(&result[idx], cur->content.redir_type, - cur->next->content.string); - cur = cur->next; - free_token_and_connect(cur->previous); - if (cur->next != NULL) - { - if (cur->previous == NULL) - *tokens = cur->next; - cur = cur->next; - free_token_and_connect(cur->previous); - } - else - { - free_token(cur); - } - } - else if (cur->type == REDIR_TOKEN) - { - // err Parsing error - free(result); - return (NULL); - } - else - { - cur = cur->next; - } - } - return (result); -} - -static t_assign **collect_assigns(t_token **tokens) -{ - t_token *cur; - t_assign **result; - int i; - - cur = *tokens; - i = 0; - while (cur != NULL && cur->type == STRING_TOKEN - && cur->content.string[0] != '"' && cur->content.string[0] != '\'' - && ft_strchr(cur->content.string, '=') != NULL) - { - i++; - cur = cur->next; - } - result = malloc(sizeof(t_assign *) * (i + 1)); - if (!result) - { - // free all tokens - return (NULL); - } - cur = *tokens; - i = 0; - while (cur != NULL && cur->type == STRING_TOKEN - && cur->content.string[0] != '"' && cur->content.string[0] != '\'' - && ft_strchr(cur->content.string, '=') != NULL) - { - result[i] = to_assign(cur->content.string); - i++; - 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 char **collect_args(t_token **tokens) { t_token *cur; @@ -159,26 +40,17 @@ static char **collect_args(t_token **tokens) cur = cur->next; } result = malloc(sizeof(char *) * (i + 1)); - if (!result) - { - // free all tokens; - return (NULL); - } + if (result == NULL) + return (free_tokens(*tokens), NULL); cur = *tokens; i = 0; while (cur != NULL && cur->type == STRING_TOKEN) { result[i] = cur->content.string; - // free token i++; cur = cur->next; + free_token(cur->previous); } result[i] = NULL; return (result); } - -static void set_redir(t_redirection *redir, int type, char *specifier) -{ - redir->type = type; - redir->specifier = specifier; -} diff --git a/src/parser.c b/src/parser.c index 66c6785..f9484c9 100644 --- a/src/parser.c +++ b/src/parser.c @@ -6,7 +6,7 @@ /* By: dkaiser next; } if (current == NULL) - { - // Free: ft_lstclear(&result, free_node); - return (NULL); - } + return (ft_lstclear(&result, free_node_wrapper), NULL); current_tokens = split_at_first(&tokens, NEWLINE_TOKEN); } return (result); @@ -91,3 +88,8 @@ static t_token *find_token_by_type(t_token *tokens, int type) } return (NULL); } + +static void free_node_wrapper(void *node) +{ + free_node((t_node *)node); +} -- cgit v1.2.3 From 2391dd08be8ebb6f11847e62ef68913faa0e0382 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Sun, 4 Aug 2024 14:36:08 +0200 Subject: updated token header but still norm erro idk --- include/token.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/token.h b/include/token.h index 6dd44c9..ddb206e 100644 --- a/include/token.h +++ b/include/token.h @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 13:27:18 by dkaiser #+# #+# */ -/* Updated: 2024/06/28 21:49:55 by chuhlig ### ########.fr */ +/* Updated: 2024/08/04 14:34:52 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,9 +47,8 @@ t_token *new_redir_token(int type, t_token *previous, void free_token(t_token *token); void print_token(t_token *token); -void conditional_print(char *string, int start_of_string, int i, int offset, t_token **token_list); +void conditional_print(char *string, int start_of_string, int i, t_token **token_list); void tokenizer(char *s, t_token **token_list); void print_token(t_token *token); - #endif \ No newline at end of file -- cgit v1.2.3 From 0c14e472ffa09b741ed549208fbc028d759dba17 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Sun, 4 Aug 2024 14:36:51 +0200 Subject: made it norm comform exept one funkction to much --- src/tokenizer.c | 318 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 201 insertions(+), 117 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index ddc33da..4059526 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -6,31 +6,20 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */ -/* Updated: 2024/07/22 14:18:02 by chuhlig ### ########.fr */ +/* Updated: 2024/08/04 14:32:56 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include "token.h" -// char *ft_strncpy(char *dst, const char *src, size_t n) -// { -// char *start; - -// start = dst; -// while (n-- > 0 && *src) -// *dst++ = *src++; -// while (n-- > 0) -// *dst++ = '\0'; -// return (start); -// } -char *ft_strncpy(char *s1, char *s2, int n) +char *ft_strncpy(char *s1, char *s2, int n) { - int i = -1; + int i; + i = -1; while (++i < n && s2[i]) s1[i] = s2[i]; - s1[i] = '\0'; return (s1); } @@ -54,13 +43,13 @@ void print_token(t_token *token) } } -//s[i] should be right bc i wanna start at specific pos -void conditional_print(char *string, int start_of_string, int i, int offset, t_token **token_list) +void conditional_print(char *string, int start_of_string, int i, + t_token **token_list) { char *line; int len; - len = i + offset - start_of_string + 1; + len = i - start_of_string + 1; if (len > 0) { line = (char *)malloc(len); @@ -70,117 +59,95 @@ void conditional_print(char *string, int start_of_string, int i, int offset, t_t } ft_strncpy(line, string + start_of_string, len); line[len] = '\0'; - while (*line == ' ' || *line == '\t' || *line == '\0') + while (*line == ' ' || *line == '\t') line++; if (*line != '\0') { *token_list = new_str_token(line, *token_list, NULL); print_token(*token_list); } - // free(line); } } -void tokenizer(char *s, t_token **token_list) +int symbol_checker(char *s, int i, t_token **token_list) +{ + if ((s[i] == '<' || s[i] == '>') && s[i + 1] == s[i]) + { + if (s[i] == '<') + *token_list = new_redir_token(INPUT_LIMITER, *token_list, NULL); + else + *token_list = new_redir_token(OUTPUT_APPEND, *token_list, NULL); + print_token(*token_list); + i++; + } + else + { + if (s[i] == '<') + *token_list = new_redir_token(INPUT_FILE, *token_list, NULL); + else if (s[i] == '|') + *token_list = new_token(PIPE_TOKEN, *token_list, NULL); + else if (s[i] == '\n') + *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); + else + *token_list = new_redir_token(OUTPUT_OVERRIDE, *token_list, NULL); + print_token(*token_list); + } + return (i); +} + +int check_for_string(char *s, int i, int *start_of_string, t_token **token_list) { - char *quotes; char quote_check; - // char c; + int ignore_space; + + ignore_space = 0; + quote_check = '\0'; + if (ignore_space && s[i] == quote_check) + { + quote_check = '\0'; + ignore_space = 0; + } + else if (!ignore_space && ft_strchr("\"\'", s[i])) + { + quote_check = s[i]; + ignore_space = 1; + } + if ((!ignore_space && (s[i] == '\0' || s[i] == ' ' + || s[i] == '\t')) || i == ft_strlen(s) - 1) + { + if (s[i + 1] == '\0') + i++; + conditional_print(s, *start_of_string, i - 1, token_list); + *start_of_string = i + 1; + } + return (i); +} + +void tokenizer(char *s, t_token **token_list) +{ int start_of_string; int ignore_space; int i; + char quote_check; - quotes = "\"\'"; quote_check = '\0'; start_of_string = 0; ignore_space = 0; i = 0; if (!s || !*s) return ; - while (s[i] && s) + while (s && s[i]) { - // c = s[i]; - // if (!ignore_space && (c == '|' || c == '\n' || c == '<' || c == '>')) - if (!ignore_space && (s[i] == '|' || s[i] == '\n' || s[i] == '<' || s[i] == '>')) + if (!ignore_space && (s[i] == '|' || s[i] == '\n' + || s[i] == '<' || s[i] == '>')) { - conditional_print(s, start_of_string, i, 0, token_list); - // if ((c == '<' || c == '>') && s[i + 1] == c) - if ((s[i] == '<' || s[i] == '>') && s[i + 1] == s[i]) - { - // if (c == '<') - if (s[i] == '<') - *token_list = new_redir_token(INPUT_LIMITER, - *token_list, NULL); - else - *token_list = new_redir_token(OUTPUT_APPEND, - *token_list, NULL); - print_token(*token_list); - i++; - } - else - { - // if (c == '<') - if (s[i] == '<') - *token_list = new_redir_token(INPUT_FILE, - *token_list, NULL); - // else if (c == '|') - else if (s[i] == '|') - *token_list = new_token(PIPE_TOKEN, *token_list, NULL); - // else if (c == '\n') - else if (s[i] == '\n') - *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); - else - *token_list = new_redir_token(OUTPUT_OVERRIDE, - *token_list, NULL); - print_token(*token_list); - // i++; - } + i = symbol_checker(s, i, token_list); start_of_string = i + 1; } - // else if (ignore_space && c == quote_check) - // mew update for the sting part 18.07 - else if (ignore_space && s[i] == quote_check) + else { - quote_check = '\0'; - ignore_space = 0; + i = check_for_string(s, i, &start_of_string, token_list); } - // else if (!ignore_space && ft_strchr(quotes, c)) - else if (!ignore_space && ft_strchr(quotes, s[i])) - { - quote_check = s[i]; - ignore_space = 1; - } - // else if ((!ignore_space && (c == '\0' || c == ' ' || c == '\t')) || i == ft_strlen(s) - 1) - if ((!ignore_space && (s[i] == '\0' || s[i] == ' ' || s[i] == '\t')) || i == ft_strlen(s) - 1) - { - if (s[i + 1] == '\0') - i++; - conditional_print(s, start_of_string, i, 0, token_list); - start_of_string = i + 1; - } - // else if (!ignore_space && ft_strchr(quotes, c)) - // else if (!ignore_space) - // { - // if(ft_strchr(quotes, s[i])) - // { - // quote_check = s[i]; - // ignore_space = 1; - // } - // else if (s[i] == '\0' || s[i] == ' ' || s[i] == '\t' || i == ft_strlen(s) - 1) - // { - // if (s[i + 1] == '\0') - // i++; - // conditional_print(s, start_of_string, i, 0, token_list); - // start_of_string = i + 1; - // } - // } - // else if (ignore_space && (s[i] == quote_check || s[i + 1] == '\0'))// secon part out of while loop? - // { - // quote_check = '\0'; - // ignore_space = 0; - // conditional_print(s, start_of_string, i, 0, token_list); - // start_of_string = i + 1; - // } i++; } } @@ -215,18 +182,23 @@ void tokenizer(char *s, t_token **token_list) // Minishell $ test // STRING_TOKEN: � // ================================================================= -// ==66482==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000002835 at pc 0x00010bb02c68 bp 0x7ffee41034b0 sp 0x7ffee41034a8 +// ==66482==ERROR: AddressSanitizer: +//heap-buffer-overflow on address 0x602000002835 +//at pc 0x00010bb02c68 bp 0x7ffee41034b0 sp 0x7ffee41034a8 // READ of size 1 at 0x602000002835 thread T0 // #0 0x10bb02c67 in tokenizer tokenizer.c:91 // #1 0x10bb00c66 in repl repl.c:30 // #2 0x10bb00684 in main main.c:19 // #3 0x7fff733a7cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8) -// 0x602000002835 is located 0 bytes to the right of 5-byte region [0x602000002830,0x602000002835) +// 0x602000002835 is located 0 bytes +//to the right of 5-byte region [0x602000002830,0x602000002835) // allocated by thread T0 here: -// #0 0x10bba517d in wrap_malloc+0x9d (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4917d) +// #0 0x10bba517d in wrap_malloc+0x9d +//(libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4917d) // #1 0x10bb38c44 in xmalloc+0x8 (libreadline.8.dylib:x86_64+0x25c44) -// #2 0x10bb16096 in readline_internal_teardown+0xfa (libreadline.8.dylib:x86_64+0x3096) +// #2 0x10bb16096 in readline_internal_teardown+0xfa +//(libreadline.8.dylib:x86_64+0x3096) // #3 0x10bb15bb4 in readline+0x5b (libreadline.8.dylib:x86_64+0x2bb4) // #4 0x10bb00ba3 in repl repl.c:25 // #5 0x10bb00684 in main main.c:19 @@ -270,8 +242,10 @@ void tokenizer(char *s, t_token **token_list) // othere error currently // test // STRING_TOKEN: -// minishell(86892,0x111ae2dc0) malloc: *** error for object 0x7fedf3200014: pointer being freed was not allocated -// minishell(86892,0x111ae2dc0) malloc: *** set a breakpoint in malloc_error_break to debug +// minishell(86892,0x111ae2dc0) malloc: *** +//error for object 0x7fedf3200014: pointer being freed was not allocated +// minishell(86892,0x111ae2dc0) malloc: *** +//set a breakpoint in malloc_error_break to debug // zsh: abort ./minishell // chuhlig@1-E-9 minishell % ./minishell // Minishell $ "test" @@ -279,8 +253,10 @@ void tokenizer(char *s, t_token **token_list) // Minishell $ "test test" // Minishell $ te // STRING_TOKEN: ` -// minishell(86928,0x114a76dc0) malloc: *** error for object 0x7fcaa8d04f27: pointer being freed was not allocated -// minishell(86928,0x114a76dc0) malloc: *** set a breakpoint in malloc_error_break to debug +// minishell(86928,0x114a76dc0) malloc: *** +//error for object 0x7fcaa8d04f27: pointer being freed was not allocated +// minishell(86928,0x114a76dc0) malloc: *** +//set a breakpoint in malloc_error_break to debug // zsh: abort ./minishell // chuhlig@1-E-9 minishell % ./minishell // Minishell $ a @@ -290,8 +266,10 @@ void tokenizer(char *s, t_token **token_list) // chuhlig@1-E-9 minishell % ./minishell // Minishell $ a // STRING_TOKEN: ^ -// minishell(86958,0x11c50adc0) malloc: *** error for object 0x7fb24a800011: pointer being freed was not allocated -// minishell(86958,0x11c50adc0) malloc: *** set a breakpoint in malloc_error_break to debug +// minishell(86958,0x11c50adc0) malloc: *** +//error for object 0x7fb24a800011: pointer being freed was not allocated +// minishell(86958,0x11c50adc0) malloc: *** +//set a breakpoint in malloc_error_break to debug // zsh: abort ./minishell // chuhlig@1-E-9 minishell % ./minishell // Minishell $ a @@ -395,15 +373,19 @@ void tokenizer(char *s, t_token **token_list) // Minishell $ // STRING_TOKEN: � // STRING_TOKEN: ��D� -// minishell(95695,0x10c1addc0) malloc: *** error for object 0x7f844c004407: pointer being freed was not allocated -// minishell(95695,0x10c1addc0) malloc: *** set a breakpoint in malloc_error_break to debug +// minishell(95695,0x10c1addc0) malloc: *** error +//for object 0x7f844c004407: pointer being freed was not allocated +// minishell(95695,0x10c1addc0) malloc: *** +//set a breakpoint in malloc_error_break to debug // zsh: abort ./minishell // chuhlig@1-E-11 minishell % ./minishell // Minishell $ // STRING_TOKEN: � // STRING_TOKEN: � -// minishell(95853,0x118e33dc0) malloc: *** error for object 0x7fe72b405977: pointer being freed was not allocated -// minishell(95853,0x118e33dc0) malloc: *** set a breakpoint in malloc_error_break to debug +// minishell(95853,0x118e33dc0) malloc: *** error for object +//0x7fe72b405977: pointer being freed was not allocated +// minishell(95853,0x118e33dc0) malloc: *** +//set a breakpoint in malloc_error_break to debug // zsh: abort ./minishell // chuhlig@1-E-11 minishell % test // chuhlig@1-E-11 minishell % pwd @@ -416,4 +398,106 @@ void tokenizer(char *s, t_token **token_list) // STRING_TOKEN: ` // STRING_TOKEN: // STRING_TOKEN: test -// Minishell $ \ No newline at end of file +// Minishell $ +///////////////////////////////// +// ./minishell +// Minishell $ test +// STRING_TOKEN: test +// Minishell $ test +// STRING_TOKEN: test +// Minishell $ test +// STRING_TOKEN: test +// Minishell $ test dsads a +// STRING_TOKEN: test +// STRING_TOKEN: dsads +// STRING_TOKEN: a +// Minishell $ test dsads adsadsa saddas as dadsdas a dsdsa d "test" +// STRING_TOKEN: test +// STRING_TOKEN: dsads +// STRING_TOKEN: adsadsa +// STRING_TOKEN: saddas +// STRING_TOKEN: as +// STRING_TOKEN: dadsdas +// STRING_TOKEN: a +// STRING_TOKEN: dsdsa +// STRING_TOKEN: d +// STRING_TOKEN: "test" +// Minishell $ test dsads adsadsa saddas as dadsdas a dsdsa d "test +// STRING_TOKEN: test +// STRING_TOKEN: dsads +// STRING_TOKEN: adsadsa +// STRING_TOKEN: saddas +// STRING_TOKEN: as +// STRING_TOKEN: dadsdas +// STRING_TOKEN: a +// STRING_TOKEN: dsdsa +// STRING_TOKEN: d +// STRING_TOKEN: "test +// Minishell test dsads adsadsa saddas as dadsdas a dsdsa d "test ... <>< +// STRING_TOKEN: test +// STRING_TOKEN: dsads +// STRING_TOKEN: adsadsa +// STRING_TOKEN: saddas +// STRING_TOKEN: as +// STRING_TOKEN: dadsdas +// STRING_TOKEN: a +// STRING_TOKEN: dsdsa +// STRING_TOKEN: d +// STRING_TOKEN: "test ... <><><>|| +/// now follow a older version where i tried to eliminate the "" case + // else if (!ignore_space && ft_strchr(quotes, c)) + // else if (!ignore_space) + // { + // if(ft_strchr(quotes, s[i])) + // { + // quote_check = s[i]; + // ignore_space = 1; + // } + // else if (s[i] == '\0' || s[i] == ' ' || + //s[i] == '\t' || i == ft_strlen(s) - 1) + // { + // if (s[i + 1] == '\0') + // i++; + // conditional_print(s, start_of_string, i, 0, token_list); + // start_of_string = i + 1; + // } + // } + // else if (ignore_space && (s[i] == quote_check + //|| s[i + 1] == '\0'))// secon part out of while loop? + // { + // quote_check = '\0'; + // ignore_space = 0; + // conditional_print(s, start_of_string, i, 0, token_list); + // start_of_string = i + 1; + // } + +// char *ft_strncpy(char *dst, const char *src, size_t n) +// { +// char *start; + +// start = dst; +// while (n-- > 0 && *src) +// *dst++ = *src++; +// while (n-- > 0) +// *dst++ = '\0'; +// return (start); +// } +//costum is space? + // else if (ignore_space && s[i] == quote_check) + // { + // quote_check = '\0'; + // ignore_space = 0; + // } + // else if (!ignore_space && ft_strchr("\"\'", s[i])) + // { + // quote_check = s[i]; + // ignore_space = 1; + // } + // if ((!ignore_space && (s[i] == '\0' + //|| s[i] == ' ' || s[i] == '\t')) || i == ft_strlen(s) - 1) + // { + // if (s[i + 1] == '\0') + // i++; + // conditional_print(s, start_of_string, i - 1, 0, token_list); + // start_of_string = i + 1; + // } \ No newline at end of file -- 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(-) 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 7d5284d8a26fae896d2e0fa875d34d9186ed5235 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:21:18 +0200 Subject: added second version at some point --- lib/libft/ft_memset.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/libft/ft_memset.c b/lib/libft/ft_memset.c index 58c5e1e..085df1d 100644 --- a/lib/libft/ft_memset.c +++ b/lib/libft/ft_memset.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_memset.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: dkaiser +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 09:58:19 by dkaiser #+# #+# */ -/* Updated: 2024/03/10 13:13:09 by dkaiser ### ########.fr */ +/* Updated: 2024/07/11 23:52:13 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,3 +35,13 @@ void *ft_memset(void *b, int c, size_t len) /* printf("ft_memset: %s\n", ft_memset((char *)str, 'A' + 255, 5)); */ /* printf("memset: %s\n", memset((char *)str, 'A' + 255, 5)); */ /* } */ + +// void *ft_memset(void *b, int c, size_t len) +// { +// void *savearg; + +// savearg = b; +// while (len--) +// *(unsigned char *)b++ = (unsigned char)c; +// return (savearg); +// } \ No newline at end of file -- cgit v1.2.3 From d3474100c72be3384d8fe8ca9e6a24260d0c1b52 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:21:45 +0200 Subject: updated the date in header --- src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 016ede6..8523b9e 100644 --- a/src/main.c +++ b/src/main.c @@ -3,14 +3,14 @@ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: dkaiser +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/22 17:14:03 by dkaiser #+# #+# */ -/* Updated: 2024/06/25 13:58:24 by dkaiser ### ########.fr */ +/* Updated: 2024/07/18 16:44:14 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ -#include "minishell.h" +#include "../include/minishell.h" int main(void) { -- cgit v1.2.3 From 9f48d6912e02fa5fcca46bb5f493bc2267ec8c82 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:22:54 +0200 Subject: removed .vscode --- .vscode/c_cpp_properties.json | 18 ------------- .vscode/launch.json | 13 --------- .vscode/settings.json | 62 ------------------------------------------- 3 files changed, 93 deletions(-) delete mode 100644 .vscode/c_cpp_properties.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 97c1779..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "configurations": [ - { - "name": "macos-clang-x64", - "includePath": [ - "${workspaceFolder}/**" - ], - "compilerPath": "/usr/bin/clang", - "cStandard": "${default}", - "cppStandard": "${default}", - "intelliSenseMode": "macos-clang-x64", - "compilerArgs": [ - "" - ] - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index ecd0fa2..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "lldb", - "request": "launch", - "args": [], - "cwd": "/Users/chuhlig/Desktop/minishell/", - "program": "/Users/chuhlig/Desktop/minishell/minishell" - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ae14d75..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "C_Cpp_Runner.cCompilerPath": "clang", - "C_Cpp_Runner.cppCompilerPath": "clang++", - "C_Cpp_Runner.debuggerPath": "lldb", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic", - "-Wshadow", - "-Wformat=2", - "-Wcast-align", - "-Wconversion", - "-Wsign-conversion", - "-Wnull-dereference" - ], - "C_Cpp_Runner.msvcWarnings": [ - "/W4", - "/permissive-", - "/w14242", - "/w14287", - "/w14296", - "/w14311", - "/w14826", - "/w44062", - "/w44242", - "/w14905", - "/w14906", - "/w14263", - "/w44265", - "/w14928" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false, - "C_Cpp_Runner.useUndefinedSanitizer": false, - "C_Cpp_Runner.useLeakSanitizer": false, - "C_Cpp_Runner.showCompilationTime": false, - "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false, - "files.associations": { - "minishell.h": "c" - } -} \ No newline at end of file -- cgit v1.2.3 From 0c0539fae76a678018af015e8d0f498fd5c19add Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:24:32 +0200 Subject: removed debugs functions out of header --- include/token.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/token.h b/include/token.h index ddb206e..d7ff9f9 100644 --- a/include/token.h +++ b/include/token.h @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 13:27:18 by dkaiser #+# #+# */ -/* Updated: 2024/08/04 14:34:52 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 13:23:27 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,10 +45,6 @@ t_token *new_redir_token(int type, t_token *previous, t_token *next); void free_token(t_token *token); - -void print_token(t_token *token); -void conditional_print(char *string, int start_of_string, int i, t_token **token_list); void tokenizer(char *s, t_token **token_list); -void print_token(t_token *token); #endif \ No newline at end of file -- cgit v1.2.3 From 429730860776816050abd40a318de993c0c69e17 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:25:33 +0200 Subject: removed notes out of tokenizer.c --- src/tokenizer.c | 352 +------------------------------------------------------- 1 file changed, 1 insertion(+), 351 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index 4059526..5aa4895 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/04 14:32:56 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 13:24:59 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -151,353 +151,3 @@ void tokenizer(char *s, t_token **token_list) i++; } } - -///s[i] != ' ' -//mazbe remove c -// why handle space? -//readline delete mazbe? - -// errors today if i change the con print cond removing *line == '\0' -// ./minishell -// Minishell $ test -// Minishell $ idk -// Minishell $ why you idiot a re doing nothing -// zsh: segmentation fault ./minishell -// chuhlig@1-E-9 minishell % ./minishell -// Minishell $ a -// Minishell $ aaa -// Minishell $ aaaaaaaaaaaaaa -// Minishell $ aa aa -// zsh: segmentation fault ./minishell - -// also some space reconizing is wrong -//also the part with cond &s[i] or just s seem f up -//tested different strncpy still errors -// removed anoying brackets to short it -//added pipe and \n token -// string still not works fine mazybe readline and input understanding - -// error with extra condition: -// ./minishell -// Minishell $ test -// STRING_TOKEN: � -// ================================================================= -// ==66482==ERROR: AddressSanitizer: -//heap-buffer-overflow on address 0x602000002835 -//at pc 0x00010bb02c68 bp 0x7ffee41034b0 sp 0x7ffee41034a8 -// READ of size 1 at 0x602000002835 thread T0 -// #0 0x10bb02c67 in tokenizer tokenizer.c:91 -// #1 0x10bb00c66 in repl repl.c:30 -// #2 0x10bb00684 in main main.c:19 -// #3 0x7fff733a7cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8) - -// 0x602000002835 is located 0 bytes -//to the right of 5-byte region [0x602000002830,0x602000002835) -// allocated by thread T0 here: -// #0 0x10bba517d in wrap_malloc+0x9d -//(libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x4917d) -// #1 0x10bb38c44 in xmalloc+0x8 (libreadline.8.dylib:x86_64+0x25c44) -// #2 0x10bb16096 in readline_internal_teardown+0xfa -//(libreadline.8.dylib:x86_64+0x3096) -// #3 0x10bb15bb4 in readline+0x5b (libreadline.8.dylib:x86_64+0x2bb4) -// #4 0x10bb00ba3 in repl repl.c:25 -// #5 0x10bb00684 in main main.c:19 -// #6 0x7fff733a7cc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8) - -// SUMMARY: AddressSanitizer: heap-buffer-overflow tokenizer.c:91 in tokenizer -// Shadow bytes around the buggy address: -// 0x1c04000004b0: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa -// 0x1c04000004c0: fa fa fd fa fa fa fd fa fa fa fd fd fa fa fd fd -// 0x1c04000004d0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd -// 0x1c04000004e0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd -// 0x1c04000004f0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd -// =>0x1c0400000500: fa fa 00 00 fa fa[05]fa fa fa 00 04 fa fa 05 fa -// 0x1c0400000510: fa fa 05 fa fa fa fa fa fa fa fa fa fa fa fa fa -// 0x1c0400000520: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa -// 0x1c0400000530: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa -// 0x1c0400000540: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa -// 0x1c0400000550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa -// Shadow byte legend (one shadow byte represents 8 application bytes): -// Addressable: 00 -// Partially addressable: 01 02 03 04 05 06 07 -// Heap left redzone: fa -// Freed heap region: fd -// Stack left redzone: f1 -// Stack mid redzone: f2 -// Stack right redzone: f3 -// Stack after return: f5 -// Stack use after scope: f8 -// Global redzone: f9 -// Global init order: f6 -// Poisoned by user: f7 -// Container overflow: fc -// Array cookie: ac -// Intra object redzone: bb -// ASan internal: fe -// Left alloca redzone: ca -// Right alloca redzone: cb -// Shadow gap: cc -// ==66482==ABORTING - -// othere error currently -// test -// STRING_TOKEN: -// minishell(86892,0x111ae2dc0) malloc: *** -//error for object 0x7fedf3200014: pointer being freed was not allocated -// minishell(86892,0x111ae2dc0) malloc: *** -//set a breakpoint in malloc_error_break to debug -// zsh: abort ./minishell -// chuhlig@1-E-9 minishell % ./minishell -// Minishell $ "test" -// Minishell $ "testtest" -// Minishell $ "test test" -// Minishell $ te -// STRING_TOKEN: ` -// minishell(86928,0x114a76dc0) malloc: *** -//error for object 0x7fcaa8d04f27: pointer being freed was not allocated -// minishell(86928,0x114a76dc0) malloc: *** -//set a breakpoint in malloc_error_break to debug -// zsh: abort ./minishell -// chuhlig@1-E-9 minishell % ./minishell -// Minishell $ a -// STRING_TOKEN: -// Minishell $ a -// zsh: segmentation fault ./minishell -// chuhlig@1-E-9 minishell % ./minishell -// Minishell $ a -// STRING_TOKEN: ^ -// minishell(86958,0x11c50adc0) malloc: *** -//error for object 0x7fb24a800011: pointer being freed was not allocated -// minishell(86958,0x11c50adc0) malloc: *** -//set a breakpoint in malloc_error_break to debug -// zsh: abort ./minishell -// chuhlig@1-E-9 minishell % ./minishell -// Minishell $ a -// zsh: segmentation fault ./minishell - -///do i need to update after cont print i? -// end quote not works atm and have to check the lenth -// how to handle not in quote text command -// space generell need to be fixed - -/// 1425 2207 -// Minishell $ test test "ters" -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters" -// Minishell $ test test "ters -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters -// Minishell $ test test "ters " "a -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters " -// STRING_TOKEN: "a -// Minishell $ |||| <><> <><> <<< >>>> ||| -// STRING_TOKEN: | -// PIPE_TOKEN -// STRING_TOKEN: | -// PIPE_TOKEN -// STRING_TOKEN: | -// PIPE_TOKEN -// STRING_TOKEN: | -// PIPE_TOKEN -// STRING_TOKEN: -// STRING_TOKEN: < -// REDIR_TOKEN: 0 -// STRING_TOKEN: > -// REDIR_TOKEN: 2 -// STRING_TOKEN: < -// REDIR_TOKEN: 0 -// STRING_TOKEN: > -// REDIR_TOKEN: 2 -// STRING_TOKEN: ^ -// STRING_TOKEN: < -// REDIR_TOKEN: 0 -// STRING_TOKEN: > -// REDIR_TOKEN: 2 -// STRING_TOKEN: < -// REDIR_TOKEN: 0 -// STRING_TOKEN: > -// REDIR_TOKEN: 2 -// STRING_TOKEN: ^ -// STRING_TOKEN: < -// REDIR_TOKEN: 1 -// STRING_TOKEN: < -// REDIR_TOKEN: 0 -// STRING_TOKEN: � -// STRING_TOKEN: > -// REDIR_TOKEN: 3 -// STRING_TOKEN: > -// REDIR_TOKEN: 3 -// STRING_TOKEN: -// STRING_TOKEN: | -// PIPE_TOKEN -// STRING_TOKEN: | -// PIPE_TOKEN -// STRING_TOKEN: | -// PIPE_TOKEN -// STRING_TOKEN: -// Minishell $ test test "ters " "a asddddsa asdss -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters " -// STRING_TOKEN: "a asddddsa asdss -// Minishell $ test test "ters " "a asddddsa asdss ' test -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters " -// STRING_TOKEN: "a asddddsa asdss ' test -// Minishell $ test test "ters " "a asddddsa asdss ' test" -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters " -// STRING_TOKEN: "a asddddsa asdss ' test" -// Minishell $ test test "ters " "a asddddsa asdss ' test -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters " -// STRING_TOKEN: "a asddddsa asdss ' test -// Minishell $ test test "ters " "a asddddsa asdss ' te' -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters " -// STRING_TOKEN: "a asddddsa asdss ' te' -// Minishell $ test test "ters " "a asddddsa asdss ' te'" 'tes -// STRING_TOKEN: test -// STRING_TOKEN: test -// STRING_TOKEN: "ters " -// STRING_TOKEN: "a asddddsa asdss ' te'" -// STRING_TOKEN: 'tes -// Minishell $ -// STRING_TOKEN: � -// STRING_TOKEN: ��D� -// minishell(95695,0x10c1addc0) malloc: *** error -//for object 0x7f844c004407: pointer being freed was not allocated -// minishell(95695,0x10c1addc0) malloc: *** -//set a breakpoint in malloc_error_break to debug -// zsh: abort ./minishell -// chuhlig@1-E-11 minishell % ./minishell -// Minishell $ -// STRING_TOKEN: � -// STRING_TOKEN: � -// minishell(95853,0x118e33dc0) malloc: *** error for object -//0x7fe72b405977: pointer being freed was not allocated -// minishell(95853,0x118e33dc0) malloc: *** -//set a breakpoint in malloc_error_break to debug -// zsh: abort ./minishell -// chuhlig@1-E-11 minishell % test -// chuhlig@1-E-11 minishell % pwd -// /Users/chuhlig/Desktop/minishell -// chuhlig@1-E-11 minishell % ./minishell -// Minishell $ test -// STRING_TOKEN: -// STRING_TOKEN: test -// Minishell $ test -// STRING_TOKEN: ` -// STRING_TOKEN: -// STRING_TOKEN: test -// Minishell $ -///////////////////////////////// -// ./minishell -// Minishell $ test -// STRING_TOKEN: test -// Minishell $ test -// STRING_TOKEN: test -// Minishell $ test -// STRING_TOKEN: test -// Minishell $ test dsads a -// STRING_TOKEN: test -// STRING_TOKEN: dsads -// STRING_TOKEN: a -// Minishell $ test dsads adsadsa saddas as dadsdas a dsdsa d "test" -// STRING_TOKEN: test -// STRING_TOKEN: dsads -// STRING_TOKEN: adsadsa -// STRING_TOKEN: saddas -// STRING_TOKEN: as -// STRING_TOKEN: dadsdas -// STRING_TOKEN: a -// STRING_TOKEN: dsdsa -// STRING_TOKEN: d -// STRING_TOKEN: "test" -// Minishell $ test dsads adsadsa saddas as dadsdas a dsdsa d "test -// STRING_TOKEN: test -// STRING_TOKEN: dsads -// STRING_TOKEN: adsadsa -// STRING_TOKEN: saddas -// STRING_TOKEN: as -// STRING_TOKEN: dadsdas -// STRING_TOKEN: a -// STRING_TOKEN: dsdsa -// STRING_TOKEN: d -// STRING_TOKEN: "test -// Minishell test dsads adsadsa saddas as dadsdas a dsdsa d "test ... <>< -// STRING_TOKEN: test -// STRING_TOKEN: dsads -// STRING_TOKEN: adsadsa -// STRING_TOKEN: saddas -// STRING_TOKEN: as -// STRING_TOKEN: dadsdas -// STRING_TOKEN: a -// STRING_TOKEN: dsdsa -// STRING_TOKEN: d -// STRING_TOKEN: "test ... <><><>|| -/// now follow a older version where i tried to eliminate the "" case - // else if (!ignore_space && ft_strchr(quotes, c)) - // else if (!ignore_space) - // { - // if(ft_strchr(quotes, s[i])) - // { - // quote_check = s[i]; - // ignore_space = 1; - // } - // else if (s[i] == '\0' || s[i] == ' ' || - //s[i] == '\t' || i == ft_strlen(s) - 1) - // { - // if (s[i + 1] == '\0') - // i++; - // conditional_print(s, start_of_string, i, 0, token_list); - // start_of_string = i + 1; - // } - // } - // else if (ignore_space && (s[i] == quote_check - //|| s[i + 1] == '\0'))// secon part out of while loop? - // { - // quote_check = '\0'; - // ignore_space = 0; - // conditional_print(s, start_of_string, i, 0, token_list); - // start_of_string = i + 1; - // } - -// char *ft_strncpy(char *dst, const char *src, size_t n) -// { -// char *start; - -// start = dst; -// while (n-- > 0 && *src) -// *dst++ = *src++; -// while (n-- > 0) -// *dst++ = '\0'; -// return (start); -// } -//costum is space? - // else if (ignore_space && s[i] == quote_check) - // { - // quote_check = '\0'; - // ignore_space = 0; - // } - // else if (!ignore_space && ft_strchr("\"\'", s[i])) - // { - // quote_check = s[i]; - // ignore_space = 1; - // } - // if ((!ignore_space && (s[i] == '\0' - //|| s[i] == ' ' || s[i] == '\t')) || i == ft_strlen(s) - 1) - // { - // if (s[i + 1] == '\0') - // i++; - // conditional_print(s, start_of_string, i - 1, 0, token_list); - // start_of_string = i + 1; - // } \ No newline at end of file -- cgit v1.2.3 From d6e50007009baf751930aec184218b4ced7dda19 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:42:32 +0200 Subject: added strncpy in lib --- lib/libft/ft_strncpy.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/libft/ft_strncpy.c diff --git a/lib/libft/ft_strncpy.c b/lib/libft/ft_strncpy.c new file mode 100644 index 0000000..30a9d3d --- /dev/null +++ b/lib/libft/ft_strncpy.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: chuhlig +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/08/05 13:41:47 by chuhlig #+# #+# */ +/* Updated: 2024/08/05 13:42:00 by chuhlig ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncpy(char *s1, char *s2, int n) +{ + int i; + + i = -1; + while (++i < n && s2[i]) + s1[i] = s2[i]; + return (s1); +} \ No newline at end of file -- cgit v1.2.3 From 68af24d0597b06516891199bde4178a2d1552e09 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:43:07 +0200 Subject: remove strncpy out of tokenizer f --- src/tokenizer.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index 5aa4895..a2f6fa4 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -6,23 +6,13 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/28 20:55:50 by chuhlig #+# #+# */ -/* Updated: 2024/08/05 13:24:59 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 13:41:54 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include "token.h" -char *ft_strncpy(char *s1, char *s2, int n) -{ - int i; - - i = -1; - while (++i < n && s2[i]) - s1[i] = s2[i]; - return (s1); -} - void print_token(t_token *token) { if (token->type == STRING_TOKEN) -- cgit v1.2.3 From b0cd3bb37124f19fcf285976d59ae8c0ae262b66 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:44:04 +0200 Subject: update for sanityzer in condiprint --- src/tokenizer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index a2f6fa4..bb76b9e 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/05 13:41:54 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 13:43:39 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,7 +48,7 @@ void conditional_print(char *string, int start_of_string, int i, exit(EXIT_FAILURE); } ft_strncpy(line, string + start_of_string, len); - line[len] = '\0'; + line[len - 1] = '\0'; while (*line == ' ' || *line == '\t') line++; if (*line != '\0') -- cgit v1.2.3 From e9909e4159ab95f2d8faf9a92ff9a53dc0bd791a Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:46:24 +0200 Subject: made the if debug around print token --- src/tokenizer.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index bb76b9e..4babe52 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/05 13:43:39 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 13:45:55 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,21 +15,24 @@ void print_token(t_token *token) { - if (token->type == STRING_TOKEN) + if (DEBUG) { - printf("STRING_TOKEN: %s\n", token->content.string); - } - else if (token->type == REDIR_TOKEN) - { - printf("REDIR_TOKEN: %d\n", token->content.redir_type); - } - else if (token->type == PIPE_TOKEN) - { - printf("PIPE_TOKEN\n"); - } - else if (token->type == NEWLINE_TOKEN) - { - printf("NEWLINE_TOKEN\n"); + if (token->type == STRING_TOKEN) + { + printf("STRING_TOKEN: %s\n", token->content.string); + } + else if (token->type == REDIR_TOKEN) + { + printf("REDIR_TOKEN: %d\n", token->content.redir_type); + } + else if (token->type == PIPE_TOKEN) + { + printf("PIPE_TOKEN\n"); + } + else if (token->type == NEWLINE_TOKEN) + { + printf("NEWLINE_TOKEN\n"); + } } } -- cgit v1.2.3 From 243d01380b6cf295a540c37bc83f2e669fbc09ea Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:47:00 +0200 Subject: fixed norm stuff --- src/tokenizer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index 4babe52..5bef39b 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/05 13:45:55 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 13:46:42 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,7 @@ void print_token(t_token *token) } } + void conditional_print(char *string, int start_of_string, int i, t_token **token_list) { -- 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(-) 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 06c41263920edf9f8a39ba6e7a44143dfa7515b2 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 13:55:36 +0200 Subject: added in header as well --- lib/libft/libft.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/libft/libft.h b/lib/libft/libft.h index 2de723b..67fbb0f 100644 --- a/lib/libft/libft.h +++ b/lib/libft/libft.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* libft.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: dkaiser +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/10 16:37:54 by dkaiser #+# #+# */ -/* Updated: 2024/06/24 16:44:44 by dkaiser ### ########.fr */ +/* Updated: 2024/08/05 13:55:13 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,6 +57,7 @@ void ft_putchar_fd(char c, int fd); void ft_putstr_fd(char *s, int fd); void ft_putendl_fd(char *s, int fd); void ft_putnbr_fd(int n, int fd); +char *ft_strncpy(char *s1, char *s2, int n); typedef struct s_list { -- cgit v1.2.3 From 0539428e0b7e17713904d4dae33e3150b74e964f Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Mon, 5 Aug 2024 21:47:31 +0200 Subject: tried without manz changes to improve it pls test it also doueble and single quote again --- lib/libft/ft_strncpy.c | 5 +++-- src/repl.c | 2 +- src/tokenizer.c | 52 +++++++++++++++++++++++++++++++++----------------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/lib/libft/ft_strncpy.c b/lib/libft/ft_strncpy.c index 30a9d3d..9d772cb 100644 --- a/lib/libft/ft_strncpy.c +++ b/lib/libft/ft_strncpy.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/05 13:41:47 by chuhlig #+# #+# */ -/* Updated: 2024/08/05 13:42:00 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 14:22:26 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,5 +17,6 @@ char *ft_strncpy(char *s1, char *s2, int n) i = -1; while (++i < n && s2[i]) s1[i] = s2[i]; + // s1[i] = '\0'; return (s1); -} \ No newline at end of file +} diff --git a/src/repl.c b/src/repl.c index 99293e2..e1ca7a6 100644 --- a/src/repl.c +++ b/src/repl.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2024/07/15 19:53:52 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 20:20:02 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/tokenizer.c b/src/tokenizer.c index 5bef39b..635e31e 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/05 13:46:42 by chuhlig ### ########.fr */ +/* Updated: 2024/08/05 21:45:55 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,13 +46,13 @@ void conditional_print(char *string, int start_of_string, int i, len = i - start_of_string + 1; if (len > 0) { - line = (char *)malloc(len); + line = (char *)malloc(len + 1); if (!line) { exit(EXIT_FAILURE); } ft_strncpy(line, string + start_of_string, len); - line[len - 1] = '\0'; + line[len] = '\0'; while (*line == ' ' || *line == '\t') line++; if (*line != '\0') @@ -91,12 +91,13 @@ int symbol_checker(char *s, int i, t_token **token_list) int check_for_string(char *s, int i, int *start_of_string, t_token **token_list) { - char quote_check; - int ignore_space; + static char quote_check; + static int ignore_space; - ignore_space = 0; - quote_check = '\0'; - if (ignore_space && s[i] == quote_check) + // ignore_space = 0; + // quote_check = '\0'; + if (ignore_space && (s[i] == '\0' || s[i] == '|' || s[i] == '\n' + || s[i] == '<' || s[i] == '>')) { quote_check = '\0'; ignore_space = 0; @@ -107,11 +108,10 @@ int check_for_string(char *s, int i, int *start_of_string, t_token **token_list) ignore_space = 1; } if ((!ignore_space && (s[i] == '\0' || s[i] == ' ' - || s[i] == '\t')) || i == ft_strlen(s) - 1) + || s[i] == '\t' || s[i + 1] == '|' || s[i + 1] == '\n' + || s[i + 1] == '<' || s[i + 1] == '>')) || i == ft_strlen(s) - 1) { - if (s[i + 1] == '\0') - i++; - conditional_print(s, *start_of_string, i - 1, token_list); + conditional_print(s, *start_of_string, i, token_list); *start_of_string = i + 1; } return (i); @@ -120,19 +120,17 @@ int check_for_string(char *s, int i, int *start_of_string, t_token **token_list) void tokenizer(char *s, t_token **token_list) { int start_of_string; - int ignore_space; + int f; int i; - char quote_check; - quote_check = '\0'; start_of_string = 0; - ignore_space = 0; + f = 0; i = 0; if (!s || !*s) return ; while (s && s[i]) { - if (!ignore_space && (s[i] == '|' || s[i] == '\n' + if (!f && (s[i] == '|' || s[i] == '\n' || s[i] == '<' || s[i] == '>')) { i = symbol_checker(s, i, token_list); @@ -140,8 +138,28 @@ void tokenizer(char *s, t_token **token_list) } else { + f = start_of_string; i = check_for_string(s, i, &start_of_string, token_list); + if (f != start_of_string) + f = 0; + else + f = 1; } i++; } } + +// Minishell $ |abc|cba +// PIPE_TOKEN +// STRING_TOKEN: abc +// PIPE_TOKEN +// STRING_TOKEN: cba +// Minishell $ ||abc a||cba +// PIPE_TOKEN +// PIPE_TOKEN +// STRING_TOKEN: abc +// STRING_TOKEN: a +// PIPE_TOKEN +// PIPE_TOKEN +// STRING_TOKEN: cba +// Minishell $ \ No newline at end of file -- cgit v1.2.3 From 36d2b4da2887419705cd22eb97a6283be86816f4 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Thu, 8 Aug 2024 17:10:25 +0200 Subject: Add data structure and prototypes for env --- include/env.h | 23 +++++++++++++++++++++++ include/minishell.h | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 include/env.h diff --git a/include/env.h b/include/env.h new file mode 100644 index 0000000..1ea6f2e --- /dev/null +++ b/include/env.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* env.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser # include -- cgit v1.2.3 From c1f342c71f703a73c83b960bfa4321ce9be90e9a Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Thu, 8 Aug 2024 18:53:32 +0200 Subject: old version improved for edgecase and removed leaks --- src/tokenizer.c | 112 ++++++++++++++++++++++---------------------------------- 1 file changed, 44 insertions(+), 68 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index 635e31e..40d54c8 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/05 21:45:55 by chuhlig ### ########.fr */ +/* Updated: 2024/08/08 18:50:53 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,92 +63,68 @@ void conditional_print(char *string, int start_of_string, int i, } } -int symbol_checker(char *s, int i, t_token **token_list) -{ - if ((s[i] == '<' || s[i] == '>') && s[i + 1] == s[i]) - { - if (s[i] == '<') - *token_list = new_redir_token(INPUT_LIMITER, *token_list, NULL); - else - *token_list = new_redir_token(OUTPUT_APPEND, *token_list, NULL); - print_token(*token_list); - i++; - } - else - { - if (s[i] == '<') - *token_list = new_redir_token(INPUT_FILE, *token_list, NULL); - else if (s[i] == '|') - *token_list = new_token(PIPE_TOKEN, *token_list, NULL); - else if (s[i] == '\n') - *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); - else - *token_list = new_redir_token(OUTPUT_OVERRIDE, *token_list, NULL); - print_token(*token_list); - } - return (i); -} - -int check_for_string(char *s, int i, int *start_of_string, t_token **token_list) -{ - static char quote_check; - static int ignore_space; - - // ignore_space = 0; - // quote_check = '\0'; - if (ignore_space && (s[i] == '\0' || s[i] == '|' || s[i] == '\n' - || s[i] == '<' || s[i] == '>')) - { - quote_check = '\0'; - ignore_space = 0; - } - else if (!ignore_space && ft_strchr("\"\'", s[i])) - { - quote_check = s[i]; - ignore_space = 1; - } - if ((!ignore_space && (s[i] == '\0' || s[i] == ' ' - || s[i] == '\t' || s[i + 1] == '|' || s[i + 1] == '\n' - || s[i + 1] == '<' || s[i + 1] == '>')) || i == ft_strlen(s) - 1) - { - conditional_print(s, *start_of_string, i, token_list); - *start_of_string = i + 1; - } - return (i); -} - void tokenizer(char *s, t_token **token_list) { + char *quotes; + char quote_check; int start_of_string; - int f; + int ignore_space; int i; + quotes = "\"\'"; + quote_check = '\0'; start_of_string = 0; - f = 0; + ignore_space = 0; i = 0; if (!s || !*s) return ; - while (s && s[i]) + while (s[i]) { - if (!f && (s[i] == '|' || s[i] == '\n' - || s[i] == '<' || s[i] == '>')) + if (!ignore_space && (s[i] == '|' || s[i] == '\n' || s[i] == '<' || s[i] == '>')) { - i = symbol_checker(s, i, token_list); + conditional_print(s, start_of_string, i - 1, token_list); + if ((s[i] == '<' || s[i] == '>') && s[i + 1] == s[i]) + { + if (s[i] == '<') + *token_list = new_redir_token(INPUT_LIMITER, *token_list, NULL); + else + *token_list = new_redir_token(OUTPUT_APPEND, *token_list, NULL); + i++; + } + else + { + if (s[i] == '<') + *token_list = new_redir_token(INPUT_FILE, *token_list, NULL); + else if (s[i] == '|') + *token_list = new_token(PIPE_TOKEN, *token_list, NULL); + else if (s[i] == '\n') + *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); + else + *token_list = new_redir_token(OUTPUT_OVERRIDE, *token_list, NULL); + } + print_token(*token_list); start_of_string = i + 1; } - else + else if (ignore_space && s[i] == quote_check) { - f = start_of_string; - i = check_for_string(s, i, &start_of_string, token_list); - if (f != start_of_string) - f = 0; - else - f = 1; + quote_check = '\0'; + ignore_space = 0; + } + else if (!ignore_space && ft_strchr(quotes, s[i])) + { + quote_check = s[i]; + ignore_space = 1; + } + else if ((!ignore_space && (s[i] == ' ' || s[i] == '\t')) || i == ft_strlen(s) - 1) + { + conditional_print(s, start_of_string, i, token_list); + start_of_string = i + 1; } i++; } } + // Minishell $ |abc|cba // PIPE_TOKEN // STRING_TOKEN: abc -- cgit v1.2.3 From ea3195deefdc728b7fe8268bfeab82dc85415111 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 9 Aug 2024 11:45:22 +0200 Subject: shorten version with bugg --- src/tokenizer.c | 187 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 77 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index 40d54c8..fd4fefd 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/08 18:50:53 by chuhlig ### ########.fr */ +/* Updated: 2024/08/09 11:43:51 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,35 +15,30 @@ void print_token(t_token *token) { - if (DEBUG) + if (token->type == STRING_TOKEN) { - if (token->type == STRING_TOKEN) - { - printf("STRING_TOKEN: %s\n", token->content.string); - } - else if (token->type == REDIR_TOKEN) - { - printf("REDIR_TOKEN: %d\n", token->content.redir_type); - } - else if (token->type == PIPE_TOKEN) - { - printf("PIPE_TOKEN\n"); - } - else if (token->type == NEWLINE_TOKEN) - { - printf("NEWLINE_TOKEN\n"); - } + printf("STRING_TOKEN: %s\n", token->content.string); + } + else if (token->type == REDIR_TOKEN) + { + printf("REDIR_TOKEN: %d\n", token->content.redir_type); + } + else if (token->type == PIPE_TOKEN) + { + printf("PIPE_TOKEN\n"); + } + else if (token->type == NEWLINE_TOKEN) + { + printf("NEWLINE_TOKEN\n"); } } - -void conditional_print(char *string, int start_of_string, int i, - t_token **token_list) +void conditional_print(char *string, int start_of_string, int i, t_token **token_list) { char *line; int len; - len = i - start_of_string + 1; + len = i - start_of_string; if (len > 0) { line = (char *)malloc(len + 1); @@ -63,79 +58,117 @@ void conditional_print(char *string, int start_of_string, int i, } } +void handle_special_chars(char *s, int *i, int *start, t_token **token_list) +{ + conditional_print(s, *start, *i, token_list); // Pass correct boundaries + if (s[*i] == '<' && s[*i + 1] == '<') + *token_list = new_redir_token(INPUT_LIMITER, *token_list, NULL); + else if (s[*i] == '>' && s[*i + 1] == '>') + *token_list = new_redir_token(OUTPUT_APPEND, *token_list, NULL); + else if (s[*i] == '<') + *token_list = new_redir_token(INPUT_FILE, *token_list, NULL); + else if (s[*i] == '>') + *token_list = new_redir_token(OUTPUT_OVERRIDE, *token_list, NULL); + else if (s[*i] == '|') + *token_list = new_token(PIPE_TOKEN, *token_list, NULL); + else if (s[*i] == '\n') + *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); + print_token(*token_list); + if (s[*i] == '<' || s[*i] == '>') + (*i)++; + *start = *i + 1; +} + void tokenizer(char *s, t_token **token_list) { - char *quotes; char quote_check; - int start_of_string; - int ignore_space; + int pos; int i; + int f; - quotes = "\"\'"; - quote_check = '\0'; - start_of_string = 0; - ignore_space = 0; - i = 0; - if (!s || !*s) - return ; - while (s[i]) + f = 0; + i = -1; + pos = 0; + while (s[++i]) { - if (!ignore_space && (s[i] == '|' || s[i] == '\n' || s[i] == '<' || s[i] == '>')) - { - conditional_print(s, start_of_string, i - 1, token_list); - if ((s[i] == '<' || s[i] == '>') && s[i + 1] == s[i]) - { - if (s[i] == '<') - *token_list = new_redir_token(INPUT_LIMITER, *token_list, NULL); - else - *token_list = new_redir_token(OUTPUT_APPEND, *token_list, NULL); - i++; - } - else - { - if (s[i] == '<') - *token_list = new_redir_token(INPUT_FILE, *token_list, NULL); - else if (s[i] == '|') - *token_list = new_token(PIPE_TOKEN, *token_list, NULL); - else if (s[i] == '\n') - *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); - else - *token_list = new_redir_token(OUTPUT_OVERRIDE, *token_list, NULL); - } - print_token(*token_list); - start_of_string = i + 1; - } - else if (ignore_space && s[i] == quote_check) - { - quote_check = '\0'; - ignore_space = 0; - } - else if (!ignore_space && ft_strchr(quotes, s[i])) + if (!f && ft_strchr("|<>\\n", s[i])) + handle_special_chars(s, &i, &pos, token_list); + else if (f && s[i] == quote_check) + f = 0; + else if (!f && ft_strchr("\'\"", s[i])) { + f = 1; quote_check = s[i]; - ignore_space = 1; } - else if ((!ignore_space && (s[i] == ' ' || s[i] == '\t')) || i == ft_strlen(s) - 1) + if ((!f && (s[i] == ' ' || s[i] == '\t')) || s[i + 1] == '\0') { - conditional_print(s, start_of_string, i, token_list); - start_of_string = i + 1; + conditional_print(s, pos, i, token_list); + pos = i + 1; } - i++; } } +// Minishell $ echo "Hello World"|grep 'Hello|cat -e +// STRING_TOKEN: echo +// STRING_TOKEN: "Hello World" +// PIPE_TOKEN +// STRING_TOKEN: grep +// STRING_TOKEN: 'Hello|cat -e +// Minishell $ -// Minishell $ |abc|cba +// Minishell $ Minishell $ echo "Hello World"|grep 'Hello|cat -e +// STRING_TOKEN: echo +// STRING_TOKEN: "Hello World" +// PIPE_TOKEN +// STRING_TOKEN: grep +// STRING_TOKEN: 'Hello|cat -e +// Minishell $ +// STRING_TOKEN: Mi +// STRING_TOKEN: Mi +// STRING_TOKEN: ishell +// STRING_TOKEN: $ +// STRING_TOKEN: echo +// STRING_TOKEN: "Hello World" +// PIPE_TOKEN +// STRING_TOKEN: grep +// STRING_TOKEN: 'Hello|cat -e +// STRING_TOKEN: echo +// STRING_TOKEN: "Hello World" +// PIPE_TOKEN +// STRING_TOKEN: grep +// STRING_TOKEN: 'Hello // PIPE_TOKEN -// STRING_TOKEN: abc +// STRING_TOKEN: cat +// STRING_TOKEN: -e +// Mi +// STRING_TOKEN: -e +// Mi +// STRING_TOKEN: ishell +// STRING_TOKEN: $ +// Minishell $ echo "Hello World"|grep 'Hello|cat -e +// STRING_TOKEN: echo +// STRING_TOKEN: "Hello World" // PIPE_TOKEN -// STRING_TOKEN: cba -// Minishell $ ||abc a||cba +// STRING_TOKEN: grep +// STRING_TOKEN: 'Hello|cat -e +// Minishell $ echo "Hello World"|grep 'Hello|cat -e +// STRING_TOKEN: echo +// STRING_TOKEN: "Hello World" // PIPE_TOKEN +// STRING_TOKEN: grep +// STRING_TOKEN: 'Hello|cat -e +// Minishell $ echo "Hello World"|grep 'Hello|cat -e +// STRING_TOKEN: echo +// STRING_TOKEN: "Hello World" // PIPE_TOKEN -// STRING_TOKEN: abc -// STRING_TOKEN: a +// STRING_TOKEN: grep +// STRING_TOKEN: 'Hello|cat -e +// Minishell $ echo "Hello World"|grep 'Hello'|cat -e +// STRING_TOKEN: echo +// STRING_TOKEN: "Hello World" // PIPE_TOKEN +// STRING_TOKEN: grep +// STRING_TOKEN: 'Hello' // PIPE_TOKEN -// STRING_TOKEN: cba -// Minishell $ \ No newline at end of file +// STRING_TOKEN: cat +// STRING_TOKEN: -e \ No newline at end of file -- cgit v1.2.3 From 4bcb095085729d9681f58ae110a3b550e4c697eb Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 9 Aug 2024 12:40:16 +0200 Subject: fixed the -1 letter tstill dont try \\ xd and for the case < in.txt cat -e > out.txt | grep test im working on it >D --- src/tokenizer.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index fd4fefd..f8ab9c4 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 11:43:51 by chuhlig ### ########.fr */ +/* Updated: 2024/08/09 12:37:08 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,30 +15,34 @@ void print_token(t_token *token) { - if (token->type == STRING_TOKEN) + if (DEBUG) { - printf("STRING_TOKEN: %s\n", token->content.string); - } - else if (token->type == REDIR_TOKEN) - { - printf("REDIR_TOKEN: %d\n", token->content.redir_type); - } - else if (token->type == PIPE_TOKEN) - { - printf("PIPE_TOKEN\n"); - } - else if (token->type == NEWLINE_TOKEN) - { - printf("NEWLINE_TOKEN\n"); + if (token->type == STRING_TOKEN) + { + printf("STRING_TOKEN: %s\n", token->content.string); + } + else if (token->type == REDIR_TOKEN) + { + printf("REDIR_TOKEN: %d\n", token->content.redir_type); + } + else if (token->type == PIPE_TOKEN) + { + printf("PIPE_TOKEN\n"); + } + else if (token->type == NEWLINE_TOKEN) + { + printf("NEWLINE_TOKEN\n"); + } } } -void conditional_print(char *string, int start_of_string, int i, t_token **token_list) +void conditional_print(char *string, int start_of_string, int i, + t_token **token_list) { char *line; int len; - len = i - start_of_string; + len = i - start_of_string + 1; if (len > 0) { line = (char *)malloc(len + 1); @@ -60,7 +64,7 @@ void conditional_print(char *string, int start_of_string, int i, t_token **token void handle_special_chars(char *s, int *i, int *start, t_token **token_list) { - conditional_print(s, *start, *i, token_list); // Pass correct boundaries + conditional_print(s, *start, *i - 1, token_list); if (s[*i] == '<' && s[*i + 1] == '<') *token_list = new_redir_token(INPUT_LIMITER, *token_list, NULL); else if (s[*i] == '>' && s[*i + 1] == '>') @@ -86,9 +90,9 @@ void tokenizer(char *s, t_token **token_list) int i; int f; - f = 0; - i = -1; pos = 0; + i = -1; + f = 0; while (s[++i]) { if (!f && ft_strchr("|<>\\n", s[i])) @@ -100,7 +104,7 @@ void tokenizer(char *s, t_token **token_list) f = 1; quote_check = s[i]; } - if ((!f && (s[i] == ' ' || s[i] == '\t')) || s[i + 1] == '\0') + if ((!f && (s[i] == ' ' || s[i] == '\t')) || i == ft_strlen(s) - 1) { conditional_print(s, pos, i, token_list); pos = i + 1; @@ -108,6 +112,7 @@ void tokenizer(char *s, t_token **token_list) } } + // Minishell $ echo "Hello World"|grep 'Hello|cat -e // STRING_TOKEN: echo // STRING_TOKEN: "Hello World" -- cgit v1.2.3 From 665e9eb6fe20730b2f98cbc0f6617985204accc7 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 9 Aug 2024 13:00:47 +0200 Subject: test version with a bunch of fixes --- src/tokenizer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index f8ab9c4..672b6dc 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 12:37:08 by chuhlig ### ########.fr */ +/* Updated: 2024/08/09 12:59:03 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,7 +78,7 @@ void handle_special_chars(char *s, int *i, int *start, t_token **token_list) else if (s[*i] == '\n') *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); print_token(*token_list); - if (s[*i] == '<' || s[*i] == '>') + if (s[*i + 1] == '<' || s[*i + 1] == '>') (*i)++; *start = *i + 1; } @@ -95,7 +95,7 @@ void tokenizer(char *s, t_token **token_list) f = 0; while (s[++i]) { - if (!f && ft_strchr("|<>\\n", s[i])) + if (!f && ft_strchr("|<>\n", s[i])) handle_special_chars(s, &i, &pos, token_list); else if (f && s[i] == quote_check) f = 0; -- cgit v1.2.3 From 88030338953372eb0d223cf27fd5c96063ac7ee2 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 9 Aug 2024 15:28:03 +0200 Subject: fixed norm errors that i saw --- lib/libft/ft_strncpy.c | 3 +-- out.txt~ | 1 + src/repl.c | 6 ++--- src/tokenizer.c | 68 +------------------------------------------------- 4 files changed, 6 insertions(+), 72 deletions(-) create mode 100644 out.txt~ diff --git a/lib/libft/ft_strncpy.c b/lib/libft/ft_strncpy.c index 9d772cb..a1a2293 100644 --- a/lib/libft/ft_strncpy.c +++ b/lib/libft/ft_strncpy.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/05 13:41:47 by chuhlig #+# #+# */ -/* Updated: 2024/08/05 14:22:26 by chuhlig ### ########.fr */ +/* Updated: 2024/08/09 15:26:40 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,5 @@ char *ft_strncpy(char *s1, char *s2, int n) i = -1; while (++i < n && s2[i]) s1[i] = s2[i]; - // s1[i] = '\0'; return (s1); } diff --git a/out.txt~ b/out.txt~ new file mode 100644 index 0000000..73b4a2f --- /dev/null +++ b/out.txt~ @@ -0,0 +1 @@ +Hello World jdksan dsajklasdj dasjkldsajkl dasjkldsajkladsjkl dasjkl diff --git a/src/repl.c b/src/repl.c index e1ca7a6..1fd7be7 100644 --- a/src/repl.c +++ b/src/repl.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2024/08/05 20:20:02 by chuhlig ### ########.fr */ +/* Updated: 2024/08/09 15:27:11 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,8 @@ void repl(const char *prompt) { char *input; t_token *token_list; - t_token *current; - t_token *next; + t_token *current; + t_token *next; while (1) { diff --git a/src/tokenizer.c b/src/tokenizer.c index 672b6dc..267068a 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 12:59:03 by chuhlig ### ########.fr */ +/* Updated: 2024/08/09 15:27:31 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -111,69 +111,3 @@ void tokenizer(char *s, t_token **token_list) } } } - - -// Minishell $ echo "Hello World"|grep 'Hello|cat -e -// STRING_TOKEN: echo -// STRING_TOKEN: "Hello World" -// PIPE_TOKEN -// STRING_TOKEN: grep -// STRING_TOKEN: 'Hello|cat -e -// Minishell $ - -// Minishell $ Minishell $ echo "Hello World"|grep 'Hello|cat -e -// STRING_TOKEN: echo -// STRING_TOKEN: "Hello World" -// PIPE_TOKEN -// STRING_TOKEN: grep -// STRING_TOKEN: 'Hello|cat -e -// Minishell $ -// STRING_TOKEN: Mi -// STRING_TOKEN: Mi -// STRING_TOKEN: ishell -// STRING_TOKEN: $ -// STRING_TOKEN: echo -// STRING_TOKEN: "Hello World" -// PIPE_TOKEN -// STRING_TOKEN: grep -// STRING_TOKEN: 'Hello|cat -e -// STRING_TOKEN: echo -// STRING_TOKEN: "Hello World" -// PIPE_TOKEN -// STRING_TOKEN: grep -// STRING_TOKEN: 'Hello -// PIPE_TOKEN -// STRING_TOKEN: cat -// STRING_TOKEN: -e -// Mi -// STRING_TOKEN: -e -// Mi -// STRING_TOKEN: ishell -// STRING_TOKEN: $ -// Minishell $ echo "Hello World"|grep 'Hello|cat -e -// STRING_TOKEN: echo -// STRING_TOKEN: "Hello World" -// PIPE_TOKEN -// STRING_TOKEN: grep -// STRING_TOKEN: 'Hello|cat -e -// Minishell $ echo "Hello World"|grep 'Hello|cat -e -// STRING_TOKEN: echo -// STRING_TOKEN: "Hello World" -// PIPE_TOKEN -// STRING_TOKEN: grep -// STRING_TOKEN: 'Hello|cat -e -// Minishell $ echo "Hello World"|grep 'Hello|cat -e -// STRING_TOKEN: echo -// STRING_TOKEN: "Hello World" -// PIPE_TOKEN -// STRING_TOKEN: grep -// STRING_TOKEN: 'Hello|cat -e -// Minishell $ echo "Hello World"|grep 'Hello'|cat -e -// STRING_TOKEN: echo -// STRING_TOKEN: "Hello World" -// PIPE_TOKEN -// STRING_TOKEN: grep -// STRING_TOKEN: 'Hello' -// PIPE_TOKEN -// STRING_TOKEN: cat -// STRING_TOKEN: -e \ No newline at end of file -- cgit v1.2.3 From 645f4455d403e7f25386be25256718e9597161ca Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 9 Aug 2024 15:40:42 +0200 Subject: removed normitte errors in tokenizer --- src/tokenizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tokenizer.c b/src/tokenizer.c index 267068a..34685ac 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:27:31 by chuhlig ### ########.fr */ +/* Updated: 2024/08/09 15:40:00 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ -- cgit v1.2.3 From e197ecae60b005b0cfe7270f243740ae967bcb7d Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Fri, 9 Aug 2024 16:19:16 +0200 Subject: remove out.txt --- out.txt~ | 1 - 1 file changed, 1 deletion(-) delete mode 100644 out.txt~ diff --git a/out.txt~ b/out.txt~ deleted file mode 100644 index 73b4a2f..0000000 --- a/out.txt~ +++ /dev/null @@ -1 +0,0 @@ -Hello World jdksan dsajklasdj dasjkldsajkl dasjkldsajkladsjkl dasjkl -- 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(-) 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 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 From 0d4f9e94f6d28a154ae4be3b918bfb014b4fa1e0 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Sun, 11 Aug 2024 15:15:06 +0200 Subject: fixed |> fixed norm added new function --- include/token.h | 5 +++-- lib/libft/Makefile | 1 + lib/libft/ft_isspace.c | 20 ++++++++++++++++++++ lib/libft/libft.h | 3 ++- src/repl.c | 4 ++-- src/tokenizer.c | 17 +++++++++-------- 6 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 lib/libft/ft_isspace.c diff --git a/include/token.h b/include/token.h index d7ff9f9..80ace03 100644 --- a/include/token.h +++ b/include/token.h @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/27 13:27:18 by dkaiser #+# #+# */ -/* Updated: 2024/08/05 13:23:27 by chuhlig ### ########.fr */ +/* Updated: 2024/08/11 13:46:22 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,7 @@ t_token *new_redir_token(int type, t_token *previous, t_token *next); void free_token(t_token *token); -void tokenizer(char *s, t_token **token_list); +void tokenizer(char *s, t_token **token_list, + char quote_check); #endif \ No newline at end of file diff --git a/lib/libft/Makefile b/lib/libft/Makefile index 6951c43..6f2950c 100644 --- a/lib/libft/Makefile +++ b/lib/libft/Makefile @@ -10,6 +10,7 @@ SRC = ft_atoi.c \ ft_isascii.c \ ft_isdigit.c \ ft_isprint.c \ + ft_isspace.c \ ft_itoa.c \ ft_memchr.c \ ft_memcmp.c \ diff --git a/lib/libft/ft_isspace.c b/lib/libft/ft_isspace.c new file mode 100644 index 0000000..63f21fa --- /dev/null +++ b/lib/libft/ft_isspace.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isspace.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: chuhlig +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/08/11 13:59:45 by chuhlig #+# #+# */ +/* Updated: 2024/08/11 14:04:23 by chuhlig ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isspace(char c) +{ + if (c == ' ' || c == '\t') + return (1); + return (0); +} diff --git a/lib/libft/libft.h b/lib/libft/libft.h index 67fbb0f..abb739d 100644 --- a/lib/libft/libft.h +++ b/lib/libft/libft.h @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/10 16:37:54 by dkaiser #+# #+# */ -/* Updated: 2024/08/05 13:55:13 by chuhlig ### ########.fr */ +/* Updated: 2024/08/11 14:01:57 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,7 @@ int ft_isalpha(int c); int ft_isdigit(int c); int ft_isalnum(int c); int ft_isprint(int c); +int ft_isspace(char c); int ft_isascii(int c); int ft_strlen(const char *str); void *ft_memset(void *b, int c, size_t len); diff --git a/src/repl.c b/src/repl.c index 1fd7be7..fe9faf3 100644 --- a/src/repl.c +++ b/src/repl.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2024/08/09 15:27:11 by chuhlig ### ########.fr */ +/* Updated: 2024/08/11 14:41:29 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,8 +27,8 @@ void repl(const char *prompt) return ; add_history(input); token_list = NULL; - tokenizer(input, &token_list); current = token_list; + tokenizer(input, &token_list, '\0'); while (current != NULL) { next = current->next; diff --git a/src/tokenizer.c b/src/tokenizer.c index 34685ac..a9a86ca 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 14:52:54 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,7 @@ void print_token(t_token *token) } } -void conditional_print(char *string, int start_of_string, int i, +void snap_string_token(char *string, int start_of_string, int i, t_token **token_list) { char *line; @@ -64,7 +64,7 @@ void conditional_print(char *string, int start_of_string, int i, void handle_special_chars(char *s, int *i, int *start, t_token **token_list) { - conditional_print(s, *start, *i - 1, token_list); + snap_string_token(s, *start, *i - 1, token_list); if (s[*i] == '<' && s[*i + 1] == '<') *token_list = new_redir_token(INPUT_LIMITER, *token_list, NULL); else if (s[*i] == '>' && s[*i + 1] == '>') @@ -78,14 +78,15 @@ void handle_special_chars(char *s, int *i, int *start, t_token **token_list) else if (s[*i] == '\n') *token_list = new_token(NEWLINE_TOKEN, *token_list, NULL); print_token(*token_list); - if (s[*i + 1] == '<' || s[*i + 1] == '>') + if (s[*i] == '<' && s[*i + 1] == '<') + (*i)++; + if (s[*i] == '>' && s[*i + 1] == '>') (*i)++; *start = *i + 1; } -void tokenizer(char *s, t_token **token_list) +void tokenizer(char *s, t_token **token_list, char quote_check) { - char quote_check; int pos; int i; int f; @@ -104,9 +105,9 @@ void tokenizer(char *s, t_token **token_list) f = 1; quote_check = s[i]; } - if ((!f && (s[i] == ' ' || s[i] == '\t')) || i == ft_strlen(s) - 1) + if ((!f && (ft_isspace(s[i + 1]))) || i == ft_strlen(s) - 1) { - conditional_print(s, pos, i, token_list); + snap_string_token(s, pos, i, token_list); pos = i + 1; } } -- cgit v1.2.3 From bc55ab9621c9aa80c12f257d043597188f6ad64d Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Thu, 29 Aug 2024 15:31:07 +0200 Subject: Update repl --- src/repl.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/repl.c b/src/repl.c index fe9faf3..01bcd76 100644 --- a/src/repl.c +++ b/src/repl.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2024/08/11 14:41:29 by chuhlig ### ########.fr */ +/* Updated: 2024/08/29 15:29:16 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,7 @@ void repl(const char *prompt) { char *input; t_token *token_list; - t_token *current; - t_token *next; + t_list *lines; while (1) { @@ -27,14 +26,10 @@ void repl(const char *prompt) return ; add_history(input); token_list = NULL; - current = token_list; tokenizer(input, &token_list, '\0'); - while (current != NULL) - { - next = current->next; - free_token(current); - current = next; - } + lines = parse(token_list); + if (lines) + print_ast(lines->content); free(input); } } -- cgit v1.2.3 From 61fe4e28bf95f782105a2907cd6fbfc196a6874b Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Thu, 29 Aug 2024 16:44:56 +0200 Subject: Handle empty input --- src/repl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/repl.c b/src/repl.c index 01bcd76..02fb879 100644 --- a/src/repl.c +++ b/src/repl.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2024/08/29 15:29:16 by dkaiser ### ########.fr */ +/* Updated: 2024/08/29 15:37:27 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,8 @@ void repl(const char *prompt) input = readline(prompt); if (input == NULL) return ; + if (input[0] == '\0') + continue ; add_history(input); token_list = NULL; tokenizer(input, &token_list, '\0'); -- cgit v1.2.3 From f24b063f2135f495193dac4847b9f2489d1d954a Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 13 Sep 2024 16:23:04 +0200 Subject: Fix SEGV on invalid redirection --- src/new_node.c | 14 +++++++++----- src/print_ast.c | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/new_node.c b/src/new_node.c index 6da9f9e..5c770aa 100644 --- a/src/new_node.c +++ b/src/new_node.c @@ -6,7 +6,7 @@ /* By: dkaiser content.cmd.args = args; - node->content.cmd.redirs[0] = redirs[0]; - node->content.cmd.redirs[1] = redirs[1]; - free(redirs); - return (node); + if (redirs != NULL) + { + node->content.cmd.redirs[0] = redirs[0]; + node->content.cmd.redirs[1] = redirs[1]; + free(redirs); + return (node); + } + return (NULL); } t_node *new_string_node(char *string) diff --git a/src/print_ast.c b/src/print_ast.c index a511246..e1f0158 100644 --- a/src/print_ast.c +++ b/src/print_ast.c @@ -6,7 +6,7 @@ /* By: dkaiser type == CMD_NODE) + if (!ast) + panic("Parsing error"); + else if (ast->type == CMD_NODE) print_cmd_node(ast, indent); else if (ast->type == PIPE_NODE) { -- cgit v1.2.3 From 60adeb49de9458b4e2af0abd1c7b256da0950bc3 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Fri, 13 Sep 2024 16:27:13 +0200 Subject: Fix norme issues for env.h and repl.c TODO: Fix for tokenizer.c as well. This was probably already solved in another branch though. --- include/env.h | 23 ++++++++++++----------- src/repl.c | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/env.h b/include/env.h index 1ea6f2e..f3d3c75 100644 --- a/include/env.h +++ b/include/env.h @@ -6,18 +6,19 @@ /* By: dkaiser +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2024/08/29 15:37:27 by dkaiser ### ########.fr */ +/* Updated: 2024/09/13 16:26:35 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ void repl(const char *prompt) { char *input; t_token *token_list; - t_list *lines; + t_list *lines; while (1) { -- cgit v1.2.3 From 2a3c0b5dd78c7305ef154c2579225dba81813ad2 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 17 Sep 2024 14:39:04 +0200 Subject: Fix pipe parsing error --- src/parser.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/parser.c b/src/parser.c index f9484c9..4ad514d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -6,11 +6,12 @@ /* By: dkaiser next; + if (result == split) + result = NULL; free_token(split); return (result); } -- cgit v1.2.3 From cf8754ca029817f092f5159b1c4bc3bbabec4217 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 17 Sep 2024 15:09:24 +0200 Subject: Add error messages --- src/collect_redirs.c | 4 ++-- src/parser.c | 3 ++- src/print_ast.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/collect_redirs.c b/src/collect_redirs.c index d50bec4..9beddf7 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,7 +6,7 @@ /* By: dkaiser type == REDIR_TOKEN) { - dbg("TODO: Add parsing errmsg"); + printf("Parsing error.\n"); return (free(result), NULL); } else diff --git a/src/parser.c b/src/parser.c index 4ad514d..6993a1f 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) -- cgit v1.2.3 From e8891daeb2e9cf26dc6be1f4d3693734d7a9c5c1 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 17 Sep 2024 17:25:28 +0200 Subject: Fix redir ignored at end --- src/collect_redirs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 9beddf7..79ae95c 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,7 +6,7 @@ /* By: dkaiser next; } + if (cur && cur->type == REDIR_TOKEN) + { + printf("Parsing error.\n"); + return (free(result), NULL); + } return (result); } -- cgit v1.2.3 From 1fec66236f1811a3eeac673d0002fe8d9d3d8835 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 17 Sep 2024 19:25:13 +0200 Subject: Fix error message printing --- src/collect_redirs.c | 16 +++++++++------- src/new_node.c | 4 +++- src/parser.c | 40 ++++++++++------------------------------ 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 79ae95c..60f197b 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,7 +6,7 @@ /* By: dkaiser next != NULL) { if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) + { + is_redir_only = 0; + if (cur->previous == NULL && cur->next->next == NULL) + is_redir_only = 1; cur = collect_redir(tokens, result, cur); + if (is_redir_only) + *tokens = NULL; + } else if (cur->type == REDIR_TOKEN) - { - printf("Parsing error.\n"); return (free(result), NULL); - } else cur = cur->next; } if (cur && cur->type == REDIR_TOKEN) - { - printf("Parsing error.\n"); return (free(result), NULL); - } return (result); } diff --git a/src/new_node.c b/src/new_node.c index 5c770aa..c58d291 100644 --- a/src/new_node.c +++ b/src/new_node.c @@ -6,7 +6,7 @@ /* By: dkaiser next = ft_lstnew(parse_statement(current_tokens)); - current = current->next; - } - if (current == NULL) - return (ft_lstclear(&result, free_node_wrapper), NULL); - current_tokens = split_at_first(&tokens, NEWLINE_TOKEN); - } - return (result); + if ((*tokens).type == PIPE_TOKEN) + result = NULL; + else + result = parse_statement(tokens); + if (result == NULL) + printf("Parsing error.\n"); + return (ft_lstnew(result)); } static t_node *parse_statement(t_token *tokens) @@ -53,7 +39,6 @@ static t_node *parse_statement(t_token *tokens) if (left_side_tokens == NULL) { free_tokens(tokens); - printf("Parsing error.\n"); return (NULL); } else if (tokens != NULL) @@ -97,8 +82,3 @@ static t_token *find_token_by_type(t_token *tokens, int type) } return (NULL); } - -static void free_node_wrapper(void *node) -{ - free_node((t_node *)node); -} -- cgit v1.2.3 From e7d58349800bd6bb0f139eec411bfd434f2c824f Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 17 Sep 2024 19:28:37 +0200 Subject: Make norminette happy and fry my brain. I just summoned some cosmic horror, but at least norminette doesn't complain anymore. --- src/collect_redirs.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 60f197b..8917c78 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,7 +6,7 @@ /* By: dkaiser type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) { - is_redir_only = 0; - if (cur->previous == NULL && cur->next->next == NULL) - is_redir_only = 1; cur = collect_redir(tokens, result, cur); - if (is_redir_only) - *tokens = NULL; + *tokens = (t_token *)(((unsigned long)*tokens) & (~0 + * (!cur->previous && !cur->next->next))); } else if (cur->type == REDIR_TOKEN) return (free(result), NULL); -- cgit v1.2.3 From 4765148b87b6c095aae1b32b023d5815356584c3 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 17 Sep 2024 19:49:29 +0200 Subject: Banish the cosmic horror --- src/collect_redirs.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/collect_redirs.c b/src/collect_redirs.c index 8917c78..9ac1605 100644 --- a/src/collect_redirs.c +++ b/src/collect_redirs.c @@ -6,7 +6,7 @@ /* By: dkaiser next != NULL) { if (cur->type == REDIR_TOKEN && cur->next->type == STRING_TOKEN) - { - cur = collect_redir(tokens, result, cur); - *tokens = (t_token *)(((unsigned long)*tokens) & (~0 - * (!cur->previous && !cur->next->next))); - } + collect_and_check_redir(tokens, result, &cur); else if (cur->type == REDIR_TOKEN) return (free(result), NULL); else @@ -46,6 +44,19 @@ t_redirection *collect_redirs(t_token **tokens) return (result); } +static void collect_and_check_redir(t_token **tokens, t_redirection *result, + t_token **cur) +{ + int is_redir_only; + + is_redir_only = 0; + if ((*cur)->previous == NULL && (*cur)->next->next == NULL) + is_redir_only = 1; + *cur = collect_redir(tokens, result, *cur); + if (is_redir_only) + *tokens = NULL; +} + static t_token *collect_redir(t_token **tokens, t_redirection *result, t_token *cur) { -- cgit v1.2.3