/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_b_export.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 #include "ft_b_env.h" #include "ft_f_fail.h" #include "ft_s_struct.h" #include "ft_u_utils.h" static int8_t ft_check_valid_identifier(const char *arg) { char *ptr; ptr = (char*)arg; if (ft_isalpha(ptr[0])) { return (1); } return (0); } static int8_t ft_check_equals(const char *arg) { char *ptr; ptr = (char*)arg; while (*ptr) { if (*ptr == '=') return (1); ptr++; } return (0); } uint8_t ft_b_export(char *args[], t_msh *msh) { const uint64_t argc = ft_get_argc((const char**)args); char **ptr; int8_t next; uint8_t r; if (argc == 0) { return (ft_b_env(NULL, msh)); } ptr = args; r = 0; while (*ptr) { next = 0; if (!ft_check_valid_identifier(*ptr)) { ft_fail_identifier("export", *ptr); next = 1; r = 1; } if (next == 0 && !ft_check_equals(*ptr)) next = 1; ptr++; } /* TODO: finish export */ return (r); }