c kc
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/28 14:29:21 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/01 20:07:08 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -49,4 +49,5 @@ void print_parsed_cmd(t_cmd *cmd)
|
||||
printf("[PIPE] ");
|
||||
cmd = cmd->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/30 17:29:07 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/04/01 20:08:24 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,12 +14,21 @@
|
||||
|
||||
void exec_command_bonus(t_msh *msh, char *cmd_str)
|
||||
{
|
||||
t_cmd *cmds;
|
||||
t_cmd *cmds;
|
||||
t_cmd *tmp;
|
||||
|
||||
(void)msh;
|
||||
printf("cmd : %s\n",cmd_str);
|
||||
cmds = parsing_bonus(cmd_str);
|
||||
printf("%p\n", cmds);
|
||||
tmp = check_cmds_syntax(cmds);
|
||||
if(tmp)
|
||||
{
|
||||
print_syntax_error_bonus(tmp);
|
||||
printf("error\n");
|
||||
free_cmd(cmds);
|
||||
return;
|
||||
}
|
||||
printf("has address : %d\n", cmds!=0);
|
||||
msh->tokens = parse_command(cmd_str, msh->env);
|
||||
msh->cmds = cmds;
|
||||
print_parsed_cmd(cmds);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/30 17:15:14 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/04/01 20:15:11 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -41,19 +41,9 @@ typedef struct s_cmd
|
||||
struct s_cmd *next;
|
||||
} t_cmd;
|
||||
|
||||
typedef enum e_token_type
|
||||
{
|
||||
ARG,
|
||||
RED_O,
|
||||
RED_O_APP,
|
||||
RED_I,
|
||||
HERE_DOC
|
||||
} t_token_type;
|
||||
|
||||
|
||||
typedef struct s_token
|
||||
{
|
||||
t_token_type type;
|
||||
char *value;
|
||||
struct s_token *next;
|
||||
} t_token;
|
||||
@ -115,6 +105,7 @@ void parse_var(t_msh *msh, char *line);
|
||||
void print_parsed_token(t_token *cmd);//debug
|
||||
int get_var_name_len(char *command);
|
||||
void handle_minishellrc(t_msh *msh);
|
||||
t_cmd *check_cmds_syntax(t_cmd *cmds);
|
||||
char *get_tmp_file_name(t_msh *msh);
|
||||
int get_args_count(t_cmd *cmds);
|
||||
char **env_to_char_tab(t_env *env);
|
||||
@ -132,6 +123,8 @@ void get_cmd_path(t_msh *msh);
|
||||
t_token *free_token(t_token *cmd);
|
||||
int set_echoctl(int value);
|
||||
int print_env(t_env *env);
|
||||
t_cmd *free_cmd(t_cmd *cmd);
|
||||
void print_syntax_error_bonus(t_cmd *cmd);
|
||||
int ft_export(t_msh *msh);
|
||||
void free_env(t_env *env);
|
||||
int ft_unset(t_msh *msh);
|
||||
|
@ -6,13 +6,13 @@
|
||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */
|
||||
/* Updated: 2024/03/30 16:44:47 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/01 20:04:55 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int check_syntax(char *cmd)
|
||||
int check_str_syntax(char *cmd)
|
||||
{
|
||||
int in_quote;
|
||||
int in_dquote;
|
||||
@ -119,6 +119,45 @@ char *get_cmd_value(char **cmd , t_cmd_type type)
|
||||
(*cmd)++;
|
||||
return(res);
|
||||
}
|
||||
void print_syntax_error_bonus(t_cmd *cmd)
|
||||
{
|
||||
if (cmd->cmd_type == CMD || cmd->cmd_type == PAREN)
|
||||
return;
|
||||
|
||||
ft_printf_fd(2, "minishell : syntax error near unexpected token `");
|
||||
if(cmd->cmd_type == AND)
|
||||
ft_printf_fd(2, "AND");
|
||||
if(cmd->cmd_type == OR)
|
||||
ft_printf_fd(2, "OR");
|
||||
if(cmd->cmd_type == PIPE)
|
||||
ft_printf_fd(2, "PIPE");
|
||||
ft_printf_fd(2, "'\n");
|
||||
}
|
||||
|
||||
t_cmd *check_cmds_syntax(t_cmd *cmds)
|
||||
{
|
||||
t_cmd_type last;
|
||||
t_token *token;
|
||||
|
||||
if(cmds->cmd_type == OR || cmds->cmd_type == AND || cmds->cmd_type == PIPE)
|
||||
return(cmds);
|
||||
last = cmds->cmd_type;
|
||||
cmds = cmds->next;
|
||||
while(cmds)
|
||||
{
|
||||
if(cmds->cmd_type == OR || cmds->cmd_type == AND || cmds->cmd_type == PIPE)
|
||||
if((last != CMD && last != PAREN) || (!cmds->next && cmds->next->cmd_type != CMD && cmds->next->cmd_type != PAREN))
|
||||
return(cmds);
|
||||
if(cmds->cmd_type == CMD || cmds->cmd_type == PAREN)
|
||||
{
|
||||
token = parse_command(cmds->value, 0);
|
||||
if(!token)
|
||||
return(cmds);
|
||||
free_token(token);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
t_cmd *parsing_bonus(char *cmd)
|
||||
{
|
||||
@ -127,7 +166,7 @@ t_cmd *parsing_bonus(char *cmd)
|
||||
char *value;
|
||||
|
||||
res = 0;
|
||||
if (!check_syntax(cmd))
|
||||
if (!check_str_syntax(cmd))
|
||||
return (0);
|
||||
while (*cmd)
|
||||
{
|
||||
|
Reference in New Issue
Block a user