-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsh.h
114 lines (95 loc) · 2.77 KB
/
sh.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sh.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpoveda- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/09 21:57:48 by dpoveda- #+# #+# */
/* Updated: 2021/12/18 20:45:03 by dpoveda- ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SH_H
# define SH_H
/*** INCLUDES ***/
/* mishell includes */
# include <sh/main.h>
# include <sh/builtin.h>
# include <sh/colors.h>
# include <sh/utils.h>
# include <sh/signals.h>
# include <sh/prompt.h>
# include <sh/lexer.h>
# include <sh/parser.h>
# include <sh/ast.h>
# include <sh/exec.h>
# include <sh/read_config.h>
/* our own implementation of libc */
# include <libft.h>
/* standard libraries */
# include <stdlib.h>
# include <string.h>
# include <stdio.h>
/* sys libraries */
# include <sys/types.h>
# include <sys/wait.h>
# include <limits.h>
# include <dirent.h>
/* signals */
# include <signal.h>
/* readline libraries */
# include <readline/readline.h>
# include <readline/history.h>
/* standard unix library */
# include <unistd.h>
/* terminal library */
# include <termios.h>
# include <term.h>
/* open() */
# include <fcntl.h>
/*** DEFINES ***/
/* temp files */
# define TMPDIR "/tmp"
/* bool */
# ifndef TRUE
# define TRUE 1
# endif
# ifndef FALSE
# define FALSE 0
# endif
/* path */
# ifndef PATH_MAX
# define PATH_MAX 256
# endif
/*** DATA ***/
/* shell global struct
*
* status => last exit status
* *env => enviroment vars
* *prev => to save previous token when we tokenize a enviroment variable
* *tok => to iterate tokens (used for creating the ast)
* **so_ast => save current "and or" ast node to attach nodes
* *cmd_ast => save current command ast node to attach args and redirs
* *bi => built-in list
* fd_bak => backup STDIN and STDOUT fd
* last_pid => last process in pipe pid
* is_child => if a process is a child
* is_expd => if token vars are already expanded
* tokdel => if token was deleted during lexer
*/
typedef struct s_sh {
int status;
t_list **env;
t_tok *prev;
t_tok *tok;
t_ast **ao_ast;
t_ast *cmd_ast;
t_blti *bi;
int fd_bak[2];
pid_t last_pid;
t_bool is_child;
t_bool is_expd;
t_bool tokdel;
} t_sh;
extern t_sh g_sh;
#endif