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(-) (limited to 'src/repl.c') 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 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(-) (limited to 'src/repl.c') 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 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~ (limited to 'src/repl.c') 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 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 (limited to 'src/repl.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(-) (limited to 'src/repl.c') 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(-) (limited to 'src/repl.c') 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 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(-) (limited to 'src/repl.c') 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