mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-14 00:08:47 +02:00
「✨」 feat: Did a lot of things, don't know what but it work
This commit is contained in:
45
src/parsing/check_error/check_pipe.c
Normal file
45
src/parsing/check_error/check_pipe.c
Normal file
@ -0,0 +1,45 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_pipe.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/30 12:52:22 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/30 17:26:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include "parsing.h"
|
||||
#include <stdbool.h>
|
||||
#include "error_msg.h"
|
||||
|
||||
size_t strlen_till_end_char(char *s, int c)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
tmp = s;
|
||||
while (*tmp && *tmp == c)
|
||||
tmp++;
|
||||
return (tmp - s);
|
||||
}
|
||||
|
||||
bool check_pipe(char *readline)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
tmp = readline;
|
||||
while (*tmp)
|
||||
{
|
||||
if (*tmp == '|' && is_inquote(readline, tmp - readline) == FALSE)
|
||||
{
|
||||
tmp++;
|
||||
tmp += strlen_till_end_char(tmp, ' ');
|
||||
if (!*tmp)
|
||||
return (send_error_parsing("No command after pipe"));
|
||||
}
|
||||
tmp++;
|
||||
}
|
||||
return (false);
|
||||
}
|
@ -6,11 +6,12 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/21 11:59:34 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/21 12:40:56 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/30 16:11:23 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
#include "error_msg.h"
|
||||
#include "tokenizer.h"
|
||||
|
||||
size_t count_quote(char *readline, t_quote type)
|
||||
@ -29,20 +30,15 @@ size_t count_quote(char *readline, t_quote type)
|
||||
return (count);
|
||||
}
|
||||
|
||||
void check_quote(char *readline)
|
||||
bool check_quote(char *readline)
|
||||
{
|
||||
size_t count;
|
||||
|
||||
count = count_quote(readline, DOUBLE);
|
||||
if (count % 2)
|
||||
{
|
||||
ft_putendl_fd("double quote error", STDERR_FILENO);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return (send_error_parsing("double quote not closed"));
|
||||
count = count_quote(readline, SINGLE);
|
||||
if (count % 2)
|
||||
{
|
||||
ft_putendl_fd("single quote error", STDERR_FILENO);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return (send_error_parsing("single quote not closed"));
|
||||
return (false);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 18:17:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/24 12:51:27 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/30 13:49:21 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
#include "parsing.h"
|
||||
#include "error_msg.h"
|
||||
|
||||
void check_redir(t_list *redir, char **argv)
|
||||
bool check_redir(t_list *redir)
|
||||
{
|
||||
t_list *tmp;
|
||||
t_redirection *tmp_redir;
|
||||
@ -25,9 +25,10 @@ void check_redir(t_list *redir, char **argv)
|
||||
tmp_redir = tmp->content;
|
||||
if (tmp_redir->sign == HEREDOC && \
|
||||
!((t_redirection *)(tmp->content))->file_name)
|
||||
send_error(ERROR_NO_EOF, argv);
|
||||
return (send_error_parsing(ERROR_NO_EOF));
|
||||
if (!((t_redirection *)(tmp->content))->file_name)
|
||||
send_error(ERROR_NO_REDIR, argv);
|
||||
return (send_error_parsing(ERROR_NO_REDIR));
|
||||
tmp = tmp->next;
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 17:40:13 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/04 16:43:53 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/30 13:54:53 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -48,7 +48,7 @@ bool check_if_file(char *readline)
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool check_syntax(char *readline, char **argv)
|
||||
bool check_syntax(char *readline)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
@ -56,15 +56,9 @@ bool check_syntax(char *readline, char **argv)
|
||||
while (*tmp)
|
||||
{
|
||||
if (check_triple(tmp))
|
||||
{
|
||||
send_error(ERROR_SYNTAX, argv);
|
||||
return (true);
|
||||
}
|
||||
return (send_error_parsing(ERROR_SYNTAX));
|
||||
if (check_if_file(tmp))
|
||||
{
|
||||
send_error(ERROR_SYNTAX, argv);
|
||||
return (true);
|
||||
}
|
||||
return (send_error_parsing(ERROR_SYNTAX));
|
||||
tmp++;
|
||||
}
|
||||
return (false);
|
||||
|
@ -6,14 +6,31 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 18:09:49 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/04 15:39:24 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/30 16:11:03 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *get_program_name(char *argv_one)
|
||||
{
|
||||
static char prog_name[255];
|
||||
|
||||
if (argv_one)
|
||||
ft_strlcpy(prog_name, argv_one, ft_strlen(argv_one) + 1);
|
||||
return (prog_name);
|
||||
}
|
||||
|
||||
void send_error(char *msg, char **argv)
|
||||
{
|
||||
ft_putstr_fd(argv[0], STDERR_FILENO);
|
||||
ft_putendl_fd(msg, STDERR_FILENO);
|
||||
}
|
||||
|
||||
bool send_error_parsing(char *msg)
|
||||
{
|
||||
ft_putstr_fd(get_program_name(NULL), STDERR_FILENO);
|
||||
ft_putstr_fd(": Error: ", STDERR_FILENO);
|
||||
ft_putendl_fd(msg, STDERR_FILENO);
|
||||
return (true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user