aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Uhlig2024-08-05 21:47:31 +0200
committerChristopher Uhlig2024-08-05 21:47:31 +0200
commit0539428e0b7e17713904d4dae33e3150b74e964f (patch)
treec7a4c5632a40eb37772cbb40cd4393bf2fb9fe7f
parent06c41263920edf9f8a39ba6e7a44143dfa7515b2 (diff)
downloadminishell-0539428e0b7e17713904d4dae33e3150b74e964f.tar.gz
minishell-0539428e0b7e17713904d4dae33e3150b74e964f.zip
tried without manz changes to improve it pls test it also doueble and single quote again
-rw-r--r--lib/libft/ft_strncpy.c5
-rw-r--r--src/repl.c2
-rw-r--r--src/tokenizer.c52
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 <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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