unsetenv OK
This commit is contained in:
parent
3c4b194553
commit
79ac0a8edc
5 changed files with 22 additions and 39 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */
|
/* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/24 20:08:12 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 22:59:28 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,9 +15,6 @@
|
||||||
int fd_replace(int fd1, int fd2)
|
int fd_replace(int fd1, int fd2)
|
||||||
{
|
{
|
||||||
if (fd1 != fd2)
|
if (fd1 != fd2)
|
||||||
{
|
|
||||||
DG("%i ---> %i", fd2, fd1);
|
|
||||||
return (dup2_close(fd1, fd2));
|
return (dup2_close(fd1, fd2));
|
||||||
}
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/21 15:28:51 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 23:03:58 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,6 +20,13 @@
|
||||||
#define CDERR_2 "cd: HOME not set"
|
#define CDERR_2 "cd: HOME not set"
|
||||||
#define CDERR_3 "cd: too many arguments{eoc}"
|
#define CDERR_3 "cd: too many arguments{eoc}"
|
||||||
|
|
||||||
|
static g_cliopts g_cdotps =
|
||||||
|
{
|
||||||
|
{'P', NULL, CD_OPT_P, CD_OPT_L, NULL},
|
||||||
|
{'L', NULL, CD_OPT_L, CD_OPT_P, NULL},
|
||||||
|
{0, NULL, 0, 0, NULL},
|
||||||
|
}
|
||||||
|
|
||||||
static char *builtin_cd_special(char *const av[], char *const env[])
|
static char *builtin_cd_special(char *const av[], char *const env[])
|
||||||
{
|
{
|
||||||
char *target;
|
char *target;
|
||||||
|
|
@ -44,30 +51,13 @@ static char *builtin_cd_special(char *const av[], char *const env[])
|
||||||
return (target);
|
return (target);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int builtin_cd_opts(char *const av[], int *opts)
|
void setwd(char *var)
|
||||||
{
|
{
|
||||||
int i;
|
char *cwd;
|
||||||
int j;
|
|
||||||
|
|
||||||
i = 1;
|
cwd = getcwd(NULL, 0);
|
||||||
if (av)
|
builtin_setenv(path, (char*[4]){"setenv", var, cwd, NULL}, envp);
|
||||||
while (av[i] && av[i][0] == '-' && av[i][1])
|
free(cwd);
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
while (av[i][++j])
|
|
||||||
{
|
|
||||||
if (av[i][j] == 'P')
|
|
||||||
*opts = CDOPT_P;
|
|
||||||
else if (av[i][j] == 'L')
|
|
||||||
*opts = CDOPT_L;
|
|
||||||
else if (av[i][j] == '-')
|
|
||||||
return (i + 1);
|
|
||||||
else
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int builtin_cd(const char *path,
|
int builtin_cd(const char *path,
|
||||||
|
|
@ -76,15 +66,13 @@ int builtin_cd(const char *path,
|
||||||
int i;
|
int i;
|
||||||
int opts;
|
int opts;
|
||||||
char *target;
|
char *target;
|
||||||
char *cwd;
|
|
||||||
|
|
||||||
opts = CDOPT_L;
|
data->flag = CD_OPT_L;
|
||||||
|
if (cliopts(av, g_cdopts, &data))
|
||||||
i = builtin_cd_opts(av, &opts);
|
i = builtin_cd_opts(av, &opts);
|
||||||
|
setwd("OLDPWD");
|
||||||
if (!(target = builtin_cd_special(av + i, envp)))
|
if (!(target = builtin_cd_special(av + i, envp)))
|
||||||
return (1);
|
return (1);
|
||||||
cwd = getcwd(NULL, 0);
|
|
||||||
builtin_setenv(path, (char*[4]){"setenv", "OLDPWD", cwd, NULL}, envp);
|
|
||||||
free(cwd);
|
|
||||||
if (chdir(target))
|
if (chdir(target))
|
||||||
{
|
{
|
||||||
SH_ERR(CDERR_1, target);
|
SH_ERR(CDERR_1, target);
|
||||||
|
|
@ -92,9 +80,7 @@ int builtin_cd(const char *path,
|
||||||
}
|
}
|
||||||
else if (target != av[i])
|
else if (target != av[i])
|
||||||
ft_printf("%s\n", target);
|
ft_printf("%s\n", target);
|
||||||
cwd = getcwd(NULL, 0);
|
setwd("PWD");
|
||||||
builtin_setenv(path, (char*[4]){"setenv", "PWD", cwd, NULL}, envp);
|
|
||||||
free(cwd);
|
|
||||||
if (!ft_strcmp(*(av + i), "-"))
|
if (!ft_strcmp(*(av + i), "-"))
|
||||||
free(target);
|
free(target);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/23 18:26:59 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 22:43:49 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/23 18:24:41 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 22:59:17 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ int builtin_unsetenv(const char *path, char *const av[], char *const envp[])
|
||||||
while (*env && (*env)[j])
|
while (*env && (*env)[j])
|
||||||
{
|
{
|
||||||
if (ft_strcmp((*env)[j], av[i]) == '='
|
if (ft_strcmp((*env)[j], av[i]) == '='
|
||||||
&& ft_strlen(av[1]) == ft_strlenchr((*env)[i], '='))
|
&& ft_strlen(av[i]) == ft_strlenchr((*env)[j], '='))
|
||||||
ft_sstrdel(*env, j);
|
ft_sstrdel(*env, j);
|
||||||
else
|
else
|
||||||
j++;
|
j++;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
|
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/22 19:23:55 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 22:43:37 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue