fixed exec error and normed

This commit is contained in:
mdev9
2024-02-16 15:11:20 +01:00
parent 9d15c79d02
commit c3aefd859b
5 changed files with 41 additions and 41 deletions

16
debug.c
View File

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* debug.c :+: :+: :+: */ /* debug.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/15 14:16:47 by tomoron #+# #+# */ /* Created: 2024/02/15 14:16:47 by tomoron #+# #+# */
/* Updated: 2024/02/15 14:45:29 by tomoron ### ########.fr */ /* Updated: 2024/02/16 15:08:40 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,16 +14,16 @@
void print_parsed_cmd(t_cmd *cmd) void print_parsed_cmd(t_cmd *cmd)
{ {
while(cmd) while (cmd)
{ {
printf("["); printf("[");
if(cmd->type == ARG) if (cmd->type == ARG)
printf("ARG : %s",cmd->token); printf("ARG : %s", cmd->token);
else if(cmd->type == PIPE) else if (cmd->type == PIPE)
printf("PIPE"); printf("PIPE");
else if(cmd->type == OR) else if (cmd->type == OR)
printf("OR"); printf("OR");
else if(cmd->type == AND) else if (cmd->type == AND)
printf("AND"); printf("AND");
printf("] "); printf("] ");
cmd = cmd->next; cmd = cmd->next;

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* env_to_char_tab.c :+: :+: :+: */ /* env_to_char_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/16 13:30:18 by tomoron #+# #+# */ /* Created: 2024/02/16 13:30:18 by tomoron #+# #+# */
/* Updated: 2024/02/16 14:31:07 by tomoron ### ########.fr */ /* Updated: 2024/02/16 15:08:53 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,32 +14,32 @@
int get_env_len(t_env *env) int get_env_len(t_env *env)
{ {
int res; int res;
res = 0; res = 0;
while(env) while (env)
{ {
res++; res++;
env = env->next; env = env->next;
} }
return(res); return (res);
} }
char **env_to_char_tab(t_env *env) char **env_to_char_tab(t_env *env)
{ {
char **res; char **res;
int i; int i;
char *tmp; char *tmp;
res = ft_calloc(get_env_len(env) + 1, sizeof(char *)); res = ft_calloc(get_env_len(env) + 1, sizeof(char *));
i = 0; i = 0;
while(res && env) while (res && env)
{ {
tmp = ft_strjoin(env->name, "="); tmp = ft_strjoin(env->name, "=");
tmp = ft_strjoin_free(tmp, env->value, 1); tmp = ft_strjoin_free(tmp, env->value, 1);
res[i] = tmp; res[i] = tmp;
i++; i++;
env = env->next; env = env->next;
} }
return(res); return (res);
} }

4
exec.c
View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ /* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
/* Updated: 2024/02/16 14:41:43 by marde-vr ### ########.fr */ /* Updated: 2024/02/16 15:10:43 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -112,7 +112,7 @@ void get_cmd_path(t_cmd *cmd, t_env *env)
int found; int found;
found = 0; found = 0;
if (access(cmd->token, X_OK != -1)) if (access(cmd->token, X_OK) != -1)
found = 1; found = 1;
else else
{ {

View File

@ -3,22 +3,22 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* ft_strisnbr.c :+: :+: :+: */ /* ft_strisnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/11 17:14:58 by tomoron #+# #+# */ /* Created: 2024/02/11 17:14:58 by tomoron #+# #+# */
/* Updated: 2024/02/12 03:21:56 by tomoron ### ########.fr */ /* Updated: 2024/02/16 15:07:30 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
int ft_strisnbr(char *str) int ft_strisnbr(char *str)
{ {
if(!str) if (!str)
return(0); return (0);
while(*str) while (*str)
{ {
if(*str < '0' || *str > '9') if (*str < '0' || *str > '9')
return(0); return (0);
str++; str++;
} }
return(1); return (1);
} }

View File

@ -6,14 +6,14 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
/* Updated: 2024/02/16 14:52:11 by tomoron ### ########.fr */ /* Updated: 2024/02/16 15:09:25 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int is_cmd_char(char c) int is_cmd_char(char c)
{ {
return(!ft_isspace(c) && c != '|' && c != '&' && c != '<' && c != '>'); return (!ft_isspace(c) && c != '|' && c != '&' && c != '<' && c != '>');
} }
char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
@ -37,7 +37,7 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
i += add_var_to_str(res + i, cmd, env); i += add_var_to_str(res + i, cmd, env);
} }
else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote)) else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote))
|| (**cmd != '\'' && **cmd != '"')) || (**cmd != '\'' && **cmd != '"'))
res[i++] = **cmd; res[i++] = **cmd;
(*cmd)++; (*cmd)++;
} }
@ -46,27 +46,27 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env)
t_token_type get_token_type(char **command) t_token_type get_token_type(char **command)
{ {
t_token_type res; t_token_type res;
while (ft_isspace(**command)) while (ft_isspace(**command))
(*command)++; (*command)++;
if((*command)[0] == '|' && (*command)[1] == '|') if ((*command)[0] == '|' && (*command)[1] == '|')
res = OR; res = OR;
else if((*command)[0] == '&' && (*command)[1] == '&') else if ((*command)[0] == '&' && (*command)[1] == '&')
res = AND; res = AND;
else if ((*command)[0] == '>' && (*command)[1] == '>') else if ((*command)[0] == '>' && (*command)[1] == '>')
res = RED_O_APP; res = RED_O_APP;
else if((*command)[0] == '<' && (*command)[1] == '<') else if ((*command)[0] == '<' && (*command)[1] == '<')
res = HERE_DOC; res = HERE_DOC;
else if((*command)[0] == '>') else if ((*command)[0] == '>')
res = RED_O; res = RED_O;
else if((*command)[0] == '<') else if ((*command)[0] == '<')
res = RED_I; res = RED_I;
else if((*command)[0] == '|') else if ((*command)[0] == '|')
res = PIPE; res = PIPE;
else else
res = ARG; res = ARG;
if(res == OR || res == AND || res == RED_O_APP || res == HERE_DOC) if (res == OR || res == AND || res == RED_O_APP || res == HERE_DOC)
(*command) += 2; (*command) += 2;
if (res == RED_O || res == RED_I || res == PIPE) if (res == RED_O || res == RED_I || res == PIPE)
(*command)++; (*command)++;