」 feat: Did a lot of things, don't know what but it work

This commit is contained in:
2024-06-30 18:03:58 +02:00
parent 3d7669d056
commit f0c0830c4d
19 changed files with 188 additions and 111 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 20:25:06 by adjoly #+# #+# */ /* Created: 2024/05/20 20:25:06 by adjoly #+# #+# */
/* Updated: 2024/06/29 16:25:47 by adjoly ### ########.fr */ /* Updated: 2024/06/30 16:08:28 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,12 +16,17 @@
/** /**
* Here we define all the error message * Here we define all the error message
*/ */
# include <stdbool.h>
# define ERROR_SYNTAX ": syntax error" # define ERROR_SYNTAX ": syntax error"
# define ERROR_NO_REDIR ": need redirection file" # define ERROR_NO_REDIR ": need redirection file"
# define ERROR_NO_EOF ": need delimiter to heredoc" # define ERROR_NO_EOF ": need delimiter to heredoc"
# define ERROR_NO_FILE "No such file or directory" # define ERROR_NO_FILE "No such file or directory"
# define ERROR_CMD_PIPE "No command after pipe"
# define ERROR_COREDUMP "(core dumped)" # define ERROR_COREDUMP "(core dumped)"
char *get_program_name(char *argv_one);
bool send_error_parsing(char *msg);
#endif #endif

View File

