diff options
Diffstat (limited to 'src/eval')
| -rw-r--r-- | src/eval/cmd.c | 19 | ||||
| -rw-r--r-- | src/eval/eval.c | 10 | ||||
| -rw-r--r-- | src/eval/redir.c | 30 |
3 files changed, 51 insertions, 8 deletions
diff --git a/src/eval/cmd.c b/src/eval/cmd.c index a35a73d..d107ce2 100644 --- a/src/eval/cmd.c +++ b/src/eval/cmd.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/14 10:41:31 by charles #+# #+# */ -/* Updated: 2020/10/09 14:31:45 by cacharle ### ########.fr */ +/* Updated: 2020/10/10 11:32:36 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,14 @@ pid_t g_child_pid = -1; +/* +** \brief Function wrapped in fork_wrap. +** If it's a builtin, call the coresponding builtin function +** Otherwise call execve +** \param param Parameters of this function +** \return The status of the builtin or the error code of execve +*/ + static int st_wrapped_cmd(t_fork_param_cmd *param) { int status; @@ -36,6 +44,15 @@ static int st_split_destroy_ret(int ret, char **strs) return (ret); } +/* +** \brief Evaluate a command +** \param fds Input/output file descriptor of the command +** \param env Environment +** \param ast Comment AST node +** \return EVAL_FATAL no allocation error, +** the status of the runned command otherwise +*/ + int eval_cmd(int fds[2], t_env env, t_ast *ast) { t_fork_param_cmd param; diff --git a/src/eval/eval.c b/src/eval/eval.c index 032fc30..f78e8ee 100644 --- a/src/eval/eval.c +++ b/src/eval/eval.c @@ -6,7 +6,7 @@ /* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/09/13 20:38:06 by charles #+# #+# */ -/* Updated: 2020/10/09 16:12:27 by cacharle ### ########.fr */ +/* Updated: 2020/10/10 11:28:12 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,11 +21,9 @@ static int st_replace(int oldfd, int newfd) /* ** \brief Wrap a function in a fork -** \param fds fork read/write file descriptors -** \param passed param of the wrapped function -** \param wrapped function to wrap -** \param child_pid Pointer where to store the child pid -** or NULL if the child should be waited +** \param fds Fork read/write file descriptors +** \param passed Param of the wrapped function +** \param wrapped Function to wrap ** \return The child status code or EVAL_FATAL on error */ diff --git a/src/eval/redir.c b/src/eval/redir.c index 9d88b29..8c154d5 100644 --- a/src/eval/redir.c +++ b/src/eval/redir.c @@ -6,12 +6,21 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/15 11:05:34 by charles #+# #+# */ -/* Updated: 2020/10/09 14:38:16 by cacharle ### ########.fr */ +/* Updated: 2020/10/10 11:40:16 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "eval.h" +/* +** \brief Open a file and close the previous opened file +** if there was one already setup +** \param filename File to open +** \param fd File descriptor to set or replace +** \param oflag Flag passed to the open function +** \return 0 on success, the error status code otherwise +*/ + static int st_open_replace(char *filename, int *fd, int oflag) { if (fd == NULL) @@ -31,6 +40,15 @@ static int st_open_replace(char *filename, int *fd, int oflag) return (0); } +/* +** \brief Call st_open_replace with different argument +** according to the redirection type +** \param filename Name of the file to open +** \param fds Input/output file descriptors +** \param tag Token tag of the redirection +** \return Whatever st_open_replace returns +*/ + static int st_open_replace_dispatch(char *filename, int fds[2], enum e_tok tag) { int *fd; @@ -64,6 +82,16 @@ static int st_tok_lsts_destroy_ret( return (ret); } +/* +** \brief Extract redirections from tokens +** \param redirs List of token of redirection, in the format +** redir token -> n sticked string token -> redir token -> ... +** \param env Environement need for interpolation of redirection filename +** \param fds Input/output file descriptor to setup +** \return 0 on success, +** the command evaluation error status code otherwise +*/ + int redir_extract(t_tok_lst **redirs, t_env env, int fds[2]) { t_tok_lst *after; |
