/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* b_alias.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #ifdef __linux__ # include #else # include #endif #include "b_alias_print.h" #include "b_alias_register.h" #include "d_define.h" #include "s_struct.h" #include "u_alias.h" #include "u_utils.h" #include "u_vars.h" static unsigned char b_print_arg_next(char *ptr, const char arg[], t_bool invalid, t_msh *msh) { char val[ARG_MAX]; if (*ptr == C_NUL) { if (u_get_alias_value(val, arg, ARG_MAX, msh) != 0) { ft_printf("alias %s='%s'", arg, val); return (0); } else { ft_dprintf(STDERR_FILENO, "minishell: alias: %s: not found\n", arg); return (1); } } else if (*ptr == C_EQUALS && invalid == TRUE) { ft_strlcpy(val, arg, ptr - arg); ft_dprintf(STDERR_FILENO, "minishell: alias: `%s': invalid alias name\n", val); return (1); } return (0); } static unsigned char b_print_arg(const char arg[], t_msh *msh) { char *ptr; t_bool invalid; ptr = (char*)arg; invalid = FALSE; while (*ptr != C_NUL && *ptr != C_EQUALS) { if (ft_iswhitespace(*ptr) == TRUE) invalid = TRUE; ptr++; } return (b_print_arg_next(ptr, arg, invalid, msh)); } unsigned char b_alias(char *args[], t_msh *msh) { const unsigned long argc = u_builtins_get_argc((const char**)args); int i; unsigned char ret; ret = 0; if (argc == 0) { if (msh->alias == NULL) return (0); b_print_alias_list(msh); } else if (argc > 0) { i = 0; while (args[i] != NULL) { if (b_print_arg(args[i], msh) != 0) { ret = 1; } i++; } } return (ret); } void b_alias_mute(char *args[], t_msh *msh) { const unsigned long argc = u_builtins_get_argc((const char**)args); int i; if (argc > 0) { i = 0; while (args[i] != NULL) { b_register_arg(args[i], msh); i++; } } }