/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* export.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet next != NULL) { write(fd, "declare -x ", 11); ft_putstr_fd(((t_env *)(current->content))->key, fd); if (((t_env *)(current->content))->value != NULL) { ft_putstr_fd("=", fd); write(fd, "\"", 1); ft_putstr_fd(((t_env *)(current->content))->value, fd); write(fd, "\"\n", 2); } else write(fd, "\n", 2); current = current->next; } } int add_export(t_list **env, char *args, int fd) { char *key; char *value; key = args; if (ft_strchr(args, '=') != NULL) { key = ft_strndup(args, ft_strnchr(args, '=')); if (key == NULL) return (1); if (ft_strlen(key) == 0) return (error(args, fd)); if (possible_key(key) == 2) { key[ft_strlen(key) - 1] = '\0'; value = ft_strjoin(get_value_by_key(key, env), ft_strchr(args, '=') + 1); } else value = ft_strchr(args, '=') + 1; } else { value = get_value_by_key(key, env); if (ft_strlen(value) == 0) value = NULL; if(possible_key(key) == 2) return (error(key, fd)); } if (!possible_key(key)) return (error(key, fd)); create_value_by_key_dup(key, value, env); return (0); } int export(t_list **env, char **args, int fd) { int err; int i; err = 0; if (args[0] == NULL) print_export(env, fd); else { i = -1; while (args[++i]) if (add_export(env, args[i], fd) == 1) err = 1; } return (err); } /* int main(int argc, char *argv[], char **env) { t_list **n_env; (void)argc; n_env = init_env(env); export(n_env, argv + 1, 1); return (0); }*/