-
Notifications
You must be signed in to change notification settings - Fork 0
/
minishell.h
executable file
·302 lines (252 loc) · 6.88 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fflores <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/26 20:01:30 by fflores #+# #+# */
/* Updated: 2021/01/26 20:02:35 by fflores ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <fcntl.h>
# include <string.h>
# include <errno.h>
# include <sys/syslimits.h>
# include <sys/stat.h>
# include "./libft/libft.h"
# include "./get_next_line/get_next_line.h"
# include "./ft_printf/ft_printf.h"
# define PATHINPROMPT 1
# define SHELL_PROMPT "minishell$ "
# define TEST 0
extern int g_sigint_flag;
extern int g_last_pid;
extern int g_last_exit_status;
typedef struct s_token
{
char *data;
struct s_token *next;
} t_token;
typedef struct s_command
{
int is_found;
char *correct_path;
char **argv;
short is_append;
char *out_file_name;
char *input_file_name;
short is_pipe;
int file_fd_in;
int file_fd_out;
} t_command;
typedef struct s_shell
{
char **path;
t_command *command;
char *cwd;
char **env;
int env_len;
char **buildin_commands;
int fd_stdin;
int fd_stdout;
int fd_pipe[2];
int parsing_error;
char *last_var;
t_token *tokens;
char *line;
char *buf;
} t_shell;
typedef struct s_quotes
{
int sq;
int dq;
} t_quotes;
/*
** split_env_variable.c
*/
char *get_var_name(t_shell *shell, char *str);
char *get_var_value(t_shell *shell, char *str);
/*
** pwd.c
*/
void pwd(t_shell *shell);
/*
** echo.c
*/
void echo(char **args);
/*
** env.c
*/
void print_env(t_shell *shell);
/*
** exit.c
*/
void exit_shell(t_shell *shell, int exit_status);
void close_shell(t_shell *shell);
/*
** unset.c
*/
void unset(t_shell *shell, t_command *command);
int unset_valid(char *name);
/*
** export.c
*/
void export(t_shell *shell, t_command *command);
int export_valid(char *name);
/*
** cd.c
*/
void cd(t_shell *shell, char **args);
int check_env_exist(t_shell *shell, char *variable);
void add_env(t_shell *shell, char *variable, char *value);
void upd_env(t_shell *shell, char *variable,
char *new_value);
/*
** parse_line.c
*/
t_token *parse_line(t_shell *shell, char *line);
void free_tokens(t_shell *shell);
int is_buildin_command(t_shell *shell, char *command);
char *skip_whitespaces(char *str);
void print_error(char *error_source, char *error_msg,
int new_line);
/*
** readline.c
*/
int read_line_from_stdin(t_shell *shell, char **line);
int shell_gnl(t_shell *shell, char **line);
int shell_get_line(t_shell *shell, char **temp_line,
char **line);
int shell_read_fd(t_shell *shell, char **line,
char **temp_line, char *buf);
/*
** signals.c
*/
void set_signals_handlers(void);
/*
** execute.c
*/
void execute(t_shell *shell, t_command *command);
int wait_for_process(void);
int run_buildin(t_shell *shell, t_command *command);
/*
** expand_str.c
*/
int expand_str(t_shell *shell, t_token *token, char *data);
/*
** parse_tokens.c
*/
t_token *parse_tokens(t_shell *shell, t_token *token);
int is_escape_char(char ch);
/*
** check_command.c
*/
void check_correct_command(t_shell *shell,
t_command *command, char *data);
/*
** main.c
*/
void free_command(t_shell *shell);
/*
** check_tokens.c
*/
int check_tokens(t_shell *shell, t_token *tokens);
/*
** expand_utils.c
*/
char *arg_type_num(char **var_name, t_shell *shell,
char **new_data, char **data);
char *arg_type_alpha(char **var_name, t_shell *shell,
char **new_data, char **data);
/*
** expand_variable.c
*/
int expand_variable(t_shell *shell, char **new_data,
char **data);
/*
** errors.c
*/
void print_error(char *error_source, char *error_msg,
int new_line);
/*
** fork_utils.c
*/
int wait_for_process(void);
int set_fd_in(t_shell *shell, t_command *command);
int set_fd_out(t_shell *shell, t_command *command);
void child_process(t_shell *shell, t_command *command);
void parent_process(t_shell *shell, int pid);
/*
** parse_line_utils.c
*/
char *skip_whitespaces(char *str);
int skip_backslashed(t_token *token, char **line, int i);
t_token *token_init(t_shell *shell, size_t len);
t_token *create_next_token(t_shell *shell, t_token *token,
char *line);
void remove_last_token(t_shell *shell);
/*
** parse_line_utils2.c
*/
int process_single_quote(t_quotes *quote, t_token *token,
char **line, int i);
int process_double_quote(t_quotes *quote, t_token *token,
char **line, int i);
int process_operators(t_shell *shell, t_token **token,
char **line, int i);
int process_whitespaces(t_shell *shell, t_token **token,
char **line, int i);
int process_out_operator(t_shell *shell, t_token **token,
char **line, int i);
int check_quotes_error(int single_q, int double_q,
t_shell *shell);
void ambiguous_redirect_error(t_shell *shell);
void open_file_error(t_shell *shell, char *filename);
t_token *get_next_token(t_token *token);
/*
** utils_1.c
*/
char *get_from_env(char *to_find, char **env);
void get_env(t_shell *shell, char **env);
void get_buildin_commands(t_shell *shell);
t_shell *init_shell(char **env);
void print_prompt(void);
/*
** utils_2.c
*/
void get_shell_cwd(t_shell *shell);
char *get_prompt(t_shell *shell);
int get_array_len(char **array);
void get_shell_path(t_shell *shell, char **env);
void upd_shell_path(t_shell *shell);
/*
** utils_3.c
*/
int is_escape_char(char ch);
/*
** utils.c
*/
void remove_env(t_shell *shell, char *variable);
/*
** free_shell.c
*/
void free_buf(t_shell *shell);
void nested_free(char **array);
void free_tokens(t_shell *shell);
static void free_shell(t_shell *shell);
/*
** check_command_utils.c
*/
int is_builtin_command(t_shell *shell, char *command);
int prepath_check(t_shell *shell, t_command *command,
char *data);
int check_buildin_abs_rel(t_shell *shell,
t_command *command,
char *data, int ret);
#endif