-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
40 lines (39 loc) · 1.04 KB
/
Copy pathshell.c
File metadata and controls
40 lines (39 loc) · 1.04 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
#include "shell.h"
/**
* main - Main function for the custom shell.
* @arg_count: The number of arguments.
* @arguments: The array of arguments.
* @environment: The array of environment variables.
* Return: 0 on success.
*/
int main(int __attribute__((unused)) arg_count, char **arguments,
char **environment)
{
size_t line_size = 0;
char *input_line = NULL, **command_tokens, *executable_path,
*prompt = "$ ";
while (1)
{
if (isatty(STDIN_FILENO) != 0)
write(STDOUT_FILENO, prompt, string_length(prompt));
input_line = NULL;
read_line(&input_line, line_size);
command_tokens = split_string(input_line, " ");
exit_shell(command_tokens, input_line);
executable_path = get_executable_path(command_tokens[0],
environment);
if (executable_path == NULL)
{
print_custom_error(arguments[0], command_tokens[0]);
free(command_tokens);
free(input_line);
continue;
}
else
process_command(command_tokens, environment,
executable_path, input_line);
if (isatty(STDIN_FILENO) == 0)
exit(0);
}
return (0);
}