-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
50 lines (44 loc) · 802 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
48
49
50
#include "shell.h"
#include <stdlib.h>
#include <unistd.h>
/**
* main_errors_helper - error handler to prevent more than 40 line
* @text: error message
* @code: exit code
* Return: Nothing.
*/
void main_errors_helper(char *text, int code)
{
perror(text);
exit(code);
}
/**
* main - the program starts here.
* @argc: argument length
* @argv: arguments
* Return: 0
*/
int main(int argc, char *argv[])
{
char *prompt = "#cisfun$ ", *line, **args;
int status = 1;
(void)argc;
do {
if (isatty(STDIN_FILENO))
write(STDIN_FILENO, prompt, _strlen(prompt));
line = read_line();
if (line == NULL)
{
free(line);
break;
}
args = parse_line(line);
if (args[0] != NULL)
{
execute_command(args, argv);
free(args);
}
free(line);
} while (status);
return (0);
}