terminado
This commit is contained in:
@@ -15,15 +15,15 @@
|
||||
static uint8_t export_one(char *arg, t_minishell *msh);
|
||||
static uint8_t print_exported(t_minishell *msh);
|
||||
static void **entries_to_array(t_list *lst, size_t *count,
|
||||
bool add_oldpwd);
|
||||
static void sort_entries(t_map_entry **entries, size_t count);
|
||||
bool add_oldpwd, t_map_entry *oldpwd_entry);
|
||||
static bool print_sorted_entries(t_map_entry **entries, size_t count);
|
||||
bool export_is_valid_identifier(const char *arg, size_t name_len);
|
||||
void export_parse_assignment(char *arg, char **eq_pos,
|
||||
size_t *name_len, bool *append);
|
||||
uint8_t export_set_assigned_value(const char *name, char *eq_pos,
|
||||
bool append, t_minishell *msh);
|
||||
bool export_print_declaration(const char *name, const char *value);
|
||||
static t_map_entry g_oldpwd_entry = {"OLDPWD", NULL};
|
||||
void export_sort_entries(t_map_entry **entries, size_t count);
|
||||
|
||||
uint8_t builtin_export(
|
||||
t_command cmd,
|
||||
@@ -82,42 +82,36 @@ static uint8_t print_exported(
|
||||
{
|
||||
t_list *entries;
|
||||
t_map_entry **sorted_entries;
|
||||
t_map_entry oldpwd_entry;
|
||||
size_t count;
|
||||
size_t i;
|
||||
bool add_oldpwd;
|
||||
|
||||
entries = ft_hashmap_entries(msh->variables.environment);
|
||||
if (entries == NULL)
|
||||
return (EXIT_SUCCESS);
|
||||
add_oldpwd = !ft_hashmap_contains_key(msh->variables.environment, "OLDPWD");
|
||||
oldpwd_entry = (t_map_entry){"OLDPWD", NULL};
|
||||
sorted_entries = (t_map_entry **)entries_to_array(entries, &count,
|
||||
add_oldpwd);
|
||||
!ft_hashmap_contains_key(msh->variables.environment, "OLDPWD"),
|
||||
&oldpwd_entry);
|
||||
ft_lstclear_nodes(&entries);
|
||||
if (sorted_entries == NULL)
|
||||
return (EXIT_FAILURE);
|
||||
sort_entries(sorted_entries, count);
|
||||
i = 0;
|
||||
while (i < count)
|
||||
{
|
||||
if (!export_print_declaration((char *)sorted_entries[i]->key,
|
||||
(char *)sorted_entries[i]->value))
|
||||
return (free(sorted_entries), EXIT_FAILURE);
|
||||
i++;
|
||||
}
|
||||
free(sorted_entries);
|
||||
return (EXIT_SUCCESS);
|
||||
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
|
||||
bool add_oldpwd,
|
||||
t_map_entry *oldpwd_entry
|
||||
)
|
||||
{
|
||||
void **array;
|
||||
t_list *node;
|
||||
void **array;
|
||||
t_list *node;
|
||||
t_map_entry *entry;
|
||||
size_t i;
|
||||
size_t i;
|
||||
|
||||
*count = (size_t)ft_lstsize(entries) + (size_t)add_oldpwd;
|
||||
array = (void **)malloc(sizeof(void *) * (*count));
|
||||
@@ -133,35 +127,25 @@ static void **entries_to_array(
|
||||
node = node->next;
|
||||
}
|
||||
if (add_oldpwd)
|
||||
array[i++] = &g_oldpwd_entry;
|
||||
array[i++] = oldpwd_entry;
|
||||
*count = i;
|
||||
return (array);
|
||||
}
|
||||
|
||||
static void sort_entries(
|
||||
static bool print_sorted_entries(
|
||||
t_map_entry **entries,
|
||||
size_t count
|
||||
)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
t_map_entry *tmp;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < count)
|
||||
{
|
||||
j = i + 1;
|
||||
while (j < count)
|
||||
{
|
||||
if (ft_strcmp((char *)entries[i]->key,
|
||||
(char *)entries[j]->key) > 0)
|
||||
{
|
||||
tmp = entries[i];
|
||||
entries[i] = entries[j];
|
||||
entries[j] = tmp;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (!export_print_declaration((char *)entries[i]->key,
|
||||
(char *)entries[i]->value))
|
||||
return (false);
|
||||
i++;
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user