-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.h
More file actions
162 lines (131 loc) · 4.03 KB
/
Copy pathexecutor.h
File metadata and controls
162 lines (131 loc) · 4.03 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* executor.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yucchen <yucchen@student.42singapore.sg +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/30 20:12:24 by yucchen #+# #+# */
/* Updated: 2026/01/12 16:02:29 by yucchen ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef EXECUTOR_H
# define EXECUTOR_H
# include "libft/libft.h"
# include <errno.h>
# include <fcntl.h>
# include <readline/history.h>
# include <readline/readline.h>
# include <signal.h>
# include <sys/types.h> // pid_t
# include <sys/wait.h> // waitpid
# include <sys/stat.h> // stat
# include <signal.h>
extern int g_last_status;
typedef enum e_redir_type
{
R_IN, // <
R_OUT, // >
R_APPEND, // >>
R_HEREDOC, // <<
} t_redir_type;
typedef struct s_redir
{
t_redir_type type;
char *file; // delimiter for heredoc
int is_heredoc_tmp;
int heredoc_expand;
struct s_redir *next;
} t_redir;
typedef struct s_cmd
{
char **argv;
t_redir *redirs; // linked list of t_redir
struct s_cmd *next; // for pipeline: cmd1 | cmd2 | ...
} t_cmd;
typedef struct s_env
{
char *key;
char *value;
struct s_env *next;
} t_env;
typedef struct s_child
{
t_cmd *cmd_head;
t_env **env;
char **envp;
} t_child;
typedef struct s_pipex
{
t_cmd *head;
t_cmd *cur;
t_env **env;
char **envp;
int cnt;
pid_t *pids;
int i;
int prev_read;
int pipefd[2];
int is_last;
int status;
} t_pipex;
// heredoc_utils.c
char *gen_temp_filename(void);
char *heredoc_update_word(char *src, t_env *env);
// heredoc.c
int run_heredocs(t_cmd *cmd_list, t_env *env);
// signals.c
void sigint_prompt(int sig);
void setup_sig(void);
// path.c
char *search_path(const char *cmd, char **envp);
// executor_utils1.c
void ft_free_array(char **array);
void child_cleanup(t_cmd *cmd_head, t_env **env, char **envp);
void try_exec(t_cmd *cmd, t_child *child);
// executor_utils2.c
void exec_child_cmd(t_cmd *cmd, t_env **env, char **envp, t_cmd *cmd_head);
int run_exit_in_parent(t_cmd *cmd);
int run_builtin_in_parent(t_cmd *cmd, t_env **env);
void exitcode_from_status(int status);
// executor_utils3.c
int pipex_init(t_pipex *pipex, t_cmd *cmd_list, t_env **env, char **envp);
int pipex_open_pipe(t_pipex *pipex);
void fork_fail(int is_last, int pipefd[2], int prev_read, pid_t *pids);
void child_process(t_pipex *pipex);
// executor.c
int execute(t_cmd *cmd_list, t_env **env);
// redir.c
int apply_redirs(t_cmd *cmd);
int apply_redirs_touch(t_cmd *cmd);
// env_utils.c
t_env **env_to_array(t_env *env);
void sort_env_array(t_env **array);
char *join_key_value(const char *key, const char *value);
int env_cnt_value(t_env *env);
// builtin_echo.c
int builtin_echo(char **argv);
// builtin_pwd.c
int builtin_pwd(void);
// builtin_env.c
void free_env_list(t_env *env);
char **env_to_envp_array(t_env *env);
t_env *create_env_list(char **envp);
void update_shlvl(t_env **env);
int builtin_env(char **argv, t_env *env);
// builtin_cd.c
char *getenv_value(t_env *env, const char *key);
void set_env(t_env **env, char *key, char *value);
int builtin_cd(char **argv, t_env **env);
// builtin_export.c
int builtin_export(char **argv, t_env **env);
// builtin_unset.c
int builtin_unset(char **argv, t_env **env);
// builtin_exit.c
int builtin_exit(char **argv);
int should_exit(char **argv);
// builtins.c
int ft_strcmp(const char *s1, const char *s2);
int is_builtin(const char *cmd);
int run_builtin(t_cmd *cmd, t_env **env);
#endif