-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
47 lines (43 loc) · 842 Bytes
/
Copy pathmain.c
File metadata and controls
47 lines (43 loc) · 842 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 - Main program
* @argc: Argument count
* @argv: Argument vector
* @env: environment variable
*
* Return: This will be returned by the shell program
*/
int main(int argc, char **argv, char **env)
{
char *line = NULL, *prompt = ">> $ ", **tokens = NULL;
int mode;
if (argc > 1 || argv == NULL)
write(2, "Please run with no arguments\n", 29), exit(127);
signal(SIGINT, signal_handler);
/* Handle Non-interactive mode */
mode = isatty(0);
while (1)
{
if (mode == 1)
write(STDOUT_FILENO, prompt, 5);
line = _getline();
if (line != NULL)
{
comment_handler(line);
tokens = _token(line);
if (tokens[0] == NULL || tokens == NULL)
{
free(line), free_token_array(tokens);
}
else
{
exec_cmd(tokens, argv, line, env);
}
}
else
{
exit(0);
}
}
return (0);
}