maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
redirect_in.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* redirect_in.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: dmdemirk <dmdemirk@student.42london.c +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/07/11 14:32:40 by dmdemirk #+# #+# */
9/* Updated: 2024/07/11 14:53:27 by dmdemirk ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "tokens.h"
14#include "shell.h"
15#include "redirection.h"
16#include "execute.h"
17#include <string.h>
18#include <sys/wait.h>
19
20int redirect_in(t_ast *node, t_ms_data *data);
21
22/*
23 ! FIX
24 wc < input.txt - work fine
25 wc -l < input.txt - not work (:bad address error)
26 */
27
38int redirect_in(t_ast *node, t_ms_data *data)
39{
40 pid_t pid;
41
42 pid = fork();
43 if (pid == -1)
44 return (1);
45 if (pid == 0)
46 {
47 data->std_in = open_file(node->right, "<");
48 if (data->std_in == -1)
49 return (1);
50 execute_ast(node->left, data);
51 exit(0);
52 }
53 waitpid(pid, &data->exit_status, 0);
54 return (0);
55}
int execute_ast(t_ast *node, t_ms_data *data)
execute Abstract Syntax Tree
Definition execute.c:38
int redirect_in(t_ast *node, t_ms_data *data)
redirection input in context of executing AST
Definition redirect_in.c:38
int open_file(t_ast *node, char *direction)
open file in the context of redirection
Definition utils.c:34
Definition tokens.h:50
struct s_ast * right
Definition tokens.h:54
struct s_ast * left
Definition tokens.h:53
int exit_status
Definition shell.h:30
int std_in
Definition shell.h:26