」 feat: $ working

This commit is contained in:
2024-06-20 14:28:54 +02:00
parent 6ae7296237
commit 64ede5becd
7 changed files with 30 additions and 33 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
/* Updated: 2024/06/11 15:18:38 by adjoly ### ########.fr */
/* Updated: 2024/06/18 12:58:53 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,8 +36,8 @@ typedef enum s_quote
bool check_syntax(char *readline, char **argv);
void send_error(char *msg, char **argv);
void check_redir(t_list *redir, char **argv);
t_cmd *get_redir_fd(void *content);
t_list *get_cmd_list(t_list *list);
t_cmd *get_redir_fd(void *content, t_env *env);
t_list *get_cmd_list(t_list *list, t_env *env);
char **split_argv(char *readline);
char *env_var_replace(char *readline, t_env *env);
size_t get_size_with_env(char *readline, t_env *env);

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/06/11 13:37:20 by adjoly ### ########.fr */
/* Updated: 2024/06/20 14:00:59 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -87,9 +87,8 @@ int main(int ac, char **av, char **env)
if (is_str(test, "exit"))
break ;
piped = tokenizer(test);
check_redir(((t_token *)(piped->content))->redirection, av);
ft_putendl_fd(env_var_replace(test, &env_l), STDOUT_FILENO);
cmd_list = get_cmd_list(piped);
//check_redir(((t_token *)(piped->content))->redirection, av);
cmd_list = get_cmd_list(piped, &env_l);
//exec_split_cmd(cmd_list, &env_l);
/*while (cmd_list)
{
@ -97,9 +96,9 @@ int main(int ac, char **av, char **env)
cmd_list = cmd_list->next;
}*/
print_cmd(cmd_list->content);
free(test);
ft_lstclear(&piped, free_token);
ft_free("a", &lll);
//free(test);
//ft_lstclear(&piped, free_token);
//ft_free("a", &lll);
}
ft_free("a", &lll);
return (0);

View File

@ -6,11 +6,12 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/05 21:14:04 by adjoly #+# #+# */
/* Updated: 2024/06/11 16:26:06 by adjoly ### ########.fr */
/* Updated: 2024/06/20 14:14:57 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <stdio.h>
#include "parsing.h"
#include "env.h"
@ -37,15 +38,12 @@ char *env_var_replace(char *readline, t_env *env)
tmp = readline;
while (*tmp)
{
print_quote_type(__is_quote(*tmp));
if (*tmp == '$' && is_inquote(tmp, tmp - readline + 1) != SINGLE)
if (*tmp == '$' && is_inquote(readline, tmp - readline) != SINGLE)
{
tmp++;
dollar_size = strlen_till_notalnum(tmp);
ft_putnbr_fd(dollar_size, STDOUT_FILENO);
dollar = env_getn_value(tmp, env, dollar_size);
write(1, tmp, dollar_size);
ft_putendl_fd(dollar, STDOUT_FILENO);
printf("%zu\n", dollar_size);
dollar = env_getn_value(tmp, env, dollar_size - 1);
if (!dollar)
{
tmp += dollar_size;

View File

@ -6,14 +6,14 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/31 12:47:13 by adjoly #+# #+# */
/* Updated: 2024/05/31 13:29:46 by adjoly ### ########.fr */
/* Updated: 2024/06/18 12:58:36 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "parsing.h"
t_list *get_cmd_list(t_list *list)
t_list *get_cmd_list(t_list *list, t_env *env)
{
t_list *tmp;
t_list *cmd_list;
@ -22,7 +22,7 @@ t_list *get_cmd_list(t_list *list)
cmd_list = NULL;
while (tmp)
{
ft_lstadd_back(&cmd_list, ft_lstnew(get_redir_fd(tmp->content)));
ft_lstadd_back(&cmd_list, ft_lstnew(get_redir_fd(tmp->content, env)));
tmp = tmp->next;
}
return (cmd_list);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */
/* Updated: 2024/06/04 15:35:30 by adjoly ### ########.fr */
/* Updated: 2024/06/20 12:30:56 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,9 +14,10 @@
#include "tokenizer.h"
#include "execution.h"
#include <fcntl.h>
#include <stdio.h>
#include "libft.h"
t_cmd *get_redir_fd(void *content)
t_cmd *get_redir_fd(void *content, t_env *env)
{
t_token *token;
t_list *tmp;
@ -68,6 +69,7 @@ t_cmd *get_redir_fd(void *content)
cmd->infile = STDIN_FILENO;
if (out == INFILE)
cmd->outfile = STDOUT_FILENO;
cmd = split_cmd(token->argv, cmd);
char *ll = env_var_replace(token->argv, env);
cmd = split_cmd(ll, cmd);
return (cmd);
}

View File

@ -6,12 +6,13 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 20:06:13 by adjoly #+# #+# */
/* Updated: 2024/06/11 15:26:56 by adjoly ### ########.fr */
/* Updated: 2024/06/20 11:07:56 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
#include "libft.h"
#include <stdio.h>
t_quote __is_quote(char c)
{
@ -27,12 +28,8 @@ char *search_for_next_quote(char *s, t_quote quote_type)
char *tmp;
tmp = s;
while (*tmp)
{
if (__is_quote(*tmp) == quote_type)
break ;
while (*tmp && __is_quote(*tmp) != quote_type)
tmp++;
}
return (tmp);
}
@ -43,19 +40,20 @@ t_quote is_inquote(char *s, size_t i)
t_quote quote_type;
start_quote = 0;
printf("%zu", i);
tmp = s;
quote_type = FALSE;
while (*tmp)
{
if ((size_t)(tmp - s) > i)
if ((size_t)(tmp - s + 1) > i)
break ;
if (__is_quote(*tmp) != FALSE)
{
start_quote = tmp - s;
quote_type = __is_quote(*tmp);
tmp = search_for_next_quote(tmp, quote_type);
tmp++;
if (*tmp && (start_quote < i && (size_t)(tmp - s) > i))
tmp = search_for_next_quote(tmp, quote_type);
if ((start_quote < i && (size_t)(tmp - s) > i))
return (quote_type);
else if (!*tmp)
return (NOT_CLOSED);

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 15:00:32 by adjoly #+# #+# */
/* Updated: 2024/06/08 18:31:42 by mmoussou ### ########.fr */
/* Updated: 2024/06/18 12:56:43 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */