Commit 335ebabd authored by pêle-mêle's avatar pêle-mêle
Browse files

catch ambiguous redirections

parent a992e4f9
......@@ -54,6 +54,7 @@ enum e_retcode
MALLOC_ERR,
WRITE_ERR,
GNL_ERR,
AMBIG_REDIR
};
enum e_redir_op
......
......@@ -54,7 +54,8 @@ typedef struct s_state_machine
int stat_loc;
t_byte pipe_flag;
t_byte var_state;
uint8_t pad[6];
t_byte ambig_redir;
uint8_t pad[5];
} t_state_machine;
typedef char *(*t_parse)(t_state_machine *, char *);
......
......@@ -101,14 +101,16 @@ int handle_execution(t_xe *xe, int fd_in, int proc)
cur_command = parse_one_command(xe);
if (cur_command == NULL)
return (MALLOC_ERR);
if (cur_command->args != NULL)
{
return (handle_command(cur_command, xe, fd_in, proc));
}
else
{
dup2(xe->backup_stdout, STDOUT_FILENO);
dup2(xe->backup_stdin, STDIN_FILENO);
(void)fd_in;
(void)proc;
// if (cur_command->args != NULL)
// {
// return (handle_command(cur_command, xe, fd_in, proc));
// }
// else
// {
// dup2(xe->backup_stdout, STDOUT_FILENO);
// dup2(xe->backup_stdin, STDIN_FILENO);
return (SUCCESS);
}
// }
}
......@@ -2,19 +2,12 @@
char *angle_bracket(t_state_machine *machine, char *line)
{
// if (reset_buf(machine) == FAILURE)
// return(NULL);
// if (machine->cur_token->redir != NO_REDIR)
// machine->error = REDIR_PATH_INVALID;
// else
// {
line = new_redir_info(machine, line);
if (line == NULL)
return (NULL);
line++;
machine->state = SPACE;
machine->cur_token_stack = &machine->redir_paths;
// }
return (line);
}
......@@ -181,7 +174,11 @@ int parse_input(char **line, char **env, int stat_loc, t_command *command)
command->redir_types = machine.redir_types;
command->args = machine.args;
if (*line == NULL)
{
if (machine.ambig_redir == TRUE)
return (AMBIG_REDIR);
return (FAILURE);
}
// ft_printarray_fd(machine.args, STDOUT_FILENO);
// printf("REDIR PATHS:\n");
// ft_printarray_fd(machine.redir_paths, STDOUT_FILENO);
......@@ -208,8 +205,10 @@ t_command *parse_one_command(t_xe *xe)
ret = parse_input(&xe->line, xe->env, xe->stat_loc, cur_command);
if (ret == FAILURE)
{
free(cur_command);
free(cur_command); // et args, redir_paths et types
return (NULL);
}
else if (ret == AMBIG_REDIR)
;
return (cur_command);
}
......@@ -101,6 +101,12 @@ char *parse_variable(t_state_machine *machine, char *line)
i = 0;
if (ft_isspace(var_value[i]) && machine->cur_arg[0] != '\0')
{
if (machine->cur_token_stack == &machine->redir_paths)
{
machine->ambig_redir = TRUE;
free(var_value);
return (NULL);
}
if (add_arg(machine) == FAILURE)
{
free(var_value);
......@@ -114,6 +120,12 @@ char *parse_variable(t_state_machine *machine, char *line)
{
if (ft_isspace(var_value[i]))
{
if (machine->cur_token_stack == &machine->redir_paths)
{
machine->ambig_redir = TRUE;
free(var_value);
return (NULL);
}
if (add_arg(machine) == FAILURE)
{
free(var_value);
......@@ -149,6 +161,12 @@ int add_arg(t_state_machine *machine)
}
machine->cur_arg = NULL;
}
else if (machine->cur_token_stack == &machine->redir_paths)
{
machine->ambig_redir = TRUE;
free(machine->cur_arg);
return (FAILURE);
}
return (SUCCESS);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment