Skip to content

Commit d9137fe

Browse files
author
Alvaro Ruben Lopez Mohedano
committed
fixed some leaks and norminette
1 parent 8c6b810 commit d9137fe

12 files changed

+46
-37
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@
4646
.DS_Store
4747
*.mod*
4848
*.cmd
49-
.tmp_versions/
49+
.tmp_versions/
50+
51+
.vscode/launch.json
52+
.vscode/tasks.json

aux.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hola
2+
estoy en el campus 42
3+
adios

src/builtin.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: alvalope <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/07/13 18:14:51 by alvalope #+# #+# */
9-
/* Updated: 2023/07/27 11:36:01 by alvalope ### ########.fr */
9+
/* Updated: 2023/08/02 15:44:09 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -153,6 +153,7 @@ void execute_export(char **args)
153153
t_envp *new_var;
154154

155155
i = 1;
156+
write(1, "1", 1);
156157
if (!args[i])
157158
execute_env(1);
158159
if (ft_strchr(args[i], '='))

src/executer.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: alvalope <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/06/20 12:57:41 by alvalope #+# #+# */
9-
/* Updated: 2023/07/27 14:18:22 by alvalope ### ########.fr */
9+
/* Updated: 2023/08/02 13:36:08 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -50,8 +50,8 @@ void ft_separate_cmd(t_pipex *p, t_aux *auxs, char **argv, char **paths)
5050
else
5151
p->paths[auxs->cmd] = ft_strdup(argv[auxs->i]);
5252
p->args[auxs->cmd][auxs->args] = argv[auxs->i];
53-
auxs->i++;
5453
}
54+
auxs->i++;
5555
}
5656

5757
int ft_separate_cmd2(t_pipex *p, t_aux *auxs, int argc, char **argv)
@@ -81,11 +81,12 @@ void ft_main(char **argv, int argc, char **paths)
8181
t_aux auxs;
8282

8383
auxs.pipes = ft_count_pipes(argv, argc - 1);
84-
auxs.i = 1;
84+
auxs.i = 0;
8585
ft_reserve_mem(&p, auxs.pipes + 1, ft_count_max_args(argv, argc, auxs.i));
8686
ft_count_args(argv, argc, &p);
8787
auxs.i = 0;
8888
auxs.cmd = 0;
89+
//ft_printf("QWE%d %d", auxs.i, argc);
8990
while (auxs.i < argc)
9091
{
9192
ft_separate_cmd(&p, &auxs, argv, paths);

src/executer_utils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: alvalope <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/06/29 12:12:37 by alvalope #+# #+# */
9-
/* Updated: 2023/07/26 16:05:10 by alvalope ### ########.fr */
9+
/* Updated: 2023/08/02 13:05:06 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

src/executer_utils2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: alvalope <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/07/12 20:49:40 by alvalope #+# #+# */
9-
/* Updated: 2023/07/26 15:41:29 by alvalope ### ########.fr */
9+
/* Updated: 2023/08/02 13:06:54 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

src/ft_do_commands_first_last.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: alvalope <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/07/26 16:07:23 by alvalope #+# #+# */
9-
/* Updated: 2023/07/27 15:41:37 by alvalope ### ########.fr */
9+
/* Updated: 2023/08/02 12:10:52 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

src/ft_do_commands_utils.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: alvalope <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/06/20 14:22:03 by alvalope #+# #+# */
9-
/* Updated: 2023/07/26 16:04:12 by alvalope ### ########.fr */
9+
/* Updated: 2023/08/02 13:08:13 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -105,13 +105,13 @@ void ft_open_first_out_file(t_pipex *p, int fd[2], int n_com)
105105

106106
if (p->outfl[0])
107107
{
108-
if (p->outmode[p->i])
109-
file = open(p->outfl[p->i], O_WRONLY | O_CREAT | O_APPEND, 0644);
108+
if (p->outmode[0])
109+
file = open(p->outfl[0], O_WRONLY | O_CREAT | O_APPEND, 0644);
110110
else
111111
file = open(p->outfl[0], O_WRONLY | O_CREAT | O_TRUNC, 0644);
112112
if (file == -1)
113113
{
114-
ft_write_error("file", strerror(errno), p->outfl[p->i]);
114+
ft_write_error("file", strerror(errno), p->outfl[0]);
115115
exit(EXIT_FAILURE);
116116
}
117117
if (dup2(file, STDOUT_FILENO) == -1)

src/ft_parser.c

+17-16
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
/* ::: :::::::: */
44
/* ft_parser.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: ysingh <ysingh@student.42malaga.com> +#+ +:+ +#+ */
6+
/* By: alvalope <alvalope@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/05/31 18:59:41 by ysingh #+# #+# */
9-
/* Updated: 2023/07/27 23:16:26 by ysingh ### ########.fr */
9+
/* Updated: 2023/08/02 15:40:58 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "minishell.h"
1414

15-
char *ft_call_replace(char *prompt)
15+
char *ft_call_replace(char *prompt)
1616
{
17-
char *start;
18-
char *end;
19-
char *replace;
20-
int i;
17+
char *start;
18+
char *end;
19+
char *replace;
20+
int i;
2121

2222
i = 0;
2323
while (prompt[i])
@@ -26,15 +26,15 @@ char *ft_call_replace(char *prompt)
2626
{
2727
replace = ">";
2828
start = prompt + i;
29-
end = prompt + i+2;
30-
prompt = ft_replace(prompt,start, end, replace);
29+
end = prompt + i + 2;
30+
prompt = ft_replace(prompt, start, end, replace);
3131
}
3232
else if (prompt[i] == '<' && prompt[i + 1] == '>')
3333
{
3434
replace = "<";
3535
start = prompt + i;
36-
end = prompt + i+2;
37-
prompt = ft_replace(prompt,start, end, replace);
36+
end = prompt + i + 2;
37+
prompt = ft_replace(prompt, start, end, replace);
3838
}
3939
i++;
4040
}
@@ -52,6 +52,7 @@ char **ft_parser(char *prompt)
5252
if (prompt[ft_strlen(prompt) - 1] == ' ')
5353
cmd = ft_charpp_del_back(cmd);
5454
cmd = ft_expand_vars(cmd);
55+
print_charpp(cmd);
5556
free(prompt);
5657
return (cmd);
5758
}
@@ -77,11 +78,11 @@ char **ft_cmdtrim(char *prompt)
7778
{
7879
while (prompt[i] == ' ')
7980
i++;
80-
//if (prompt[i] == DQ)
81-
// aux = ft_call_dq(prompt, &i);
82-
//else if (prompt[i] == SQ)
83-
// aux = ft_call_sq(prompt, &i);
84-
if (prompt[i] == '<')
81+
if (prompt[i] == DQ)
82+
aux = ft_call_dq(prompt, &i);
83+
else if (prompt[i] == SQ)
84+
aux = ft_call_sq(prompt, &i);
85+
else if (prompt[i] == '<')
8586
aux = ft_call_red(prompt, &i);
8687
else if (prompt[i] == '>')
8788
aux = ft_call_redback(prompt, &i);

src/main.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: alvalope <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/05/31 18:59:03 by ysingh #+# #+# */
9-
/* Updated: 2023/07/24 16:11:07 by alvalope ### ########.fr */
9+
/* Updated: 2023/08/02 12:16:12 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -34,14 +34,14 @@ int main(int argc, char **argv __attribute__((unused)), char **envp)
3434
if (ft_check_cmd(line))
3535
{
3636
cmds = ft_parser(line);
37-
//ft_executer(cmds, g_global.path);
37+
ft_executer(cmds, g_global.path);
3838
}
3939
else
4040
{
4141
ft_error("minishell syntax error\n", line);
4242
g_global.exit_status = 258;
4343
}
44-
ft_charppfree(cmds);
44+
//ft_charppfree(cmds);
4545
}
4646
}
4747

src/utils.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/* ::: :::::::: */
44
/* utils.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: ysingh <ysingh@student.42malaga.com> +#+ +:+ +#+ */
6+
/* By: alvalope <alvalope@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/05/31 19:09:06 by ysingh #+# #+# */
9-
/* Updated: 2023/07/27 22:54:41 by ysingh ### ########.fr */
9+
/* Updated: 2023/08/02 13:18:57 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -71,9 +71,9 @@ int ft_check_last_pipe(char *str)
7171
int i;
7272

7373
i = ft_strlen(str) - 1;
74-
while (str[i] == ' ' || str[i] == '\t')
74+
while (str[i] && (str[i] == ' ' || str[i] == '\t'))
7575
i -= 1;
76-
if (str[i] == '|' || str[i] == '<' || str[i] == '>')
76+
if (str[i] && (str[i] == '|' || str[i] == '<' || str[i] == '>'))
7777
return (0);
7878
return (1);
7979
}

src/utils2.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/* ::: :::::::: */
44
/* utils2.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: ysingh <ysingh@student.42.fr> +#+ +:+ +#+ */
6+
/* By: alvalope <alvalope@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2023/06/01 16:43:44 by ysingh #+# #+# */
9-
/* Updated: 2023/07/21 12:43:48 by ysingh ### ########.fr */
9+
/* Updated: 2023/07/26 16:34:00 by alvalope ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

0 commit comments

Comments
 (0)