]> git.dkaiser.de - 42/minishell.git/commitdiff
fixed |> fixed norm added new function
authorChristopher Uhlig <chuhlig@2-C-7.42heilbronn.de>
Sun, 11 Aug 2024 13:15:06 +0000 (15:15 +0200)
committerChristopher Uhlig <chuhlig@2-C-7.42heilbronn.de>
Sun, 11 Aug 2024 13:15:06 +0000 (15:15 +0200)
include/token.h
lib/libft/Makefile
lib/libft/ft_isspace.c [new file with mode: 0644]
lib/libft/libft.h
src/repl.c
src/tokenizer.c

index d7ff9f9d7dfe1032aede4d808def31e4c125d3ac..80ace0310918d159cdf46a98dc47c2eb180744ae 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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
index 6951c4311fc10b4907d10d400e1a5fe0522fb149..6f2950c5c99f6c7a7a5db44f23b1e2d7bdbb93e6 100644 (file)
@@ -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 (file)
index 0000000..63f21fa
--- /dev/null
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   ft_isspace.c                                       :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   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);
+}
index 67fbb0f038b8e89e92cbe09f6fef30442c7b4da5..abb739da6253d2904bd29c7b1122598bce8386da 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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);
index 1fd7be7c442399781a698179559be38d33f13528..fe9faf36694c625e5b49784b00f61dd55a0d6d6d 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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;
index 34685ace77667a188813f719ec4e1a84ee014af3..a9a86ca0bee03841cf8909a919f92427495cf06f 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: chuhlig <chuhlig@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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;
                }
        }