env to char tab et correction du .h

This commit is contained in:
2024-02-16 14:32:01 +01:00
parent 78ac4effc4
commit 98e3b5cfe2
4 changed files with 67 additions and 19 deletions

View File

@ -6,7 +6,7 @@
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
# Updated: 2024/02/15 14:44:14 by tomoron ### ########.fr #
# Updated: 2024/02/16 14:26:43 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -21,6 +21,7 @@ SRCS = main.c\
pwd.c\
parsing.c\
debug.c\
env_to_char_tab.c\
parsing_var.c
OBJS = $(SRCS:.c=.o)

45
env_to_char_tab.c Normal file
View File

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

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
/* Updated: 2024/02/16 12:50:33 by tomoron ### ########.fr */
/* Updated: 2024/02/16 13:15:22 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,8 +23,8 @@ typedef enum e_token_type
ARG,
PIPE,
RED_O,
RED_O_APP,
RED_I,
RED_I_APP,
HERE_DOC,
OR,
AND

View File

@ -6,14 +6,14 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */
/* Updated: 2024/02/13 18:22:38 by tomoron ### ########.fr */
/* Updated: 2024/02/16 14:25:36 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int is_cmd_char(char c)
{
return(!ft_isspace(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)
@ -46,23 +46,25 @@ 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 res;
while (ft_isspace(**command))
(*command)++;
if((*command)[0] == '|' && (*command)[1] == '|')
{
(*command) += 2;
return(OR);
}
if((*command)[0] == '&' && (*command)[1] == '&')
{
(*command) += 2;
return(AND);
}
if((*command)[0] == '|')
{
(*command) += 1;
return(PIPE);
}
res = OR;
else if((*command)[0] == '&' && (*command)[1] == '&')
res = AND;
else if ((*command)[0] == '>' && (*command)[1] == '>')
res = RED_O_APP;
else if((*command)[0] == '<' && (*command)[1] == '<')
res = HERE_DOC;
else if((*command)[0] == '>')
res = RED_O;
else if((*command)[0] == '<')
res = RED_I;
else if((*command)[0] == '|')
res = PIPE;
return (ARG);
}