mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
2
Makefile
2
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
|
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/04/24 10:49:52 by adjoly #+# #+# #
|
# Created: 2024/04/24 10:49:52 by adjoly #+# #+# #
|
||||||
# Updated: 2024/05/09 16:05:08 by adjoly ### ########.fr #
|
# Updated: 2024/05/21 20:56:16 by adjoly ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
19
include/error_msg.h
Normal file
19
include/error_msg.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* error_msg.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/05/20 20:25:06 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/05/20 21:00:45 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef ERROR_MSG_H
|
||||||
|
# define ERROR_MSG_H
|
||||||
|
/**
|
||||||
|
* Here we define all the error message
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/05/19 13:45:01 by adjoly ### ########.fr */
|
/* Updated: 2024/05/23 19:56:20 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,18 +24,52 @@ typedef struct s_cmd
|
|||||||
int outfile;
|
int outfile;
|
||||||
} t_cmd;
|
} t_cmd;
|
||||||
|
|
||||||
|
typedef enum s_quote
|
||||||
|
{
|
||||||
|
NOT_CLOSED = -1,
|
||||||
|
FALSE,
|
||||||
|
SINGLE,
|
||||||
|
DOUBLE
|
||||||
|
} t_quote;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Take the argv of a command a split the argv and the command it self
|
* @brief Take the argv of a command a split the argv and the
|
||||||
|
* command it self
|
||||||
*
|
*
|
||||||
* @param The full argv of the command
|
* @param cmd_av The full argv of the command
|
||||||
*
|
*
|
||||||
* @return (t_cmd *) cmd and argv splited into a struct
|
* @return (t_cmd *) cmd and argv splited into a struct
|
||||||
*/
|
*/
|
||||||
t_cmd *split_cmd(char *cmd_av);
|
t_cmd *split_cmd(char *cmd_av);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* @deprecated
|
* @brief Take a string and an index and check if the character
|
||||||
|
* at the index is in quote
|
||||||
|
*
|
||||||
|
* @param s The string to search in
|
||||||
|
* @param i The index of the character to check
|
||||||
|
*
|
||||||
|
* @return (t_quote) The type of quote if between, if not return FALSE or
|
||||||
|
* NOT_CLOSED if the quote is not closed
|
||||||
*/
|
*/
|
||||||
t_list *split_pipe(char *readline);
|
t_quote is_inquote(char *s, size_t i);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Take a character and check if it is a quote and return the
|
||||||
|
* type of quote
|
||||||
|
*
|
||||||
|
* @param c The character to check
|
||||||
|
*
|
||||||
|
* @return (t_quote) The type of quote or FALSE
|
||||||
|
*/
|
||||||
|
t_quote __is_quote(char c);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ONLY FOR DEBUG TO BE REMOVED
|
||||||
|
*/
|
||||||
|
void print_quote_type(t_quote type);
|
||||||
|
void print_redir_sign(t_redirection_sign redir_sign);
|
||||||
|
void print_token(t_token *token);
|
||||||
|
void print_redir(t_redirection *redir);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,20 +6,19 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/18 20:14:15 by adjoly #+# #+# */
|
/* Created: 2024/05/18 20:14:15 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/05/19 14:02:58 by adjoly ### ########.fr */
|
/* Updated: 2024/05/24 15:00:52 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef TOKENIZER_H
|
#ifndef TOKENIZER_H
|
||||||
# define TOKENIZER_H
|
# define TOKENIZER_H
|
||||||
|
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include <stdbool.h>
|
|
||||||
|
|
||||||
typedef enum s_redirection_sign
|
typedef enum s_redirection_sign
|
||||||
{
|
{
|
||||||
HEREDOC,
|
|
||||||
INFILE,
|
INFILE,
|
||||||
|
HEREDOC,
|
||||||
OUTFILE,
|
OUTFILE,
|
||||||
OUT_APPEND,
|
OUT_APPEND,
|
||||||
} t_redirection_sign;
|
} t_redirection_sign;
|
||||||
@ -37,9 +36,27 @@ typedef struct s_token
|
|||||||
} t_token;
|
} t_token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert the raw command into a t_token that contains the argv of the command an a linked list of redirection
|
* @brief Take a string and tell what type of redirect it is
|
||||||
*
|
*
|
||||||
* @param cmd A string that containt the command to tokenize
|
* @param A string that contain a redirection sign
|
||||||
|
*
|
||||||
|
* @return (t_redirection_sign) The sign of the redirecition
|
||||||
|
*/
|
||||||
|
t_redirection_sign __to_redir_sign(char *redir_sign);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Take a string and split the filename and the redirect sign
|
||||||
|
* @param redir_s A string that contain a redirection
|
||||||
|
*
|
||||||
|
* @return (t_redirection) The splited redirection
|
||||||
|
*/
|
||||||
|
t_redirection *__to_redir(char *redir_s);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert the raw command into a t_token that contains
|
||||||
|
* the argv of the command an a linked list of redirection
|
||||||
|
*
|
||||||
|
* @param cmd A string that contain the command to tokenize
|
||||||
*
|
*
|
||||||
* @return (t_token *) The tokenized version of the command
|
* @return (t_token *) The tokenized version of the command
|
||||||
*
|
*
|
||||||
@ -47,16 +64,18 @@ typedef struct s_token
|
|||||||
t_token *__to_token(char *cmd);
|
t_token *__to_token(char *cmd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief **
|
* @brief
|
||||||
*
|
*
|
||||||
* @param
|
* @param The readline output
|
||||||
*
|
*
|
||||||
* @return ()
|
* @return (t_list *) A linked lst of all the command splited
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
t_list *__split_pipe(char *readline);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert the readline output, split all command and put it in linked list of t_token (given by t_token function)
|
* @brief Convert the readline output, split all command and put
|
||||||
|
* it in linked list of t_token (given by t_token function)
|
||||||
*
|
*
|
||||||
* @param readline The readline output
|
* @param readline The readline output
|
||||||
*
|
*
|
||||||
|
BIN
libft/include/libft.h.gch
Normal file
BIN
libft/include/libft.h.gch
Normal file
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angoulem +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/11/08 21:44:04 by mmoussou #+# #+# */
|
/* Created: 2023/11/08 21:44:04 by mmoussou #+# #+# */
|
||||||
/* Updated: 2023/11/13 19:31:49 by mmoussou ### ########.fr */
|
/* Updated: 2024/05/22 11:35:58 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ void ft_lstclear(t_list **lst, void (*del)(void *))
|
|||||||
|
|
||||||
if (!lst || !del)
|
if (!lst || !del)
|
||||||
return ;
|
return ;
|
||||||
while (*lst)
|
while (*lst && lst && del)
|
||||||
{
|
{
|
||||||
tmp = (*lst)->next;
|
tmp = (*lst)->next;
|
||||||
ft_lstdelone(*lst, del);
|
ft_lstdelone(*lst, del);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/03 19:35:01 by mmoussou #+# #+# */
|
/* Created: 2024/01/03 19:35:01 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/05/16 17:36:58 by adjoly ### ########.fr */
|
/* Updated: 2024/05/23 20:01:55 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ char *ft_strjoin_free_s1(char *s1, const char *s2)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
|
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
|
||||||
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
|
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
|
||||||
if (s1)
|
if (*s1)
|
||||||
free(s1);
|
free(s1);
|
||||||
return (fstr);
|
return (fstr);
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ char *ft_strjoin_free_s2(const char *s1, char *s2)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
|
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
|
||||||
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
|
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
|
||||||
if (s2)
|
if (*s2)
|
||||||
free(s2);
|
free(s2);
|
||||||
return (fstr);
|
return (fstr);
|
||||||
}
|
}
|
||||||
@ -77,9 +77,9 @@ char *ft_strjoin_free(char *s1, char *s2)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
|
ft_strlcpy(fstr, s1, ft_strlen(s1) + 1);
|
||||||
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
|
ft_strlcat(fstr, s2, ft_strlen(s1) + ft_strlen(s2) + 1);
|
||||||
if (s1)
|
if (*s1)
|
||||||
free(s1);
|
free(s1);
|
||||||
if (s2)
|
if (*s2)
|
||||||
free(s2);
|
free(s2);
|
||||||
return (fstr);
|
return (fstr);
|
||||||
}
|
}
|
||||||
|
38
src/main.c
38
src/main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/05/22 15:38:22 by mmoussou ### ########.fr */
|
/* Updated: 2024/05/24 15:01:05 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,8 +19,9 @@
|
|||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
|
#include "prompt.h"
|
||||||
|
|
||||||
void print_cmd(t_cmd cmd)
|
/*void print_cmd(t_cmd cmd)
|
||||||
{
|
{
|
||||||
ft_putendl_fd(cmd.cmd, 1);
|
ft_putendl_fd(cmd.cmd, 1);
|
||||||
while (*(cmd.argv))
|
while (*(cmd.argv))
|
||||||
@ -28,21 +29,16 @@ void print_cmd(t_cmd cmd)
|
|||||||
ft_putendl_fd(*(cmd.argv), 1);
|
ft_putendl_fd(*(cmd.argv), 1);
|
||||||
(cmd.argv)++;
|
(cmd.argv)++;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void print_pipe(t_list *pipe)
|
void print_pipe(t_list *pipe)
|
||||||
{
|
{
|
||||||
t_list *tmp;
|
t_list *tmp;
|
||||||
|
|
||||||
tmp = pipe;
|
tmp = pipe;
|
||||||
if (!pipe->next)
|
|
||||||
{
|
|
||||||
print_cmd(*(t_cmd*)tmp->content);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (tmp)
|
while (tmp)
|
||||||
{
|
{
|
||||||
print_cmd(*(t_cmd*)tmp->content);
|
ft_putendl_fd(tmp->content, STDOUT_FILENO);
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,9 +47,10 @@ int main(int ac, char **av, char **env)
|
|||||||
{
|
{
|
||||||
//ft_heredoc("EOF");
|
//ft_heredoc("EOF");
|
||||||
char *test;
|
char *test;
|
||||||
char **lll;
|
|
||||||
char *prompt;
|
char *prompt;
|
||||||
t_list *cmd;
|
char **lll;
|
||||||
|
t_list *piped;
|
||||||
|
//t_token *token;
|
||||||
|
|
||||||
(void)ac;
|
(void)ac;
|
||||||
(void)av;
|
(void)av;
|
||||||
@ -68,11 +65,24 @@ int main(int ac, char **av, char **env)
|
|||||||
if (!*lll)
|
if (!*lll)
|
||||||
continue ;
|
continue ;
|
||||||
if (is_str(test, "exit"))
|
if (is_str(test, "exit"))
|
||||||
break ;
|
break;
|
||||||
cmd = split_pipe(test);
|
piped = __split_pipe(test);
|
||||||
print_pipe(cmd);
|
print_redir(__to_redir(piped->content));
|
||||||
|
//free(token);
|
||||||
|
free(test);
|
||||||
|
ft_lstclear(&piped, &free);
|
||||||
ft_free("a", &lll);
|
ft_free("a", &lll);
|
||||||
}
|
}
|
||||||
ft_free("a", &lll);
|
ft_free("a", &lll);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*int main()
|
||||||
|
{
|
||||||
|
char *ll = "asdf\"xf\"asfffd";
|
||||||
|
t_quote d;
|
||||||
|
|
||||||
|
d = is_inquote(ll, 6);
|
||||||
|
ft_printf("%c\n", *(ll+6));
|
||||||
|
print_quote_type(d);
|
||||||
|
}*/
|
||||||
|
47
src/parsing/debug_print.c
Normal file
47
src/parsing/debug_print.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include "parsing.h"
|
||||||
|
|
||||||
|
void print_quote_type(t_quote type)
|
||||||
|
{
|
||||||
|
if (type == SINGLE)
|
||||||
|
ft_putendl_fd("SINGLE", STDOUT_FILENO);
|
||||||
|
else if (type == DOUBLE)
|
||||||
|
ft_putendl_fd("DOUBLE", STDOUT_FILENO);
|
||||||
|
else if (type == FALSE)
|
||||||
|
ft_putendl_fd("FALSE", STDOUT_FILENO);
|
||||||
|
else if (type == NOT_CLOSED)
|
||||||
|
ft_putendl_fd("NOT_CLOSED", STDOUT_FILENO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_redir_sign(t_redirection_sign redir_sign)
|
||||||
|
{
|
||||||
|
if (redir_sign == HEREDOC)
|
||||||
|
ft_putendl_fd("HEREDOC", STDOUT_FILENO);
|
||||||
|
else if (redir_sign == INFILE)
|
||||||
|
ft_putendl_fd("INFILE", STDOUT_FILENO);
|
||||||
|
else if (redir_sign == OUTFILE)
|
||||||
|
ft_putendl_fd("OUTFILE", STDOUT_FILENO);
|
||||||
|
else if (redir_sign == OUT_APPEND)
|
||||||
|
ft_putendl_fd("OUT_APPEND", STDOUT_FILENO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_redir(t_redirection *redir)
|
||||||
|
{
|
||||||
|
ft_putstr_fd("file_name : ", STDOUT_FILENO);
|
||||||
|
if (redir->file_name)
|
||||||
|
ft_putendl_fd(redir->file_name, STDOUT_FILENO);
|
||||||
|
ft_putstr_fd("", STDOUT_FILENO);
|
||||||
|
print_redir_sign(redir->sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_token(t_token *token)
|
||||||
|
{
|
||||||
|
t_list *tmp;
|
||||||
|
|
||||||
|
tmp = token->redirection;
|
||||||
|
while (tmp)
|
||||||
|
{
|
||||||
|
print_redir((t_redirection*)tmp->content);
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
ft_putendl_fd(token->argv, STDOUT_FILENO);
|
||||||
|
}
|
66
src/parsing/is_inquote.c
Normal file
66
src/parsing/is_inquote.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* is_inquote.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/05/20 20:06:13 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/05/21 20:34:14 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "parsing.h"
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_quote __is_quote(char c)
|
||||||
|
{
|
||||||
|
if (c == 39)
|
||||||
|
return (SINGLE);
|
||||||
|
if (c == 34)
|
||||||
|
return (DOUBLE);
|
||||||
|
return (FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *search_for_next_quote(char *s, t_quote quote_type)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
tmp = s;
|
||||||
|
while (*tmp)
|
||||||
|
{
|
||||||
|
if (__is_quote(*tmp) == quote_type)
|
||||||
|
break ;
|
||||||
|
tmp++;
|
||||||
|
}
|
||||||
|
return (tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_quote is_inquote(char *s, size_t i)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
size_t start_quote;
|
||||||
|
t_quote quote_type;
|
||||||
|
|
||||||
|
start_quote = 0;
|
||||||
|
tmp = s;
|
||||||
|
quote_type = FALSE;
|
||||||
|
while (*tmp)
|
||||||
|
{
|
||||||
|
if ((size_t)(tmp - s) > i)
|
||||||
|
break ;
|
||||||
|
if (__is_quote(*tmp) != FALSE)
|
||||||
|
{
|
||||||
|
start_quote = tmp - s;
|
||||||
|
quote_type = __is_quote(*tmp);
|
||||||
|
tmp = search_for_next_quote(tmp, quote_type);
|
||||||
|
tmp++;
|
||||||
|
if (*tmp && (start_quote < i && (size_t)(tmp - s) > i))
|
||||||
|
return (quote_type);
|
||||||
|
else if (!*tmp)
|
||||||
|
return (NOT_CLOSED);
|
||||||
|
}
|
||||||
|
tmp++;
|
||||||
|
}
|
||||||
|
return (FALSE);
|
||||||
|
}
|
72
src/parsing/tokenizer/__to_token.c
Normal file
72
src/parsing/tokenizer/__to_token.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* __to_token.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/05/20 21:05:04 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/05/25 14:05:02 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "tokenizer.h"
|
||||||
|
#include "parsing.h"
|
||||||
|
|
||||||
|
t_redirection_sign __to_redir_sign(char *redir_sign)
|
||||||
|
{
|
||||||
|
if (redir_sign[0] == '<' && redir_sign[1] != '<')
|
||||||
|
return (INFILE);
|
||||||
|
else if (redir_sign[0] == '<' && redir_sign[1] == '<')
|
||||||
|
return (HEREDOC);
|
||||||
|
else if (redir_sign[0] == '>' && redir_sign[1] == '>')
|
||||||
|
return (OUT_APPEND);
|
||||||
|
else if (redir_sign[0] == '>' && redir_sign[1] != '>')
|
||||||
|
return (OUTFILE);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_redirection *__to_redir(char *redir_s)
|
||||||
|
{
|
||||||
|
t_redirection *redir;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
redir = ft_calloc(sizeof(t_redirection), 1);
|
||||||
|
redir->sign = __to_redir_sign(redir_s);
|
||||||
|
if (redir->sign == HEREDOC || redir->sign == OUT_APPEND)
|
||||||
|
redir_s += 2;
|
||||||
|
else
|
||||||
|
redir_s++;
|
||||||
|
while (*redir_s && *redir_s == ' ')
|
||||||
|
redir_s++;
|
||||||
|
tmp = redir_s;
|
||||||
|
while (*tmp && ft_isalnum(*tmp))
|
||||||
|
tmp++;
|
||||||
|
redir->file_name = ft_calloc(tmp - redir_s + 1, sizeof(char));
|
||||||
|
ft_strlcpy(redir->file_name, redir_s, tmp - redir_s + 1);
|
||||||
|
return (redir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*t_token *__to_token(char *cmd)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
t_token *token;
|
||||||
|
t_redirection *tmp_redir;
|
||||||
|
char *argv;
|
||||||
|
|
||||||
|
tmp = cmd;
|
||||||
|
argv = NULL;
|
||||||
|
token = ft_calloc(sizeof(t_token), 1);
|
||||||
|
while (*tmp)
|
||||||
|
{
|
||||||
|
if (*tmp == '<' || *tmp == '>')
|
||||||
|
{
|
||||||
|
tmp_redir = __to_redir(tmp);
|
||||||
|
ft_lstadd_back(&(token->redirection), ft_lstnew((void *)&tmp_redir));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ft_strjoin_free_s1(argv, &(*tmp));
|
||||||
|
tmp++;
|
||||||
|
}
|
||||||
|
return (token);
|
||||||
|
}*/
|
@ -1,34 +1,25 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* split_pipe.c :+: :+: :+: */
|
/* tokenizer.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/07 13:26:40 by adjoly #+# #+# */
|
/* Created: 2024/05/18 20:13:50 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/05/18 17:12:42 by adjoly ### ########.fr */
|
/* Updated: 2024/05/20 22:51:45 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "tokenizer.h"
|
||||||
#include "parsing.h"
|
|
||||||
|
|
||||||
t_list *split_pipe(char *readline)
|
/*t_list *tokenizer(char *readline)
|
||||||
{
|
{
|
||||||
char **split;
|
t_list *token;
|
||||||
char **tmp;
|
t_list *piped;
|
||||||
t_list *list;
|
|
||||||
|
|
||||||
split = ft_split(readline, '|');
|
piped = __split_pipe(readline);
|
||||||
tmp = split;
|
while (piped && *piped)
|
||||||
if (!*(split+1))
|
|
||||||
return (ft_lstnew((void *)readline));
|
|
||||||
list = NULL;
|
|
||||||
while (tmp && *tmp)
|
|
||||||
{
|
{
|
||||||
ft_lstadd_back(&list, ft_lstnew((void *)(*tmp)));
|
|
||||||
tmp++;
|
|
||||||
}
|
}
|
||||||
free(split);
|
}*/
|
||||||
return (list);
|
|
||||||
}
|
|
Reference in New Issue
Block a user