-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminibash.h
executable file
·242 lines (219 loc) · 7.06 KB
/
minibash.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
#ifndef MINIBASH_H
# define MINIBASH_H
# include <term.h>
# include <unistd.h>
# include <string.h>
# include <curses.h>
# include <stdlib.h>
# include <stdio.h>
# include <termcap.h>
# include <strings.h>
# include <errno.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <sys/stat.h>
# include <fcntl.h>
# define ZERO 0b00000000
# define PIPE 0b00000001
# define SYNTAX_ERR 0b00000010
# define IGNORE 0b00000010
# define REDIR_OUT 0b00000100
# define REDIR_APPEND 0b00001000
# define REDIR_IN 0b00010000
# define AMBIGUOUS 0b00000001
# define QUOTED 0b00100000
# define SINGLE 0b00100000
# define DOUBLED 0b01000000
# define ESCAPED 0b10000000
# define WRONG_ARGS "wrong input arguments, should be : ./minishell"
# define PROMPT "\033[1;36mminibash\033[0m : "
# define UP "\e[A"
# define DOWN "\e[B"
# define LEFT "\e[C"
# define RIGHT "\e[D"
# define DEL "\x7f"
# define CTRLD "\04"
int g_ret_status;
typedef enum e_modes
{
NOT_CANON,
CANON,
WAS_SIGN,
NO_SIGN
} t_modes;
typedef struct s_env
{
char *key;
char *value;
struct s_env *next;
} t_env;
typedef struct s_history
{
char *command;
char *cache;
size_t len;
size_t cache_len;
struct s_history *prev;
struct s_history *next;
} t_history;
typedef struct s_redir_chain
{
char *path;
unsigned char type;
struct s_redir_chain *next;
} t_redir_chain;
typedef struct s_seq
{
char *run;
char **args;
unsigned char info;
struct s_redir_chain *redirect;
struct s_redir_chain *tmp_redir;
struct s_seq *pipe;
struct s_seq *next;
} t_seq;
typedef struct s_quo_split
{
char *arg;
struct s_quo_split *next;
} t_quo_split;
typedef struct s_quo
{
int after_space;
int split_len;
t_quo_split *split;
char *start;
char *end;
int slashes;
int last_slash;
} t_quo;
typedef struct s_shell
{
t_history *history;
t_history *hist_ptr;
t_history *hist_curr;
t_env *env;
size_t env_size;
t_seq *seq;
size_t sep[2];
} t_shell;
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
char *ft_strdup(const char *s1);
char *ft_strjoin(char const *s1, char const *s2);
int ft_putchar(int c);
size_t ft_strlen(const char *s);
void ft_bzero(void *s, size_t n);
void *ft_memset(void *b, int c, size_t len);
int ft_strncmp(const char *s1, const char *s2, size_t n);
char *ft_substr(char const *s, unsigned int start, size_t len);
char *ft_strchr(const char *s, int c);
char *ft_itoa(int n);
int ft_atoi(const char *str);
char **ft_split(char const *s, char c);
void ft_twodarr_free(char ***arr, size_t len);
size_t ft_twodarr_len(char **arr);
char *ft_strtrim(char const *s1, char const *set);
size_t ft_numchstr(char *s, char ch);
char *ft_strchrset(char *s, char *set);
char *ft_strjoin_space(char const *s1, char const *s2);
int ft_strempty(char *s);
int ft_in_set(const char *set, char ch);
t_list *put_to_sort_list(char *content, t_list *start, \
t_list *prev, t_list *corrent);
t_list *ft_lstnew(void *content);
void ft_lstadd_front(t_list **lst, t_list *new);
void ft_lstclear(t_list **lst, void (*del)(void *));
void ft_lstdelone(t_list *lst, void (*del)(void *));
char *ft_low_str(char *str);
char *ft_strjoin_sym(char const *s1, char const *s2, char sym);
char *ft_genstr(char sym, int num);
char *ft_strrchr(const char *s, int c);
int ft_isdigit(int c);
void lite_error(char *comment);
void free_error(char *comment, t_shell **shell);
void free_seq(t_seq **seq);
void ft_readline(t_shell *shell, ssize_t read_len);
void set_mode(int type);
void prompt(void);
void init_hist(t_shell *shell);
void handle_up(t_shell *shell);
void handle_down(t_shell *shell);
void handle_del(t_shell *shell);
void handle_execute(t_shell *shell);
void deal_cache(t_shell *shell);
void find_external(t_shell *shell);
void set_signals(void);
int *signal_tracker(void);
void envp_to_list(char **envp, t_shell *shell);
char **envp_to_arr(t_shell *shell);
char *envp_get_value(t_shell *shell, char *match);
int envp_set_value(t_shell *shell, char *param, char *value);
int envp_new_value(t_shell *shell, char *param, char *value);
void parser(t_shell *shell);
void free_split(char ***split, t_shell *shell);
int init_seq(t_seq **seq);
void parse_split(t_seq *tmp_seq, t_shell *shell, char sym, char *str);
void trim_or_not(char *split, t_seq *tmp_seq);
void parse_one(t_seq *tmp_seq, t_shell *shell);
int is_builtin(char *s);
void parse_redirect(t_seq *tmp_seq, t_shell *shell, t_quo *quo);
void dollar_path(t_redir_chain *tmp_redir, t_shell *shell, t_quo *quo);
void parse_input(t_redir_chain *tmp_redir, t_shell *shell, t_quo *quo);
void parse_output(t_redir_chain *tmp_redir, t_shell *shell, t_quo *quo);
int syntax_error(t_shell *shell, char sym);
void parse_quotes(t_seq *tmp_seq, t_shell *shell);
int init_quo_split(t_quo_split **new);
void free_quotes(t_quo **quo);
void error_quotes(t_quo **quo, t_shell **shell);
void fill_after_quotes(t_seq *tmp_seq, t_shell *shell, t_quo *quo);
int precheck_syntax(t_shell *shell);
int quo_syntax_return(unsigned char f);
void manage_before(char **before, t_shell *shell, size_t len);
void join_args(t_seq *tmp_seq, t_shell *shell, t_quo *quo, \
t_quo_split *tmp_split);
void shut_escape(t_quo *quo);
void join_args2_utils(t_quo *quo, char **tmp2, char **arg);
void join_one_sym(t_shell *shell, t_quo *quo, char **str, char *sym);
void join_routine(t_seq *tmp_seq, t_shell *shell, t_quo *quo, \
t_quo_split *tmp_split);
void parse_singleq(t_seq *tmp_seq, t_shell *shell, t_quo *quo, \
t_quo_split *tmp_split);
void parse_escape(t_seq *tmp_seq, t_shell *shell, t_quo *quo, \
t_quo_split *tmp_split);
void parse_doubleq(t_seq *tmp_seq, t_shell *shell, t_quo *quo, \
t_quo_split *tmp_split);
int even_escaped(char *start, char *str);
void parse_dollar(t_seq *tmp_seq, t_shell *shell, t_quo *quo, \
t_quo_split *tmp_split);
void error_dollar(char **value, t_quo *quo, t_shell *shell);
void redirect_join(t_seq *tmp_seq, t_shell *shell, t_quo *quo);
void join_args2(t_seq *tmp_seq, t_shell *shell, t_quo *quo, char **arg);
int cancel_escape(t_seq *tmp_seq, t_shell *shell, t_quo *quo, \
t_quo_split *tmp_split);
void what_parse(t_seq *tmp_seq, t_shell *shell, t_quo *quo, \
t_quo_split *tmp_split);
int run_one(t_seq *tmp_seq, t_shell *shell);
int run_builtin(t_seq *tmp_seq, t_shell *shell);
void handle_eacces(char *comm);
int run_pipe(t_seq *tmp_seq, t_shell *shell);
int run_redirect(t_seq *tmp_seq);
char *pwd(t_shell *shell);
int builtins_pwd(t_shell *shell, t_seq *tmp_seq, char *str_low);
int builtins_cd(t_shell *shell, t_seq *tmp_seq, char *str_low, char *param);
int builtins_env(t_shell *shell, t_seq *tmp_seq, char *str_low);
int builtins_echo(t_seq *tmp_seq, char *str_low, int n, int i);
int builtins_unset_value(t_shell *shell, t_seq *tmp_seq, char *str_low, \
int flag);
int builtins_exit(t_shell *shell, t_seq *tmp_seq, char *str_low, \
int n_args);
int builtins_export(t_shell *shell, t_seq *tmp_seq, char *str_low, \
int flag);
int redir(t_seq *tmp_seq, char **str_low, int flag);
int check_is_valid(t_seq *tmp_seq, int i, int flag, int n);
int print_export(t_shell *shell, t_list *key_sort, t_list *sort_start, \
t_env *tmp);
#endif