forked from muratkaanmesum/minishell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminishell.h
125 lines (120 loc) · 3.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmesum <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/10 12:47:38 by mmesum #+# #+# */
/* Updated: 2023/03/29 16:24:14 by mmesum ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include "libft/libft.h"
# include <errno.h>
# include <readline/history.h>
# include <readline/readline.h>
# include <signal.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <sys/ioctl.h>
# include <unistd.h>
extern struct s_execute *g_execute;
enum e_token
{
I_REDIRECTION,
O_REDIRECTION,
HERE_DOC,
APPEND_RED,
PIPE,
COMMAND,
ARG,
OPTION,
AND,
OR,
ENV_COMMAND,
ENV,
RED_FILE,
OPEN_PAR,
CLOSE_PAR,
UNKNOWN_TOKEN,
UNKNOWN
};
typedef struct s_redirections
{
char **infile;
enum e_token *infile_type;
int infile_count;
char **outfile;
enum e_token *outfile_type;
int outfile_count;
} t_redirections;
typedef struct s_command
{
char *command;
char **arguments;
int argument_count;
} t_command;
typedef struct s_node
{
struct s_command *command;
struct s_node **connections;
int connection_count;
int is_subshell;
int is_arithmetic;
struct s_token *tokens;
struct s_redirections *redirections;
enum e_token left_operator;
enum e_token right_operator;
int in_fd;
int out_fd;
struct s_execute *execute;
} t_node;
typedef struct s_execute
{
int last_exit_code;
struct s_node *top_node;
char **env;
char **export;
int only_red_count;
char *input;
int exit_code;
} t_execute;
typedef struct s_token
{
int id;
enum e_token token;
int start_index;
int end_index;
char *str;
} t_token;
t_token *lexer(char *str);
t_node *parser(t_token *tokens, t_execute *execute);
void print_token(t_token *token);
int parse_error(t_token *tokens);
void expander(t_node *head);
int is_arithmetic(t_token *tokens);
int check_first(t_token *tokens);
void wildcard(t_node *node);
void print_tree(t_node *head);
int get_last_execute_code(t_node *head);
int execute(t_node *head);
void free_tree(t_node *head);
int get_length(char *str);
void free_double_ptr(char **arr);
void free_tokens(t_token *token);
void ctrl_c(int sig);
void ctrl_d(t_execute *execute);
void free_execute(t_execute *execute);
int get_env_len(char *env);
int get_double_ptr_len(char **arr);
int get_token_len(t_token *tokens);
void exec_rest(t_node *head);
int parse_error_free(t_node *head, t_token *tokens,
char *inpt);
int first_check_free(t_token *tokens, char *inpt);
void free_all_node_tokens(t_node *node);
int quotes_control(char *command);
#endif