merge conflit (j'aime pas les headers)

This commit is contained in:
2024-02-16 21:26:10 +01:00
4 changed files with 63 additions and 4 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/16 16:28:16 by tomoron ### ########.fr #
# Updated: 2024/02/16 21:24:47 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -22,10 +22,13 @@ SRCS = main.c\
parsing.c\
debug.c\
env_to_char_tab.c\
parsing_var.c
parsing_var.c\
minishellrc.c
OBJS = $(SRCS:.c=.o)
OBJS_DIR = objs
FLAGS = -Wall -Wextra -Werror -g
LIBFT = libft/libft.a
@ -35,6 +38,7 @@ NAME = minishell
all: $(NAME)
$(NAME) : $(LIBFT) $(OBJS)
mkdir $(OBJS_DIR)
$(CC) $(FLAGS) $(OBJS) $(LIBFT) -lreadline -o $(NAME)
$(LIBFT):

6
main.c
View File

@ -6,7 +6,11 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
<<<<<<< HEAD
/* Updated: 2024/02/16 16:37:13 by tomoron ### ########.fr */
=======
/* Updated: 2024/02/16 18:21:27 by marde-vr ### ########.fr */
>>>>>>> ad1de58fb2aacb8a3b1b7ef5d74fc6d87f4550b2
/* */
/* ************************************************************************** */
@ -71,6 +75,8 @@ int main(int argc, char **argv, char **envp)
(void)argc;
(void)argv;
env = get_env(envp);
if (env)
handle_minishellrc(env);
while (env && command)
{
prompt = get_prompt();

View File

@ -6,18 +6,20 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
/* Updated: 2024/02/16 16:32:33 by tomoron ### ########.fr */
/* Updated: 2024/02/16 21:25:14 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MINISHELL_H
# define MINISHELL_H
# include <readline/readline.h>
# include <readline/history.h>
# include <limits.h>
# include <stdio.h>//debug
# include <sys/wait.h>
# include "libft/libft.h"
# include "fcntl.h"
typedef enum e_token_type
{
@ -63,5 +65,6 @@ int is_cmd_char(char c);
void print_parsed_cmd(t_cmd *cmd);//debug
void ft_exit(t_cmd *cmd, t_env *env, int error_code);
char **env_to_char_tab(t_env *env);
void handle_minishellrc(t_env *env);
#endif

46
minishellrc.c Normal file
View File

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minishellrc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/16 17:40:16 by marde-vr #+# #+# */
/* Updated: 2024/02/16 18:25:56 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void handle_minishellrc(t_env *env)
{
char *home;
char *rc_path;
int fd;
char *line;
t_cmd *parsed_cmd;
home = ft_get_env(env, "HOME");
rc_path = ft_strjoin(home, "/.minishellrc");
if (access(rc_path, R_OK) != -1)
{
fd = open(rc_path, O_RDONLY);
if (fd == -1)
{
free(env);
perror("open");
return ;
}
line = get_next_line(fd);
while (line)
{
parsed_cmd = parse_command(line, env);
exec_command(parsed_cmd, env);
free(parsed_cmd);
free(line);
line = get_next_line(fd);
}
close(fd);
}
free(rc_path);
}