/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* export.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: sede-san variables.environment); if (entries == NULL) return (EXIT_SUCCESS); oldpwd_entry = (t_map_entry){"OLDPWD", NULL}; sorted_entries = (t_map_entry **)entries_to_array(entries, &count, !ft_hashmap_contains_key(msh->variables.environment, "OLDPWD"), &oldpwd_entry); ft_lstclear_nodes(&entries); if (sorted_entries == NULL) return (EXIT_FAILURE); export_sort_entries(sorted_entries, count); if (!print_sorted_entries(sorted_entries, count)) return (free(sorted_entries), EXIT_FAILURE); return (free(sorted_entries), EXIT_SUCCESS); } static void **entries_to_array( t_list *entries, size_t *count, bool add_oldpwd, t_map_entry *oldpwd_entry ) { void **array; t_list *node; t_map_entry *entry; size_t i; *count = (size_t)ft_lstsize(entries) + (size_t)add_oldpwd; array = (void **)malloc(sizeof(void *) * (*count)); if (array == NULL) return (NULL); i = 0; node = entries; while (node != NULL) { entry = (t_map_entry *)node->content; if (entry != NULL && ft_strcmp((char *)entry->key, "_") != 0) array[i++] = entry; node = node->next; } if (add_oldpwd) array[i++] = oldpwd_entry; *count = i; return (array); } static bool print_sorted_entries( t_map_entry **entries, size_t count ) { size_t i; i = 0; while (i < count) { if (!export_print_declaration((char *)entries[i]->key, (char *)entries[i]->value)) return (false); i++; } return (true); }