-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminishell.h
More file actions
177 lines (162 loc) · 4.56 KB
/
Copy pathminishell.h
File metadata and controls
177 lines (162 loc) · 4.56 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asettar <asettar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/10 02:53:59 by asettar #+# #+# */
/* Updated: 2023/07/24 07:28:22 by asettar ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/wait.h>
# include <stdbool.h>
# include "readline/readline.h"
# include "readline/history.h"
# include "libft/libft.h"
# include <sys/errno.h>
# include <sys/ioctl.h>
# define NO_INP -3
# define NO_OUT -3
# define FSIGNAL 128
typedef struct s_env
{
char *name;
int hidden;
char *value;
struct s_env *next;
} t_env;
typedef enum e_tok
{
WRD,
SPA,
DQU,
SQU,
INP,
OUT,
HER,
APP,
PIP,
} t_tok;
typedef struct s_lex
{
t_tok tok;
char *data;
bool expanded;
struct s_lex *next;
} t_lex;
typedef struct s_redir
{
t_tok type;
char *file;
int flag;
int fd;
struct s_redir *next;
} t_redir;
typedef struct s_cmd
{
t_list *args;
char **cmd;
t_redir *redir;
int fd[2];
int inp;
int out;
int triger;
struct s_cmd *next;
} t_cmd;
typedef struct s_exec
{
char **path;
char **envp;
t_cmd **cmd;
int fd[2];
t_env **env;
} t_exec;
typedef struct s_glob
{
int status;
int her;
int under_exec;
t_cmd **cmd;
t_env **env;
t_lex **lex;
t_exec **exec;
char *pwd;
} t_glob;
extern t_glob g_glob;
// builtins :
int ft_cd(t_exec *exec, t_cmd *cmd);
int ft_echo(t_exec *exec, t_cmd *cmd);
int ft_env(t_exec *exec, t_cmd *cmd);
int ft_exit(t_exec *exec, t_cmd *cmd);
int ft_export(t_exec *exec, t_cmd *cmd);
int ft_pwd(t_exec *exec, t_cmd *cmd);
int ft_unset(t_exec *exec, t_cmd *cmd);
void construct_cmds(t_cmd **cmd, t_lex **lst, t_env *env);
// builtins -utils:
void export_args(t_list *args, t_env **env);
bool valid_identifer(char *s, int i);
void assign_new_content(t_list *args, char *new);
// parsing :
void parse_env(char **envp, t_env **env);
bool lexer(char *cmd, t_env **env);
void ft_expander(t_lex *lex, t_env *env);
void join_words(t_lex **lex);
bool check_errors(t_lex *lex);
void change_last_args(t_lex *lex, t_cmd *last);
// parsing utils:
void ft_env_add_back(t_env **env, t_env *node);
void free_env(t_env **env);
t_env *ft_new_env(char *name, char *value);
void ft_redir_add_back(t_redir **red, t_redir *new);
void ft_env_delete(t_env **env, t_env *node);
t_env *env_find(char *s, t_env *env);
void ft_lex_add_back(t_lex **lex, t_lex *new);
void ft_cmd_add_back(t_cmd **cmd, t_cmd *new);
bool is_token(char c);
bool is_word(t_lex *node);
bool is_redir(t_lex *node);
char *replace_dolar(char *data, t_env *env);
void exec_builtins(t_exec *exec, t_cmd *node);
void lex_del_one(t_lex **lex, t_lex *node);
void create_new_cmd(t_cmd **cmd, t_cmd **last, bool *new_cmd);
// execution:
void execute(t_cmd **cmd, t_env **env);
void open_herdocs(t_cmd *cmd, t_env *env);
void exec_commands(t_cmd **cmd, t_env **env);
void open_redirs(t_cmd *cmd);
// execution utils:
void clear_and_exit(t_cmd **cmd, t_env **env);
bool command_exist(char **cmd, char **path);
bool is_builtin(char *s);
void extract_args(t_cmd *cmd);
void update_exit_status(int pid);
char **extract_envp(t_env *env);
char **get_path(t_env *env);
void exec_pipes(t_exec *exec, int *pid, t_cmd *itr);
void ft_dup2(int fdin, int fdout);
void execute_child(t_exec *exec, t_cmd *itr);
void send_to_exec(t_exec *exec, t_cmd *node);
void clear_and_exit_with_status(t_exec *exec, int status);
void close_all_next_fds(t_cmd *itr);
void free_dubptr(char **ptr);
void ft_put_error(int n, ...);
void free_cmd(t_cmd **cmd);
void free_env(t_env **env);
char *get_env(char *s, t_env *env);
void init_child_signals(void);
void ft_dup2(int fdin, int fdout);
void sigint_handler(int sig);
bool check_qutes(char *cmd);
char *ft_strrcat(char *s, char c);
t_env *ft_new_env(char *name, char *value);
void update_shell_level(t_env **env);
void exit_with_failure(void);
void free_lex(t_lex **lex);
#endif