-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminishell.h
More file actions
104 lines (81 loc) · 2.22 KB
/
minishell.h
File metadata and controls
104 lines (81 loc) · 2.22 KB
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
// 42 HEADER
#ifndef MINISHELL_H
# define MINISHELL_H
// TODO: rm stdio inc when project is complete
#include <stdio.h>
#include "libft/libft.h"
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <string.h>
#define ABS(x) x > 0 ? x : -x // who are u ? what are u doin here ?
#define COMMAND_NOT_FOUND 1270
#define RDEND 0
#define WREND 1
enum e_node_type
{
COMMAND,
REDIR_OUT_1,
REDIR_OUT_2,
REDIR_IN_1,
PIPE,
AND,
OR,
};
typedef struct s_node
{
enum e_node_type type;
char **args;
struct s_node *left;
struct s_node *right;
} t_node;
typedef struct s_options
{
int current_pwrite;
int current_pread;
int previous_pwrite;
int previous_pread;
} t_options;
typedef int (*t_eval_node_function)(t_node *n, t_options *options);
typedef int (*t_builtin_function)(char *args[]);
char **environment;
// PROCESS MANAGEMENT
int process_container(t_node *root);
int eval_node(t_node *node, t_options *options);
int run_process(t_node *n, t_options *options);
int redirect_out_trunc(t_node *n, t_options *options);
int redirect_out_append(t_node *n, t_options *options);
int redirect_in(t_node *n, t_options *options);
int pipe_processes(t_node *n, t_options *options);
int and_operator(t_node *n, t_options *opt);
int or_operator(t_node *n, t_options *opt);
// PROCESS UTILS
int isbuiltin(char *bname);
int call_builtin_function(int builtin_index, char *args[], t_options *opt);
char *isbinary(char *bname);
// FD UTILS
int close_pipe(int *read_end, int *write_end);
char *try_path(char *path);
char *build_path(char *paths, char *bname);
// BTREE UTILS
void btree_delete(t_node *node);
t_node *btree_node_new(int type, char **args);
// ENV UTILS
int valid_envar_id(const char *n);
char *get_key_value(char **tab, char *key);
int keycmp(char *str, char *key);
int push_envar(const char *str);
// BUILTINS
int ft_export(char *args[]);
int echo(char *args[]);
int env(char *args[]);
int change_dir(char *arg[]);
int ft_unset(char *arg[]);
int ft_pwd(char *arg[]);
// ERROR MANAGEMENT
void ft_perrorc(const char *from, const char *arg, const char *msg);
#endif