with modifs cd william
This commit is contained in:
commit
1460f17c30
8 changed files with 73 additions and 50 deletions
|
|
@ -6,13 +6,14 @@
|
|||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||
# Updated: 2017/03/25 19:49:22 by ariard ### ########.fr #
|
||||
# Updated: 2017/03/25 20:26:47 by jhalford ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = 42sh
|
||||
|
||||
CC = gcc
|
||||
FLAGS = -Wall -Wextra -Werror
|
||||
FLAGS = -Wall -Wextra -Werror #-fsanitize=address#-fvisibility=hidden
|
||||
D_FLAGS = -g
|
||||
|
||||
|
|
@ -32,6 +33,7 @@ SRC_BASE = \
|
|||
builtin/bt_cd_getpath.c\
|
||||
builtin/bt_cd_process_dotdot.c\
|
||||
builtin/bt_cd_process_symlink.c\
|
||||
builtin/bt_env_opt.c\
|
||||
builtin/bt_read_get.c\
|
||||
builtin/bt_read_term.c\
|
||||
builtin/builtin_cd.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 16:49:54 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/25 20:40:22 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,23 +6,27 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/25 03:54:22 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/25 20:43:52 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/25 20:49:53 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
#define CDERR_6 "cd : %s: Permission denied"
|
||||
#define CDERR_7 "cd : %s: No such file or directory"
|
||||
#define CDERR_0 "cd : %s: No such file or directory"
|
||||
#define CDERR_1 "cd : %s: Permission denied"
|
||||
#define CDERR_2 "cd : %s: Not a directory"
|
||||
#define CDERR_3 "cd : unable to proceed: %s"
|
||||
|
||||
int bt_cd_process_dotdot(char *target)
|
||||
{
|
||||
if (access(target, F_OK))
|
||||
return (SH_ERR(CDERR_0, target));
|
||||
if (access(target, X_OK))
|
||||
return (SH_ERR(CDERR_1, target));
|
||||
if (!is_directory(target))
|
||||
return (SH_ERR(CDERR_7, target));
|
||||
if (access(target, R_OK) < 0)
|
||||
return (SH_ERR(CDERR_6, target));
|
||||
return (SH_ERR(CDERR_2, target));
|
||||
if (chdir(target))
|
||||
return (SH_ERR(CDERR_7, target));
|
||||
return (SH_ERR(CDERR_3, target));
|
||||
setwd("PWD");
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,30 +6,34 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/25 15:14:55 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/25 20:38:39 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/25 20:49:16 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
#define CDERR_3 "cd : %s: Permission denied"
|
||||
#define CDERR_4 "cd : %s: No such file or directory"
|
||||
#define CDERR_5 "cd : %s: Symlink not resolved"
|
||||
#define CDERR_0 "cd : %s: No such file or directory"
|
||||
#define CDERR_1 "cd : %s: Permission denied"
|
||||
#define CDERR_2 "cd : %s: Not a directory"
|
||||
#define CDERR_3 "cd : unable to proceed: %s"
|
||||
#define CDERR_4 "cd : %s: Symlink not resolved"
|
||||
|
||||
int bt_cd_process_symlink(char *target)
|
||||
{
|
||||
char buffer[PATH_MAX + 1];
|
||||
|
||||
ft_bzero(buffer, PATH_MAX + 1);
|
||||
if (access(target, F_OK))
|
||||
return (SH_ERR(CDERR_0, target));
|
||||
if (access(target, X_OK))
|
||||
return (SH_ERR(CDERR_1, target));
|
||||
if (!is_directory(target))
|
||||
return (SH_ERR(CDERR_4, target));
|
||||
if (!access(target, R_OK))
|
||||
return (SH_ERR(CDERR_3, target));
|
||||
return (SH_ERR(CDERR_2, target));
|
||||
if (chdir(target))
|
||||
return (SH_ERR(CDERR_4, target));
|
||||
return (SH_ERR(CDERR_3, target));
|
||||
setwd("PWD");
|
||||
if (readlink(target, buffer, PATH_MAX + 1) < 0)
|
||||
return (SH_ERR(CDERR_5, target));
|
||||
return (SH_ERR(CDERR_4, target));
|
||||
else if (ft_strlen(buffer) > 0)
|
||||
builtin_setenv(NULL, (char*[]){"cd", "PWD", buffer, NULL}, NULL);
|
||||
return (0);
|
||||
|
|
|
|||
38
42sh/src/builtin/bt_env_opt.c
Normal file
38
42sh/src/builtin/bt_env_opt.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* bt_env_opt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/25 20:39:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/25 20:40:24 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int bt_env_opt_i(char *opt_arg, t_env_data *data)
|
||||
{
|
||||
(void)opt_arg;
|
||||
ft_tabdel(&data->custom_env);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_env_opt_u(char *opt_arg, t_env_data *data)
|
||||
{
|
||||
int i;
|
||||
char **env;
|
||||
|
||||
if (!(env = data->custom_env))
|
||||
return (0);
|
||||
i = -1;
|
||||
while (env[++i])
|
||||
{
|
||||
if (ft_strcmp(env[i], opt_arg) == '='
|
||||
&& ft_strlen(opt_arg) == ft_strlenchr(env[i], '='))
|
||||
ft_sstrdel(env, i);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/25 15:10:52 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/25 20:40:41 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,31 +23,6 @@ static t_cliopts g_env_opts[] =
|
|||
{0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
int bt_env_opt_i(char *opt_arg, t_env_data *data)
|
||||
{
|
||||
(void)opt_arg;
|
||||
ft_tabdel(&data->custom_env);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_env_opt_u(char *opt_arg, t_env_data *data)
|
||||
{
|
||||
DG();
|
||||
int i;
|
||||
char **env;
|
||||
|
||||
if (!(env = data->custom_env))
|
||||
return (0);
|
||||
i = -1;
|
||||
while (env[++i])
|
||||
{
|
||||
if (ft_strcmp(env[i], opt_arg) == '='
|
||||
&& ft_strlen(opt_arg) == ft_strlenchr(env[i], '='))
|
||||
ft_sstrdel(env, i);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int bt_env_getcustom(char ***av, t_env_data *data)
|
||||
{
|
||||
if (!av || !*av || !data)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/14 11:27:03 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/23 11:30:30 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/25 20:26:01 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,9 +21,9 @@ void ft_add_in_history_file(char *str)
|
|||
char **hist;
|
||||
|
||||
i = 0;
|
||||
hist = ft_strsplit(str, '\n');
|
||||
if (!(home = ft_getenv(data_singleton()->env, "HOME")))
|
||||
return ;
|
||||
hist = ft_strsplit(str, '\n');
|
||||
path = ft_str3join(home, "/", ".42sh_history");
|
||||
fd = open(path, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
|
||||
if (fd > 0)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/24 15:55:08 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/25 20:27:32 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue