-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchecks.c
84 lines (81 loc) · 1.42 KB
/
checks.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
#include "shell.h"
/**
* env_check - check the code.
* @array: a double pointer
* Return: double pointer.
*/
void env_check(char **array)
{
int j, l;
if (_strlen(array[0]) == _strlen("env") && _strcmp(array[0], "env") == 0)
for (j = 0; environ[j] != NULL; j++)
{
for (l = 0; environ[j][l] != '\0'; l++)
_putchar(environ[j][l]);
_putchar('\n');
}
}
/**
* clear_check - check the code.
* @array: a double pointer
* Return: double pointer.
*/
int clear_check(char **array)
{
if (_strlen(array[0]) == _strlen("clear") && _strcmp(array[0], "clear") == 0)
{
system("clear");
return (0);
}
return (1);
}
/**
* exit_check - check the code.
* @array: a double pointer
* @line: a pointer
* @exit_stat: a variable
* Return: void.
*/
void exit_check(char **array, char *line, int exit_stat)
{
int tmp;
if (_strlen(array[0]) == _strlen("exit") && _strcmp(array[0], "exit") == 0)
{
if (array[1] != NULL)
{
tmp = atoi(array[1]);
free_2D(array);
free(line);
exit(tmp);
}
else if (exit_stat == -1)
{
free_2D(array);
free(line);
exit(0);
}
free_2D(array);
free(line);
exit(exit_stat);
}
}
/**
* spaces_tabs_check - check the code.
* @line: a pointer
* Return: double pointer.
*/
int spaces_tabs_check(char *line)
{
int i;
i = 0;
while (line[i] != '\0')
{
if (line[i] == ' ' || line[i] == '\t')
i++;
else
break;
}
if (i == _strlen(line) - 1)
return (0);
return (1);
}