-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
47 lines (39 loc) · 928 Bytes
/
main.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
#include "shell.h"
/**
* main - simple shell main function
* @ac: count of arguments
* @argv: array of arguments
*
* Return: 0 on success
*/
int main(int ac, char **argv)
{
char *line = NULL;
char **command = NULL;
int status = 0, i = 0;
/* Ignore the argument count */
(void)ac;
/* Main loop */
while (1)
{
/* Read a line from standard input */
line = read_line();
/* If end of file is reached (CTRL + D), exit the loop */
if (line == NULL)
{
/* If the input is a terminal, print a newline */
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "\n", 1);
/* Return the last command's status */
return (status);
}
i++;
/* Tokenize the line into an array of words */
command = tokenizer(line);
/* If there are no words, skip this iteration */
if (command == NULL)
continue;
/* Execute the command and store its exit status */
status = _execute(command, argv, i);
}
}