-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.h
More file actions
189 lines (144 loc) · 5.62 KB
/
Copy pathshell.h
File metadata and controls
189 lines (144 loc) · 5.62 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
#ifndef _SHELL_H_
#define _SHELL_H_
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#define END_OF_FILE -2
#define EXIT -3
/* Global history counter */
int hist;
/* Global environemnt */
extern char **environ;
/* Global program name */
char *name;
/**
* struct alias_s - A new struct defining aliases.
* @name: The name of the alias.
* @value: The value of the alias.
* @next: A pointer to another struct alias_s.
*/
typedef struct alias_s
{
char *name;
char *value;
struct alias_s *next;
} alias_t;
/* Global aliases linked list */
alias_t *aliases;
/**
* struct list_s - A new struct type defining a linked list.
* @dir: A directory path.
* @next: A pointer to another struct list_s.
*/
typedef struct list_s
{
char *dir;
struct list_s *next;
} list_t;
/**
* struct builtin_s - A new struct type defining builtin commands.
* @name: The name of the builtin command.
* @f: A function pointer to the builtin command's function.
*/
typedef struct builtin_s
{
char *name;
int (*f)(char **argv, char **front);
} builtin_t;
/********************* builtin_alias.c ********************/
int shell_lex_alias(char **args, char __attribute__((__unused__)) **front);
void set_alias(char *var_name, char *value);
void print_alias(alias_t *alias);
char **replace_aliases(char **args);
/*************************** builtin_env.c *****************************/
int shell_lex_env(char **args, char __attribute__((__unused__)) **front);
int shell_lex_setenv(char **args, char __attribute__((__unused__)) **front);
int shell_lex_unsetenv(char **args, char __attribute__((__unused__)) **front);
/***************************** builtin_help.c ************************/
void help_all(void);
void help_alias(void);
void help_cd(void);
void help_exit(void);
void help_help(void);
/****************************** buitin.c ***********************************/
int (*get_builtin(char *command))(char **args, char **front);
int shell_lex_exit(char **args, char **front);
int shell_lex_cd(char **args, char __attribute__((__unused__)) **front);
int shell_lex_help(char **args, char __attribute__((__unused__)) **front);
/*************************** create_error.c *****************************/
int num_len(int num);
char *_itoa(int num);
int create_error(char **args, int err);
/*********************** environment.c ***********************************/
char **_copyenv(void);
void free_env(void);
char **_getenv(const char *var);
/************************ error_msg_1.c ***************************************/
char *error_env(char **args);
char *error_1(char **args);
char *error_2_exit(char **args);
char *error_2_cd(char **args);
char *error_2_syntax(char **args);
/************************* error_msg_2.c *************************************/
char *error_126(char **args);
char *error_127(char **args);
/************************* getline.c **********************************/
void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size);
void assign_lineptr(char **lineptr, size_t *n, char *buffer, size_t b);
ssize_t _getline(char **lineptr, size_t *n, FILE *stream);
/********************************* help_builtin.c ***********************************/
void help_env(void);
void help_setenv(void);
void help_unsetenv(void);
/*********************************** helper_function.c ********************************/
void free_args(char **args, char **front);
char *get_pid(void);
char *get_env_value(char *beginning, int len);
void variable_replacement(char **args, int *exe_ret);
/******************************* helper_function2.c ******************************/
void handle_line(char **line, ssize_t read);
ssize_t get_new_len(char *line);
void logical_ops(char *line, ssize_t *new_len);
/******************************** input_helper ********************************/
char *get_args(char *line, int *exe_ret);
int call_args(char **args, char **front, int *exe_ret);
int run_args(char **args, char **front, int *exe_ret);
int handle_args(int *exe_ret);
int check_args(char **args);
/********************************** link_list.c **************************************/
alias_t *add_alias_end(alias_t **head, char *name, char *value);
void free_alias_list(alias_t *head);
list_t *add_node_end(list_t **head, char *dir);
void free_list(list_t *head);
/*************************************** locate.c ********************************/
char *fill_path_dir(char *path);
list_t *get_path_dir(char *path);
char *get_location(char *command);
/******************************************* proc.c ***********************************/
int cant_open(char *file_path);
int proc_file_commands(char *file_path, int *exe_ret);
/****************************************** strtok.c ************************************/
int token_len(char *str, char *delim);
int count_tokens(char *str, char *delim);
char **_strtok(char *line, char *delim);
/****************************************** string_func.c **********************************/
int _strlen(const char *s);
char *_strcpy(char *dest, const char *src);
char *_strcat(char *dest, const char *src);
char *_strncat(char *dest, const char *src, size_t n);
/**********************string_function.c **********************************************************/
char *_strchr(char *s, char c);
int _strspn(char *s, char *accept);
int _strcmp(char *s1, char *s2);
int _strncmp(const char *s1, const char *s2, size_t n);
/********************************** shell_lex_init.c *************************************/
int main(int argc, char *argv[]);
void sig_handler(int sig);
int execute(char **args, char **front);
#endif /* _SHELL_H_ */