-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
37 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/12 16:57:35 by simao #+# #+# */ | ||
/* Updated: 2023/08/08 11:25:23 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 18:08:29 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/12 16:57:31 by simao #+# #+# */ | ||
/* Updated: 2023/08/12 16:44:45 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 18:29:08 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -48,8 +48,9 @@ int calc_exit(int exit) | |
} | ||
|
||
/* Should release all allocated resources before exiting, | ||
if is_cmd == 5 -> exit has more than 1 argument*/ | ||
void cmd_exit(char *exit_nr, int is_cmd) | ||
if is_cmd == 5 -> exit has more than 1 argument | ||
is_exit: */ | ||
void cmd_exit(char *exit_nr, int is_exit) | ||
{ | ||
int number; | ||
|
||
|
@@ -60,11 +61,11 @@ void cmd_exit(char *exit_nr, int is_cmd) | |
if (get_data()->envp) | ||
free_keys(get_data()->envp); | ||
free_env(); | ||
if (is_cmd) | ||
if (is_exit) | ||
ft_printf("exit\n"); | ||
if (has_alpha(exit_nr)) | ||
ft_printf("exit: %s: numeric argument required\n", exit_nr); | ||
else if (is_cmd == 5) | ||
else if (is_exit == 5) | ||
{ | ||
ft_printf("exit: too many arguments\n"); | ||
number = 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/14 12:54:51 by simao #+# #+# */ | ||
/* Updated: 2023/08/12 16:08:19 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 17:44:49 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -39,9 +39,9 @@ void print_sorted_env(t_env *sorted_temp) | |
while (tmp) | ||
{ | ||
if (tmp->value) | ||
printf("declare -x %s=%s\n", tmp->key, tmp->value); | ||
ft_printf("declare -x %s=%s\n", tmp->key, tmp->value); | ||
else | ||
printf("declare -x %s\n", tmp->key); | ||
ft_printf("declare -x %s\n", tmp->key); | ||
tmp = tmp->nxt; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/18 18:12:49 by smagalha #+# #+# */ | ||
/* Updated: 2023/08/12 17:12:46 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 18:45:07 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -39,7 +39,9 @@ void execute_input(t_list *node, char **envp) | |
execute_builtin(node); | ||
else | ||
{ | ||
get_data()->executing_cmd = 0; | ||
get_data()->executing_cmd = 1; | ||
if (!ft_strncmp("./minishell", node->token[0], 12)) | ||
get_data()->mini_inception = 1; | ||
pid1 = fork(); | ||
if (pid1 == 0) | ||
{ | ||
|
@@ -54,6 +56,7 @@ void execute_input(t_list *node, char **envp) | |
if (WIFEXITED(status)) | ||
get_data()->exit = WEXITSTATUS(status); | ||
get_data()->executing_cmd = 0; | ||
get_data()->mini_inception = 0; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/05/25 17:45:31 by esali #+# #+# */ | ||
/* Updated: 2023/08/12 17:32:54 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 18:43:48 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -17,6 +17,7 @@ int main(int argc, char **argv, char **env) | |
if (argc != 1 || argv[1] != NULL) | ||
return (0); | ||
create_env(env); | ||
get_data()->executing_cmd = 0; | ||
increase_shlvl(); | ||
get_data()->exit = 0; | ||
get_pipe()->stdin = dup(STDIN_FILENO); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/20 17:16:06 by esali #+# #+# */ | ||
/* Updated: 2023/08/12 16:49:55 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 18:39:49 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -68,6 +68,7 @@ typedef struct s_data | |
int executing_cmd; | ||
int pid; | ||
int log_fd; | ||
int mini_inception; | ||
} t_data; | ||
|
||
/* Builtin Commands */ | ||
|
@@ -78,7 +79,7 @@ void cmd_echo(char **line); | |
void cmd_env(char **token); | ||
void cmd_export(char **variable); | ||
void cmd_unset(char **variable); | ||
void cmd_exit(char *number, int is_cmd); | ||
void cmd_exit(char *number, int is_exit); | ||
t_env *sort_loop(t_env *dup_env, t_env *sorted_env); | ||
void new_env(char *key, char *value); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/12 22:54:29 by simao #+# #+# */ | ||
/* Updated: 2023/08/08 14:45:25 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 18:48:11 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -16,8 +16,11 @@ void handle_sigint(int sig) | |
{ | ||
if (get_data()->executing_cmd) | ||
{ | ||
get_data()->exit = 127 + sig; | ||
ft_printf("\n"); | ||
if (!get_data()->mini_inception) | ||
{ | ||
get_data()->exit = 127 + sig; | ||
ft_printf("\n"); | ||
} | ||
} | ||
else | ||
{ | ||
|
@@ -37,11 +40,14 @@ void handle_sigquit(int sig) | |
{ | ||
if (get_data()->executing_cmd) | ||
{ | ||
get_data()->exit = 127 + sig; | ||
ft_printf("\b \b"); | ||
ft_printf("\b \b"); | ||
ft_printf("Quit (core dumped)\n"); | ||
cmd_exit(ft_itoa(get_data()->exit), 0); | ||
if (!get_data()->mini_inception) | ||
{ | ||
get_data()->exit = 127 + sig; | ||
ft_printf("\b \b"); | ||
ft_printf("\b \b"); | ||
ft_printf("Quit (core dumped)\n"); | ||
cmd_exit(ft_itoa(get_data()->exit), 0); | ||
} | ||
} | ||
else | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/01 19:44:27 by esali #+# #+# */ | ||
/* Updated: 2023/08/12 16:08:26 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 17:50:18 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -44,6 +44,7 @@ void new_env(char *key, char *value) | |
{ | ||
t_env *lst; | ||
|
||
ft_printf("new_env\n"); | ||
lst = get_env(); | ||
while (lst->nxt != NULL) | ||
lst = lst->nxt; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: esali <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/12 15:06:00 by esali #+# #+# */ | ||
/* Updated: 2023/08/12 17:22:42 by esali ### ########.fr */ | ||
/* Updated: 2023/08/12 18:08:36 by esali ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -46,7 +46,6 @@ void increase_shlvl(void) | |
char *env; | ||
|
||
env = ft_getenv("SHLVL"); | ||
ft_printf("env: %s", env); | ||
if (!env) | ||
shlvl = 1; | ||
if (is_digit(env) == 0) | ||
|