added minishellrc
This commit is contained in:
8
Makefile
8
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||||
# Updated: 2024/02/16 14:26:43 by tomoron ### ########.fr #
|
# Updated: 2024/02/16 18:36:48 by marde-vr ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -22,10 +22,13 @@ SRCS = main.c\
|
|||||||
parsing.c\
|
parsing.c\
|
||||||
debug.c\
|
debug.c\
|
||||||
env_to_char_tab.c\
|
env_to_char_tab.c\
|
||||||
parsing_var.c
|
parsing_var.c\
|
||||||
|
minishellrc.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
OBJS_DIR = objs
|
||||||
|
|
||||||
FLAGS = -Wall -Wextra -Werror -g
|
FLAGS = -Wall -Wextra -Werror -g
|
||||||
|
|
||||||
LIBFT = libft/libft.a
|
LIBFT = libft/libft.a
|
||||||
@ -35,6 +38,7 @@ NAME = minishell
|
|||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(NAME) : $(LIBFT) $(OBJS)
|
$(NAME) : $(LIBFT) $(OBJS)
|
||||||
|
mkdir $(OBJS_DIR)
|
||||||
$(CC) $(FLAGS) $(OBJS) $(LIBFT) -lreadline -o $(NAME)
|
$(CC) $(FLAGS) $(OBJS) $(LIBFT) -lreadline -o $(NAME)
|
||||||
|
|
||||||
$(LIBFT) :
|
$(LIBFT) :
|
||||||
|
8
main.c
8
main.c
@ -6,13 +6,13 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/15 14:13:57 by tomoron ### ########.fr */
|
/* Updated: 2024/02/16 18:21:27 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int g_return_code = 0;
|
int g_return_code = 0;
|
||||||
|
|
||||||
char *get_prompt(void)
|
char *get_prompt(void)
|
||||||
{
|
{
|
||||||
@ -71,6 +71,8 @@ int main(int argc, char **argv, char **envp)
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
env = get_env(envp);
|
env = get_env(envp);
|
||||||
|
if (env)
|
||||||
|
handle_minishellrc(env);
|
||||||
while (env && command)
|
while (env && command)
|
||||||
{
|
{
|
||||||
prompt = get_prompt();
|
prompt = get_prompt();
|
||||||
@ -81,7 +83,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
add_history(command);
|
add_history(command);
|
||||||
parsed_cmd = parse_command(command, env);
|
parsed_cmd = parse_command(command, env);
|
||||||
free(command);
|
free(command);
|
||||||
print_parsed_cmd(parsed_cmd);//debug
|
print_parsed_cmd(parsed_cmd); //debug
|
||||||
exec_command(parsed_cmd, env);
|
exec_command(parsed_cmd, env);
|
||||||
free_cmd(parsed_cmd);
|
free_cmd(parsed_cmd);
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,20 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/16 16:11:48 by marde-vr ### ########.fr */
|
/* Updated: 2024/02/16 18:00:52 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef MINISHELL_H
|
#ifndef MINISHELL_H
|
||||||
# define MINISHELL_H
|
# define MINISHELL_H
|
||||||
|
|
||||||
# include <readline/readline.h>
|
# include <readline/readline.h>
|
||||||
# include <readline/history.h>
|
# include <readline/history.h>
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
# include <stdio.h>//debug
|
# include <stdio.h>//debug
|
||||||
# include <sys/wait.h>
|
# include <sys/wait.h>
|
||||||
# include "libft/libft.h"
|
# include "libft/libft.h"
|
||||||
|
# include "fcntl.h"
|
||||||
|
|
||||||
typedef enum e_token_type
|
typedef enum e_token_type
|
||||||
{
|
{
|
||||||
@ -65,5 +67,6 @@ int is_cmd_char(char c);
|
|||||||
void print_parsed_cmd(t_cmd *cmd);//debug
|
void print_parsed_cmd(t_cmd *cmd);//debug
|
||||||
void ft_exit(t_cmd *cmd, t_env *env, int error_code);
|
void ft_exit(t_cmd *cmd, t_env *env, int error_code);
|
||||||
char **env_to_char_tab(t_env *env);
|
char **env_to_char_tab(t_env *env);
|
||||||
|
void handle_minishellrc(t_env *env);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
46
minishellrc.c
Normal file
46
minishellrc.c
Normal 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);
|
||||||
|
}
|
Reference in New Issue
Block a user