-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.h
More file actions
executable file
·210 lines (166 loc) · 5.22 KB
/
main.h
File metadata and controls
executable file
·210 lines (166 loc) · 5.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
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
#ifndef _MAIN_H_
#define _MAIN_H_
#define TOKEN_DELIMITERS "\r\a\n\t "
#define TOKEN_SIZE 128
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <signal.h>
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
extern char **environ;
/**
* struct shdata - structure that contains all relevant data
* related to the shell state
* @arguments: tokens of the command line
* @argv: array of arguments
* @counter: lines counte
* @pid: process identidier of the current shell
* @_environ: environment variables
* @input: command line written by the user
* @status: last status of the shell
*/
typedef struct shdata
{
char **arguments;
char **argv;
int counter;
char *pid;
char **_environ;
char *input;
int status;
} shell_state;
/**
* struct sep_list_s - singly linked list
* @separator: seperators
* @next: next node
*
*/
typedef struct sep_list_s
{
char separator;
struct sep_list_s *next;
} sep_list;
/**
* struct builtin_s - struct for command arguments
* @name: The name of the command builtin i.e cd, etc
* @f: pointer function
*/
typedef struct builtin_s
{
char *name;
int (*f)(shell_state *datash);
} builtin_t;
/**
* 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;
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);
r_var *add_rvar_node(r_var **head, int lvar, char *var, int lval);
void free_rvar_list(r_var **head);
int repeated_char(char *input, int i);
int error_sep_op(char *input, int i, char last);
void print_syntax_error(shell_state *datash, char *input, int i, int bool);
char *_strdup(const char *s);
int _strlen(const char *s);
char **split_line(char *input);
void check_env(r_var **h, char *in, shell_state *data);
int check_vars(r_var **h, char *in, char *st, shell_state *data);
char *replaced_input(r_var **head, char *input, char *new_input, int nlen);
char *rep_var(char *input, shell_state *datash);
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, shell_state *datash);
int split_commands(shell_state *datash, char *input);
void bring_line(char **lineptr, size_t *n, char *buffer, size_t j);
ssize_t get_line(char **lineptr, size_t *n, FILE *stream);
int exec_line(shell_state *datash);
int is_cdir(char *path, int *i);
char *_which(char *cmd, char **_environ);
int is_executable(shell_state *datash);
int check_error_cmd(char *dir, shell_state *datash);
int cmd_exec(shell_state *datash);
char *_getenv(const char *name, char **_environ);
int _env(shell_state *datash);
char *copy_info(char *name, char *value);
void set_env(char *name, char *value, shell_state *datash);
int _setenv(shell_state *datash);
int _unsetenv(shell_state *datash);
int (*get_builtin(char *cmd))(shell_state *datash);
char *strcat_cd(shell_state *, char *, char *, char *);
char *error_get_cd(shell_state *datash);
char *error_not_found(shell_state *datash);
char *error_exit_shell(shell_state *datash);
char *error_get_alias(char **arguments);
char *error_env(shell_state *datash);
char *error_syntax(char **arguments);
char *error_permission(char **arguments);
char *error_path_126(shell_state *datash);
int get_error(shell_state *datash, int eval);
int exit_cmd(shell_state *shelldata);
int cd_cmd(shell_state *shelldata);
void cd_to_dot(shell_state *shelldata);
void cd_to_previous(shell_state *shelldata);
void cd_here(shell_state *shelldata);
void cd_home(shell_state *shelldata);
void general_help(void);
void help_only(void);
void help_env(void);
void help_setenv(void);
void help_unsetenv(void);
int help_cmd(shell_state *shelldata);
void help_exit(void);
void help_alias(void);
void help_cd(void);
void free_struct(shell_state *shelldata);
void data_init(shell_state *shelldata, char **argv);
char *remove_comment(char *input);
void theshell(shell_state *shelldata);
char *line_read(int *eof_status);
int check_error(shell_state *shelldata, char *input);
int first_non_whitespace(char *input, int *i);
int my_isdigit(const char *s);
char *_strcpy(char *dest, char *src);
char *_strcat(char *dest, const char *src);
int _strcmp(char *s1, char *s2);
int compare_str(char *input, const char *delimeter);
char *_strtok(char *input, const char *delimiter);
void revString(char *s);
int getLen(int n);
char *int_to_str(int n);
int my_atoi(char *str);
char *_memcpy(void *dest, const void *src, unsigned int n);
void handle_sigint(int dummy);
char *_realloc(char *ptr, unsigned int old_size, unsigned int new_size);
char **_reallocdoublep(char **ptr, unsigned int size, unsigned int new_size);
#endif