-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cd is done , echo is done, but pipe issues lol
- Loading branch information
Showing
9 changed files
with
114 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# By: zhabri <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# Created: 2022/09/04 08:44:16 by zhabri #+# #+# # | ||
# Updated: 2023/01/03 11:40:34 by zhabri ### ########.fr # | ||
# Updated: 2023/01/03 13:17:27 by zhabri ### ########.fr # | ||
# # | ||
# **************************************************************************** # | ||
|
||
|
@@ -55,7 +55,8 @@ SRCS = minishell.c \ | |
ft_atoll.c \ | ||
ft_split_sep.c \ | ||
builtin.c \ | ||
echo.c | ||
echo.c \ | ||
cd.c | ||
|
||
OBJS = $(SRCS:.c=.o) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/03 10:49:26 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/03 11:47:01 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/03 13:16:55 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -39,6 +39,7 @@ void call_builtin(int built_in, t_cmd *cmd) | |
t_builtin *tab[7]; | ||
|
||
tab[0] = echo; | ||
tab[1] = cd; | ||
tab[5] = exit_child; | ||
tab[6] = pwd; | ||
if (cmd->fd_out != -3) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* cd.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/03 12:40:50 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/03 13:25:40 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.h" | ||
|
||
t_list *get_env_node(char *var) | ||
{ | ||
t_list *envp_entry; | ||
|
||
envp_entry = *g_glob->envp; | ||
while (ft_strncmp((char *)envp_entry->content, var, ft_strlen(var))) | ||
envp_entry = envp_entry->next; | ||
return (envp_entry); | ||
} | ||
|
||
void ft_chdir(char *dir, int size) | ||
{ | ||
char *ret; | ||
char *tmp; | ||
t_list *pwd; | ||
t_list *old_pwd; | ||
|
||
pwd = get_env_node("PWD="); | ||
old_pwd = get_env_node("OLDPWD="); | ||
ret = NULL; | ||
free_null(old_pwd->content); | ||
tmp = ft_strdup(pwd->content + 4); | ||
old_pwd->content = ft_strjoin("OLDPWD=", tmp); | ||
free_null(tmp); | ||
tmp = NULL; | ||
chdir(dir); | ||
while (ret == NULL) | ||
{ | ||
size *= 2; | ||
free_null(tmp); | ||
while (tmp == NULL) | ||
tmp = ft_calloc(size, sizeof(char)); | ||
ret = getcwd(tmp, size); | ||
} | ||
free_null(pwd->content); | ||
pwd->content = ft_strjoin("PWD=", tmp); | ||
free_null(tmp); | ||
} | ||
|
||
void cd(char *cmd) | ||
{ | ||
char **cmd_split; | ||
DIR *dir; | ||
|
||
cmd_split = ft_split_sep(cmd, " \t"); | ||
if (cmd_split[1]) | ||
{ | ||
if (cmd_split[2]) | ||
{ | ||
ft_putstr_fd("minishell: cd: too many arguments\n", 2); | ||
g_glob->exit_ret = 1; | ||
free_tab(cmd_split); | ||
return ; | ||
} | ||
dir = opendir(cmd_split[1]); | ||
if (!dir) | ||
{ | ||
perror("minishell: "); | ||
free_tab(cmd_split); | ||
return ; | ||
} | ||
ft_chdir(cmd_split[1], 16); | ||
return ; | ||
} | ||
ft_chdir(get_env_node("HOME=")->content + 5, 16); | ||
free_tab(cmd_split); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/03 11:24:58 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/03 11:40:06 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/03 13:37:13 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -20,10 +20,13 @@ static bool is_echo_with_newline(char *arg) | |
if (arg && arg[0] != '-') | ||
return (true); | ||
i = 1; | ||
while (arg[i] == 'n') | ||
i++; | ||
if (!arg[i]) | ||
return (false); | ||
if (arg) | ||
{ | ||
while (arg[i] == 'n') | ||
i++; | ||
if (!arg[i]) | ||
return (false); | ||
} | ||
return (true); | ||
} | ||
|
||
|
@@ -38,8 +41,13 @@ void echo(char *cmd) | |
newline = is_echo_with_newline(cmd_split[1]); | ||
if (!newline) | ||
i++; | ||
while (cmd_split[i]) | ||
while (cmd_split[i] && cmd_split[i + 1]) | ||
{ | ||
ft_putstr_fd(cmd_split[i++], 1); | ||
ft_putchar_fd(' ', 1); | ||
} | ||
if (cmd_split[i]) | ||
ft_putstr_fd(cmd_split[i], 1); | ||
if (newline) | ||
ft_putchar_fd('\n', 1); | ||
free_tab(cmd_split); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/30 11:56:08 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/03 11:30:29 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/03 13:34:57 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -54,6 +54,7 @@ bool exit_parent(void) | |
exit(0); | ||
} | ||
} | ||
free_tab(cmd_split); | ||
} | ||
return (false); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: zhabri <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/11/27 20:30:45 by zhabri #+# #+# */ | ||
/* Updated: 2023/01/03 11:47:48 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/03 13:25:18 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -23,8 +23,9 @@ | |
# include <errno.h> | ||
# include <readline/history.h> | ||
# include <readline/readline.h> | ||
# include "libft/includes/libft.h" | ||
# include <unistd.h> | ||
# include <dirent.h> | ||
# include "libft/includes/libft.h" | ||
|
||
# define PARENT 0 | ||
# define CHILD 1 | ||
|
@@ -77,6 +78,7 @@ typedef void t_builtin(char *cmd); | |
|
||
extern t_glob *g_glob; | ||
|
||
void cd(char *cmd); | ||
void echo(char *cmd); | ||
void call_builtin(int built_in, t_cmd *cmd); | ||
int builtin(char *cmd); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: brenaudo <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/12/21 12:02:33 by brenaudo #+# #+# */ | ||
/* Updated: 2023/01/03 11:47:55 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/03 13:41:02 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -46,6 +46,8 @@ int *pipex_loop(void) | |
pipex_loop_exit(children_pid, curr, pipes); | ||
else | ||
{ | ||
// IL FAUT ENVOYER CERTAINS TRUCS DANS LES PIPES | ||
// CF: echo haha lol | cat -e | ||
children_pid[((t_cmd *)curr->content)->cmd_idx] = -1; | ||
call_builtin(built_in, ((t_cmd *)curr->content)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: brenaudo <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/02 11:16:11 by brenaudo #+# #+# */ | ||
/* Updated: 2023/01/03 11:47:31 by zhabri ### ########.fr */ | ||
/* Updated: 2023/01/03 13:19:11 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -34,5 +34,5 @@ void pwd(char *cmd) | |
ft_putstr_fd(path, 1); | ||
ft_putchar_fd('\n', 1); | ||
free_null(path); | ||
free_null(ret); | ||
g_glob->exit_ret = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,16 @@ | |
/* By: brenaudo <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/01/02 11:31:23 by brenaudo #+# #+# */ | ||
/* Updated: 2023/01/02 11:31:34 by brenaudo ### ########.fr */ | ||
/* Updated: 2023/01/03 11:51:39 by zhabri ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.c" | ||
#include "minishell.h" | ||
|
||
void unset(char *name) | ||
{ | ||
t_list *env_cpy; | ||
|
||
env_cpy = *g_glob->envp; | ||
while (env_cpy && env_cpy->next && \ | ||
&& ft_strncmp(env_cpy->next->content, name, ft_strlen(name) + 1) != 0) | ||
|