-
Notifications
You must be signed in to change notification settings - Fork 0
/
minishell.h
167 lines (149 loc) · 5.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: user42 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/09 15:50:12 by lchapren #+# #+# */
/* Updated: 2021/03/20 12:14:45 by user42 ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include <stdlib.h>
# include <unistd.h>
# include <dirent.h>
# include <fcntl.h>
# include <errno.h>
# include <stdio.h>
# include <signal.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <sys/wait.h>
# include "libft/libft.h"
# include "cmd.h"
# define STDIN 0
# define STDOUT 1
# define STDERR 2
# define PROMPT "lchapren@minishell $ "
# define MINISHELL "minishell: "
# define SYNTAX "syntax error near: "
extern t_data g_shell;
/*
**Built-ins
*/
int call_builtin_or_pipe(t_cmd *cmd, char **envp[]);
int call_builtin(t_cmd *head, char **envp[]);
int is_builtin(char **token);
int builtin_exit(char **command);
int builtin_echo(char **token);
int builtin_pwd(void);
int builtin_env(char *envp[]);
int builtin_cd(char **token, char **envp[]);
int builtin_export(char **token, char **envp[]);
int builtin_unset(char **token, char **envp[]);
/*
**General functions
*/
char **copy_envp(char *envp[]);
char *get_pwd(void);
char *add_character(char *input, char c);
char *get_line(void);
char **copy_envp(char *envp[]);
/*
**Utility functions
*/
void initialize_data(char *envp[]);
char **alphabetically_sort_env(char *envp[]);
char **alphabetical_bubble_sort(char **array);
int characters_before_equal(char *token);
int print_export(char **sorted_env);
int export_token(char **token, char **envp[]);
int valid_token(char *token);
int nb_cd_args(char **token);
int verify_cd_args(char **token, char *envp[]);
int change_directory(char **token, char *envp[], int ret);
int only_digits(char *token);
/*
**Pipes
*/
void call_builtin_pipe(t_cmd *cmd, char *envp[]);
int exec_pipeline(t_cmd *cmd, char *envp[]);
void open_close_pipes(int *pipefd, int nb_pipes, int mode);
void child_pipe_redir(t_cmd *head, int *pipefd, int cmd_num, int nb_pipes);
void child_exec(t_cmd *cmd, char *envp[]);
int get_child_status(int child_process, int nb_pipes);
int pipe_loop(t_cmd *head, int **pipefd, char *envp[]);
/*
**Redirections
*/
void get_redir_name(char *line, int *i, char **buffer, char *envp[]);
int get_redir_type(char *line, int *i, char **buffer);
void builtin_redir(t_cmd *cmd, int *save_in, int *save_out, int mode);
int open_redir_hub(t_cmd **cmd);
int open_redir_type(t_cmd **cmd, char *file, int redir_type);
int open_redir_in(t_cmd **cmd, char *file_name);
int open_redir_out(t_cmd **cmd, char *file_name, int open_mode);
/*
**Manipulation of envp
*/
int add_token_in_envp(char *token, char **envp[]);
int modify_token_in_envp(char *token, int token_index, char **envp[]);
int search_token_in_envp(char *token, char *envp[]);
int remove_token_in_envp(int token_index, char **envp[]);
void update_pwd_envp(char *oldpwd, char **envp[]);
char *get_token_value_in_envp(char *token, char *envp[]);
char *get_env_variable(char *line, int *i, char *envp[]);
int is_env_character(char c);
/*
**Execution functions
*/
int exec_command(char **command, char *envp[]);
char *search_executable_in_path(char *executable, char **path);
char *search_executable_in_dir(char *executable, char *path);
char *is_an_executable(char *file_path, char *file_name);
int is_absolute_or_relative_path(char *path);
int directory_exists(char *dir_path);
char **get_env_path(char *envp[]);
/*
**Linked list and global
*/
int add_cmd(t_cmd **cmd);
t_cmd *allocate_list(t_cmd *cmd);
int get_length_list(t_cmd *head);
char **copy_buffer_on_array(char **buffer, char **array);
void free_command_list(t_cmd *head);
void free_shell_data(int mode);
/*
**Parsing
*/
int parsing_hub(char *line, char *envp[], int mode);
int parse_cmd_line(char *line, t_cmd **cmd, int i, char *envp[]);
int in_quotes(char *line, int pos);
int closed_quote(char *line, int pos, char quote_type);
int return_closed_quote(char *line, int i, int in_single, int in_double);
int special_action(char *line, t_cmd **cmd, int *i);
int is_special_character(char c);
void parse_backslash(char *line, char *buffer, int *i, int *j);
void parse_redirection(char *line, t_cmd **cmd, int *i, char *envp[]);
void parse_dollar(char *line, int *i, char **buffer, char *envp[]);
void store_dollar(char *line, char **buffer, char *var_name, char *value);
void parse_dollar(char *line, int *i, char **buffer, char *envp[]);
int multiline_character(char *line, char c, int *i, int mode);
int pipe_handling(char *line, t_cmd **cmd, int *i);
char *get_next_token(int *i, char *buffer, char *envp[], int mode);
char *add_on_buffer(char *buffer, char *to_add, char *line);
/*
**Signals handling
*/
void sigint_handler(int signal);
void sigquit_handler(int signal);
/*
**Error handling
*/
void print_syntax_error(char c);
void print_not_valid_idendifier(char *token);
void error_malloc(void);
void argument_error(char **command);
#endif