diff --git a/include/tokenizer.h b/include/tokenizer.h index 86113f9..3b2471f 100644 --- a/include/tokenizer.h +++ b/include/tokenizer.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 * diff --git a/src/main.c b/src/main.c index d096ce6..77f5902 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/src/parsing/debug_print.c b/src/parsing/debug_print.c index 5292c32..93dd116 100644 --- a/src/parsing/debug_print.c +++ b/src/parsing/debug_print.c @@ -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); } diff --git a/src/parsing/tokenizer/__to_token.c b/src/parsing/tokenizer/__to_token.c index d423928..4dc011d 100644 --- a/src/parsing/tokenizer/__to_token.c +++ b/src/parsing/tokenizer/__to_token.c @@ -6,11 +6,12 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); -} +}*/ diff --git a/vgcore.421022 b/vgcore.421022 new file mode 100644 index 0000000..0122fd3 Binary files /dev/null and b/vgcore.421022 differ diff --git a/vgcore.421116 b/vgcore.421116 new file mode 100644 index 0000000..3ee514f Binary files /dev/null and b/vgcore.421116 differ