-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminishell.h
151 lines (121 loc) · 6.52 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenamar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/30 18:54:15 by abenamar #+# #+# */
/* Updated: 2023/09/15 11:40:54 by abenamar ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# define _POSIX_C_SOURCE 199309L
# include <errno.h>
# include <fcntl.h>
# include <readline/readline.h>
# include <readline/history.h>
# include <signal.h>
# include <string.h>
# include <sys/stat.h>
# include <sys/types.h>
# include <sys/wait.h>
# include "libft.h"
/* ************************************************************************** */
/* */
/* utils */
/* */
/* ************************************************************************** */
# ifndef __FAILURE
# define __FAILURE "\033[01;31mx"
# endif
# ifndef __SUCCESS
# define __SUCCESS "\033[01;32mo"
# endif
# ifndef __PROMPT
# define __PROMPT "\033[00m \033[01;35mminishell\033[00m:\033[01;34m"
# endif
typedef struct s_proc
{
pid_t pid;
int readfd[2];
int writefd[2];
} t_proc;
int ft_pstderr(char *str);
int ft_pstderr2(char *s1, char *s2);
int ft_pstderr3(char *s1, char *s2, char *s3);
int ft_pstderr4(char *s1, char *s2, char *s3, char *s4);
int ft_perror(char *str);
int ft_perror2(char *s1, char *s2);
int ft_perror3(char *s1, char *s2, char *s3);
void ft_tab_free(char **tab);
t_proc *ft_prc_new(void);
void ft_prc_del(void *prc);
void ft_lst_pop(t_list **lst, void (*del)(void *));
char *ft_strjoin_and_free(char *s1, char *s2);
char *ft_str_replace(char *str, char c1, char c2);
size_t ft_is_quoted(char *str);
size_t ft_tkn_count(t_list *lst, char *str, uint8_t all);
int ft_close(int fd);
long ft_atol(const char *nptr);
char *ft_ltoa(long n);
/* ************************************************************************** */
/* */
/* environment */
/* */
/* ************************************************************************** */
char *ft_env_gets(t_list **env, char *key);
int ft_env_geti(t_list **env, char *key);
void ft_env_puts(t_list **env, char *key, char *value);
void ft_env_puti(t_list **env, char *key, int value);
char **ft_env_to_tab(t_list *lst);
char *ft_expand(char *cmd, t_list **env, uint8_t dquoted, uint8_t hdoc);
/* ************************************************************************** */
/* */
/* signals */
/* */
/* ************************************************************************** */
extern int g_signum;
uint8_t ft_signals(void);
/* ************************************************************************** */
/* */
/* redirections */
/* */
/* ************************************************************************** */
uint8_t ft_is_redirection(char *cmd);
uint8_t ft_here_document(char **limiter, t_list **env, size_t last);
uint8_t ft_redirect_input(char *file, t_list **env, size_t last);
uint8_t ft_redirect_output(char *file, int oflag, t_list **env, size_t last);
uint8_t ft_redirect(t_list **tkns, t_list **env);
/* ************************************************************************** */
/* */
/* commands */
/* */
/* ************************************************************************** */
char *ft_command_setup(char *cmd, char c1, char c2, uint8_t quote);
char **ft_command_split(char *cmd, t_list **env, char c, uint8_t expand);
/* ************************************************************************** */
/* */
/* builtins */
/* */
/* ************************************************************************** */
int ft_builtin_echo(char *cmd, char **argv, t_list **env, uint8_t silent);
int ft_builtin_cd(char *cmd, char **argv, t_list **env, uint8_t silent);
int ft_builtin_pwd(char *cmd, char **argv, t_list **env, uint8_t silent);
int ft_builtin_export(char *cmd, char **argv, t_list **env, uint8_t silent);
int ft_builtin_unset(char *cmd, char **argv, t_list **env, uint8_t silent);
int ft_builtin_env(char *cmd, char **argv, t_list **env, uint8_t silent);
int ft_builtin_exit(char *cmd, char **argv, t_list **env, uint8_t silent);
/* ************************************************************************** */
/* */
/* executions */
/* */
/* ************************************************************************** */
int ft_execve(char *cmd, t_list **env);
void ft_execute(t_list **tkns, t_list **env);
int ft_builtin(char *cmd, t_list **env, uint8_t silent);
int ft_pipeline(t_list **tkns, t_list **env);
t_list **ft_line_parse(char *line, t_list **tkns);
int ft_line_process(char **line, t_list **env);
#endif