-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #530 from biralavor/417-root-files-norminette-update
root files - applying norminette
- Loading branch information
Showing
7 changed files
with
89 additions
and
114 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
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
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,76 +6,27 @@ | |
/* By: umeneses <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/06/12 10:53:12 by umeneses #+# #+# */ | ||
/* Updated: 2024/10/09 20:01:35 by umeneses ### ########.fr */ | ||
/* Updated: 2024/10/10 08:07:19 by umeneses ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.h" | ||
|
||
static void extra_args(void) | ||
{ | ||
ft_printf(RED"Error: minishell does not accept arguments.\n"); | ||
ft_printf(CYAN"It's a kind of magic, but not that much!\n"RESET); | ||
exit (EXIT_FAILURE); | ||
} | ||
|
||
// void control_d_handler(char *input) | ||
// { | ||
// if (input == NULL) | ||
// { | ||
// ft_putendl_fd("exit", STDOUT_FILENO); | ||
// // env_holder(NULL, false, true); | ||
// // free(input); | ||
// exit_status_holder(EXIT_SUCCESS, true); | ||
// } | ||
// } | ||
|
||
bool addto_history_detector(const char *input) | ||
{ | ||
int idx; | ||
|
||
idx = 0; | ||
if (!ft_strcmp(input, "")) | ||
return (false); | ||
else | ||
{ | ||
while (input[idx]) | ||
{ | ||
if (input[idx] != 32) | ||
return (true); | ||
idx++; | ||
} | ||
} | ||
return (false); | ||
} | ||
|
||
int main(int ac, char **av, char **envp) | ||
{ | ||
char *input; | ||
|
||
if (ac > 1 && av) | ||
extra_args(); | ||
signals_init(is_interactive()); | ||
tty_proprieties_manager(false); | ||
environment_init(envp); | ||
// signals_manager(g_sigmonitor); | ||
minishell_init(ac, av, envp); | ||
while (true) | ||
{ | ||
is_after_loop(false); | ||
sigquit_activated(); | ||
// fprintf(stderr, BLUE"exit_status: %d\n"RESET, exit_status_holder(0, false)); | ||
// fprintf(stderr, YELLOW"g_sigmonitor na main: %d\n"RESET, g_sigmonitor); | ||
input = readline(GREEN"<<< Born Again (mini) SHell >>>$ "RESET); | ||
if (input == NULL) | ||
{ | ||
ft_putendl_fd("exit", STDOUT_FILENO); | ||
env_holder(NULL, false, true); | ||
close(STDIN_FILENO); | ||
close(STDOUT_FILENO); | ||
close(STDERR_FILENO); | ||
control_d_handler(); | ||
return (exit_status_holder(EXIT_SUCCESS, true)); | ||
} | ||
// control_d_handler(input); | ||
is_after_loop(true); | ||
if (addto_history_detector(input)) | ||
add_history(input); | ||
|
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,57 +6,44 @@ | |
/* By: umeneses <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/09/13 09:47:06 by umeneses #+# #+# */ | ||
/* Updated: 2024/10/09 21:51:04 by umeneses ### ########.fr */ | ||
/* Updated: 2024/10/10 08:21:25 by umeneses ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.h" | ||
|
||
volatile sig_atomic_t g_sigmonitor = 0; | ||
|
||
void signals_init(bool interactive) | ||
void signals_manager(bool interactive) | ||
{ | ||
struct sigaction signal; | ||
|
||
signal.sa_handler = interrupt_signal_runner; | ||
sigemptyset(&signal.sa_mask); | ||
signal.sa_flags = SA_RESTART; | ||
if (sigaction(SIGINT, &signal, NULL) == -1) | ||
{ | ||
perror("sigaction error"); | ||
exit(exit_status_holder(EXIT_FAILURE, true)); | ||
} | ||
sigaction_error_manager(); | ||
if (interactive) | ||
{ | ||
signal.sa_handler = SIG_IGN; | ||
sigemptyset(&signal.sa_mask); | ||
signal.sa_flags = SA_RESTART; | ||
if (sigaction(SIGQUIT, &signal, NULL) == -1) | ||
{ | ||
perror("sigaction error"); | ||
exit(exit_status_holder(EXIT_FAILURE, true)); | ||
} | ||
sigaction_error_manager(); | ||
} | ||
else | ||
{ | ||
signal.sa_handler = SIG_DFL; | ||
} | ||
sigemptyset(&signal.sa_mask); | ||
signal.sa_flags = SA_RESTART; | ||
if (sigaction(SIGQUIT, &signal, NULL) == -1) | ||
{ | ||
perror("sigaction error"); | ||
exit(exit_status_holder(EXIT_FAILURE, true)); | ||
} | ||
sigaction_error_manager(); | ||
} | ||
|
||
// void signals_manager(int sig_nbr) | ||
// { | ||
// if (sig_nbr == SIGINT) | ||
// interrupt_signal_runner(); | ||
// else if (sig_nbr == SIGQUIT) | ||
// quit_signal_blocker(); | ||
// } | ||
void sigaction_error_manager(void) | ||
{ | ||
perror("sigaction error"); | ||
exit(exit_status_holder(EXIT_FAILURE, true)); | ||
} | ||
|
||
void interrupt_signal_runner(int sig) | ||
{ | ||
|
@@ -78,33 +65,6 @@ void interrupt_signal_runner(int sig) | |
exit_status_holder(130, true); | ||
} | ||
|
||
// void quit_signal_blocker(void) | ||
// { | ||
// // static sigset_t sig_tobe_blocked; | ||
// static struct sigaction monitor_sigquit; | ||
|
||
// monitor_sigquit.sa_handler = SIG_IGN; | ||
// monitor_sigquit.sa_flags = SA_RESTART; | ||
// sigemptyset(&monitor_sigquit.sa_mask); | ||
// sigaction(SIGQUIT, &monitor_sigquit, NULL); | ||
// if (child_process_is_running(false, true)) | ||
// { | ||
// monitor_sigquit.sa_handler = SIG_DFL; | ||
// monitor_sigquit.sa_flags = SA_RESTART; | ||
// sigemptyset(&monitor_sigquit.sa_mask); | ||
// // sigemptyset(&sig_tobe_blocked); | ||
// // sigaddset(&sig_tobe_blocked, SIGQUIT); | ||
// // if (sigismember(&sig_tobe_blocked, SIGQUIT) == 1) | ||
// // sigprocmask(SIG_BLOCK, &sig_tobe_blocked, NULL); | ||
// // rl_on_new_line(); | ||
// // if (!is_after_loop(false)) | ||
// // rl_redisplay(); | ||
// // ft_putendl_fd(RED"^\\quit (core dumped) T.T"RESET, STDERR_FILENO); | ||
// // tty_proprieties_manager(true); | ||
// } | ||
// // rl_replace_line("", 0); | ||
// } | ||
|
||
bool is_after_loop(bool update) | ||
{ | ||
static bool after_loop; | ||
|
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
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: umeneses <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/08/07 12:58:03 by umeneses #+# #+# */ | ||
/* Updated: 2024/10/08 22:49:59 by umeneses ### ########.fr */ | ||
/* Updated: 2024/10/10 08:13:00 by umeneses ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -52,7 +52,7 @@ void free_env_table(t_env_entry **table) | |
if (curr) | ||
free(curr); | ||
curr = tmp; | ||
} | ||
} | ||
*table = NULL; | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* minishell_init.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: umeneses <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/10/10 08:02:42 by umeneses #+# #+# */ | ||
/* Updated: 2024/10/10 08:23:38 by umeneses ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.h" | ||
|
||
static void extra_args(void); | ||
|
||
void minishell_init(int ac, char **av, char **envp) | ||
{ | ||
if (ac > 1 && av) | ||
extra_args(); | ||
signals_manager(is_interactive()); | ||
tty_proprieties_manager(false); | ||
environment_init(envp); | ||
} | ||
|
||
static void extra_args(void) | ||
{ | ||
ft_printf(RED"Error: minishell does not accept arguments.\n"); | ||
ft_printf(CYAN"It's a kind of magic, but not that much!\n"RESET); | ||
exit (EXIT_FAILURE); | ||
} | ||
|
||
void control_d_handler(void) | ||
{ | ||
ft_putendl_fd("exit", STDOUT_FILENO); | ||
env_holder(NULL, false, true); | ||
close(STDIN_FILENO); | ||
close(STDOUT_FILENO); | ||
close(STDERR_FILENO); | ||
} | ||
|
||
bool addto_history_detector(const char *input) | ||
{ | ||
int idx; | ||
|
||
idx = 0; | ||
if (!ft_strcmp(input, "")) | ||
return (false); | ||
else | ||
{ | ||
while (input[idx]) | ||
{ | ||
if (input[idx] != 32) | ||
return (true); | ||
idx++; | ||
} | ||
} | ||
return (false); | ||
} |