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> +#+ +:+ +#+ */
|
/* 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/24 23:03:58 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 23:12:30 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
#define CDOPT_L (1 << 0)
|
#define CD_OPT_L (1 << 0)
|
||||||
#define CDOPT_P (1 << 1)
|
#define CD_OPT_P (1 << 1)
|
||||||
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
#define HAS_CDOPT_P(x) (x & CD_OPT_P)
|
||||||
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
#define HAS_CDOPT_L(x) (x & CD_OPT_L)
|
||||||
#define CDERR_1 "cd: no such file or directory: %s"
|
#define CDERR_1 "cd: no such file or directory: %s"
|
||||||
#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 =
|
static t_cliopts g_cdopts[] =
|
||||||
{
|
{
|
||||||
{'P', NULL, CD_OPT_P, CD_OPT_L, NULL},
|
{'P', NULL, CD_OPT_P, CD_OPT_L, NULL},
|
||||||
{'L', NULL, CD_OPT_L, CD_OPT_P, NULL},
|
{'L', NULL, CD_OPT_L, CD_OPT_P, NULL},
|
||||||
{0, NULL, 0, 0, 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[])
|
||||||
{
|
{
|
||||||
|
|
@ -56,32 +56,34 @@ void setwd(char *var)
|
||||||
char *cwd;
|
char *cwd;
|
||||||
|
|
||||||
cwd = getcwd(NULL, 0);
|
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);
|
free(cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int builtin_cd(const char *path,
|
int builtin_cd(const char *path,
|
||||||
char *const av[], char *const envp[])
|
char *const av[], char *const envp[])
|
||||||
{
|
{
|
||||||
int i;
|
char *target;
|
||||||
int opts;
|
t_data_template data;
|
||||||
char *target;
|
|
||||||
|
|
||||||
data->flag = CD_OPT_L;
|
(void)envp;
|
||||||
if (cliopts(av, g_cdopts, &data))
|
(void)path;
|
||||||
i = builtin_cd_opts(av, &opts);
|
data.flag = CD_OPT_L;
|
||||||
|
if (cliopts_get((char**)av, g_cdopts, &data))
|
||||||
|
return (1);
|
||||||
|
/* i = builtin_cd_opts(av, &opts); */
|
||||||
setwd("OLDPWD");
|
setwd("OLDPWD");
|
||||||
if (!(target = builtin_cd_special(av + i, envp)))
|
if (!(target = builtin_cd_special(data.av_data, envp)))
|
||||||
return (1);
|
return (1);
|
||||||
if (chdir(target))
|
if (chdir(target))
|
||||||
{
|
{
|
||||||
SH_ERR(CDERR_1, target);
|
SH_ERR(CDERR_1, target);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else if (target != av[i])
|
else if (target != *data.av_data)
|
||||||
ft_printf("%s\n", target);
|
ft_printf("%s\n", target);
|
||||||
setwd("PWD");
|
setwd("PWD");
|
||||||
if (!ft_strcmp(*(av + i), "-"))
|
if (!ft_strcmp(*data.av_data, "-"))
|
||||||
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/24 22:43:49 by jhalford ### ########.fr */
|
/* Updated: 2017/03/24 23:10:27 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue