-
Notifications
You must be signed in to change notification settings - Fork 0
/
loop.c
36 lines (33 loc) · 936 Bytes
/
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
#include "nice_header.h"
/**
* shellLoop - Run the shell
* @argv: n
* Return: nothing
*/
int shellLoop(char **argv)
{
ssize_t getLine = 1;
char **tokens = NULL, *buffer = NULL, *fullPath = NULL, *pathCopy = NULL;
Node *path = NULL;
int errorShowed = 0, counter = 1;
path = listpath(&pathCopy);
while (1)
{
fflush(stdout);
/*if (isatty(STDIN_FILENO))*/
/*write(1, "$", 1); test non interactive*/
getLine = readLine(&buffer, &tokens);
if (getLine == EOF) /* check for EOF */
break;
errorShowed = 0;
fullPath = addPath(&tokens, path);
isPath(&tokens, &fullPath, argv, &counter, &errorShowed);
isDir(&tokens, &fullPath, argv, &counter, &errorShowed);
executeLine(&buffer, &tokens, fullPath, &errorShowed);
counter++;
}
free_list(path); /* linked list with all the paths */
free(pathCopy); /* free linked list of all directories of path */
free(buffer); /* main buffer */
return (errorShowed);
}