mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-05-14 00:08:47 +02:00
「✨」 feat: Parsing of command kinda working
This commit is contained in:
33
src/parsing/check_error/check_redir.c
Normal file
33
src/parsing/check_error/check_redir.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_redir.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 18:17:26 by adjoly #+# #+# */
|
||||
/* Updated: 2024/05/30 12:52:51 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tokenizer.h"
|
||||
#include "parsing.h"
|
||||
#include "error_msg.h"
|
||||
|
||||
void check_redir(t_list *redir, char **argv)
|
||||
{
|
||||
t_list *tmp;
|
||||
t_redirection *tmp_redir;
|
||||
|
||||
tmp = redir;
|
||||
while(tmp)
|
||||
{
|
||||
tmp_redir = tmp->content;
|
||||
if (tmp_redir->sign == HEREDOC && \
|
||||
!((t_redirection *)(tmp->content))->file_name)
|
||||
send_error(ERROR_NO_EOF, argv);
|
||||
if (!((t_redirection *)(tmp->content))->file_name)
|
||||
send_error(ERROR_NO_REDIR, argv);
|
||||
tmp = tmp->next;
|
||||
}
|
||||
}
|
45
src/parsing/check_error/check_syntax.c
Normal file
45
src/parsing/check_error/check_syntax.c
Normal file
@ -0,0 +1,45 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_syntax.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 17:40:13 by adjoly #+# #+# */
|
||||
/* Updated: 2024/05/29 11:37:06 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
#include "parsing.h"
|
||||
#include "error_msg.h"
|
||||
|
||||
bool is_chevron(int c)
|
||||
{
|
||||
if (c == '<' || c == '>')
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool check_triple(char *chevron)
|
||||
{
|
||||
if (is_chevron(*chevron) && is_chevron(*(chevron + 1)) \
|
||||
&& is_chevron(*(chevron + 2)))
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
void check_syntax(char *readline, char **argv)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
tmp = readline;
|
||||
while (*tmp)
|
||||
{
|
||||
if (check_triple(tmp))
|
||||
send_error(ERROR_SYNTAX, argv);
|
||||
tmp++;
|
||||
}
|
||||
}
|
20
src/parsing/check_error/send_error.c
Normal file
20
src/parsing/check_error/send_error.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* send_error.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/28 18:09:49 by adjoly #+# #+# */
|
||||
/* Updated: 2024/05/28 18:15:09 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void send_error(char *msg, char **argv)
|
||||
{
|
||||
ft_putstr_fd(argv[0], STDERR_FILENO);
|
||||
ft_putendl_fd(msg, STDERR_FILENO);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
Reference in New Issue
Block a user