Skip to content

Commit 94c0f14

Browse files
committed
cleaned repo for final merge on main, project finished
1 parent e749de3 commit 94c0f14

19 files changed

+73
-264
lines changed

Makefile

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ #
77
# +#+#+#+#+#+ +#+ #
88
# Created: Invalid date by #+# #+# #
9-
# Updated: 2024/05/17 13:57:38 by cdomet-d ### ########lyon.fr #
9+
# Updated: 2024/05/23 17:00:41 by cdomet-d ### ########lyon.fr #
1010
# #
1111
# **************************************************************************** #
1212

@@ -92,10 +92,7 @@ SRC_HEREDOC:= heredoc.c \
9292
# ⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒ UTILS ⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒ #
9393
SRC += $(addprefix $(DIR_UTILS), $(SRC_UTILS))
9494
DIR_UTILS:= utils/
95-
SRC_UTILS:= display_data.c \
96-
display_structs_q.c \
97-
display_structs_v.c \
98-
error_handling.c \
95+
SRC_UTILS:= error_handling.c \
9996

10097
# ⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒ EXEC ⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒⌒ #
10198

includes/exec.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/03/26 15:39:49 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/23 13:28:00 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 13:22:19 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -96,10 +96,9 @@ void *heredoc_error(t_input *in, char *tmpdel, char *line, bool err);
9696
// signals -------------------
9797

9898
/* sig_set_stat.c */
99-
void set_status(t_input *in, int e_stat);
99+
void set_status(t_input *in, t_fd fd, int e_stat);
100100

101101
/* sighandler.c */
102-
int get_nonull(void);
103102
void sigend(void);
104103
void siglisten(void);
105104
char *send_eof(char *line);

includes/minishell.h

+2-16
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/* ::: :::::::: */
44
/* minishell.h :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: csweetin <csweetin@student.42.fr> +#+ +:+ +#+ */
6+
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/03/18 15:31:14 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/22 17:14:40 by csweetin ### ########.fr */
9+
/* Updated: 2024/05/23 17:13:15 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -91,20 +91,6 @@ t_env *env_newnode(char *data);
9191

9292
// utils ---------------------
9393

94-
/* display_data.c */
95-
void print_fds(t_fd *fd);
96-
97-
/* display_structs_v.c */
98-
void print_in_for(t_input *input);
99-
void print_enum(int token);
100-
void print_in_node(t_input *node, t_fd *fd, char *str);
101-
void print_env_for(t_env *env, char *str);
102-
void vdisplay_dtab(char **dtab);
103-
104-
/* display_structs_q.c */
105-
void pmin(t_input *input, char *str);
106-
void display_dtab(char **dtab);
107-
10894
/* error_handling.c */
10995
void fatal_exit(t_input **lst, int rv, char *error_message);
11096
void *print_error(int error_code, char *error_message);

src/builtins/bt_functs/exit.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/03/29 11:54:27 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/23 15:37:44 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 12:18:12 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -37,6 +37,8 @@ static bool not_num(char *str)
3737
size_t i;
3838

