diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-07-19 19:27:52 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-07-19 19:27:52 +0200 |
| commit | 6e456095fce214a2eadea0cafa3fa7ea1113b4e6 (patch) | |
| tree | 42d255dc5042f1df8079567e7ca3426d22cba24d /src/builtin | |
| parent | a478d95bed0f24f9783714600af48a6c1cde2aae (diff) | |
| download | minishell-6e456095fce214a2eadea0cafa3fa7ea1113b4e6.tar.gz minishell-6e456095fce214a2eadea0cafa3fa7ea1113b4e6.tar.bz2 minishell-6e456095fce214a2eadea0cafa3fa7ea1113b4e6.zip | |
Added errof for cleaner error message, Removed previous error functions
Diffstat (limited to 'src/builtin')
| -rw-r--r-- | src/builtin/cd.c | 14 | ||||
| -rw-r--r-- | src/builtin/exit.c | 10 | ||||
| -rw-r--r-- | src/builtin/export.c | 5 | ||||
| -rw-r--r-- | src/builtin/unset.c | 4 |
4 files changed, 12 insertions, 21 deletions
diff --git a/src/builtin/cd.c b/src/builtin/cd.c index 2377ce7..d7115e5 100644 --- a/src/builtin/cd.c +++ b/src/builtin/cd.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:20 by charles #+# #+# */ -/* Updated: 2020/07/19 15:55:08 by charles ### ########.fr */ +/* Updated: 2020/07/19 19:05:25 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,8 +25,7 @@ int builtin_cd(char **argv, t_env env) (void)env; if (argv[1] != NULL && argv[2] != NULL) { - ft_putstr_fd(g_basename, STDERR_FILENO); - ft_putendl_fd(": cd: too many arguments", STDERR_FILENO); + errorf("cd: too many arguments\n"); return (1); } if (argv[1] != NULL && argv[1][0] == '\0') @@ -35,8 +34,7 @@ int builtin_cd(char **argv, t_env env) { if ((home = env_search(env, "HOME")) == NULL) { - ft_putstr_fd(g_basename, STDERR_FILENO); - ft_putendl_fd(": cd: HOME not set", STDERR_FILENO); + errorf("cd: HOME not set\n"); return (1); } argv[1] = home; @@ -44,11 +42,7 @@ int builtin_cd(char **argv, t_env env) errno = 0; if (chdir(argv[1]) == -1) { - ft_putstr_fd(g_basename, STDERR_FILENO); - ft_putstr_fd(": cd: ", STDERR_FILENO); - ft_putstr_fd(argv[1], STDERR_FILENO); - ft_putstr_fd(": ", STDERR_FILENO); - ft_putendl_fd(strerror(errno), STDERR_FILENO); + errorf("cd: %s: %s\n", argv[1], strerror(errno)); return (1); } if (!(getcwd(buf, PATH_MAX))) diff --git a/src/builtin/exit.c b/src/builtin/exit.c index 860325e..3f1d843 100644 --- a/src/builtin/exit.c +++ b/src/builtin/exit.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:16 by charles #+# #+# */ -/* Updated: 2020/07/17 16:36:03 by charles ### ########.fr */ +/* Updated: 2020/07/19 19:12:46 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,16 +33,12 @@ int builtin_exit(char **argv, t_env env) after++; if (*after != '\0' || errno == ERANGE) { - // replace with minishell error system - ft_putstr_fd("minishell: exit: ", STDERR_FILENO); - ft_putstr_fd(argv[1], STDERR_FILENO); - ft_putstr_fd(": numeric argument required\n", STDERR_FILENO); + errorf("exit: %s: numeric argument required\n", argv[1]); return 2; } if (argv[2] != NULL) { - // replace with minishell error system - ft_putendl_fd("minishell: exit: too many arguments", STDERR_FILENO); + errorf("exit: too many arguments\n"); return 1; } } diff --git a/src/builtin/export.c b/src/builtin/export.c index 809b809..6fbb88f 100644 --- a/src/builtin/export.c +++ b/src/builtin/export.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:11:34 by charles #+# #+# */ -/* Updated: 2020/07/15 13:22:18 by charles ### ########.fr */ +/* Updated: 2020/07/19 18:46:48 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ static void st_put_declare_x(char *s) { char *equal_ptr; + // could use errorf on stdout if (s == NULL) return ; ft_putstr("declare -x "); @@ -57,7 +58,7 @@ int builtin_export(char **argv, t_env env) { if (!skip) *equal_ptr = '='; - error_put_invalid_identifier("export", argv[i]); + errorf("export: `%s': not a valid identifier\n", argv[i]); status = 1; continue; } diff --git a/src/builtin/unset.c b/src/builtin/unset.c index b7b6d58..367f063 100644 --- a/src/builtin/unset.c +++ b/src/builtin/unset.c @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:10:51 by charles #+# #+# */ -/* Updated: 2020/07/15 13:14:38 by charles ### ########.fr */ +/* Updated: 2020/07/19 18:47:36 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ int builtin_unset(char **argv, t_env env) { if (!utils_valid_identifier(argv[i])) { - error_put_invalid_identifier("unset", argv[i]); + errorf("unset: `%s': not a valid identifier\n", argv[i]); status = 1; continue; // put invalid identifier } |
