did some slight norming (200 lines of norminette and i'm not even done yet... :c)

This commit is contained in:
mdev9
2024-04-22 19:56:22 +02:00
parent 642a9ab232
commit e4df4a5655
15 changed files with 98 additions and 112 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */
/* Updated: 2024/04/22 13:40:49 by marde-vr ### ########.fr */
/* Updated: 2024/04/22 19:39:03 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
/* Updated: 2024/04/19 14:42:50 by tomoron ### ########.fr */
/* Updated: 2024/04/22 19:32:11 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
/* Updated: 2024/04/22 19:18:52 by marde-vr ### ########.fr */
/* Updated: 2024/04/22 19:55:41 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,12 +26,6 @@ void get_redirections(t_msh *msh, t_cmd *cmds)
if (!get_out_type(msh, cmds))
get_in_type(msh, cmds);
}
/*
printf("in_type:");
print_cmd_type(msh->in_type, 0);
printf("\nout_type:");
print_cmd_type(msh->out_type, 0);
printf("\n");*/
}
t_cmd *get_next_command(t_cmd *cmd)
@ -58,23 +52,18 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
if (!cmd_str)
return ;
cmds = parsing_bonus(cmd_str);
//print_parsed_cmd(cmds); // debug
tmp = check_cmds_syntax(cmds);
if (tmp)
{
print_syntax_error_bonus(tmp);
//printf("error\n"); // debug
free_cmd(cmds);
return ;
}
msh->cmds_head = cmds;
while (cmds)
{
//print_parsed_cmd(cmds); // debug
msh->tokens = parse_cmds_to_token(cmds, msh->env);
msh->cmds = cmds;
//print_msh_struct(msh); // debug
//print_parsed_token(msh->tokens); // debug
exec_commands(msh);
msh->in_fd = 0;
msh->out_fd = 0;
@ -89,14 +78,12 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
if (i != cmd_count - 1)
{
//fprintf(stderr, "piping %d", i);
if (pipe(msh->fds[i]) == -1)
{
perror("minishell: pipe");
free(cmd_args);
ft_exit(msh, 1);
}
//fprintf(stderr, "pipe: msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][1]);
}
pid = fork();
if (pid == -1)
@ -140,7 +127,8 @@ int get_cmd_count(t_cmd *cmds)
cmds = cmds->next;
if (is_cmd_type(cmds))
nb++;
while(cmds && (is_output_type(cmds) || is_input_type(cmds) || is_cmd_type(cmds)))
while (cmds && (is_output_type(cmds) || is_input_type(cmds)
|| is_cmd_type(cmds)))
cmds = cmds->next;
if (cmds && cmds->cmd_type == PIPE)
cmds = cmds->next;
@ -151,14 +139,14 @@ int get_cmd_count(t_cmd *cmds)
void print_signaled(int status)
{
int signal;
static const char *sigmsg[] = {0, "Hangup", 0, "Quit", \
"Illegal instruction", "Trace/breakpoint trap", "Aborted", "Bus error", \
"Floating point exception", "Killed", "User defined signal 1", \
"Segmentation fault (skill issue)", "User defined signal 2", 0,\
"Alarm clock", "Terminated", "Stack fault" ,0 ,0, "Stopped", "Stopped",\
"Stopped", "Stopped", 0, "CPU time limit exceeded",\
"File size limit exceeded", "Virtual time expired",\
"Profiling timer expired","I/O possible", "Power failure",\
static const char *sigmsg[] = {0, "Hangup", 0, "Quit", "Illegal \
instruction", "Trace/breakpoint trap", "Aborted", "Bus error",
"Floating point exception", "Killed", "User defined signal 1",
"Segmentation fault (skill issue)", "User defined signal 2", 0,
"Alarm clock", "Terminated", "Stack fault", 0, 0, "Stopped", "Stopped",
"Stopped", "Stopped", 0, "CPU time limit exceeded",
"File size limit exceeded", "Virtual time expired",
"Profiling timer expired", "I/O possible", "Power failure",
"Bad system call"};
signal = WTERMSIG(status);
@ -194,16 +182,16 @@ void end_execution(t_msh *msh, int cmd_count)
free_fds(msh);
msh->pids = 0;
free(msh->fds);
signal(SIGINT, signal_handler_interactive); //enables ctrl-C
signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive);
set_echoctl(0);
}
int handle_parenthesis(t_msh *msh)
{
if(!(msh->cmds->cmd_type == PAREN || (msh->cmds->cmd_type == PIPE && msh->cmds->next->cmd_type == PAREN)))
if (!(msh->cmds->cmd_type == PAREN || (msh->cmds->cmd_type == PIPE
&& msh->cmds->next->cmd_type == PAREN)))
return (0);
return (1);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
/* Updated: 2024/04/21 23:46:43 by tomoron ### ########.fr */
/* Updated: 2024/04/22 19:31:12 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
/* Updated: 2024/04/22 19:12:50 by marde-vr ### ########.fr */
/* Updated: 2024/04/22 19:50:00 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,6 @@ void redirect_input(t_msh *msh, int i, char **cmd_args)
{
if (dup2(msh->fds[i - 1][0], 0) < 0)
{
perror("dup2"); //debug
free(cmd_args);
ft_exit(msh, 1);
}
@ -82,7 +81,8 @@ int get_in_type(t_msh *msh, t_cmd *tokens)
if (open_input_file(msh, &cur_token))
return (1);
}
if (cur_token && cur_token->next && !is_operand_type(cur_token->next) && cur_token->cmd_type != PIPE && cur_token->next->cmd_type != PIPE)
if (cur_token && cur_token->next && !is_operand_type(cur_token->next)
&& cur_token->cmd_type != PIPE && cur_token->next->cmd_type != PIPE)
return (get_in_type(msh, cur_token->next));
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
/* Updated: 2024/04/22 19:13:12 by marde-vr ### ########.fr */
/* Updated: 2024/04/22 19:30:03 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,7 +46,6 @@ typedef struct s_cmd
struct s_cmd *next;
} t_cmd;
typedef struct s_token
{
char *value;

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */
/* Updated: 2024/04/22 19:12:32 by marde-vr ### ########.fr */
/* Updated: 2024/04/22 19:42:05 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,6 @@ void redirect_output(t_msh *msh, int i, char **cmd_args)
free(cmd_args);
ft_exit(msh, 1);
}
}
else
{
@ -66,7 +65,8 @@ int get_out_type(t_msh *msh, t_cmd *cmds)
msh->out_fd = 0;
ret = 0;
cur_cmd = cmds;
while (cur_cmd && cur_cmd->next && (!is_cmd_type(cur_cmd) && !is_output_type(cur_cmd)))
while (cur_cmd && cur_cmd->next && (!is_cmd_type(cur_cmd)
&& !is_output_type(cur_cmd)))
cur_cmd = cur_cmd->next;
while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd)
&& !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE)

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
/* Updated: 2024/04/19 10:43:47 by tomoron ### ########.fr */
/* Updated: 2024/04/22 19:37:26 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
@ -88,7 +88,8 @@ t_token *parse_cmds_to_token(t_cmd *command, t_env *env)
t_token *new;
res = 0;
while(command && (is_cmd_type(command) || is_output_type(command) || is_input_type(command)))
while (command && (is_cmd_type(command) || is_output_type(command)
|| is_input_type(command)))
{
if (is_cmd_type(command))
{

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */
/* Updated: 2024/04/19 10:40:51 by tomoron ### ########.fr */
/* Updated: 2024/04/22 19:38:45 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -126,6 +126,7 @@ char *get_cmd_value(char **cmd, t_cmd_type type)
(*cmd)++;
return (res);
}
void print_syntax_error_bonus(t_cmd *cmd)
{
if (cmd->cmd_type == CMD || cmd->cmd_type == PAREN)
@ -204,6 +205,7 @@ int get_next_arg_len(char *cmd)
}
return (len);
}
char *get_next_arg(char **cmd)
{
int len;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */
/* Updated: 2024/04/22 18:31:00 by tomoron ### ########.fr */
/* Updated: 2024/04/22 19:28:28 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
/* Updated: 2024/04/22 19:18:39 by marde-vr ### ########.fr */
/* Updated: 2024/04/22 19:49:36 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,7 +31,6 @@ void execute_command(t_msh *msh, char **cmd_args)
{
char **env;
//if (cmd_is_forkable_builtin(msh->tokens->value))
if (exec_builtin(msh))
{
free(cmd_args);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
/* Updated: 2024/04/21 20:22:09 by tomoron ### ########.fr */
/* Updated: 2024/04/22 19:53:34 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -57,14 +57,12 @@ int set_echoctl(int value)
{
struct termios t_p;
//ft_printf("echoctl value : %d\n",value);
if (!isatty(1))
return (0);
if (tcgetattr(1, &t_p))
return (1);
if (((t_p.c_lflag & ECHOCTL) != 0) == value)
return (0);
//ft_printf("change\n");
if (value)
t_p.c_lflag = t_p.c_lflag | ECHOCTL;
else

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/17 09:12:33 by tomoron #+# #+# */
/* Updated: 2024/04/18 20:49:00 by marde-vr ### ########.fr */
/* Updated: 2024/04/22 19:30:43 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -42,7 +42,7 @@ void sort_wildcards_token(t_token *list)
list = start;
while (list->next)
{
if (wildcard_cmp(list->value, list->next->value,
if (wildcard_cmp(list->value, list->next->value, \
"zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA9876543210") > 0)
{
swap = list->value;

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
/* Updated: 2024/04/22 16:43:31 by tomoron ### ########.fr */
/* Updated: 2024/04/22 19:53:16 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
@ -45,7 +45,6 @@ void free_msh(t_msh *msh)
void ft_exit(t_msh *msh, int exit_code)
{
//ft_printf("exiting");
set_echoctl(msh->echoctl);
free_msh(msh);
exit(exit_code);

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */
/* Updated: 2024/04/19 10:55:20 by tomoron ### ########.fr */
/* Updated: 2024/04/22 19:28:13 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"