」 feat: __to_redir and __to_redir_sign work

This commit is contained in:
2024-05-25 14:06:42 +02:00
parent 6a8a6382bd
commit f88e6380c0
6 changed files with 41 additions and 29 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/18 20:14:15 by adjoly #+# #+# */
/* Updated: 2024/05/23 12:11:42 by adjoly ### ########.fr */
/* Updated: 2024/05/24 15:00:52 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,11 +35,28 @@ typedef struct s_token
t_list *redirection;
} t_token;
/**
* @brief Take a string and tell what type of redirect it is
*
* @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 containt the command to tokenize
* @param cmd A string that contain the command to tokenize
*
* @return (t_token *) The tokenized version of the command
*

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/05/23 20:06:16 by adjoly ### ########.fr */
/* Updated: 2024/05/24 15:01:05 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,7 +49,7 @@ int main(int ac, char **av, char **env)
char *prompt;
char **lll;
t_list *piped;
t_token *token;
//t_token *token;
(void)ac;
(void)av;
@ -66,9 +66,8 @@ int main(int ac, char **av, char **env)
if (is_str(test, "exit"))
break;
piped = __split_pipe(test);
token = __to_token(piped->content);
print_token(token);
free(token);
print_redir(__to_redir(piped->content));
//free(token);
free(test);
ft_lstclear(&piped, &free);
}

View File

@ -27,7 +27,8 @@ void print_redir_sign(t_redirection_sign redir_sign)
void print_redir(t_redirection *redir)
{
ft_putstr_fd("file_name : ", STDOUT_FILENO);
ft_putendl_fd(redir->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);
}

View File

@ -6,11 +6,12 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 21:05:04 by adjoly #+# #+# */
/* Updated: 2024/05/23 20:12:03 by adjoly ### ########.fr */
/* 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)
{
@ -18,41 +19,35 @@ t_redirection_sign __to_redir_sign(char *redir_sign)
return (INFILE);
else if (redir_sign[0] == '<' && redir_sign[1] == '<')
return (HEREDOC);
else if (redir_sign[0] == '>' && redir_sign[1] != '>')
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 *__to_redir(char *redir_s)
{
char *tmp;
t_redirection *redir;
char *start_of_filename;
char *filename;
char *tmp;
redir = ft_calloc(sizeof(t_redirection), 1);
redir->sign = __to_redir_sign(redir_s);
tmp = redir_s;
if (!redir->sign)
return (NULL);
if (redir->sign % 2)
tmp++;
if (redir->sign == HEREDOC || redir->sign == OUT_APPEND)
redir_s += 2;
else
tmp += 2;
while (*tmp && *tmp != ' ')
redir_s++;
while (*redir_s && *redir_s == ' ')
redir_s++;
tmp = redir_s;
while (*tmp && ft_isalnum(*tmp))
tmp++;
start_of_filename = tmp;
while (*tmp && !ft_isalnum(*tmp))
tmp++;
filename = ft_calloc(tmp - start_of_filename + 1, sizeof(char));
ft_strlcpy(filename, start_of_filename, (tmp - start_of_filename));
redir->file_name = filename;
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)
/*t_token *__to_token(char *cmd)
{
char *tmp;
t_token *token;
@ -74,4 +69,4 @@ t_token *__to_token(char *cmd)
tmp++;
}
return (token);
}
}*/

BIN
vgcore.421022 Normal file

Binary file not shown.

BIN
vgcore.421116 Normal file

Binary file not shown.