-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_loop.c
77 lines (69 loc) · 1.23 KB
/
shell_loop.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
#include "main.h"
/**
* without_comment - deletes comments from the reg_inpute
*
* @in: reg_inpute string
* Return: reg_inpute without comments
*/
char *without_comment(char *in)
{
int i, up_to;
up_to = 0;
for (i = 0; in[i]; i++)
{
if (in[i] == '#')
{
if (i == 0)
{
free(in);
return (NULL);
}
if (in[i - 1] == ' ' || in[i - 1] == '\t' || in[i - 1] == ';')
up_to = i;
}
}
if (up_to != 0)
{
in = _realloc(in, i, up_to + 1);
in[up_to] = '\0';
}
return (in);
}
/**
* shell_loop - Loop of shell
* @data_shell: data relevant (av, reg_inpute, args)
*
* Return: no return.
*/
void shell_loop(d_sh *data_shell)
{
int loop, i_eof;
char *reg_inpute;
loop = 1;
while (loop == 1)
{
write(STDIN_FILENO, "^-^ ", 4);
reg_inpute = call_lines(&i_eof);
if (i_eof != -1)
{
reg_inpute = without_comment(reg_inpute);
if (reg_inpute == NULL)
continue;
if (check_syntax_error(data_shell, reg_inpute) == 1)
{
data_shell->status = 2;
free(reg_inpute);
continue;
}
reg_inpute = rep_var(reg_inpute, data_shell);
loop = divide_the_comad_exec(data_shell, reg_inpute);
data_shell->counter += 1;
free(reg_inpute);
}
else
{
loop = 0;
free(reg_inpute);
}
}
}