-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
70 lines (64 loc) · 1.25 KB
/
shell.c
File metadata and controls
70 lines (64 loc) · 1.25 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
#include "main.h"
/**
*displayPrompt - displays prompt
*Return: must return 0 for success
*/
/*int displayPrompt(void)
{
char buffer[1024];
if (getcwd(buffer, sizeof(buffer)) == NULL)
{
perror("getcwd");
return (-1);
}
printString("\n");
printString("(\x1B[36m$\x1B[0m)--[");
printString("\x1B[35m");
printString(buffer);
printString("\x1B[0m");
printString("]--(\x1B[36m$\x1B[0m)\n");
printString("\x1B[91m>>\x1B[0m ");
return (0);
}*/
/**
*loopPrompt - shell loop
*@data: shell data
*/
void loopPrompt(shell_data *data)
{
int n, count, eof, loop = 1;
size_t buff;
char *input_copy;
while (loop == 1)
{
/*displayPrompt();*/
write(STDIN_FILENO, "($) ", 4);
eof = _getline(&data->input, &buff, stdin);
if (eof != -1)
{
data->exitstring = 0;
input_copy = _strdup(data->input);
count = countTokens(input_copy, " ");
if ((_strncmp(data->input, "exit", 4) == 0) && (count == 1 || count == 2))
free(input_copy);
n = inputFix(data);
if (n == 0)
commandChecker(data);
else if (n == 2)
printEnv(data);
if (data->exitstring != 1)
free(input_copy);
}
else
{
loop = 0;
if (data->space != 1)
free(data->input);
else
{
data->input = _strdup(input_copy);
free(data->input);
}
}
}
}