Commit f936c635 authored by pêle-mêle's avatar pêle-mêle
Browse files

export in alpha order

parent 77e31c06
......@@ -14,7 +14,7 @@
int ft_strcmp(const char *s1, const char *s2)
{
size_t i;
size_t i;
i = 0;
//if (s1 == NULL && s2 == NULL)
......@@ -23,7 +23,7 @@ int ft_strcmp(const char *s1, const char *s2)
//return (-((unsigned char*)s2)[i]);
//else if (s2 == NULL)
//return (((unsigned char*)s1)[i]);
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != !'\0')
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0')
{
i++;
}
......
j'ai ajouté un 'make lib' comme raccourci, quand on change un truc dans la lib, ou qu'on veut recompiler tout src sans recompiler la lib (par ex pour mettre/retirer d=0)
'make lib' -> quand on change un truc dans la lib, ou qu'on veut recompiler tout src sans recompiler la lib (par ex pour mettre/retirer d=0)
use "bash --posix" to test!
export in alpha order -> merge env + exported...?
besoin de proteger ft_strcmp? (comments)
export d=\$ vs export d=\1\f ou echo \$
......
#include "execution.h"
void print_export(char **env, char **exported)
char **sort_variables(char **env, char **exported)
{
size_t equalsign_pos;
char **sorted_array;
size_t env_len;
size_t exported_len;
env_len = ft_arraylen(env);
exported_len = ft_arraylen(exported);
sorted_array = (char **)malloc(sizeof(char *) * (env_len + exported_len + 1));
if (sorted_array == NULL)
return (NULL);
ft_memcpy(sorted_array, env, sizeof(char *) * env_len);
ft_memcpy(sorted_array + env_len, exported, sizeof(char *) * exported_len);
sorted_array[env_len + exported_len] = NULL;
sort_str_array(sorted_array);
return (sorted_array);
}
int print_export(char **env, char **exported)
{
char **variables;
size_t i;
ssize_t equalsign_pos;
while (*env != NULL)
variables = sort_variables(env, exported);
if (variables == NULL)
return (FAILURE);
i = 0;
while (variables[i] != NULL)
{
equalsign_pos = ft_index(*env, '=');
ft_putstr_fd("export ", STDOUT_FILENO);// change fd
write(STDOUT_FILENO, *env, equalsign_pos + 1);// idem
ft_putchar_fd('"', STDOUT_FILENO); // idem
ft_putstr_fd(*env + equalsign_pos + 1, STDOUT_FILENO);// id
ft_putchar_fd('"', STDOUT_FILENO); // id
ft_putchar_fd('\n', STDOUT_FILENO); // id
env++;
}
if (exported != NULL)
while (*exported != NULL)
equalsign_pos = ft_index(variables[i], '=');
if (equalsign_pos != NOT_FOUND)
{
ft_putstr_fd("export ", STDOUT_FILENO);// change fd
ft_putstr_fd(*exported, STDOUT_FILENO); //idem
ft_putchar_fd('\n', STDOUT_FILENO); // idem
exported++;
write(STDOUT_FILENO, variables[i], equalsign_pos + 1);// idem
ft_putchar_fd('"', STDOUT_FILENO); // idem
ft_putstr_fd(variables[i] + equalsign_pos + 1, STDOUT_FILENO);// id
ft_putchar_fd('"', STDOUT_FILENO); // id
}
else
ft_putstr_fd(variables[i], STDOUT_FILENO); //id
ft_putchar_fd('\n', STDOUT_FILENO); // id
i++;
}
free(variables);
return (SUCCESS);
}
static int ft_env_append_from_exp(char *var, t_xe *xe, ssize_t equalsign_pos)
......@@ -175,7 +198,10 @@ static int ft_export_checks(char **args, t_xe *xe)
int ft_export(char **args, t_xe *xe)
{
if (ft_arraylen(args) == 1)
print_export(xe->env, xe->exported);
{
if (print_export(xe->env, xe->exported) != SUCCESS)
return (MALLOC_ERR);
}
else
{
if (ft_export_checks(args + 1, xe) != SUCCESS)
......
......@@ -129,8 +129,6 @@ int main(int argc, char **argv, char **env_source)
xe->env = dup_str_array(env_source);
if (xe->env == NULL)
ret = MALLOC_ERR;
else
sort_str_array(xe->env);
while (ret == SUCCESS)
ret = main_loop(xe);
free_str_array(xe->exported); // besoin de free?
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment