-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_ex.c
More file actions
93 lines (89 loc) · 1.67 KB
/
_ex.c
File metadata and controls
93 lines (89 loc) · 1.67 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
#include "sshell.h"
/**
*type_exit - get the type of exit
* @p: input user, array of pointers
* @loop: counter of loops
* @li: input user
* @i: number of pointers inside the array of pointers
* @v: arguments in input
* @m: copy of environmental variables
* @e: number of elements in m
*/
void type_exit(char **p, int loop, char *li, int i, char *v[], char **m, int e)
{
unsigned int valor = 0, cont = 0, flag = 0;
if (p[1] == NULL || (p[1][0] == '0' && p[1][1] == '\0'))
{
free(li);
gridfree(p, i);
gridfree(m, e);
exit(0);
}
else
{
while (p[1][cont] != '\0')
{
if (p[1][cont] < 48 || p[1][cont] > 57)
{
flag = 1;
break;
}
cont++;
}
if (flag == 1)
_put_err(p, loop, 1, v);
else
{
valor = _atoi(p[1]);
if (!(valor > INT_MAX))
{
valor = valor % 256;
free(li);
gridfree(p, i);
gridfree(m, e);
exit(valor);
}
else
_put_err(p, loop, 1, v);
}
}
}
/**
* _ex - finds if line input is exit therefore process termination
* @p: input of user
* @loop: loop counter
* @li: input user
* @x: number of pointers inside array of pointers
* @v: arguments in input
* @m: copy of environmental variables
* @e: number of elements in m
* Return: -1 if there is no exit or 0 if there is the word exit
*/
int _ex(char **p, int loop, char *li, int x, char *v[], char **m, int e)
{
char str[] = "exit";
int i, cont = 0, salida = -1;
i = 0;
while (p[0][i] != '\0')
{
if (i < 4)
{
if (p[0][i] == str[i])
cont++;
}
i++;
}
if (i == 4)
cont++;
if (cont == 5)
{
type_exit(p, loop, li, x, v, m, e);
salida = 0;
}
else if (cont == 4)
{
salida = 0;
_put_err(p, loop, 3, v);
}
return (salida);
}