diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index a6fbd771..bd2af6e5 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -161,7 +161,7 @@ struct s_redir t_flag type; int n; char *word; - int close; + /* int close; */ }; struct s_cmd diff --git a/42sh/src/exec/fd_is_valid.c b/42sh/src/exec/fd_is_valid.c index bcb6cdda..d89e0f49 100644 --- a/42sh/src/exec/fd_is_valid.c +++ b/42sh/src/exec/fd_is_valid.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */ -/* Updated: 2017/02/06 22:54:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 19:44:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 39b807b6..35413937 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:59:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 19:40:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_great.c b/42sh/src/exec/redirect_great.c index 4ec227d8..8b9e2a9b 100644 --- a/42sh/src/exec/redirect_great.c +++ b/42sh/src/exec/redirect_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ -/* Updated: 2017/03/05 18:07:25 by ariard ### ########.fr */ +/* Updated: 2017/03/05 19:35:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 34803f72..c210c647 100644 --- a/42sh/src/exec/redirect_greatand.c +++ b/42sh/src/exec/redirect_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ -/* Updated: 2017/03/05 18:12:26 by ariard ### ########.fr */ +/* Updated: 2017/03/05 19:44:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,26 +17,25 @@ int redirect_greatand(t_redir *redir) int fdold; int fdnew; - (void)redir; - (void)fdold; - (void)fdnew; - DG("redir greatand"); - /* - if (redir->close) + if (ft_strcmp(redir->word, "-")) { close(redir->n); return (0); } - if (redir->word.fd == redir->n) - return (0); - if (redir->word.fd > 9) - return (bad_fd(redir->word.fd)); - fdold = redir->word.fd; + if (!ft_stris(redir->word, ft_isdigit)) + { + ft_dprintf(2, "%s: %s: can only be digits", SHELL_NAME, redir->word); + return (1); + } + fdold = ft_atoi(redir->word); fdnew = redir->n; + if (fdold == fdnew) + return (0); + if (fdold > 9) + return (bad_fd(fdold)); if (fd_is_valid(fdold)) dup2_close(fdold, fdnew); else return (bad_fd(fdold)); - */ return (0); } diff --git a/42sh/src/exec/redirect_lessand.c b/42sh/src/exec/redirect_lessand.c index 0442941d..0c3b5982 100644 --- a/42sh/src/exec/redirect_lessand.c +++ b/42sh/src/exec/redirect_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */ -/* Updated: 2017/03/05 18:13:11 by ariard ### ########.fr */ +/* Updated: 2017/03/05 19:43:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,28 +17,25 @@ int redirect_lessand(t_redir *redir) int fdold; int fdnew; - (void)redir; - (void)fdold; - (void)fdnew; - /* - if (redir->close) + if (ft_strcmp(redir->word, "-")) { close(redir->n); return (0); } - if (redir->word.fd == redir->n) - return (0); - if (redir->word.fd > 9) - return (bad_fd(redir->word.fd)); - fdold = redir->word.fd; - fdnew = redir->n; - if (fd_is_valid(fdold)) + if (!ft_stris(redir->word, ft_isdigit)) { - dup2(fdold, fdnew); - close(fdold); + ft_dprintf(2, "%s: %s: can only be digits", SHELL_NAME, redir->word); + return (1); } + fdold = ft_atoi(redir->word); + fdnew = redir->n; + if (fdold == fdnew) + return (0); + if (fdold > 9) + return (bad_fd(fdold)); + if (fd_is_valid(fdold)) + dup2_close(fdold, fdnew); else return (bad_fd(fdold)); - */ return (0); } diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index bd79af4d..44a5299f 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ -/* Updated: 2017/03/05 19:30:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 19:31:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */