-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminishell.h
More file actions
284 lines (250 loc) · 8.66 KB
/
minishell.h
File metadata and controls
284 lines (250 loc) · 8.66 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mkhavari <mkhavari@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/03 17:53:51 by asemykin #+# #+# */
/* Updated: 2025/07/08 19:31:31 by mkhavari ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include "libft.h"
# include <dirent.h>
# include <errno.h>
# include <fcntl.h>
# include <readline/history.h>
# include <readline/readline.h>
# include <signal.h>
# include <stdbool.h>
# include <stdio.h>
# include <stdlib.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <termios.h>
# include <time.h>
# include <unistd.h>
# ifndef ECHOCTL
# define ECHOCTL 0001000
# endif
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 1
# endif
// extern volatile sig_atomic_t g_received_signal;
typedef enum node_type_e
{
NODE_COMMAND,
NODE_PIPE,
NODE_SEQUENCE_AND,
NODE_SEQUENCE_OR,
NODE_REDIRECT_OUT,
NODE_REDIRECT_OUT_APPEND,
NODE_REDIRECT_IN,
NODE_REDIRECT_HEREDOC,
NODE_SUBSHELL,
NODE_VAR_ASSIGNMENT,
NODE_VAR_EXPANSION,
NODE_QUOTED_STRING,
NODE_SEMI,
} t_node_type;
// each enum represent a ruke in BNF
typedef struct ast_node
{
t_node_type type;
struct ast_node *left;
struct ast_node *right;
char **args;
char **filename;
} t_ast;
typedef struct env_list
{
char *name;
char *val;
struct env_list *next;
} t_env_list;
typedef struct env_s
{
t_env_list *env;
int exit_status;
char *last_arg;
char **append_doc;
int exit_run;
} t_env_s;
typedef struct quote_helper_t
{
int i;
int j;
int x;
int k;
bool in_single;
bool in_double;
char *var_name;
char *value;
char *result;
} t_qh;
typedef struct filltoken_helper_t
{
int i;
int count;
} t_fth;
typedef struct heredoc_helper_t
{
int i;
int j;
char *var_name;
char *value;
int x;
int k;
} t_hdh;
int ft_and_q(char *input, t_env_s *env_s);
t_ast *parse(char **tokens_set, t_env_s *env_s);
t_ast *parse_cmd_line(char ***tokens, t_env_s *env_s);
char **tokenize(char *input, t_env_s *env_s);
t_ast *command_compound(char ***tokens, t_env_s *env_s);
t_ast *command(char ***tokens, t_env_s *env_s);
t_ast *subshell(char ***tokens, t_env_s *env_s);
t_ast *parse_pipe_cmd(char ***tokens, t_env_s *env_s);
t_ast *simple_cmd(char ***tokens, t_env_s *env_s);
t_ast *parse_redirection(char ***tokens, t_env_s *env_s);
t_ast *make_node_redir(char ***tokens, t_node_type type,
t_env_s *env_s);
t_ast *make_node_doc(char ***tokens, t_node_type type,
t_env_s *env_s);
void free_double_ptr(char **arr);
char **make_token(char **tokens);
int count_tokens(char *input);
char **fill_tokens(char *input, t_env_s *env_s);
int is_space(char c);
int delim_token(char ***token, char *input, int *count,
t_env_s *env_s);
void ft_child(int fd[]);
int is_symbol_token(const char *token);
int is_symbol_sub(const char *token);
int is_redirection(char *token);
int is_word(char *token);
void print_ast(t_ast *root, int level);
void free_array(char **arr);
/* ------------>execution part */
char **open_new_promt(t_env_s *env_s, char **filename);
char *executable(char *cmd, t_env_s *env_s);
int ft_execute(t_ast *root, t_env_list **env_table);
int exe_ast(t_ast **root, t_env_s *env_s);
int exe_pipe(t_ast *root, t_env_s *env_s);
int exe_simple_cmd(t_ast *node, t_env_s *env_s);
int exe_built_in(char **arg, t_env_s *env_s);
int ft_echo(char **args, t_env_s *env_s);
int exe_redirections(t_ast *node, t_env_s *env_s);
int exe_here_doc(t_ast *node, t_env_s *env_s);
int exe_redir_in(t_ast **node, t_env_s *env_s);
/* ------------------------evaluation part */
int is_built_in(char *args);
int validate_export(char **args);
int is_type_redirection(t_ast *root);
t_ast *creat_ast_node(char **args, char **filename,
t_node_type type);
void add_last_arg(char **args, t_env_s *env_s);
t_ast *ft_astlast(t_ast *ast);
void ft_astadd_left(t_ast **ast, t_ast *new);
t_ast *list_redirects(t_ast *root, t_env_s *env_s);
void free_list(t_ast *lst);
int is_not_sym_char(char c);
int is_not_word(char *token);
int get_in_child(char **input, t_env_s *env_s);
int is_tail_char(char c);
int is_only_whitespace(const char *str);
// rermember here anatolij
char **ft_get_var(char **args);
int control(char *token);
int control2(char *token);
int all_s(char *token);
int redir(char *token);
char **validate_seq(char **tokens, t_env_s *env_s);
void free_func(char ***str1, char ***str2, char **str3);
char **return_filename(char *str, char **filename, int fd[]);
int write_in_pipe(t_env_s *env_s, char *co, int fd[],
char *input);
int error_input(char *co, int fd[], char *s);
/* -------------------- env */
t_env_list *init_env(char **environ);
int update_env(t_env_s *env_s, char **args);
t_env_list *lst_last(t_env_list *env_list);
t_env_list *create_node(char **key_value);
int ft_env(t_env_list *env_table);
char **build_envp(t_env_list *env_table);
void modify_env(t_env_list **env_table, char **key_value);
void *add_env(t_env_list **env_tbl, char **k_v);
int del_env(t_env_list **env_tbl, char **args);
char **ft_get_var(char **args);
char **ft_split_export(char *str, char c);
int exist_in_env(t_env_list *temp_env, char **key_val);
int error_export(char *arg, t_env_s *env_s, char **args);
char *get_env(t_env_list *env_tbl, char *var_name);
char *get_exit_val(char *arg, t_env_s *env_s);
char *trim_open_quotes(const char *input);
char *convert_all_env_heredoc(const char *input, t_env_s *env_s);
char *convert_to_env_dsquotes(const char *input, t_env_s *env_s);
void convert_env_sdquotes_free(char **args, t_env_s *env_s);
int is_file(const char *arg);
int is_directory(const char *arg);
char **remove_empty_token(char **tokens, t_env_s *env_s);
int redir_out_child(t_ast *list, t_ast **cur);
int exe_redirect_state(t_ast *root, t_env_s *env_s);
void free_ast(t_ast *root);
void free_env(t_env_s *env_s);
void free_env_list(t_env_list **env);
void free_minishell(t_ast **root, t_env_s *env_s, char ***tokens,
char **input);
int check_directorys(t_ast *node);
int exe_subshell(t_ast **root, t_env_s *env_s);
int ft_exe_cd(char **args, t_env_list **env_tbl);
int ft_exit(char **args, t_env_s *env_s);
void update_shlvl(t_env_s *env_s);
int tokenize_parsing_execute(t_ast **root, t_env_s *env_s,
char ***tokens, char **input);
int ft_readline_setup(t_ast **root, t_env_s *env_s,
char ***tokens, char **input);
void disable_echoctl(void);
void ft_chl(int fd[], char **filename, t_env_s *env_s);
int is_symbol_filltoken(const char t_char);
void handle_general_token(char *input, int *i, int *count,
char **tokens);
int is_simple_symbol(char c);
void handle_simple_symbol(char *input, int *i, int *count,
char **tokens);
int ss_qoutes(char *input, char **tokens);
int dd_qoutes(char *input, char **tokens);
char *get_env(t_env_list *env_tbl, char *var_name);
char *get_exit_val(char *arg, t_env_s *env_s);
void write_to_result(t_qh *qvar);
int set_opening_quotes(const char input, t_qh *qvar);
int init_value(char ***tmp_token, char ***tokens, int *i,
int *j);
char *get_first_delim(char ***token, char *input, int *count);
char *contetn(int j, char *input, char *delims);
int syntax_err(char *input, t_env_s *env_s);
int init_main_values_null(int ac, char **av, char **input);
char *set_tmp(char **tmp_token, char **tokens, int i, int j);
int ft_strcmp(const char *s1, const char *s2);
int start_content(char ***tokens);
int detect_closer(char ***tokens, char *f_d);
// create_node.c
// evals.c <- remove
// evals_1.c
// evals_2.c
// evals_3.c
// utils3.c
// utils2.c
// exe_built_in_2.c
// exe_built_in_3.c
// exe_redirections_2.c
// exe_redirections_3.c
// exe_simple_cmd_2.c
// free_funcs.c
// exe_subshell.c
// exe_here_doc_2.c
// main_exe.c
// parse_doc2.c
#endif