Skip to content
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
14 changes: 6 additions & 8 deletions inc/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: rpinheir <rpinheir@student.42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/10/16 14:09:15 by rpinheir #+# #+# */
/* Updated: 2026/10/16 14:42:36 by rpinheir ### ########.ch */
/* Updated: 2026/10/29 15:35:14 by rpinheir ### ########.ch */
/* */
/* ************************************************************************** */

Expand All @@ -15,8 +15,8 @@
# define EXIT_SIGNAL_BASE 128
# define WS_SEP '\001'

# include "libft/libft.h"
# include "enum.h"
# include "libft/libft.h"

typedef struct s_token
{
Expand All @@ -25,36 +25,34 @@ typedef struct s_token
bool is_quoted;
char *value;
struct s_token *next;
} t_token;
} t_token;

typedef struct s_redir
{
t_redir_type type;
char *file;
struct s_redir *next;
bool is_quoted;
} t_redir;
} t_redir;

typedef struct s_cmd
{
char **cmd_args;
char *path;
t_redir *redirections;
struct s_cmd *next;
} t_cmd;
} t_cmd;

typedef struct s_shell
{
pid_t hereid;
int prevfd;
int wread[2];
int cmd_count;
pid_t *pids;
t_cmd *cmds;
bool print_newline;
char **env;
long long exit_status;
bool is_exitting;
} t_shell;
} t_shell;

#endif
8 changes: 4 additions & 4 deletions src/builtins/builtin_unset.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: chguerre <chguerre@student.lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/10/22 21:14:24 by chguerre #+# #+# */
/* Updated: 2026/10/26 20:48:58 by chguerre ### ########.fr */
/* Updated: 2026/10/29 15:33:37 by rpinheir ### ########.ch */
/* */
/* ************************************************************************** */

Expand All @@ -27,9 +27,9 @@ int filter_envp(t_shell *shell, char **cmd_args)
i = 1;
while (cmd_args[i])
{
keylen = strlen(cmd_args[i]);
if (shell->env[j] != NULL && ft_strncmp(shell->env[j],
cmd_args[i], keylen) == 0 && shell->env[j][keylen] == '=' )
keylen = ft_strlen(cmd_args[i]);
if (shell->env[j] != NULL && ft_strncmp(shell->env[j], cmd_args[i],
keylen) == 0 && shell->env[j][keylen] == '=')
{
finded++;
(free(shell->env[j]), shell->env[j] = NULL);
Expand Down
4 changes: 1 addition & 3 deletions src/builtins/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: chguerre <chguerre@student.42lausanne.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/10/22 14:32:50 by chguerre #+# #+# */
/* Updated: 2026/10/22 21:15:57 by chguerre ### ########.fr */
/* Updated: 2026/10/29 15:12:19 by rpinheir ### ########.ch */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -45,8 +45,6 @@ int run_builtin_parent(t_shell *shell, t_builtin builtin, t_cmd *cmd)
dup2(saved_in, STDIN_FILENO);
close(saved_in);
close(saved_out);
if (shell->is_exitting)
(close(0), close(1));
return (code);
}

Expand Down
16 changes: 7 additions & 9 deletions src/executor/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: chguerre <chguerre@student.42lausanne.c +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/10/19 20:36:59 by chguerre #+# #+# */
/* Updated: 2026/10/22 21:08:47 by chguerre ### ########.fr */
/* Updated: 2026/10/29 15:49:32 by rpinheir ### ########.ch */
/* */
/* ************************************************************************** */

Expand All @@ -16,11 +16,8 @@ void childs_exit(t_shell *shell, int i, int *fd, int code)
{
if (shell->prevfd != -1)
close(shell->prevfd);
if (i < shell->cmd_count - 1)
{
close(fd[0]);
close(fd[1]);
}
(void)fd;
(void)i;
if (shell->pids != NULL)
free(shell->pids);
ft_strfree(shell->env);
Expand Down Expand Up @@ -75,9 +72,10 @@ static void run_child(t_shell *shell, int i, int *fd, t_cmd *current)
ft_putendl_fd(": command not found", 2);
childs_exit(shell, i, fd, 127);
}
if ((execve(current->path, current->cmd_args, shell->env)) == -1)
(perror(current->cmd_args[0]),
childs_exit(shell, i, fd, 126 + (errno == ENOENT)));
execve(current->path, current->cmd_args, shell->env);
code = errno;
perror(current->cmd_args[0]);
childs_exit(shell, i, fd, 126 + (code == ENOENT));
}

int fork_setup(t_shell *shell, int i, int *fd, t_cmd *current)
Expand Down
5 changes: 4 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chguerre <chr@student.lausanne.ch> +#+ +:+ +#+ */
/* By: chguerre <chr@student.lausanne.ch> +#+ +:+
+#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/10/16 14:06:14 by rpinheir #+# #+# */
/* Updated: 2026/10/22 16:19:18 by rpinheir ### ########.ch */
Expand Down Expand Up @@ -71,6 +72,8 @@ void show_prompt(t_shell *shell)
else if (line[0] && entry_exec(line, shell) == 1)
continue ;
}
close(0);
close(1);
}

int main(int ac, char **av, char **env)
Expand Down
Loading