-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.h
executable file
·233 lines (194 loc) · 5.66 KB
/
main.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#ifndef _MAIN_H_
#define _MAIN_H_
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <limits.h>
#define BUFSIZE 1024
#define TOK_BUFSIZE 128
#define TOK_DELIM " \t\r\n\a"
/* Points to an array of pointers to strings called the "environment" */
extern char **environ;
/**
* struct data - struct that contains all relevant data on runtime
* @av: argument vector
* @input: command line written by the user
* @args: tokens of the command line
* @status: last status of the shell
* @counter: lines counter
* @_environ: environment variable
* @pid: process ID of the shell
*/
typedef struct data
{
char **av;
char *input;
char **args;
int status;
int counter;
char **_environ;
char *pid;
} data_shell;
/**
* struct sep_list_s - single linked list
* @separator: ; | &
* @next: next node
* Description: single linked list to store separators
*/
typedef struct sep_list_s
{
char separator;
struct sep_list_s *next;
} sep_list;
/**
* struct line_list_s - single linked list
* @line: command line
* @next: next node
* Description: single linked list to store command lines
*/
typedef struct line_list_s
{
char *line;
struct line_list_s *next;
} line_list;
/**
* struct r_var_list - single linked list
* @len_var: length of the variable
* @val: value of the variable
* @len_val: length of the value
* @next: next node
* Description: single linked list to store variables
*/
typedef struct r_var_list
{
int len_var;
char *val;
int len_val;
struct r_var_list *next;
} r_var;
/**
* struct builtin_s - Builtin struct for command args.
* @name: The name of the command builtin i.e cd, exit, env
* @f: data type pointer function.
*/
typedef struct builtin_s
{
char *name;
int (*f)(data_shell *datash);
} builtin_t;
/* aux_lists.c */
sep_list *add_sep_node_end(sep_list **head, char sep);
void free_sep_list(sep_list **head);
line_list *add_line_node_end(line_list **head, char *line);
void free_line_list(line_list **head);
/* aux_lists2.c */
r_var *add_rvar_node(r_var **head, int lvar, char *var, int lval);
void free_rvar_list(r_var **head);
/* aux_str functions */
char *_strcat(char *dest, const char *src);
char *_strcpy(char *dest, char *src);
int _strcmp(char *s1, char *s2);
char *_strchr(char *s, char c);
int _strspn(char *s, char *accept);
/* aux_mem.c */
void _memcpy(void *newptr, const void *ptr, unsigned int size);
void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size);
char **_reallocdp(char **ptr, unsigned int old_size, unsigned int new_size);
/* aux_str2.c */
char *_strdup(const char *s);
int _strlen(const char *s);
int cmp_chars(char str[], const char *delim);
char *_strtok(char str[], const char *delim);
int _isdigit(const char *s);
/* aux_str3.c */
void rev_string(char *s);
/* check_syntax_error.c */
int repeated_char(char *input, int i);
int error_sep_op(char *input, int i, char last);
int first_char(char *input, int *i);
void print_syntax_error(data_shell *datash, char *input, int i, int bool);
int check_syntax_error(data_shell *datash, char *input);
/* shell_loop.c */
char *without_comment(char *in);
void shell_loop(data_shell *datash);
/* read_line.c */
char *read_line(int *i_eof);
/* split.c */
char *swap_char(char *input, int bool);
void add_nodes(sep_list **head_s, line_list **head_l, char *input);
void go_next(sep_list **list_s, line_list **list_l, data_shell *datash);
int split_commands(data_shell *datash, char *input);
char **split_line(char *input);
/* rep_var.c */
void check_env(r_var **h, char *in, data_shell *data);
int check_vars(r_var **h, char *in, char *st, data_shell *data);
char *replaced_input(r_var **head, char *input, char *new_input, int nlen);
char *rep_var(char *input, data_shell *datash);
/* get_line.c */
void bring_line(char **lineptr, size_t *n, char *buffer, size_t j);
ssize_t get_line(char **lineptr, size_t *n, FILE *stream);
/* exec_line */
int exec_line(data_shell *datash);
/* cmd_exec.c */
int is_cdir(char *path, int *i);
char *_which(char *cmd, char **_environ);
int is_executable(data_shell *datash);
int check_error_cmd(char *dir, data_shell *datash);
int cmd_exec(data_shell *datash);
/* env1.c */
char *_getenv(const char *name, char **_environ);
int _env(data_shell *datash);
/* env2.c */
char *copy_info(char *name, char *value);
void set_env(char *name, char *value, data_shell *datash);
int _setenv(data_shell *datash);
int _unsetenv(data_shell *datash);
/* cd.c */
void cd_dot(data_shell *datash);
void cd_to(data_shell *datash);
void cd_previous(data_shell *datash);
void cd_to_home(data_shell *datash);
/* cd_shell.c */
int cd_shell(data_shell *datash);
/* get_builtin */
int (*get_builtin(char *cmd))(data_shell *datash);
/* _exit.c */
int exit_shell(data_shell *datash);
/* aux_stdlib.c */
int get_len(int n);
char *aux_itoa(int n);
int _atoi(char *s);
/* aux_error1.c */
char *strcat_cd(data_shell *, char *, char *, char *);
char *error_get_cd(data_shell *datash);
char *error_not_found(data_shell *datash);
char *error_exit_shell(data_shell *datash);
/* aux_error2.c */
char *error_get_alias(char **args);
char *error_env(data_shell *datash);
char *error_syntax(char **args);
char *error_permission(char **args);
char *error_path_126(data_shell *datash);
/* get_error.c */
int get_error(data_shell *datash, int eval);
/* get_sigint.c */
void get_sigint(int sig);
/* aux_help.c */
void aux_help_env(void);
void aux_help_setenv(void);
void aux_help_unsetenv(void);
void aux_help_general(void);
void aux_help_exit(void);
/* aux_help2.c */
void aux_help(void);
void aux_help_alias(void);
void aux_help_cd(void);
/* get_help.c */
int get_help(data_shell *datash);
#endif