Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KOs from tester #52

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
norminette

- name: Build
run: make
run: make
8 changes: 4 additions & 4 deletions srcs/builtins/cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
/* ::: :::::::: */
/* cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bwisniew <bwisniew@student.42lyon.fr> +#+ +:+ +#+ */
/* By: lcottet <lcottet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/14 13:57:43 by bwisniew #+# #+# */
/* Updated: 2024/04/10 15:35:37 by bwisniew ### ########.fr */
/* Updated: 2024/04/11 15:55:42 by lcottet ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"
#include "libft.h"
#include "ft_printf.h"
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

int cd_getcwd_err(t_mshell *sh, char *argv)
{
Expand Down Expand Up @@ -99,7 +99,7 @@ int cd_oldpwd(t_mshell *sh)
error("cd");
return (1);
}
printf("%s\n", oldpwd->value);
ft_printf("%s\n", oldpwd->value);
return (cd_change_env(sh, NULL));
}

Expand Down
10 changes: 5 additions & 5 deletions srcs/builtins/pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
/* ::: :::::::: */
/* pwd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bwisniew <bwisniew@student.42lyon.fr> +#+ +:+ +#+ */
/* By: lcottet <lcottet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/14 13:57:34 by bwisniew #+# #+# */
/* Updated: 2024/04/08 15:49:06 by bwisniew ### ########.fr */
/* Updated: 2024/04/11 15:54:25 by lcottet ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"
#include <stdio.h>
#include "ft_printf.h"
#include <string.h>
#include <stdlib.h>

Expand All @@ -24,7 +24,7 @@ int pwd(t_mshell *sh, t_execute *exec)
env = env_get(sh, "PWD", false);
if (env)
{
printf("%s\n", env->value);
ft_printf("%s\n", env->value);
return (0);
}
pwd = getcwd(NULL, 0);
Expand All @@ -33,7 +33,7 @@ int pwd(t_mshell *sh, t_execute *exec)
error("pwd");
return (1);
}
printf("%s\n", pwd);
ft_printf("%s\n", pwd);
free(pwd);
return (0);
}
23 changes: 15 additions & 8 deletions srcs/exec/here_doc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
/* ::: :::::::: */
/* here_doc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bwisniew <bwisniew@student.42lyon.fr> +#+ +:+ +#+ */
/* By: lcottet <lcottet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/10 20:41:37 by lcottet #+# #+# */
/* Updated: 2024/04/08 18:58:18 by lcottet ### ########.fr */
/* Updated: 2024/04/11 17:02:05 by lcottet ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"
#include "expander.h"
#include "libft.h"
#include "ft_printf.h"
#include "get_next_line.h"
#include <readline/readline.h>
#include <unistd.h>
Expand All @@ -23,11 +24,15 @@

int here_doc_line(int file, char *line)
{
if (write(file, line, ft_strlen(line)) == -1)
return (free(line), 1);
size_t i;

i = 0;
while (line[i] && line[i] != '\n')
i++;
if (write(file, line, i) == -1)
return (1);
if (write(file, "\n", 1) == -1)
return (free(line), 1);
free(line);
return (1);
return (0);
}

Expand Down Expand Up @@ -67,8 +72,10 @@ char *here_doc_getline(t_mshell *sh, size_t i, t_fd fd, int *err)
free_token(&line);
return (free(tmp), NULL);
}
*err = here_doc_line(fd, line.txt);
return (tmp);
if (!hd_cmp(((t_token *)sh->tokens.tab)[i].txt, tmp,
((t_token *)sh->tokens.tab)[i].txt_size))
*err = here_doc_line(fd, line.txt);
return (free_token(&line), tmp);
}

int get_final_heredoc_fd(t_execute *exec, t_fd old, int err)
Expand Down
12 changes: 7 additions & 5 deletions srcs/expander/expander.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* expander.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bwisniew <bwisniew@student.42lyon.fr> +#+ +:+ +#+ */
/* By: lcottet <lcottet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/21 19:13:27 by bwisniew #+# #+# */
/* Updated: 2024/04/03 18:11:59 by bwisniew ### ########.fr */
/* Updated: 2024/04/11 16:44:42 by lcottet ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -18,9 +18,12 @@ int expander(t_mshell *sh, size_t start, size_t end)
size_t token_i;
int ret;

token_i = expander_skip_file(&sh->tokens, start, end);
token_i = start;
while (token_i < end)
{
token_i = expander_skip_file(&sh->tokens, token_i, end);
if (token_i >= end)
break ;
if (!is_special(((t_token *)sh->tokens.tab)[token_i].type))
{
ret = tokens_expand(sh, token_i);
Expand All @@ -29,9 +32,8 @@ int expander(t_mshell *sh, size_t start, size_t end)
token_i += ret;
end += ret - 1;
}
else
else if (!is_type_arrow(((t_token *)sh->tokens.tab)[token_i].type))
token_i++;
token_i = expander_skip_file(&sh->tokens, token_i, end);
}
return (expander_unseparated(&sh->tokens, start, token_i));
}
8 changes: 5 additions & 3 deletions srcs/expander/expander_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
/* ::: :::::::: */
/* expander_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bwisniew <bwisniew@student.42lyon.fr> +#+ +:+ +#+ */
/* By: lcottet <lcottet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/03 13:50:42 by bwisniew #+# #+# */
/* Updated: 2024/04/03 19:17:15 by bwisniew ### ########.fr */
/* Updated: 2024/04/11 17:14:12 by lcottet ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"
#include "expander.h"
#include "libft.h"
#include <stdio.h>

size_t expander_skip_file(t_vector *lex, size_t i, size_t n)
{
Expand Down Expand Up @@ -64,7 +65,8 @@ int expand_file(t_mshell *sh, size_t token_i)
i_cp = token_i;
token_i++;
while (token_i < sh->tokens.len
&& ((t_token *)sh->tokens.tab)[token_i].is_file == 1)
&& (((t_token *)sh->tokens.tab)[token_i].is_file == 1
&& !is_type_arrow(((t_token *)sh->tokens.tab)[token_i].type)))
{
if (expand_ambi_file(&((t_token *)sh->tokens.tab)[token_i], sh) != 0)
return (1);
Expand Down
8 changes: 4 additions & 4 deletions srcs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bwisniew <bwisniew@student.42lyon.fr> +#+ +:+ +#+ */
/* By: lcottet <lcottet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/14 13:11:23 by lcottet #+# #+# */
/* Updated: 2024/04/09 16:35:22 by lcottet ### ########.fr */
/* Updated: 2024/04/11 17:13:51 by lcottet ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"
#include "lexer.h"
#include "ft_printf.h"
#include "get_next_line.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <readline/history.h>
Expand Down Expand Up @@ -99,7 +99,7 @@ int main(int argc, char **argv, char **env)
minishell(&mshell, input);
}
if (isatty(STDIN_FILENO))
printf("exit\n");
ft_printf("exit\n");
errno = 0;
finish_mshell(&mshell);
return ((char)mshell.exit);
Expand Down
2 changes: 1 addition & 1 deletion tester
Loading