-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.c
More file actions
47 lines (45 loc) · 847 Bytes
/
Copy pathloop.c
File metadata and controls
47 lines (45 loc) · 847 Bytes
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
#include"main.h"
/**
* main - the loop for simple shell.
* Return: always 0;
*/
int main(void)
{
int status;
char *input, **tokens, *buffer;
ssize_t bytes, buff_size;
const ssize_t BUFFSIZE = 1024;
status = 1;
if (isatty(STDIN_FILENO))
{
do {
printf("($)");
fflush(stdout);
input = get_input();
tokens = tokenizer(input);
if (tokens[0])
shell_executor(tokens);
free(tokens);
free(input);
} while (status);
}
else
{
buff_size = BUFFSIZE;
buffer = malloc(buff_size * sizeof(char));
if (!buffer)
perror("./hsh");
bytes = read(STDIN_FILENO, buffer, BUFFSIZE);
if ((int)bytes == -1)
perror("./hsh");
if ((int)bytes == 0)
_strcpy(buffer, "\n");
buffer[bytes] = '\0';
input = buffer;
tokens = tokenizer(input);
shell_executor(tokens);
}
free(buffer);
free(tokens);
return (0);
}