handle fd
This commit is contained in:
@@ -50,58 +50,56 @@ int nbr_argv(t_token *token)
|
||||
// *token = (*token)->next;
|
||||
//}
|
||||
|
||||
/*
|
||||
void handle_fd(t_token *token, t_cmd **cmd)
|
||||
{
|
||||
int *pipes_fd;
|
||||
|
||||
(*cmd)->fd_out = 1;
|
||||
while (token && token->id != T_PIPE)
|
||||
{
|
||||
// T_LESS : '<',
|
||||
if (token->id == T_LESS)
|
||||
{
|
||||
if ((*cmd)->fd_in != 0)
|
||||
close((*cmd)->fd_in);
|
||||
(*cmd)->fd_in = open(token->next->content, O_RDONLY | O_CREAT);
|
||||
token->id = T_TOKEN;
|
||||
token->next->id = T_TOKEN;
|
||||
}
|
||||
// T_GREAT : '>',
|
||||
if (token->id == T_GREAT)
|
||||
{
|
||||
(*cmd)->fd_out = open(token->next->content, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
token->id = T_TOKEN;
|
||||
token->next->id = T_TOKEN;
|
||||
}
|
||||
// T_DGREAT : '>>'
|
||||
if (token->id == T_DGREAT)
|
||||
{
|
||||
(*cmd)->fd_out = open(token->next->content, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU);
|
||||
token->id = T_TOKEN;
|
||||
token->next->id = T_TOKEN;
|
||||
}
|
||||
// T_DLESS : '<<' (heredoc)
|
||||
// if (token->id == T_DGREAT)
|
||||
// {
|
||||
// cmd->fd_out = open(token->next->content, O_WRONLY | O_TMPFILE | O_APPEND, S_IRWXU);
|
||||
// token->out = T_TOKEN;
|
||||
// token->next->id = T_TOKEN;
|
||||
// }
|
||||
token = token->next;
|
||||
}
|
||||
if (token && token->id == T_PIPE)
|
||||
{
|
||||
pipes_fd = calloc(2, sizeof(int));
|
||||
pipe(pipes_fd);
|
||||
if ((*cmd)->fd_out == 1)
|
||||
(*cmd)->fd_out = pipes_fd[1];
|
||||
else
|
||||
close(pipes_fd[1]);
|
||||
cmd[1]->fd_in = pipes_fd[0];
|
||||
}
|
||||
}
|
||||
*/
|
||||
//void handle_fd(t_token *token, t_cmd **cmd)
|
||||
//{
|
||||
// int *pipes_fd;
|
||||
//
|
||||
// (*cmd)->fd_out = 1;
|
||||
// while (token && token->id != T_PIPE)
|
||||
// {
|
||||
// // T_LESS : '<',
|
||||
// if (token->id == T_LESS)
|
||||
// {
|
||||
// if ((*cmd)->fd_in != 0)
|
||||
// close((*cmd)->fd_in);
|
||||
// (*cmd)->fd_in = open(token->next->content, O_RDONLY | O_CREAT);
|
||||
// token->id = T_TOKEN;
|
||||
// token->next->id = T_TOKEN;
|
||||
// }
|
||||
// // T_GREAT : '>',
|
||||
// if (token->id == T_GREAT)
|
||||
// {
|
||||
// (*cmd)->fd_out = open(token->next->content, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
// token->id = T_TOKEN;
|
||||
// token->next->id = T_TOKEN;
|
||||
// }
|
||||
// // T_DGREAT : '>>'
|
||||
// if (token->id == T_DGREAT)
|
||||
// {
|
||||
// (*cmd)->fd_out = open(token->next->content, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU);
|
||||
// token->id = T_TOKEN;
|
||||
// token->next->id = T_TOKEN;
|
||||
// }
|
||||
// // T_DLESS : '<<' (heredoc)
|
||||
// // if (token->id == T_DGREAT)
|
||||
// // {
|
||||
// // cmd->fd_out = open(token->next->content, O_WRONLY | O_TMPFILE | O_APPEND, S_IRWXU);
|
||||
// // token->out = T_TOKEN;
|
||||
// // token->next->id = T_TOKEN;
|
||||
// // }
|
||||
// token = token->next;
|
||||
// }
|
||||
// if (token && token->id == T_PIPE)
|
||||
// {
|
||||
// pipes_fd = calloc(2, sizeof(int));
|
||||
// pipe(pipes_fd);
|
||||
// if ((*cmd)->fd_out == 1)
|
||||
// (*cmd)->fd_out = pipes_fd[1];
|
||||
// else
|
||||
// close(pipes_fd[1]);
|
||||
// cmd[1]->fd_in = pipes_fd[0];
|
||||
// }
|
||||
//}
|
||||
|
||||
//int handle_builtin(t_token *token, t_cmd *cmd)
|
||||
//{
|
||||
|
||||
Reference in New Issue
Block a user