-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminishell.h
155 lines (151 loc) · 4.29 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
#ifndef MINISHELL_H
# define MINISHELL_H
//readline --> compilar con -lreadline
# include <stdio.h>
# include <readline/readline.h>
# include <readline/history.h>
//------------------
# include <stdlib.h> //malloc
# include <unistd.h> // write
# include "libft/libft.h"
# include <fcntl.h>
#include <sys/wait.h>
#include <string.h>
#include <signal.h>
//------------------ TOKEN TYPE ENUM
typedef enum s_type
{
WORD,
QUOTED,
OPERATOR
} t_type;
//------------------
//------------------ OPERATOR TYPE ENUM
typedef enum s_operator
{
INPUT,
OUTPUT,
HEREDOC,
APPEND,
PIPE
} t_operator;
//------------------
//------------------ TOKEN STRUCT
typedef struct s_token t_token;
struct s_token
{
char *value;
short is_quote;
short expand;
int has_space;
int hd_fd;
t_type type;
t_token *next;
t_token *prev;
};
//------------------
//------------------ TOKEN ARGUMENTS STRUCT
typedef struct s_args
{
char *line;
int *i;
t_token **tkn_lst;
int spaces;
} t_args;
//------------------
//-------------------ENV STRUCT
typedef struct s_env
{
char *key;
char *value;
struct s_env *next;
} t_env;
//------------------
//------------------ COMANDS STRUCTS TEST
typedef struct s_redir
{
char **operator;
char **file;
} t_redir;
typedef struct s_command
{
char *cmd;
char **args;
t_redir *redirections;
int redir_error;
int status;
int fd_in;
int fd_out;
} t_command;
//------------------
//------------------ EXPAND ARGUMENTS STRUCT
typedef struct s_expand_args {
t_token *token;
t_env *env_lst;
char *expand;
int i;
char *temp;
char *sub_expand;
int start;
} t_expand_args;
//------------------
//------------------ UTILS FUNCTIONS
char *ft_strndup(const char *str, size_t len);
int is_space(char c);
int is_special_char(char c);
//------------------ ENVIROMENT FUNCTIONS
void free_env_list(t_env *env_list);
void add_env_variable(t_env **env_list, char *key, char *value);
t_env *init_env_list(char **env);
void print_env_list(t_env *env_list);
char *get_env_value(char *str, t_env *env_list);
//------------------ TOKENIZE FUNCTIONS
t_args *pass_args(char *line, int *i, t_token **tkn_lst, int spaces);
t_token *init_token(t_type type);
void add_token(t_token **tkn_lst, t_token *token);
void free_tkn_lst(t_token *tkn_lst);
t_token *parse_quote(t_args *args, char quote, int start, int end);
t_token *manage_quote(t_args *args, int start);
t_token *parse_operator(t_operator operator, int spaces);
t_operator get_operator_type(const char *line, int i);
int create_operator_token(t_args *args, t_operator operator, int increment);
t_token *manage_operator(t_args *args);
t_token *manage_word(t_args *args);
void skip_spaces(const char *line, int *i, int *spaces);
int process_token(t_args *args);
t_token *tokenize(char *line);
//------------------ SINTAXIS FUNCTIONS
int syntax_check(t_token *tkn_lst);
//------------------ EXPANSION FUNCTIONS
char *ft_strjoin_free(char *s1, char *s2);
int is_valid_env_char(char c);
char *expand_value(t_token *token, t_env *env_lst);
void expand_variables(t_token *token, t_env *env_lst);
//------------------ COMMAND FUNCTIONS
t_command **commands(t_token *tkn_lst);
void preprocess_tokens(t_token **tkn_lst);
void free_cmd_list(t_command **cmd_list);
void execute_cmd(t_command **cmd, t_env **env);
//------------------ PRINT FUNCTIONS
void print_commands(char *line, t_command **cmd_list);
void print_tokens(char *line, t_token *tkn_lst);
//------------------ HEREDOC
int process_heredoc(t_token *heredoc_token);
//------------------ BUILTINS
void manage_builtins(t_command *cmd, t_env **env);
int is_builtin(t_command *cmd);
//------------------ EXPORT - UNSET FUNCTIONS
t_env *get_var(t_env **env, char *key);
void cu_env_var(t_env **env, char *key, char *value);
void export_new_var(t_command **cmd, t_env **env);
void delete_env_var(t_command **cmd, t_env **env);
//------------------ CD FUNCTION
void change_dir(t_command *cmd, t_env **env);
//------------------ PWD FUNCTION
void printf_pwd(t_env **env);
//------------------ ECHO FUNCTION
void get_echo(t_command **cmd);
int get_cmd_num(t_command **cmd);
//------------------ PIPES
void execute_pipes(t_command **cmds, t_env **env);
#endif