-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshell.c
More file actions
50 lines (49 loc) · 1.14 KB
/
shell.c
File metadata and controls
50 lines (49 loc) · 1.14 KB
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 "holberton.h"
/**
* main - Entry point of shell
* @ac: argument counter
* @argv: argument values
* @envp: enviroments
* Return: 0 if success
*/
int main(int ac, char *argv[], char *envp[])
{
char *lineptr = NULL, *full_path = NULL;
char interactive, *prompt = "$jessiFer> ", **myargv;
size_t n = 0;
ssize_t bytes;
int bytes_exec = 0, c_prompt = 1;
op_t operate;
(void)ac, (void)argv;
interactive = isatty(STDIN_FILENO);
if (interactive)
signal(SIGINT, sighandler);
while ((bytes = getline(&lineptr, &n, stdin)))
{
if (bytes > 0)
{ myargv = build_argv(lineptr);
if (myargv && myargv[0] != NULL)
{ operate.f = getfunction(myargv[0]);
if (operate.f != NULL)
operate.f(myargv, envp, lineptr, bytes_exec);
else
{ bytes_exec = build_path(c_prompt, &full_path, myargv[0], envp);
if (bytes_exec != 127)
bytes_exec = myexec(lineptr, full_path, myargv, envp);
free(full_path); }
}
free(myargv); }
else if (bytes < 0)
{ free(lineptr);
exit(0);
}
if (interactive)
write(1, prompt, 12);
free(lineptr);
lineptr = NULL;
myargv = NULL;
full_path = NULL;
c_prompt++;
}
return (0);
}