error message in cd builtin:

This commit is contained in:
Jack Halford 2017-03-21 15:26:43 +01:00
parent 89fd444e84
commit e34666665d
9 changed files with 26 additions and 27 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
/* Updated: 2017/03/20 16:13:24 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:20:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */ /* Created: 2017/03/20 15:52:57 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:53:17 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:19:56 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,13 +28,14 @@ t_conv g_convs[] =
int ft_vdprintf(int fd, const char *format, va_list ap) int ft_vdprintf(int fd, const char *format, va_list ap)
{ {
char *ret; char *ret;
char size;
ret = NULL; ret = NULL;
if (ft_vasprintf(&ret, format, ap)) size = ft_vasprintf(&ret, format, ap);
return (1); if (size != -1)
ft_putstr_fd(ret, fd); ft_putstr_fd(ret, fd);
ft_strdel(&ret); ft_strdel(&ret);
return (0); return (size);
} }
int ft_vasprintf(char **ret, const char *format, va_list ap) int ft_vasprintf(char **ret, const char *format, va_list ap)
@ -53,14 +54,14 @@ int ft_vasprintf(char **ret, const char *format, va_list ap)
else if (*str == '%') else if (*str == '%')
{ {
if (ft_fmtcalc(&final, &str, ap)) if (ft_fmtcalc(&final, &str, ap))
return (1); return (-1);
} }
else else
final = ft_strjoin(final, (char[]){*str++, 0}); final = ft_strjoin(final, (char[]){*str++, 0});
ft_strdel(&tmp); ft_strdel(&tmp);
} }
*ret = final; *ret = final;
return (0); return (ft_strlen(final));
} }
int ft_fmtcalc(char **final, char **str, va_list ap) int ft_fmtcalc(char **final, char **str, va_list ap)

View file

@ -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/20 12:54:02 by wescande ### ########.fr */ /* Updated: 2017/03/21 15:23:49 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,9 +16,9 @@
#define CDOPT_P (1 << 1) #define CDOPT_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 "{red}cd: no such file or directory: %s{eoc}\n" #define CDERR_1 "cd: no such file or directory: %s"
#define CDERR_2 "{red}cd: HOME not set{eoc}\n" #define CDERR_2 "cd: HOME not set"
#define CDERR_3 "{red}cd: too many arguments{eoc}\n" #define CDERR_3 "cd: too many arguments{eoc}"
static char *builtin_cd_special(char *const av[], char *const env[]) static char *builtin_cd_special(char *const av[], char *const env[])
{ {
@ -28,13 +28,13 @@ static char *builtin_cd_special(char *const av[], char *const env[])
{ {
if (!(target = ft_getenv((char**)env, "HOME"))) if (!(target = ft_getenv((char**)env, "HOME")))
{ {
ft_dprintf(2, CDERR_2); SH_ERR(CDERR_2);
return (NULL); return (NULL);
} }
} }
else if (*av && *(av + 1)) else if (*av && *(av + 1))
{ {
ft_dprintf(2, CDERR_3); SH_ERR(CDERR_3);
return (NULL); return (NULL);
} }
else if (ft_strcmp(*av, "-") == 0) else if (ft_strcmp(*av, "-") == 0)
@ -87,7 +87,7 @@ int builtin_cd(const char *path,
free(cwd); free(cwd);
if (chdir(target)) if (chdir(target))
{ {
ft_dprintf(2, CDERR_1, target); SH_ERR(CDERR_1, target);
return (builtin_return_status(0, 1)); return (builtin_return_status(0, 1));
} }
else if (target != av[i]) else if (target != av[i])

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:21:41 by jhalford #+# #+# */ /* Created: 2016/11/28 14:21:41 by jhalford #+# #+# */
/* Updated: 2017/03/20 14:40:00 by wescande ### ########.fr */ /* Updated: 2017/03/21 15:21:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:10:51 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:16:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,7 +28,7 @@ t_cliopts g_read_opts[] =
void bt_read_usage(void) void bt_read_usage(void)
{ {
ft_dprintf(2, "usage: read %s %s\n", US_READ, US_READ_1); SH_ERR("usage: read %s %s\n", US_READ, US_READ_1);
} }
int bt_read_init(t_read *data, char **av) int bt_read_init(t_read *data, char **av)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 12:48:04 by wescande #+# #+# */ /* Created: 2017/03/20 12:48:04 by wescande #+# #+# */
/* Updated: 2017/03/20 12:49:18 by wescande ### ########.fr */ /* Updated: 2017/03/21 15:21:09 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,13 +6,13 @@
/* 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/21 01:43:33 by ariard ### ########.fr */ /* Updated: 2017/03/21 15:20:27 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
#define SETERR_0 "invalid variable name\n" #define SETERR_0 "setenv: invalid variable name"
static int assign_var(char *const av[], char ***env) static int assign_var(char *const av[], char ***env)
{ {
@ -56,10 +56,10 @@ int builtin_setenv(const char *path,
else else
{ {
esc = ft_strnew((ft_strlen(av[1]) >> 3) + 1); esc = ft_strnew((ft_strlen(av[1]) >> 3) + 1);
ret = word_is_assignment((char *[]){av[1], (esc + 1)}); ret = word_is_assignment((char *[]){av[1], (esc + 1)});
ft_strdel(&esc); ft_strdel(&esc);
if (!ret && ft_strcmp(av[1], "?")) if (!ret && ft_strcmp(av[1], "?"))
return (error_msg(SETERR_0)); return (SH_ERR(SETERR_0));
assign_var(av, env); assign_var(av, env);
} }
return (envp ? builtin_return_status(0, 0) : 0); return (envp ? builtin_return_status(0, 0) : 0);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 23:21:37 by ariard #+# #+# */ /* Created: 2017/03/20 23:21:37 by ariard #+# #+# */
/* Updated: 2017/03/20 23:21:56 by ariard ### ########.fr */ /* Updated: 2017/03/21 15:20:26 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,5 +17,3 @@ int error_msg(char *msg)
ft_dprintf(2, "{red}%s{eoc}", msg); ft_dprintf(2, "{red}%s{eoc}", msg);
return (1); return (1);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:48:17 by jhalford ### ########.fr */ /* Updated: 2017/03/21 15:15:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */