mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 11:26:51 +01:00
「✨」 feat: $ working
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
|
/* 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);
|
bool check_syntax(char *readline, char **argv);
|
||||||
void send_error(char *msg, char **argv);
|
void send_error(char *msg, char **argv);
|
||||||
void check_redir(t_list *redir, char **argv);
|
void check_redir(t_list *redir, char **argv);
|
||||||
t_cmd *get_redir_fd(void *content);
|
t_cmd *get_redir_fd(void *content, t_env *env);
|
||||||
t_list *get_cmd_list(t_list *list);
|
t_list *get_cmd_list(t_list *list, t_env *env);
|
||||||
char **split_argv(char *readline);
|
char **split_argv(char *readline);
|
||||||
char *env_var_replace(char *readline, t_env *env);
|
char *env_var_replace(char *readline, t_env *env);
|
||||||
size_t get_size_with_env(char *readline, t_env *env);
|
size_t get_size_with_env(char *readline, t_env *env);
|
||||||
|
13
src/main.c
13
src/main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
/* 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"))
|
if (is_str(test, "exit"))
|
||||||
break ;
|
break ;
|
||||||
piped = tokenizer(test);
|
piped = tokenizer(test);
|
||||||
check_redir(((t_token *)(piped->content))->redirection, av);
|
//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, &env_l);
|
||||||
cmd_list = get_cmd_list(piped);
|
|
||||||
//exec_split_cmd(cmd_list, &env_l);
|
//exec_split_cmd(cmd_list, &env_l);
|
||||||
/*while (cmd_list)
|
/*while (cmd_list)
|
||||||
{
|
{
|
||||||
@ -97,9 +96,9 @@ int main(int ac, char **av, char **env)
|
|||||||
cmd_list = cmd_list->next;
|
cmd_list = cmd_list->next;
|
||||||
}*/
|
}*/
|
||||||
print_cmd(cmd_list->content);
|
print_cmd(cmd_list->content);
|
||||||
free(test);
|
//free(test);
|
||||||
ft_lstclear(&piped, free_token);
|
//ft_lstclear(&piped, free_token);
|
||||||
ft_free("a", &lll);
|
//ft_free("a", &lll);
|
||||||
}
|
}
|
||||||
ft_free("a", &lll);
|
ft_free("a", &lll);
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/05 21:14:04 by adjoly #+# #+# */
|
/* 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 <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
|
|
||||||
@ -37,15 +38,12 @@ char *env_var_replace(char *readline, t_env *env)
|
|||||||
tmp = readline;
|
tmp = readline;
|
||||||
while (*tmp)
|
while (*tmp)
|
||||||
{
|
{
|
||||||
print_quote_type(__is_quote(*tmp));
|
if (*tmp == '$' && is_inquote(readline, tmp - readline) != SINGLE)
|
||||||
if (*tmp == '$' && is_inquote(tmp, tmp - readline + 1) != SINGLE)
|
|
||||||
{
|
{
|
||||||
tmp++;
|
tmp++;
|
||||||
dollar_size = strlen_till_notalnum(tmp);
|
dollar_size = strlen_till_notalnum(tmp);
|
||||||
ft_putnbr_fd(dollar_size, STDOUT_FILENO);
|
printf("%zu\n", dollar_size);
|
||||||
dollar = env_getn_value(tmp, env, dollar_size);
|
dollar = env_getn_value(tmp, env, dollar_size - 1);
|
||||||
write(1, tmp, dollar_size);
|
|
||||||
ft_putendl_fd(dollar, STDOUT_FILENO);
|
|
||||||
if (!dollar)
|
if (!dollar)
|
||||||
{
|
{
|
||||||
tmp += dollar_size;
|
tmp += dollar_size;
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/31 12:47:13 by adjoly #+# #+# */
|
/* 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 "libft.h"
|
||||||
#include "parsing.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 *tmp;
|
||||||
t_list *cmd_list;
|
t_list *cmd_list;
|
||||||
@ -22,7 +22,7 @@ t_list *get_cmd_list(t_list *list)
|
|||||||
cmd_list = NULL;
|
cmd_list = NULL;
|
||||||
while (tmp)
|
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;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
return (cmd_list);
|
return (cmd_list);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */
|
/* 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 "tokenizer.h"
|
||||||
#include "execution.h"
|
#include "execution.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "libft.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_token *token;
|
||||||
t_list *tmp;
|
t_list *tmp;
|
||||||
@ -68,6 +69,7 @@ t_cmd *get_redir_fd(void *content)
|
|||||||
cmd->infile = STDIN_FILENO;
|
cmd->infile = STDIN_FILENO;
|
||||||
if (out == INFILE)
|
if (out == INFILE)
|
||||||
cmd->outfile = STDOUT_FILENO;
|
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);
|
return (cmd);
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,13 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/20 20:06:13 by adjoly #+# #+# */
|
/* 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 "parsing.h"
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
t_quote __is_quote(char c)
|
t_quote __is_quote(char c)
|
||||||
{
|
{
|
||||||
@ -27,12 +28,8 @@ char *search_for_next_quote(char *s, t_quote quote_type)
|
|||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
tmp = s;
|
tmp = s;
|
||||||
while (*tmp)
|
while (*tmp && __is_quote(*tmp) != quote_type)
|
||||||
{
|
|
||||||
if (__is_quote(*tmp) == quote_type)
|
|
||||||
break ;
|
|
||||||
tmp++;
|
tmp++;
|
||||||
}
|
|
||||||
return (tmp);
|
return (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,19 +40,20 @@ t_quote is_inquote(char *s, size_t i)
|
|||||||
t_quote quote_type;
|
t_quote quote_type;
|
||||||
|
|
||||||
start_quote = 0;
|
start_quote = 0;
|
||||||
|
printf("%zu", i);
|
||||||
tmp = s;
|
tmp = s;
|
||||||
quote_type = FALSE;
|
quote_type = FALSE;
|
||||||
while (*tmp)
|
while (*tmp)
|
||||||
{
|
{
|
||||||
if ((size_t)(tmp - s) > i)
|
if ((size_t)(tmp - s + 1) > i)
|
||||||
break ;
|
break ;
|
||||||
if (__is_quote(*tmp) != FALSE)
|
if (__is_quote(*tmp) != FALSE)
|
||||||
{
|
{
|
||||||
start_quote = tmp - s;
|
start_quote = tmp - s;
|
||||||
quote_type = __is_quote(*tmp);
|
quote_type = __is_quote(*tmp);
|
||||||
tmp = search_for_next_quote(tmp, quote_type);
|
|
||||||
tmp++;
|
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);
|
return (quote_type);
|
||||||
else if (!*tmp)
|
else if (!*tmp)
|
||||||
return (NOT_CLOSED);
|
return (NOT_CLOSED);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/04 15:00:32 by adjoly #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user