ca compile
This commit is contained in:
parent
79ac0a8edc
commit
62a314d659
2 changed files with 18 additions and 16 deletions
|
|
@ -6,26 +6,26 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/24 23:03:58 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/24 23:12:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
#define CDOPT_L (1 << 0)
|
||||
#define CDOPT_P (1 << 1)
|
||||
#define CD_OPT_L (1 << 0)
|
||||
#define CD_OPT_P (1 << 1)
|
||||
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
||||
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
||||
#define CDERR_1 "cd: no such file or directory: %s"
|
||||
#define CDERR_2 "cd: HOME not set"
|
||||
#define CDERR_3 "cd: too many arguments{eoc}"
|
||||
|
||||
static g_cliopts g_cdotps =
|
||||
static t_cliopts g_cdopts[] =
|
||||
{
|
||||
{'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[])
|
||||
{
|
||||
|
|
@ -56,32 +56,34 @@ void setwd(char *var)
|
|||
char *cwd;
|
||||
|
||||
cwd = getcwd(NULL, 0);
|
||||
builtin_setenv(path, (char*[4]){"setenv", var, cwd, NULL}, envp);
|
||||
builtin_setenv(NULL, (char*[4]){"setenv", var, cwd, NULL}, NULL);
|
||||
free(cwd);
|
||||
}
|
||||
|
||||
int builtin_cd(const char *path,
|
||||
char *const av[], char *const envp[])
|
||||
{
|
||||
int i;
|
||||
int opts;
|
||||
char *target;
|
||||
t_data_template data;
|
||||
|
||||
data->flag = CD_OPT_L;
|
||||
if (cliopts(av, g_cdopts, &data))
|
||||
i = builtin_cd_opts(av, &opts);
|
||||
(void)envp;
|
||||
(void)path;
|
||||
data.flag = CD_OPT_L;
|
||||
if (cliopts_get((char**)av, g_cdopts, &data))
|
||||
return (1);
|
||||
/* i = builtin_cd_opts(av, &opts); */
|
||||
setwd("OLDPWD");
|
||||
if (!(target = builtin_cd_special(av + i, envp)))
|
||||
if (!(target = builtin_cd_special(data.av_data, envp)))
|
||||
return (1);
|
||||
if (chdir(target))
|
||||
{
|
||||
SH_ERR(CDERR_1, target);
|
||||
return (1);
|
||||
}
|
||||
else if (target != av[i])
|
||||
else if (target != *data.av_data)
|
||||
ft_printf("%s\n", target);
|
||||
setwd("PWD");
|
||||
if (!ft_strcmp(*(av + i), "-"))
|
||||
if (!ft_strcmp(*data.av_data, "-"))
|
||||
free(target);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/24 22:43:49 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/24 23:10:27 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue