-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
51 lines (48 loc) · 879 Bytes
/
Copy pathmain.c
File metadata and controls
51 lines (48 loc) · 879 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
48
49
50
51
#include "header.h"
/**
* main - entry point for custom shell
*
* Return: 0
*/
int main(void)
{
char *line = NULL;
size_t len = 0;
ssize_t rd;
char **argv = NULL;
char **tokens = pathTok();
int i;
/* Ignore signals */
signal(SIGINT, SIG_IGN);
while (1)
{
if (isatty(STDIN_FILENO))
write(1, "$ ", 2);
rd = getline(&line, &len, stdin);
/* handles Ctrl+D presses */
if (rd == -1)
{
if (isatty(STDIN_FILENO))
write(1, "\n", 1);
break;
}
/* prep line */
i = remove_new_line(line);
if (!i)
continue;
/* verify a command is present */
if (line != NULL && rd > 1)
{
/* seperate line into command and arguments */
argv = seperate_line(line);
/* execute command */
execute_command(argv, line, tokens);
}
/* reset pathname */
if (argv != NULL && rd > 1)
free(argv);
}
free(line);
free(tokens);
return (0);
}