-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionality.c
147 lines (134 loc) · 2.82 KB
/
functionality.c
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
#include "shell.h"
void custom_null_command(char *one);
void custom_get_out(char *one, char **two);
void custom_env_end(char *one, char **two, char **env);
void custom_print_env(char **two);
/**
* Custom_execute - This Function perform verify
* and execute every command.
* @one: Char double pointer that
* points to a command to perform.
* @two: char pointer that points
* to command in getline.
* @env: char double pointer that
* points to the environemet variable.
* @three: char double pointer that
* points to argument Counter.
* @four: int that represents the
* number of times that executed.
*
* Return: Nothing(void).
*/
void Custom_execute(char **one, char *two, char **env, char **three, int four)
{
struct stat fileStat;
if (one == NULL)
{
custom_null_command(two);
}
else if (_strcmp("exit", one[0]))
{
custom_get_out(two, one);
}
else if (_strcmp("env", one[0]))
{
custom_env_end(two, one, env);
}
else if (stat(one[0], &fileStat) == 0)
{
execve(one[0], one, NULL);
}
else
{
custom_path(one, two, env, three, four);
}
}
/**
* custom_null_command - THis Function Free
* the buffer that is created.
* @one: char pointer that points to a buffer
* taked from getline.
*Return: Nothing(void).
*/
void custom_null_command(char *one)
{
free(one);
exit(EXIT_SUCCESS);
}
/**
* custom_get_out - this function Free
* the buffer and the commands taken from getline.
* @one: char pointer that points
* to a buffer taked from getline.
* @two: char double pointer that
* points to the command inserted.
* Return: Nothing(void).
*/
void custom_get_out(char *one, char **two)
{
unsigned int three = 0;
free(one);
if (two != NULL)
{
while (two[three])
{
free(two[three]);
three++;
}
if (two[three] == NULL)
free(two[three]);
free(two);
}
exit(EXIT_SUCCESS);
}
/**
* custom_env_end - this Function frees
* the buffer and commands created in getline.
* @one: Char pointer that points
* to a buffer from getline.
* @two: char double pointer that points to
* an array store commands.
* @env: char double pointer that points to
* enviroment variables
*
* Return: Nothing(void).
*/
void custom_env_end(char *one, char **two, char **env)
{
unsigned int three = 0;
free(one);
if (two != NULL)
{
while (two[three])
{
free(two[three]);
three++;
}
if (two[three] == NULL)
free(two[three]);
free(two);
}
custom_print_env(env);
exit(EXIT_SUCCESS);
}
/**
* custom_print_env - THis Function prints
* all enviroment variables.
*
* @two: char double pointer that points
* to a enviroment variables for the user.
*
* Return: Nothing(void).
*/
void custom_print_env(char **two)
{
unsigned int three = 0;
unsigned int four;
while (two[three])
{
four = _strlen(two[three]);
write(STDOUT_FILENO, two[three], four);
write(STDOUT_FILENO, "\n", 1);
three++;
}
}