-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminishell.h
296 lines (251 loc) · 8.79 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emansoor <emansoor@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/08 13:21:33 by sataskin #+# #+# */
/* Updated: 2024/07/23 10:38:35 by emansoor ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include <stdio.h>
# include <unistd.h>
# include <stdlib.h>
# include <sys/wait.h>
# include <readline/readline.h>
# include <readline/history.h>
# include "libft/libft.h"
# include <signal.h>
# include <termios.h>
# include <fcntl.h>
extern int g_sig;
# define PINK "\001\e[95m\002"
# define PROMPT "MINISHELL💖~$ "
# define HDOC "> "
# define RESET "\001\e[0m\002"
# define READ_END 0
# define WRITE_END 1
typedef struct s_cmds
{
char **command;
char *path;
char *infile_name;
char **outfile_name;
char *heredoc;
int c_pid;
int fd_infile;
int *fd_outfile;
int id;
int commands;
int builtin;
int append;
int valid;
int exit_status;
struct s_cmds *next;
} t_cmds;
typedef struct s_toks
{
char *content;
int file;
int command;
int argument;
int pipe;
int in_redir;
int out_redir;
int append;
int heredoc;
int heredoc_delimiter;
int id;
struct s_toks *next;
} t_toks;
typedef struct s_env
{
char *key;
char *value;
int equal;
int index;
struct s_env *next;
} t_env;
typedef struct s_mini
{
t_env *env;
t_cmds *cmds;
char **env_p;
int shlvl;
int saved_stdin;
int saved_stdout;
int exit_code;
int syntax;
char *pwd;
char *oldpwd;
} t_mini;
/* PARSING */
char *ft_strtok(char *str);
void token_cleanup(t_mini *shell, t_toks **tokens);
void expand_dollar(t_mini *shell, t_toks **token, int *index,
int in_doubles);
t_toks *checker(char *input, t_mini *shell);
void ft_lstadd_back_toks(t_toks **lst, t_toks *new);
void ft_lstclear_toks(t_toks **lst);
t_toks *ft_lstnew_toks(char *content);
int ft_lstsize_toks(t_toks *lst);
t_toks *ft_lstlast_toks(t_toks *lst);
void identify_delims(t_toks **tokens);
void identify_heredoc(t_toks **tokens);
void recognize_file(t_toks **tokens);
void identifier(t_toks **tokens);
void identify_commands(t_toks **tokens);
void identify_args(t_toks **tokens);
t_cmds *ft_lstnew_pars(int index);
int ft_lstsize_pars(t_cmds *lst);
t_cmds *ft_lstlast_pars(t_cmds *lst);
void ft_lstadd_back_pars(t_cmds **lst, t_cmds *new);
void ft_lstclear_pars(t_cmds **lst);
int in_quotes(char *token, size_t index);
void no_blanks_cleanup(t_toks **tokens, t_mini *shell);
void add_indexes(t_toks **tokens);
int quote_check(char *token);
void initialize_token(t_toks *new_node);
int parser(char *rl, t_mini *shell);
int struct_sum(t_toks *token);
void build_command_list(t_toks **tokens, t_mini *shell);
void add_builtin_info(t_cmds **cmds);
void add_cmds_info(t_cmds **cmds);
char **ft_splitstr(char const *s, char *c);
void validate_commands(t_mini *shell, t_cmds *cmd);
int validate_command(char *command, char **paths);
char *full_path(char *path, char *command);
void fill_cmd_info(t_cmds **cmds, t_toks **tokens);
void fill_redir_info(t_mini *shell, t_cmds **cmds, t_toks **tokens);
int syntax_check(t_toks *token, t_cmds **cmds, t_mini *shell);
int syntax_checker(t_cmds **cmds, t_cmds *cmd,
t_toks *token, t_mini *shell);
void sure_pipe(t_toks *token);
void sure_inredir(t_toks *token);
void sure_outredir(t_toks *token);
void sure_append(t_toks *token);
void sure_hredir(t_toks *token);
int redir_found(t_toks *token, int type);
int doubredir_found(t_toks *token, int type);
void check_append(t_toks *token, t_toks *next);
void add_pipe_info(t_toks *token);
void add_inredir_info(t_toks *token);
void add_outredir_info(t_toks *token);
void add_append_info(t_toks *token);
void add_hredir_info(t_toks *token);
int split_by_delim(t_toks **tokens, t_toks *token, char delim, char *divid);
int identify_expandable(char *token);
t_env *key_finder(char *var, t_env **envs);
void build_list_delimstr(t_toks **addition, char *content,
char **new_tokens, char *delim);
void build_list(t_toks **addition, char *content,
char **new_tokens, char delim);
void strcpy_without_quotes(char *to, char *from, int fstquote, int sqnquote);
int end_quote_index(t_mini *shell, t_toks **token, int *index);
int get_index(char **array);
int copy_filenames(char **to, char **from, char *new_file, int index);
void parser_error(char *str);
int add_heredoc_info(t_mini *shell, t_cmds *cmd, t_toks *token);
int update_heredoc_info(t_mini *shell, t_cmds *cmd, t_toks *token);
t_toks *add_infile_info(t_mini *shell, t_cmds *cmd, t_toks *token,
int heredoc_flag);
t_toks *add_outfile_info(t_mini *shell, t_cmds *cmd, t_toks *token,
int append_flag);
void expand_exit_code(t_toks **tokens, t_mini *shell);
int identify_exitcode(t_mini *shell, t_toks **token, int *index,
int in_doubles);
void trim_token(t_toks **token);
int check_for_previous_cmds(t_toks **tokens, int index);
int syntax_scan(t_mini *shell, t_toks **tokens);
int is_delimiter(char *str);
/* INPUT VALIDATION */
void open_files(t_mini *shell, t_cmds **cmds);
void close_files(t_cmds **cmds);
int is_dir(char *command);
void print_dirmsg(t_cmds *cmd, t_mini *shell);
void dot_cmd(t_mini *shell, t_cmds *cmd);
void nonexistent_cmd(t_mini *shell, t_cmds *cmd);
void heredoc(t_mini *shell, t_cmds *cmd);
void open_with_correct_flags(t_cmds *cmd, int index);
void clear_temp(t_cmds **cmds);
/* FOR CREATING ENV */
void ft_lstadd_back_mini(t_env **lst, t_env *new);
char *get_key(t_mini *shell, char *str);
char *get_value(t_mini *shell, char *envp);
void add_input(t_mini *shell, t_env *node, char *envp);
t_env *add_env(t_mini *shell, char **envp);
/* FOR PANIC */
void free_env(t_env *env);
void ft_freearray(char **array);
void free_data(t_mini *shell, char *message);
void panic(t_mini *shell, int error_code);
/* FOR SIGNALs */
void par_sig_handler(int sig);
void set_signal(int mode);
void rl_replace_line(const char *text, int clear_undo);
void rl_redisplay(void);
void set_term(int num);
/* FOR EXPORT */
void print_export(t_env *env);
void export(t_mini *shell, t_cmds *cmd);
int lstsize(t_env *lst);
t_env *find_next(t_env *env);
void change_index(t_env **env);
void update_index(t_env **env);
void edit_env(t_mini *shell, t_env *node, char *str);
void new_env(t_mini *shell, t_env **env, char *str);
/* FOR UNSET */
void ft_realunset(t_env **env, char *str);
void ft_unset(t_mini *shell, t_cmds *cmd);
/* CHECKING FOR VALID KEY */
int validity(char *str, char *function);
/* FOR PWD */
void pwd(t_mini *shell, t_cmds *cmd);
/* FOR ENV */
void ft_env(t_mini *shell, t_cmds *cmd);
//char **ltoa(t_env *env);
char **ltoa(t_env **env);
/* FOR CD */
void ft_cd(t_mini *shell, t_cmds *cmd);
void set_data(t_mini *shell, char **envp);
/* BUILTIN ERROR */
void cd_error(t_mini *shell, char *test, char *path);
void cd_more(t_mini *shell, char *message);
void childish(t_mini *shell);
/* BUILTIN UTILS */
t_env *retrieve_key(t_env *env, char *str);
/* FOR EXIT */
void real_exit(t_mini *shell, char *str, int i);
void print_toomany(t_mini *shell);
void print_letter(t_mini *shell, char *str);
int check_num(char *str);
void now_exit(t_mini *shell, char **str);
/* FOR ECHO */
void ft_echo(t_mini *shell, t_cmds *cmds);
/* FOR TESTING */
void print_cmd_info(t_cmds **cmds);
/* FOR EXECUTION */
void check_builtin(t_mini *shell, t_cmds *cmd);
void run_commands(t_mini *shell);
void run_multiple(t_mini *shell, t_cmds *cmds);
void execute(t_mini *shell, t_cmds *cmd);
void first_command(t_mini *shell, t_cmds *cmd);
void last_command(t_mini *shell, t_cmds *cmd);
void run_a_single_cmd(t_mini *shell, t_cmds *cmd);
void minishell(t_mini *shell);
int safe_to_run(t_cmds *cmds);
void restore_fds(t_mini *shell);
void set_pipes(t_mini *shell, t_cmds *cmd);
void run_builtin(t_mini *shell, t_cmds *cmd);
int duplicate_fds(t_cmds *cmd);
void exit_code(t_mini *shell, int code, int sig);
void update_exitcode(t_mini *shell, t_cmds *cmds);
void write_exit(t_mini *shell, t_cmds *cmd);
void free_and_exit(t_mini *shell, char *message);
int funtastic(t_mini *shell);
void heredoc_typer(t_env *env, char *str, int fd);
t_env *hdoc_key(char *str, int index, t_env *env);
#endif