mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「✨」 feat: Did a lot of things, don't know what but it work
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
*/
|
||||
# include <stdbool.h>
|
||||
|
||||
# define ERROR_SYNTAX ": syntax error"
|
||||
# define ERROR_NO_REDIR ": need redirection file"
|
||||
# define ERROR_NO_EOF ": need delimiter to heredoc"
|
||||
# define ERROR_NO_FILE "No such file or directory"
|
||||
# define ERROR_CMD_PIPE "No command after pipe"
|
||||
|
||||
# define ERROR_COREDUMP "(core dumped)"
|
||||
|
||||
char *get_program_name(char *argv_one);
|
||||
bool send_error_parsing(char *msg);
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
} t_quote;
|
||||
|
||||
bool check_syntax(char *readline, char **argv);
|
||||
bool check_syntax(char *readline);
|
||||
void send_error(char *msg, char **argv);
|
||||
void check_redir(t_list *redir, char **argv);
|
||||
t_cmd *get_redir_fd(void *content, t_env *env);
|
||||
t_list *get_cmd_list(t_list *list, t_env *env);
|
||||
bool check_redir(t_list *redir);
|
||||
t_cmd *get_redir_fd(void *content);
|
||||
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 *env_var_replace(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);
|
||||
void check_quote(char *readline);
|
||||
bool check_quote(char *readline);
|
||||
t_quote __is_quote(char c);
|
||||
char *search_for_next_quote(char *s, t_quote quote_type);
|
||||
bool check_pipe(char *readline);
|
||||
char **split_argv(char *readline);
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
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_redir(t_redirection *redir);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,
|
||||
OUTFILE,
|
||||
OUT_APPEND,
|
||||
} t_redirection_sign;
|
||||
} t_redir_sign;
|
||||
|
||||
typedef struct s_redirection
|
||||
{
|
||||
char *file_name;
|
||||
t_redirection_sign sign;
|
||||
char *file_name;
|
||||
t_redir_sign sign;
|
||||
} t_redirection;
|
||||
|
||||
typedef struct s_token
|
||||
@ -42,7 +42,7 @@ typedef struct s_token
|
||||
*
|
||||
* @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
|
||||
|
21
src/main.c
21
src/main.c
@ -6,13 +6,14 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.h>
|
||||
#include <readline/readline.h>
|
||||
#include "error_msg.h"
|
||||
#include <readline/history.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
@ -95,25 +96,25 @@ int main(int ac, char **av, char **env)
|
||||
|
||||
(void)ac;
|
||||
(void)av;
|
||||
get_program_name(av[0]);
|
||||
piped = NULL;
|
||||
if (env_init(env, &env_l))
|
||||
return (EXIT_FAILURE);
|
||||
sigemptyset(&(sigset_t){SIGQUIT});
|
||||
signal(SIGINT, &sigggg);
|
||||
signal(SIGQUIT, &siggg_backslash);
|
||||
signal(SIGSEGV, &siggg_d);
|
||||
//signal(SIGSEGV, &siggg_d);
|
||||
while (1)
|
||||
{
|
||||
prompt = get_prompt(env_l);
|
||||
test = readline(prompt);
|
||||
free(prompt);
|
||||
add_history(test);
|
||||
check_syntax(test, av);
|
||||
if (check_syntax(test))
|
||||
continue ;
|
||||
lll = ft_split(test, ' ');
|
||||
if (!*lll)
|
||||
continue ;
|
||||
else if (is_str(test, "exit"))
|
||||
break ;
|
||||
else if (is_str(test, "pwd"))
|
||||
{
|
||||
ft_pwd();
|
||||
@ -136,10 +137,14 @@ int main(int ac, char **av, char **env)
|
||||
}
|
||||
else if (is_str(test, "exit"))
|
||||
exit(EXIT_SUCCESS);
|
||||
check_quote(test);
|
||||
if (check_quote(test))
|
||||
continue ;
|
||||
if (check_pipe(test))
|
||||
continue ;
|
||||
piped = tokenizer(test);
|
||||
check_redir(((t_token *)(piped->content))->redirection, av);
|
||||
cmd_list = get_cmd_list(piped, &env_l);
|
||||
if (check_redir(((t_token *)(piped->content))->redirection))
|
||||
continue ;
|
||||
cmd_list = get_cmd_list(piped);
|
||||
exec_split_cmd(cmd_list, &env_l);
|
||||
free(test);
|
||||
ft_lstclear(&piped, free_token);
|
||||
|
45
src/parsing/check_error/check_pipe.c
Normal file
45
src/parsing/check_error/check_pipe.c
Normal 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);
|
||||
}
|
@ -6,11 +6,12 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "error_msg.h"
|
||||
#include "tokenizer.h"
|
||||
|
||||
size_t count_quote(char *readline, t_quote type)
|
||||
@ -29,20 +30,15 @@ size_t count_quote(char *readline, t_quote type)
|
||||
return (count);
|
||||
}
|
||||
|
||||
void check_quote(char *readline)
|
||||
bool check_quote(char *readline)
|
||||
{
|
||||
size_t count;
|
||||
|
||||
count = count_quote(readline, DOUBLE);
|
||||
if (count % 2)
|
||||
{
|
||||
ft_putendl_fd("double quote error", STDERR_FILENO);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return (send_error_parsing("double quote not closed"));
|
||||
count = count_quote(readline, SINGLE);
|
||||
if (count % 2)
|
||||
{
|
||||
ft_putendl_fd("single quote error", STDERR_FILENO);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return (send_error_parsing("single quote not closed"));
|
||||
return (false);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "error_msg.h"
|
||||
|
||||
void check_redir(t_list *redir, char **argv)
|
||||
bool check_redir(t_list *redir)
|
||||
{
|
||||
t_list *tmp;
|
||||
t_redirection *tmp_redir;
|
||||
@ -25,9 +25,10 @@ void check_redir(t_list *redir, char **argv)
|
||||
tmp_redir = tmp->content;
|
||||
if (tmp_redir->sign == HEREDOC && \
|
||||
!((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)
|
||||
send_error(ERROR_NO_REDIR, argv);
|
||||
return (send_error_parsing(ERROR_NO_REDIR));
|
||||
tmp = tmp->next;
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
bool check_syntax(char *readline, char **argv)
|
||||
bool check_syntax(char *readline)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
@ -56,15 +56,9 @@ bool check_syntax(char *readline, char **argv)
|
||||
while (*tmp)
|
||||
{
|
||||
if (check_triple(tmp))
|
||||
{
|
||||
send_error(ERROR_SYNTAX, argv);
|
||||
return (true);
|
||||
}
|
||||
return (send_error_parsing(ERROR_SYNTAX));
|
||||
if (check_if_file(tmp))
|
||||
{
|
||||
send_error(ERROR_SYNTAX, argv);
|
||||
return (true);
|
||||
}
|
||||
return (send_error_parsing(ERROR_SYNTAX));
|
||||
tmp++;
|
||||
}
|
||||
return (false);
|
||||
|
@ -6,14 +6,31 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
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)
|
||||
{
|
||||
ft_putstr_fd(argv[0], 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);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ void print_quote_type(t_quote type)
|
||||
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)
|
||||
ft_putendl_fd("HEREDOC", STDOUT_FILENO);
|
||||
|
@ -6,14 +6,14 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "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 *cmd_list;
|
||||
@ -22,7 +22,7 @@ t_list *get_cmd_list(t_list *list, t_env *env)
|
||||
cmd_list = NULL;
|
||||
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;
|
||||
}
|
||||
return (cmd_list);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "execution.h"
|
||||
#include <fcntl.h>
|
||||
#include "minishell.h"
|
||||
#include <stdio.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_redirection *tmp_redir;
|
||||
t_redirection_sign out;
|
||||
t_redirection_sign in;
|
||||
t_cmd *cmd;
|
||||
t_list *tmp;
|
||||
t_redir_sign sign[2];
|
||||
t_cmd *cmd;
|
||||
|
||||
(void)env;
|
||||
token = (t_token *)content;
|
||||
tmp = token->redirection;
|
||||
tmp = ((t_token *)content)->redirection;
|
||||
cmd = NULL;
|
||||
out = INFILE;
|
||||
in = OUTFILE;
|
||||
sign[0] = INFILE;
|
||||
sign[1] = OUTFILE;
|
||||
cmd = ft_calloc(sizeof(t_cmd), 1);
|
||||
while (tmp)
|
||||
{
|
||||
tmp_redir = (t_redirection *)tmp->content;
|
||||
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);
|
||||
}
|
||||
open_redir((t_redirection *)tmp->content, cmd, sign);
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (in == OUTFILE)
|
||||
cmd->infile = STDIN_FILENO;
|
||||
if (out == INFILE)
|
||||
if (sign[0] == INFILE)
|
||||
cmd->outfile = STDOUT_FILENO;
|
||||
// char *ll = env_var_replace(token->argv, env);
|
||||
cmd = split_cmd(token->argv, cmd);
|
||||
if (sign[1] == OUTFILE)
|
||||
cmd->infile = STDIN_FILENO;
|
||||
cmd = split_cmd(((t_token *)content)->argv, cmd);
|
||||
return (cmd);
|
||||
}
|
||||
|
43
src/parsing/open_redir.c
Normal file
43
src/parsing/open_redir.c
Normal 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);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
size_t __get_len_arg(char *s)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
|
||||
if (*s == SINGLE || *s == DOUBLE)
|
||||
return (search_for_next_quote((s + 1), __is_quote(*s)) - s + 1);
|
||||
tmp = s;
|
||||
@ -70,7 +70,7 @@ char **split_argv(char *readline)
|
||||
tmp++;
|
||||
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_av++;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
pipe = NULL;
|
||||
(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));
|
||||
if (!tmp_pipe)
|
||||
|
@ -6,13 +6,13 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
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] != '<')
|
||||
return (INFILE);
|
||||
|
@ -6,11 +6,12 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "parsing.h"
|
||||
|
||||
t_list *tokenizer(char *readline)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
prompt = env_get_value("USER", &env);//getenv("USER");
|
||||
prompt = env_get_value("USER", &env);
|
||||
if (!prompt)
|
||||
prompt = ft_strdup("nixos");
|
||||
prompt = ft_strjoin(prompt, "@");
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 *home;
|
||||
|
||||
pwd = env_get_value("PWD", &env);//getenv("PWD");
|
||||
pwd = env_get_value("PWD", &env);
|
||||
if (!pwd)
|
||||
return (NULL);
|
||||
home = env_get_value("HOME", &env);//getenv("HOME");
|
||||
home = env_get_value("HOME", &env);
|
||||
if (!pwd)
|
||||
return (NULL);
|
||||
if (!ft_strncmp(pwd, home, ft_strlen(home) - 1))
|
||||
|
Reference in New Issue
Block a user