-
Notifications
You must be signed in to change notification settings - Fork 0
/
char_handler.c
85 lines (67 loc) · 1.1 KB
/
char_handler.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"
/**
* grid_free - free grid of int ptrs
* @gridd: Char double ptr freed
* @_height: int for height to be passed
* Return: void
*/
void grid_free(char **gridd, int _height)
{
int k;
for (k = 0; k < _height; k++)
free(gridd[k]);
free(gridd);
}
/**
* no_nul - remov new line using NULL char
* @l: c_lin
* Return: nothing
*/
void no_nul(char *l)
{
int i = 0;
while (l[i])
{
if (l[i] == '\n')
{
l[i] = '\0';
return;
}
i++;
}
}
/**
* char_special - exits shell and handles
* @byt: nbr of byt read from inpt
* @buffer: buffer char
* @exit_st: exit status
* Return: 0 succces
*/
int char_special(char *buffer, ssize_t byt, int *exit_st)
{
int i = 0;
if (byt == EOF && isatty(STDIN_FILENO) == 1)
{
put_char('\n');
free(buffer);
exit(*exit_st);
}
if (byt == EOF && isatty(STDIN_FILENO) == 0)
{
free(buffer);
exit(*exit_st);
}
if (str_cmp(buffer, "\n") == 0)
{
*exit_st = 0;
return (127);
}
while (buffer[i] != '\n')
{
if (buffer[i] != ' ' && buffer[i] != '\t')
return (0);
++i;
}
*exit_st = 0;
return (127);
}