/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* export.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/16 09:41:29 by narnaud #+# #+# */ /* Updated: 2022/04/14 07:45:21 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" int ft_unset(char **argv, int input_fd, int output_fd) { (void)output_fd; (void)input_fd; if (!argv[1]) { //read(input_fd, PIPE_MAX_SIZE); return (1); } return (0); } int ft_env(char **argv, int input_fd, int output_fd) { (void)output_fd; (void)input_fd; (void)argv; int i; i = 0; while (g_env[i]) { printf("%s\n", g_env[i]); i++; } return (0); } int is_valid_identifier(char *ident) { if (ft_isalpha(ident[0]) || ident[0] == '_') { while (*ident) { if (!ft_isalpha(*ident) && !ft_isdigit(*ident) && *ident != '_') return (0); ident++; } return (1); } return (0); } int ft_export(char **argv, int input_fd, int output_fd) { char **new; char **env; int i; (void)output_fd; (void)input_fd; i = 0; new = ft_split(argv[1], '='); if (!is_valid_identifier(new[0])) { printf ("export: not an identifier: %s\n", new[0]); return (0); } while (g_env[i]) { env = ft_split(g_env[i], '='); if (!ft_strncmp(new[0], env[0], ft_strlen(new[0]) + 1)) { g_env[i] = argv[1]; return (1); } i++; } g_env[i] = argv[1]; g_env[i + 1] = NULL; return (1); }