-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_instance.c
More file actions
42 lines (35 loc) · 981 Bytes
/
shell_instance.c
File metadata and controls
42 lines (35 loc) · 981 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
#include "shell.h"
/**
* _shell_instance - and instance of the shell
* Return: status code
*/
int _shell_instance(void)
{
/* char *welcome = generate_prompt_line("BIT.SH"); */
char *buffer = NULL, *pPath = NULL;
char **t_args = NULL;
ssize_t EOFCheck;
unsigned int stat = 1;
size_t getLineLen = 0;
write(STDOUT_FILENO, "$ ", 2);
/* signal(SIGINT, SIG_IGN); */
EOFCheck = getline(&buffer, &getLineLen, stdin);
if (EOFCheck == -1)
stat = _SHELL_END_, write(STDOUT_FILENO, "\n", 1);
if (EOFCheck == 1)
stat = _SKIP_;
if (stat == _NORMAL_)
t_args = tokeniser(&buffer, "' '\n\t");
/* printf("LOLOLO[%s]\n", t_args[0]); */
if (stat == _NORMAL_)
stat = run_built_in(t_args);
if (stat == _NORMAL_ && (t_args[0][0] != '.' && t_args[0][1] != '/'))
pPath = get_path_args(t_args[0]);
if (stat == _NORMAL_)
exec_process(pPath ? pPath : t_args[0], t_args), wait(NULL);
/* free(welcome); */
free(buffer);
free(t_args);
free(pPath);
return (stat);
}