split valid_command.c in two files
This commit is contained in:
2
Makefile
2
Makefile
@@ -34,7 +34,7 @@ SRCS = main.c \
|
||||
signals.c error_wrappers.c last_exit_status.c \
|
||||
lexing.c fill_token.c check_operators.c \
|
||||
parsing.c create_pipeline.c \
|
||||
valid_syntax.c valid_pipeline.c valid_command.c valid_io_redirect.c \
|
||||
valid_syntax.c valid_pipeline.c valid_command.c rules_command.c valid_io_redirect.c \
|
||||
expansions.c expand_token.c rejoin_after_expand.c new_token_for_each_field.c \
|
||||
redirections.c here_doc.c \
|
||||
exec_cmd_line.c pipeline.c \
|
||||
|
||||
83
srcs/parsing/valid_syntax/rules_command.c
Normal file
83
srcs/parsing/valid_syntax/rules_command.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rules_command.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/24 18:52:05 by lperrey #+# #+# */
|
||||
/* Updated: 2021/12/17 03:18:49 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int valid_io_redirect(t_token **token_list);
|
||||
|
||||
// cmd_prefix cmd_name cmd_suffix
|
||||
int valid_command_rule1(t_token **token_list)
|
||||
{
|
||||
while (valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_token(token_list, T_WORD))
|
||||
{
|
||||
while (valid_token(token_list, T_WORD)
|
||||
|| valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_prefix cmd_name
|
||||
int valid_command_rule2(t_token **token_list)
|
||||
{
|
||||
while (valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_token(token_list, T_WORD))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_name cmd_suffix
|
||||
int valid_command_rule3(t_token **token_list)
|
||||
{
|
||||
if (valid_token(token_list, T_WORD))
|
||||
{
|
||||
while (valid_token(token_list, T_WORD) || valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_name
|
||||
int valid_command_rule4(t_token **token_list)
|
||||
{
|
||||
if (valid_token(token_list, T_WORD))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_prefix
|
||||
int valid_command_rule5(t_token **token_list)
|
||||
{
|
||||
while (valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -6,19 +6,17 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/24 18:52:05 by lperrey #+# #+# */
|
||||
/* Updated: 2021/12/17 03:14:06 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/12/17 03:28:53 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int valid_io_redirect(t_token **token_list);
|
||||
|
||||
static int valid_command_rule1(t_token **token_list);
|
||||
static int valid_command_rule2(t_token **token_list);
|
||||
static int valid_command_rule3(t_token **token_list);
|
||||
static int valid_command_rule4(t_token **token_list);
|
||||
static int valid_command_rule5(t_token **token_list);
|
||||
int valid_command_rule1(t_token **token_list);
|
||||
int valid_command_rule2(t_token **token_list);
|
||||
int valid_command_rule3(t_token **token_list);
|
||||
int valid_command_rule4(t_token **token_list);
|
||||
int valid_command_rule5(t_token **token_list);
|
||||
|
||||
int valid_command(t_token **token_list)
|
||||
{
|
||||
@@ -41,71 +39,3 @@ int valid_command(t_token **token_list)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_prefix cmd_name cmd_suffix
|
||||
static int valid_command_rule1(t_token **token_list)
|
||||
{
|
||||
while (valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_token(token_list, T_WORD))
|
||||
{
|
||||
while (valid_token(token_list, T_WORD)
|
||||
|| valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_prefix cmd_name
|
||||
static int valid_command_rule2(t_token **token_list)
|
||||
{
|
||||
while (valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_token(token_list, T_WORD))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_name cmd_suffix
|
||||
static int valid_command_rule3(t_token **token_list)
|
||||
{
|
||||
if (valid_token(token_list, T_WORD))
|
||||
{
|
||||
while (valid_token(token_list, T_WORD) || valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_name
|
||||
static int valid_command_rule4(t_token **token_list)
|
||||
{
|
||||
if (valid_token(token_list, T_WORD))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cmd_prefix
|
||||
static int valid_command_rule5(t_token **token_list)
|
||||
{
|
||||
while (valid_io_redirect(token_list))
|
||||
{
|
||||
if (valid_command_separator(*token_list))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user