-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_token_0.c
48 lines (47 loc) · 995 Bytes
/
check_token_0.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
#include "shell.h"
/**
* checkTokens - Checks the command in the tokens array
*
* @tokens: An array of command tokens
* @argv: An array of command line arguments
* @line: A pointer to the command line
* @status2: A pointer to the status
*/
void checkTokens(char **tokens, char **argv, char *line, int *status2)
{
if (strcmp(tokens[0], "cd") == 0)
{
implementCdCommand(tokens, argv);
}
if (strcmp(tokens[0], "env") == 0)
{
printEnvironment();
}
if (myCustomStrcmp(tokens[0], "setenv") == 0)
{
if (tokens[1] != NULL)
{
myCustomSetenv(tokens[1], tokens[2], 1);
}
}
if (myCustomStrcmp(tokens[0], "unsetenv") == 0)
{
if (tokens[1] != NULL)
{
myCustomUnsetenv(tokens[1]);
}
}
if (myCustomStrcmp(tokens[0], "exit") == 0)
{
if (tokens[1] != NULL && (myCustomAtoi(tokens[1]) > 0 ||
myCustomAtoi(tokens[1]) < 0 ||
myCustomAtoi(tokens[1]) == 0))
{
*status2 = findExitStatus(tokens, line, argv);
}
}
if (tokens == NULL)
{
free(line);
}
}