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 (limited to '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 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 'lib/libft/ft_strncpy.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 'lib/libft/ft_strncpy.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