3939
i = 0;
40+
if (isdigit(str[i]) || str[i] == '+' || str[i] == '-')
41+
i++;
4042
while (str[i])
4143
{
4244
if (!isdigit(str[i]))
@@ -61,7 +63,7 @@ int mh_exit(char **line, t_input *in)
6163
{
6264
unsigned long long int rv;
6365

64-
printf("exit\n");
66+
ft_putstr_fd("exit\n", STDERR_FILENO);
6567
if (line && *line)
6668
{
6769
free(*line);

src/exec/exec.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/03/25 14:26:17 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/23 11:54:58 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 14:45:12 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -21,10 +21,14 @@ static void *ft_execve(t_input *in)
2121
if (!tmp->data)
2222
return (NULL);
2323
arenv = NULL;
24-
arenv = arenvlst(tmp->env);
25-
if (!arenv)
26-
return (display_exec_error(tmp), NULL);
27-
if (tmp->data[0] && access(tmp->data[0], X_OK) != -1)
24+
if (in->env)
25+
{
26+
arenv = arenvlst(tmp->env);
27+
if (!arenv)
28+
return (NULL);
29+
}
30+
if (tmp->data[0] && access(tmp->data[0], X_OK) != -1 && \
31+
path_slash(tmp->data[0]))
2832
execve(tmp->data[0], tmp->data, arenv);
2933
if (arenv)
3034
free_dtab(arenv);

src/exec/utils/arenvlst.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/03/25 14:27:46 by cdomet-d #+# #+# */
9-
/* Updated: 2024/04/09 15:02:45 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 11:04:27 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -40,15 +40,15 @@ char **arenvlst(t_env *env)
4040
i = 0;
4141
arenv = malloc(sizeof(char *) * (env_len(env) + 1));
4242
if (!arenv)
43-
return (print_error(errno, "arenvlst (malloc)"));
43+
return (print_error(errno, "minishell"));
4444
arenv[env_len(env)] = 0;
4545
while (tmp)
4646
{
4747
arenv[i] = ft_strdup(tmp->env);
4848
if (!arenv[i])
4949
{
5050
free_dtab(arenv);
51-
return (print_error(errno, "arenvlst (malloc 2)"));
51+
return (print_error(errno, "minishell"));
5252
}
5353
i++;
5454
tmp = tmp->next;

src/exec/utils/exec_utils.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/04/18 14:05:08 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/21 19:35:50 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 13:25:39 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -46,7 +46,7 @@ void close_and_wait(t_input *in, t_fd *fd)
4646
waitpid(fd->pid, &e_stat, 0);
4747
while (wait(0) != -1 && errno != ECHILD)
4848
;
49-
set_status(in, e_stat);
49+
set_status(in, *fd, e_stat);
5050
}
5151

5252
void *create_child(t_fd *fd)

src/exec/utils/redirection_utils.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/04/07 22:44:46 by jauseff #+# #+# */
9-
/* Updated: 2024/05/23 11:20:40 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 11:26:29 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -54,6 +54,8 @@ bool is_last(t_input *in)
5454

5555
void *open_infiles(t_fd *fd, t_input *tmp)
5656
{
57+
if (!tmp->data || !tmp->data[0])
58+
return (NULL);
5759
fd->ffd = open(tmp->data[0], O_RDONLY);
5860
if (tmp->tok == heredoc)
5961
unlink(tmp->data[0]);
@@ -78,6 +80,8 @@ void *open_infiles(t_fd *fd, t_input *tmp)
7880

7981
void *open_outfiles(t_fd *fd, t_input *tmp)
8082
{
83+
if (!tmp->data || !tmp->data[0])
84+
return (NULL);
8185
if (tmp->tok == outredir)
8286
fd->ffd = open(tmp->data[0], O_CREAT | O_TRUNC | O_RDWR, 0644);
8387
else if (tmp->tok == append)

src/heredoc/heredoc.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/04/12 11:51:17 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/21 16:54:54 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 13:29:38 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -59,17 +59,19 @@ static char *gen_filename(int fn)
5959
if (!strfn)
6060
return (print_error(errno, "minishell: heredoc"));
6161
filename = ft_strjoin("/tmp/tmp_", strfn);
62+
free(strfn);
6263
if (!filename)
6364
return (print_error(errno, "minishell: heredoc"));
64-
free(strfn);
6565
return (filename);
6666
}
6767

6868
static void *create_hfile(t_fd *fd, t_input *tmp, char *filename)
6969
{
70+
if (!filename)
71+
return (NULL);
7072
fd->hfd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0644);
7173
if (fd->hfd == -1)
72-
return (print_error(errno, "minishell: heredoc"));
74+
return (free (filename), print_error(errno, "minishell: heredoc"));
7375
if (!h_rl(fd->hfd, tmp))
7476
return (free (filename), close(fd->hfd), NULL);
7577
free(filename);
@@ -90,13 +92,19 @@ void *create_hdocs(t_fd *fd, t_input *in)
9092
while (op_true(tmp, heredoc))
9193
{
9294
if (!create_hfile(fd, tmp, gen_filename(fn)))
95+
{
96+
free(tmp->data[0]);
97+
tmp->data[0] = NULL;
9398
return (NULL);
99+
}
94100
free(tmp->data[0]);
95101
in->status = tmp->status;
96102
tmp->data[0] = gen_filename(fn);
103+
if (!tmp->data[0])
104+
return (NULL);
97105
tmp = find_here(tmp, true);
98106
fn++;
99107
}
100-
set_status(in, 0);
108+
set_status(in, *fd, 0);
101109
return ((int *) true);
102110
}

src/heredoc/heredoc_errors.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/05/16 16:14:03 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/21 16:39:26 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 12:03:51 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -17,8 +17,12 @@ void *heredoc_error(t_input *in, char *tmpdel, char *line, bool err)
1717
if (in->data[0][0] < 0)
1818
in->data[0][0] *= -1;
1919
if (err)
20+
{
21+
if (errno == ENOMEM)
22+
print_error(errno, "minishell");
2023
verror \
2124
("minishell: ", "warning: expected delimiter: ", in->data[0]);
25+
}
2226
free(tmpdel);
2327
free(line);
2428
return (NULL);

src/heredoc/heredoc_expand.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/05/03 17:48:21 by csweetin #+# #+# */
9-
/* Updated: 2024/05/16 15:40:26 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 11:14:28 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

src/heredoc/heredoc_utils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/04/26 17:39:51 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/17 15:09:25 by cdomet-d ### ########lyon.fr */
9+
/* Updated: 2024/05/24 13:53:13 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

src/main.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@
33
/* ::: :::::::: */
44
/* main.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: csweetin <csweetin@student.42.fr> +#+ +:+ +#+ */
6+
/* By: cdomet-d <cdomet-d@student.42lyon.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/04/12 18:04:56 by cdomet-d #+# #+# */
9-
/* Updated: 2024/05/23 16:16:38 by csweetin ### ########.fr */
9+
/* Updated: 2024/05/24 13:12:18 by cdomet-d ### ########lyon.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "parsing.h"
1414

1515
int g_sig;
1616

17-
static void init_all(char **str, char **envp, t_env **env, t_input **input)
17+
static int init_all(char **str, char **envp, t_env **env, t_input **input)
1818
{
19+
if (!isatty(0) || !isatty(1))
20+
return (print_error(errno, "minishell"), 0);
1921
*str = NULL;
2022
*env = NULL;
2123
*input = NULL;
2224
create_env(envp, env);
25+
siglisten();
26+
return (1);
2327
}
2428

2529
static t_env *process_line(char **line, t_input *in, t_env **env, int *stat)
@@ -54,10 +58,10 @@ int main(int argc, char **argv, char **envp)
5458

5559
if (argc != 1)
5660
return (print_error(errno, "minishell: too many arguments"), 1);
61+
if (!init_all(&line, envp, &env, &input))
62+
return (1);
5763
(void)argv;
5864
status = 0;
59-
init_all(&line, envp, &env, &input);
60-
siglisten();
6165
while (1)
6266
{
6367
sigend();

0 commit comments

Comments
 (0)