-
Notifications
You must be signed in to change notification settings - Fork 1
/
minishell.h
210 lines (176 loc) · 5.01 KB
/
minishell.h
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gfernand <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/25 16:01:46 by gfernand #+# #+# */
/* Updated: 2023/12/26 17:34:44 by gfernand ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# define NORMAL 0
# define HEREDOC 1
# define APPEND 1
# define PARENT 0
# define CHILD 1
# define RETVAL 1
# define ERR_MEMORY "Error allocating memory\n"
# define ERR_PIPES "Error creating pipe\n"
# include <dirent.h>
# include <fcntl.h>
# include <readline/readline.h>
# include <readline/history.h>
# include <stdlib.h>
# include <unistd.h>
# include <sys/wait.h>
# include <stdlib.h>
# include <unistd.h>
# include <termios.h>
# include <limits.h>
# include <sys/wait.h>
# include "libft.h"
# define ENTRADA_MS "\033[93mminishell > \033[0;0m"
extern int g_signal;
typedef struct s_red
{
int num;
char **file;
int *type;
} t_red;
typedef struct s_cmdred
{
t_red *inred;
t_red *outred;
} t_cmdred;
typedef struct s_bridge
{
t_cmdred *redirect;
char ***commands;
int n_cmds;
char **m_env;
int ret;
} t_bdg;
typedef struct s_here
{
int count;
int here_pipe[2];
} t_here;
typedef struct s_exec
{
pid_t *pid;
int **pipe;
int **in_out;
t_here *here;
char **paths;
t_bdg *bridge;
} t_exec;
typedef struct s_parse
{
char **env;
char *r_env;
int nb_env;
int l_d;
int a;
char *rdirect;
int start_rdir;
int n_ip;
int n_op;
int locate_ip_dir;
int locate_op_dir;
t_bdg *bridge;
} t_parse;
void rl_replace_line(const char *text, int clear_undo);
/* PARSE */
t_bdg *start_parse(char *input, char **m_env);
int check_rps(t_bdg *bridge, char *input, char c);
int check_input(char *input);
char **split_quote(const char *s, char c);
int quote(const char *s, int i);
char *remove_quotes(const char *s);
/* ENV */
char *environments(t_parse *parse, char *s);
int count_env(char *s);
char *cut_and_get_env(t_parse *parse, char *s, int i);
int env_to_str(t_parse *parse, char *s, int i, int e);
int type_of_quote(char *str, int i, int quote);
/* REDIRECTIONS */
char **fill_redirections(t_parse *parse, t_bdg *bridge, char **s);
void count_redirections(t_parse *parse, char *s);
int take_redirection(t_parse *parse, char **s, int i, int j);
char **cut_rdir_in_cmds(t_parse *parse, char **s, int i, int j);
/* SIGNALS */
void heredoc_signals(void);
void input_signals(void);
void process_signals(void);
void ctr(void);
char *worth_part(char *s);
///// EXECUTION /////
//execution.c
void execution(t_bdg *bridge);
//execution_utils.c
void close_all(t_exec *exec);
char *last_pwd(char *arg, t_bdg *bridge);
char *parse_chdir(char *arg, t_bdg *bridge);
int check_dir(char *chdirectory, char *arg);
void check_access(char *file);
//child_process.c
void child_process(t_exec exec, int num);
//set_redirections.c
void set_redirections(t_exec *exec, int num);
//init_utils.c
void init_heredoc(t_exec *exec, t_bdg *bridge);
void init_in_out(t_exec *exec, t_bdg *bridge);
///// BUILTINS /////
//built_ins.c
int is_parent_builtin(char *commands);
int is_builtin(char *commands);
void builtins(t_bdg *bridge, char **commands, int type);
//cd.c
int cd(t_bdg *bridge, char **commands);
char *get_pwd(void);
//pwd.c
int pwd(void);
//unset.c
int unset(t_bdg *bridge, char **commands);
void b_delete(char ***m_env, char *key);
//export.c
int b_export(t_bdg *bridge, char **commands);
void add(char ***m_env, char *str, int type);
//env_sort.c
void env_sorted(t_bdg *bridge);
//echo.c
int echo(char **commands);
//exit.c
int b_exit(char **commands, int type);
///// ENVIROMENT /////
//enviroment.c
int env(char **m_env);
char **dup_env(char **envp);
char *getenv_value(char **m_env, char *key);
int env_len(char **env);
void free_env(char **env);
//return_val.c
void set_ret_val(t_bdg *bridge, int val);
int get_ret_val(char **m_env);
///// ERRORS /////
//errors.c
void error_msg(char *msg, int val);
void exit_msg(char *msg, int val);
//// LIBFT /////
int ft_atoi(const char *str);
char *ft_itoa(int n);
char **ft_split(const char *s, char c);
char *ft_strjoin(char const *s1, char const *s2);
int ft_strncmp(char const *s1, char const *s2, size_t n);
size_t ft_strlen(char const *str);
char *ft_strdup(const char *src);
int ft_isalpha(int c);
void ft_putstr_fd(char *s, int fd);
void ft_putchar_fd(char c, int fd);
//// HERE_DOC ////
void load_heredoc(t_exec *exec);
int count_heredocs(t_red *red);
#endif