evaluation done

This commit is contained in:
kinou-p 2022-04-26 11:27:00 +02:00
parent 0da6bb86c4
commit df04c2fecc
13 changed files with 26 additions and 47 deletions

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/03/06 12:50:24 by apommier #+# #+# # # Created: 2022/03/06 12:50:24 by apommier #+# #+# #
# Updated: 2022/04/22 11:25:14 by apommier ### ########.fr # # Updated: 2022/04/23 13:33:48 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -41,15 +41,15 @@ SRCS = srcs/main.c\
srcs/set_quote/set_var.c\ srcs/set_quote/set_var.c\
OBJS = ${SRCS:.c=.o} OBJS = ${SRCS:.c=.o}
CC = clang CC = gcc
CFLAGS = -Wall -Wextra -Werror -g CFLAGS = -Wall -Wextra -Werror -fcommon
LIB = -lreadline LIB = -lreadline
RM = rm -rf RM = rm -rf
LIBFT = ./libft LIBFT = ./libft
${NAME}: ${OBJS} ${NAME}: ${OBJS}
@make bonus -C ${LIBFT} @make bonus -C ${LIBFT}
@${CC} ${LIB} ${OBJS} ${LIBFT}/libft.a -o ${NAME} ${CC} ${OBJS} ${LIBFT}/libft.a -o ${NAME} -lreadline
all: ${NAME} all: ${NAME}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */ /* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
/* Updated: 2022/04/22 13:01:36 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:37:53 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,8 +27,8 @@
# include <errno.h> # include <errno.h>
# include <signal.h> # include <signal.h>
# include <dirent.h> # include <dirent.h>
# include <readline/readline.h>
int g_var; # include <readline/history.h>
// Command Data Structure // Command Data Structure
@ -48,6 +48,8 @@ typedef struct s_simple {
char *cmd; char *cmd;
} t_s_cmd; } t_s_cmd;
int g_var;
// Describes a complete command with the multiple pipes if any // Describes a complete command with the multiple pipes if any
// and input/output redirection if any. // and input/output redirection if any.
typedef struct s_command { typedef struct s_command {

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* cd.c :+: :+: :+: */ /* cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/21 18:30:26 by sadjigui #+# #+# */ /* Created: 2022/03/21 18:30:26 by sadjigui #+# #+# */
/* Updated: 2022/04/20 16:09:32 by sadjigui ### ########.fr */ /* Updated: 2022/04/23 13:10:35 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,11 +15,10 @@
void add_one(t_s_cmd *cmd) void add_one(t_s_cmd *cmd)
{ {
char p[1024]; char p[1024];
char *str;
int i; int i;
i = find_it(cmd->big_cmd->env, "PWD"); i = find_it(cmd->big_cmd->env, "PWD");
str = getcwd(p, sizeof(p)); getcwd(p, sizeof(p));
free(cmd->big_cmd->env[i]); free(cmd->big_cmd->env[i]);
cmd->big_cmd->env[i] = ft_strjoin("PWD=", p); cmd->big_cmd->env[i] = ft_strjoin("PWD=", p);
} }
@ -87,13 +86,10 @@ int check_dir(t_s_cmd *cmd)
int open_directory(t_s_cmd *cmd) int open_directory(t_s_cmd *cmd)
{ {
char *p; char *p;
int j;
int i; int i;
p = NULL; p = NULL;
i = 0; i = 0;
if (find_it(cmd->big_cmd->env, "PWD") != -1)
j = size_path(cmd->big_cmd->env);
if (cmd->nb_args > 2) if (cmd->nb_args > 2)
return (cd_error(cmd, "Minishell: cd: too many arguments", 1)); return (cd_error(cmd, "Minishell: cd: too many arguments", 1));
if (!cmd->args[1]) if (!cmd->args[1])

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* unset.c :+: :+: :+: */ /* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 18:26:29 by sadjigui #+# #+# */ /* Created: 2022/03/11 18:26:29 by sadjigui #+# #+# */
/* Updated: 2022/04/20 15:01:03 by sadjigui ### ########.fr */ /* Updated: 2022/04/23 13:09:17 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -42,10 +42,8 @@ void unset_variable(t_s_cmd *cmd, int i)
int find_variable(char *variable, t_s_cmd *cmd) int find_variable(char *variable, t_s_cmd *cmd)
{ {
int i; int i;
int j;
i = find_it(cmd->big_cmd->env, variable); i = find_it(cmd->big_cmd->env, variable);
j = 0;
if (check_variable(variable) == 1) if (check_variable(variable) == 1)
{ {
ft_putstr_fd("Minishell: unset: `", 2); ft_putstr_fd("Minishell: unset: `", 2);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */ /* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
/* Updated: 2022/04/22 11:43:15 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:16:15 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -73,6 +73,7 @@ int main(int ac, char **av, char **path)
{ {
char **env; char **env;
(void)av;
if (!isatty(0)) if (!isatty(0))
{ {
printf("Not today\n"); printf("Not today\n");

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */ /* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
/* Updated: 2022/04/22 11:24:40 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:18:23 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,9 +14,6 @@
void exit_shell(t_cmd *cmd, int ret) void exit_shell(t_cmd *cmd, int ret)
{ {
int i;
i = 0;
ft_putstr_fd("exit\n", 1); ft_putstr_fd("exit\n", 1);
close (0); close (0);
close (1); close (1);
@ -32,7 +29,6 @@ void exit_shell(t_cmd *cmd, int ret)
close(cmd->current_s_cmd->fd[1]); close(cmd->current_s_cmd->fd[1]);
free_cmd(cmd); free_cmd(cmd);
rl_clear_history(); rl_clear_history();
clear_history();
cmd = 0; cmd = 0;
exit(ret); exit(ret);
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */ /* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
/* Updated: 2022/04/22 11:50:17 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:07:57 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,9 +16,7 @@ t_s_cmd *set_s_cmd(char *line, int index)
{ {
t_s_cmd *s_cmd; t_s_cmd *s_cmd;
char **split_line; char **split_line;
int i;
i = 0;
s_cmd = malloc(sizeof(t_s_cmd)); s_cmd = malloc(sizeof(t_s_cmd));
if (!s_cmd) if (!s_cmd)
return (0); return (0);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/09 23:58:21 by apommier #+# #+# */ /* Created: 2022/04/09 23:58:21 by apommier #+# #+# */
/* Updated: 2022/04/19 17:19:17 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:11:50 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -85,17 +85,13 @@ int parse_quote(t_cmd *cmd)
{ {
int i; int i;
int j; int j;
char *swap;
i = -1; i = -1;
while (cmd->s_cmds[++i]) while (cmd->s_cmds[++i])
{ {
j = -1; j = -1;
while (cmd->s_cmds[i]->args[++j]) while (cmd->s_cmds[i]->args[++j])
{
swap = cmd->s_cmds[i]->args[j];
cmd->s_cmds[i]->args[j] = set_var(cmd, cmd->s_cmds[i]->args[j]); cmd->s_cmds[i]->args[j] = set_var(cmd, cmd->s_cmds[i]->args[j]);
}
if (!is_builtin(cmd->s_cmds[i]->args[0])) if (!is_builtin(cmd->s_cmds[i]->args[0]))
{ {
cmd->s_cmds[i]->cmd = get_command(cmd->s_cmds[i]->args, cmd->path); cmd->s_cmds[i]->cmd = get_command(cmd->s_cmds[i]->args, cmd->path);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/10 19:50:50 by apommier #+# #+# */ /* Created: 2022/04/10 19:50:50 by apommier #+# #+# */
/* Updated: 2022/04/19 16:15:11 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:11:27 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,7 +31,7 @@ int next_quote(const char *s, int i)
while (s[i] != '\'') while (s[i] != '\'')
i++; i++;
} }
else else if (double_quote)
{ {
while (s[i] != '"') while (s[i] != '"')
i++; i++;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/19 14:46:01 by apommier #+# #+# */ /* Created: 2022/04/19 14:46:01 by apommier #+# #+# */
/* Updated: 2022/04/22 11:24:15 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:08:11 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,9 +17,7 @@ char *set_heredoc(int index, char **in)
char *nbr_file; char *nbr_file;
char *file_name; char *file_name;
int fd; int fd;
int i;
i = 0;
if (index) if (index)
{ {
nbr_file = ft_itoa(index + 1); nbr_file = ft_itoa(index + 1);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/19 14:44:22 by apommier #+# #+# */ /* Created: 2022/04/19 14:44:22 by apommier #+# #+# */
/* Updated: 2022/04/22 11:43:15 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:08:35 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,13 +32,10 @@ int check_access_input(t_s_cmd *cmd)
char *set_input(char *line, t_s_cmd *cmd, int index) char *set_input(char *line, t_s_cmd *cmd, int index)
{ {
int i; int i;
int word_index;
word_index = 0;
i = index + 1; i = index + 1;
if (line[i] == '<') if (line[i] == '<')
i++; i++;
word_index = i;
while (line[i] == ' ' && line[i]) while (line[i] == ' ' && line[i])
i++; i++;
while ((line[i] != ' ' && line[i] != '<' && line[i] != '>') && line[i]) while ((line[i] != ' ' && line[i] != '<' && line[i] != '>') && line[i])

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/19 14:45:10 by apommier #+# #+# */ /* Created: 2022/04/19 14:45:10 by apommier #+# #+# */
/* Updated: 2022/04/22 13:02:24 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:08:53 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,14 +53,11 @@ int check_access_output(t_s_cmd *cmd)
char *set_output(char *line, t_s_cmd *cmd, int index) char *set_output(char *line, t_s_cmd *cmd, int index)
{ {
int i; int i;
int word_index;
word_index = 0;
i = index; i = index;
i++; i++;
if (line[i] == '>') if (line[i] == '>')
i++; i++;
word_index = i;
while (line[i] == ' ' && line[i]) while (line[i] == ' ' && line[i])
i++; i++;
while ((line[i] != ' ' && line[i] != '<' && line[i] != '>') && line[i]) while ((line[i] != ' ' && line[i] != '<' && line[i] != '>') && line[i])

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/19 15:30:30 by apommier #+# #+# */ /* Created: 2022/04/19 15:30:30 by apommier #+# #+# */
/* Updated: 2022/04/22 11:43:15 by apommier ### ########.fr */ /* Updated: 2022/04/23 13:12:16 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
void crtl_c(int num) void crtl_c(int num)
{ {
num = 0; (void)num;
g_var = 130; g_var = 130;
printf("\n"); printf("\n");
rl_replace_line("", 0); rl_replace_line("", 0);