@ -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/29 15:31:02 by adjoly ### ########.fr */ /* Updated: 2024/06/30 17:27:13 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,18 +33,20 @@ typedef enum s_quote
DOUBLE = 34 DOUBLE = 34
} t_quote; } t_quote;
bool check_syntax(char *readline, char **argv); bool check_syntax(char *readline);
void send_error(char *msg, char **argv); void send_error(char *msg, char **argv);
void check_redir(t_list *redir, char **argv); bool check_redir(t_list *redir);
t_cmd *get_redir_fd(void *content, t_env *env); t_cmd *get_redir_fd(void *content);
t_list *get_cmd_list(t_list *list, t_env *env); t_list *get_cmd_list(t_list *list);
void open_redir(t_redirection *redir, t_cmd *cmd, t_redir_sign sign[2]);
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);
size_t strlen_till_char(char *s, int c); size_t strlen_till_char(char *s, int c);
void check_quote(char *readline); bool check_quote(char *readline);
t_quote __is_quote(char c); t_quote __is_quote(char c);
char *search_for_next_quote(char *s, t_quote quote_type); char *search_for_next_quote(char *s, t_quote quote_type);
bool check_pipe(char *readline);
char **split_argv(char *readline); char **split_argv(char *readline);
/** /**
* @brief Take the argv of a command a split the argv and the * @brief Take the argv of a command a split the argv and the
@ -82,7 +84,7 @@ t_quote __is_quote(char c);
* ONLY FOR DEBUG TO BE REMOVED * ONLY FOR DEBUG TO BE REMOVED
*/ */
void print_quote_type(t_quote type); void print_quote_type(t_quote type);
void print_redir_sign(t_redirection_sign redir_sign); void print_redir_sign(t_redir_sign redir_sign);
void print_token(t_token *token); void print_token(t_token *token);
void print_redir(t_redirection *redir); void print_redir(t_redirection *redir);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/18 20:14:15 by adjoly #+# #+# */ /* Created: 2024/05/18 20:14:15 by adjoly #+# #+# */
/* Updated: 2024/06/26 12:45:41 by adjoly ### ########.fr */ /* Updated: 2024/06/30 17:18:32 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,12 +21,12 @@ typedef enum s_redirection_sign
HEREDOC, HEREDOC,
OUTFILE, OUTFILE,
OUT_APPEND, OUT_APPEND,
} t_redirection_sign; } t_redir_sign;
typedef struct s_redirection typedef struct s_redirection
{ {
char *file_name; char *file_name;
t_redirection_sign sign; t_redir_sign sign;
} t_redirection; } t_redirection;
typedef struct s_token typedef struct s_token
@ -42,7 +42,7 @@ typedef struct s_token
* *
* @return (t_redirection_sign) The sign of the redirecition * @return (t_redirection_sign) The sign of the redirecition
*/ */
t_redirection_sign __to_redir_sign(char *redir_sign); t_redir_sign __to_redir_sign(char *redir_sign);
/** /**
* @brief Take a string and split the filename and the redirect * @brief Take a string and split the filename and the redirect

View File

@ -6,13 +6,14 @@
/* 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/29 19:44:30 by adjoly ### ########.fr */ /* Updated: 2024/06/30 17:28:28 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <readline/readline.h> #include <readline/readline.h>
#include "error_msg.h"
#include <readline/history.h> #include <readline/history.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
@ -95,25 +96,25 @@ int main(int ac, char **av, char **env)
(void)ac; (void)ac;
(void)av; (void)av;
get_program_name(av[0]);
piped = NULL; piped = NULL;
if (env_init(env, &env_l)) if (env_init(env, &env_l))
return (EXIT_FAILURE); return (EXIT_FAILURE);
sigemptyset(&(sigset_t){SIGQUIT}); sigemptyset(&(sigset_t){SIGQUIT});
signal(SIGINT, &sigggg); signal(SIGINT, &sigggg);
signal(SIGQUIT, &siggg_backslash); signal(SIGQUIT, &siggg_backslash);
signal(SIGSEGV, &siggg_d); //signal(SIGSEGV, &siggg_d);
while (1) while (1)
{ {
prompt = get_prompt(env_l); prompt = get_prompt(env_l);
test = readline(prompt); test = readline(prompt);
free(prompt); free(prompt);
add_history(test); add_history(test);
check_syntax(test, av); if (check_syntax(test))
continue ;
lll = ft_split(test, ' '); lll = ft_split(test, ' ');
if (!*lll) if (!*lll)
continue ; continue ;
else if (is_str(test, "exit"))
break ;
else if (is_str(test, "pwd")) else if (is_str(test, "pwd"))
{ {
ft_pwd(); ft_pwd();
@ -136,10 +137,14 @@ int main(int ac, char **av, char **env)
} }
else if (is_str(test, "exit")) else if (is_str(test, "exit"))
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
check_quote(test); if (check_quote(test))
continue ;
if (check_pipe(test))
continue ;
piped = tokenizer(test); piped = tokenizer(test);
check_redir(((t_token *)(piped->content))->redirection, av); if (check_redir(((t_token *)(piped->content))->redirection))
cmd_list = get_cmd_list(piped, &env_l); continue ;
cmd_list = get_cmd_list(piped);
exec_split_cmd(cmd_list, &env_l); exec_split_cmd(cmd_list, &env_l);
free(test); free(test);
ft_lstclear(&piped, free_token); ft_lstclear(&piped, free_token);

View File

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_pipe.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 12:52:22 by adjoly #+# #+# */
/* Updated: 2024/06/30 17:26:09 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "parsing.h"
#include <stdbool.h>
#include "error_msg.h"
size_t strlen_till_end_char(char *s, int c)
{
char *tmp;
tmp = s;
while (*tmp && *tmp == c)
tmp++;
return (tmp - s);
}
bool check_pipe(char *readline)
{
char *tmp;
tmp = readline;
while (*tmp)
{
if (*tmp == '|' && is_inquote(readline, tmp - readline) == FALSE)
{
tmp++;
tmp += strlen_till_end_char(tmp, ' ');
if (!*tmp)
return (send_error_parsing("No command after pipe"));
}
tmp++;
}
return (false);
}

View File

@ -6,11 +6,12 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/21 11:59:34 by adjoly #+# #+# */ /* Created: 2024/06/21 11:59:34 by adjoly #+# #+# */
/* Updated: 2024/06/21 12:40:56 by adjoly ### ########.fr */ /* Updated: 2024/06/30 16:11:23 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parsing.h" #include "parsing.h"
#include "error_msg.h"
#include "tokenizer.h" #include "tokenizer.h"
size_t count_quote(char *readline, t_quote type) size_t count_quote(char *readline, t_quote type)
@ -29,20 +30,15 @@ size_t count_quote(char *readline, t_quote type)
return (count); return (count);
} }
void check_quote(char *readline) bool check_quote(char *readline)
{ {
size_t count; size_t count;
count = count_quote(readline, DOUBLE); count = count_quote(readline, DOUBLE);
if (count % 2) if (count % 2)
{ return (send_error_parsing("double quote not closed"));
ft_putendl_fd("double quote error", STDERR_FILENO);
exit (EXIT_FAILURE);
}
count = count_quote(readline, SINGLE); count = count_quote(readline, SINGLE);
if (count % 2) if (count % 2)
{ return (send_error_parsing("single quote not closed"));
ft_putendl_fd("single quote error", STDERR_FILENO); return (false);
exit (EXIT_FAILURE);
}
} }

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 18:17:26 by adjoly #+# #+# */ /* Created: 2024/05/28 18:17:26 by adjoly #+# #+# */
/* Updated: 2024/06/24 12:51:27 by adjoly ### ########.fr */ /* Updated: 2024/06/30 13:49:21 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
#include "parsing.h" #include "parsing.h"
#include "error_msg.h" #include "error_msg.h"
void check_redir(t_list *redir, char **argv) bool check_redir(t_list *redir)
{ {
t_list *tmp; t_list *tmp;
t_redirection *tmp_redir; t_redirection *tmp_redir;
@ -25,9 +25,10 @@ void check_redir(t_list *redir, char **argv)
tmp_redir = tmp->content; tmp_redir = tmp->content;
if (tmp_redir->sign == HEREDOC && \ if (tmp_redir->sign == HEREDOC && \
!((t_redirection *)(tmp->content))->file_name) !((t_redirection *)(tmp->content))->file_name)
send_error(ERROR_NO_EOF, argv); return (send_error_parsing(ERROR_NO_EOF));
if (!((t_redirection *)(tmp->content))->file_name) if (!((t_redirection *)(tmp->content))->file_name)
send_error(ERROR_NO_REDIR, argv); return (send_error_parsing(ERROR_NO_REDIR));
tmp = tmp->next; tmp = tmp->next;
} }
return (false);
} }

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 17:40:13 by adjoly #+# #+# */ /* Created: 2024/05/28 17:40:13 by adjoly #+# #+# */
/* Updated: 2024/06/04 16:43:53 by adjoly ### ########.fr */ /* Updated: 2024/06/30 13:54:53 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -48,7 +48,7 @@ bool check_if_file(char *readline)
return (false); return (false);
} }
bool check_syntax(char *readline, char **argv) bool check_syntax(char *readline)
{ {
char *tmp; char *tmp;
@ -56,15 +56,9 @@ bool check_syntax(char *readline, char **argv)
while (*tmp) while (*tmp)
{ {
if (check_triple(tmp)) if (check_triple(tmp))
{ return (send_error_parsing(ERROR_SYNTAX));
send_error(ERROR_SYNTAX, argv);
return (true);
}
if (check_if_file(tmp)) if (check_if_file(tmp))
{ return (send_error_parsing(ERROR_SYNTAX));
send_error(ERROR_SYNTAX, argv);
return (true);
}
tmp++; tmp++;
} }
return (false); return (false);

View File

@ -6,14 +6,31 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 18:09:49 by adjoly #+# #+# */ /* Created: 2024/05/28 18:09:49 by adjoly #+# #+# */
/* Updated: 2024/06/04 15:39:24 by adjoly ### ########.fr */ /* Updated: 2024/06/30 16:11:03 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *get_program_name(char *argv_one)
{
static char prog_name[255];
if (argv_one)
ft_strlcpy(prog_name, argv_one, ft_strlen(argv_one) + 1);
return (prog_name);
}
void send_error(char *msg, char **argv) void send_error(char *msg, char **argv)
{ {
ft_putstr_fd(argv[0], STDERR_FILENO); ft_putstr_fd(argv[0], STDERR_FILENO);
ft_putendl_fd(msg, STDERR_FILENO); ft_putendl_fd(msg, STDERR_FILENO);
} }
bool send_error_parsing(char *msg)
{
ft_putstr_fd(get_program_name(NULL), STDERR_FILENO);
ft_putstr_fd(": Error: ", STDERR_FILENO);
ft_putendl_fd(msg, STDERR_FILENO);
return (true);
}

View File

@ -12,7 +12,7 @@ void print_quote_type(t_quote type)
ft_putendl_fd("NOT_CLOSED", STDOUT_FILENO); ft_putendl_fd("NOT_CLOSED", STDOUT_FILENO);
} }
void print_redir_sign(t_redirection_sign redir_sign) void print_redir_sign(t_redir_sign redir_sign)
{ {
if (redir_sign == HEREDOC) if (redir_sign == HEREDOC)
ft_putendl_fd("HEREDOC", STDOUT_FILENO); ft_putendl_fd("HEREDOC", STDOUT_FILENO);

View File

@ -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/06/18 12:58:36 by adjoly ### ########.fr */ /* Updated: 2024/06/30 17:28:40 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include "parsing.h" #include "parsing.h"
t_list *get_cmd_list(t_list *list, t_env *env) t_list *get_cmd_list(t_list *list)
{ {
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, t_env *env)
cmd_list = NULL; cmd_list = NULL;
while (tmp) while (tmp)
{ {
ft_lstadd_back(&cmd_list, ft_lstnew(get_redir_fd(tmp->content, env))); ft_lstadd_back(&cmd_list, ft_lstnew(get_redir_fd(tmp->content)));
tmp = tmp->next; tmp = tmp->next;
} }
return (cmd_list); return (cmd_list);

View File

@ -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/29 15:32:44 by adjoly ### ########.fr */ /* Updated: 2024/06/30 17:34:47 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,63 +14,30 @@
#include "tokenizer.h" #include "tokenizer.h"
#include "execution.h" #include "execution.h"
#include <fcntl.h> #include <fcntl.h>
#include "minishell.h"
#include <stdio.h> #include <stdio.h>
#include "libft.h" #include "libft.h"
t_cmd *get_redir_fd(void *content, t_env *env) t_cmd *get_redir_fd(void *content)
{ {
t_token *token; t_list *tmp;
t_list *tmp; t_redir_sign sign[2];
t_redirection *tmp_redir; t_cmd *cmd;
t_redirection_sign out;
t_redirection_sign in;
t_cmd *cmd;
(void)env; tmp = ((t_token *)content)->redirection;
token = (t_token *)content;
tmp = token->redirection;
cmd = NULL; cmd = NULL;
out = INFILE; sign[0] = INFILE;
in = OUTFILE; sign[1] = OUTFILE;
cmd = ft_calloc(sizeof(t_cmd), 1); cmd = ft_calloc(sizeof(t_cmd), 1);
while (tmp) while (tmp)
{ {
tmp_redir = (t_redirection *)tmp->content; open_redir((t_redirection *)tmp->content, cmd, sign);
if (tmp_redir->sign == (t_redirection_sign)HEREDOC)
{
if (cmd->infile != 0)
close(cmd->infile);
in = HEREDOC;
cmd->infile = ft_heredoc(tmp_redir->file_name);
}
else if (tmp_redir->sign == INFILE)
{
if (cmd->infile != 0)
close(cmd->infile);
cmd->infile = open(tmp_redir->file_name, O_RDONLY);
in = INFILE;
}
else if (tmp_redir->sign == OUTFILE)
{
if (cmd->infile != 0)
close(cmd->outfile);
out = OUTFILE;
cmd->outfile = open(tmp_redir->file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
}
else if (tmp_redir->sign == OUT_APPEND)
{
if (cmd->infile != 0)
close(cmd->outfile);
out = OUT_APPEND;
cmd->outfile = open(tmp_redir->file_name, O_CREAT | O_APPEND | O_WRONLY, 0644);
}
tmp = tmp->next; tmp = tmp->next;
} }
if (in == OUTFILE) if (sign[0] == INFILE)
cmd->infile = STDIN_FILENO;
if (out == INFILE)
cmd->outfile = STDOUT_FILENO; cmd->outfile = STDOUT_FILENO;
// char *ll = env_var_replace(token->argv, env); if (sign[1] == OUTFILE)
cmd = split_cmd(token->argv, cmd); cmd->infile = STDIN_FILENO;
cmd = split_cmd(((t_token *)content)->argv, cmd);
return (cmd); return (cmd);
} }

43
src/parsing/open_redir.c Normal file
View File

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* open_redir.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 15:56:53 by adjoly #+# #+# */
/* Updated: 2024/06/30 18:03:14 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "tokenizer.h"
#include <fcntl.h>
#include "execution.h"
#include "parsing.h"
t_redir_sign __close_unused_fd(t_cmd *cmd, t_redir_sign sign)
{
if (cmd->outfile != 0 && sign >= 2)
close(cmd->outfile);
else if (cmd->infile != 0 && sign < 2)
close(cmd->infile);
return (sign);
}
void open_redir(t_redirection *redir, t_cmd *cmd, t_redir_sign sign[2])
{
if (redir->sign == OUTFILE || redir->sign == OUT_APPEND)
sign[0] = __close_unused_fd(cmd, redir->sign);
if (redir->sign == INFILE || redir->sign == HEREDOC)
sign[1] = __close_unused_fd(cmd, redir->sign);
if (redir->sign == HEREDOC)
cmd->infile = ft_heredoc(redir->file_name);
else if (redir->sign == INFILE)
cmd->infile = open(redir->file_name, O_RDONLY);
else if (redir->sign == OUTFILE)
cmd->outfile = open(redir->file_name, \
O_CREAT | O_TRUNC | O_WRONLY, 0644);
else if (redir->sign == OUT_APPEND)
cmd->outfile = open(redir->file_name, \
O_CREAT | O_APPEND | O_WRONLY, 0644);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/05 13:48:57 by adjoly #+# #+# */ /* Created: 2024/06/05 13:48:57 by adjoly #+# #+# */
/* Updated: 2024/06/29 15:29:48 by adjoly ### ########.fr */ /* Updated: 2024/06/30 16:03:46 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -70,7 +70,7 @@ char **split_argv(char *readline)
tmp++; tmp++;
else else
{ {
*tmp_av = ft_calloc(__get_len_arg(tmp), sizeof(char)); *tmp_av = ft_calloc(__get_len_arg(tmp) + 1, sizeof(char));
tmp += __cpy_arg(*tmp_av, tmp); tmp += __cpy_arg(*tmp_av, tmp);
tmp_av++; tmp_av++;
} }

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 20:01:25 by adjoly #+# #+# */ /* Created: 2024/05/20 20:01:25 by adjoly #+# #+# */
/* Updated: 2024/05/28 16:43:21 by adjoly ### ########.fr */ /* Updated: 2024/06/30 16:04:09 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,9 +24,10 @@ t_list *__split_pipe(char *readline)
start_of_pipe = readline; start_of_pipe = readline;
pipe = NULL; pipe = NULL;
(void)pipe; (void)pipe;
while (*tmp) while (*tmp && tmp)
{ {
if (*tmp == '|' && is_inquote(readline, (tmp - readline)) == FALSE) if (*tmp && *tmp == '|' \
&& is_inquote(readline, (tmp - readline)) == FALSE)
{ {
tmp_pipe = ft_calloc(tmp - start_of_pipe + 1, sizeof(char)); tmp_pipe = ft_calloc(tmp - start_of_pipe + 1, sizeof(char));
if (!tmp_pipe) if (!tmp_pipe)

View File

@ -6,13 +6,13 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/25 15:06:40 by adjoly #+# #+# */ /* Created: 2024/05/25 15:06:40 by adjoly #+# #+# */
/* Updated: 2024/05/25 15:06:49 by adjoly ### ########.fr */ /* Updated: 2024/06/30 17:27:57 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "tokenizer.h" #include "tokenizer.h"
t_redirection_sign __to_redir_sign(char *redir_sign) t_redir_sign __to_redir_sign(char *redir_sign)
{ {
if (redir_sign[0] == '<' && redir_sign[1] != '<') if (redir_sign[0] == '<' && redir_sign[1] != '<')
return (INFILE); return (INFILE);

View File

@ -6,11 +6,12 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/18 20:13:50 by adjoly #+# #+# */ /* Created: 2024/05/18 20:13:50 by adjoly #+# #+# */
/* Updated: 2024/05/28 16:41:49 by adjoly ### ########.fr */ /* Updated: 2024/06/30 13:12:38 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "tokenizer.h" #include "tokenizer.h"
#include "parsing.h"
t_list *tokenizer(char *readline) t_list *tokenizer(char *readline)
{ {

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */ /* Created: 2024/04/30 13:25:42 by adjoly #+# #+# */
/* Updated: 2024/05/27 19:01:17 by adjoly ### ########.fr */ /* Updated: 2024/06/30 15:41:16 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ char *get_prompt(t_env env)
{ {
char *prompt; char *prompt;
prompt = env_get_value("USER", &env);//getenv("USER"); prompt = env_get_value("USER", &env);
if (!prompt) if (!prompt)
prompt = ft_strdup("nixos"); prompt = ft_strdup("nixos");
prompt = ft_strjoin(prompt, "@"); prompt = ft_strjoin(prompt, "@");

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */ /* Created: 2024/05/02 14:42:00 by adjoly #+# #+# */
/* Updated: 2024/06/11 16:04:42 by adjoly ### ########.fr */ /* Updated: 2024/06/30 15:41:46 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,10 +19,10 @@ char *get_pwd(t_env env)
char *pwd; char *pwd;
char *home; char *home;
pwd = env_get_value("PWD", &env);//getenv("PWD"); pwd = env_get_value("PWD", &env);
if (!pwd) if (!pwd)
return (NULL); return (NULL);
home = env_get_value("HOME", &env);//getenv("HOME"); home = env_get_value("HOME", &env);
if (!pwd) if (!pwd)
return (NULL); return (NULL);
if (!ft_strncmp(pwd, home, ft_strlen(home) - 1)) if (!ft_strncmp(pwd, home, ft_strlen(home) - 1))