aboutsummaryrefslogtreecommitdiff
path: root/include/eval.h
blob: bde0cd7f1aa4d2a80d60f88d7a7b8173a2481a22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   eval.h                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: charles <charles@student.42.fr>            +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/01 17:05:30 by charles           #+#    #+#             */
/*   Updated: 2020/06/17 15:49:49 by nahaddac         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef EVAL_H
# define EVAL_H

/*
** \file   eval.h
** \brief  Evaluation module
*/

# include "minishell.h"
# include "ast.h"

/*
** \brief        Evaluation state struct
*/

typedef struct
{
	t_path		path;
	t_env		env;
}				t_eval_state;

/*
** \brief      Evaluation status struct
*/

typedef struct	s_eval_status
{
	char		*err;
	int			status;
}				t_eval_status;

typedef struct
{
	t_eval_state	*state;
	t_op			*op;
	int fd_in;
	int fd_out;
}					t_fork_param_line;

typedef struct
{
	char			*exec_path;
	char			**argv;
	t_env			env;
	t_builtin_func	builtin;
}					t_fork_param_cmd;

#define MS_NO_FD -2

/*
** eval.c
*/

int				eval(int fd_in, int fd_out, t_eval_state *state, t_ast *ast);

/*
** exec.c
*/

bool			exec_is_path(char *path_str);
bool			exec_is_valid(char *exec_path);
char			*exec_search_path(t_path path, char *path_var, char *exec_name);

enum			e_error
{
	ERROR_AMBIGUOUS_REDIR,
	ERROR_OPEN,
	ERROR_CMD_NOT_FOUND,
	ERROR_SYNTAX,
};

typedef struct
{
	enum e_error	id;
	int				status;
	char			*msg;       // if NULL call strerror
	// char			*basename;
}					t_error;

/*
** error.c
*/

void			error_eval_put(enum e_error id, char *unexpected);

/*
** cmd.c
*/

int				eval_cmd(t_env env, t_path path, t_ast *ast);

/*
** redir.c
*/

bool			redir_extract(t_ftlst *redirs, t_env env, int *fd_in, int *fd_out);

#endif