12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #include "sh.h"
- t_list *g_lenv;
- //lst.c
- /*char *get_env(t_list *en, char *var);
- void listchainify();//
- void tabify(t_list *en);//
- int lstsize(t_list *en);//
- void ft_putlist(t_list *elem);//
- int delenv(t_list *env, char *name);*/
- char *get_env(t_list *env, char *var)
- {
- if (ft_strcmp(env->content, var) == 61)
- return (ft_strchr(env->content, '=') + 1);
- if (env->next != NULL)
- return (get_env(env->next, var));
- return (NULL);
- }
- void listchainify(void)
- {
- int i;
- i = 0;
- while (g_tenv[i] != NULL)
- i++;
- while (--i >= 0)
- ft_lstadd(&g_lenv, ft_lstnew(g_tenv[i], sizeof(char *)));
- }
- void tabify(t_list *en)
- {
- int j;
- int i;
- if (g_lenv == NULL)
- return ;
- i = lstsize(g_lenv);
- g_tenv = (char **)malloc(sizeof(char *) * (i + 1));
- j = -1;
- while (++j < i)
- {
- g_tenv[j] = ft_strdup(en->content);
- en = en->next;
- }
- g_tenv[j] = NULL;
- }
- int lstsize(t_list *env)
- {
- int i;
- i = 1;
- while (1)
- {
- i++;
- env = env->next;
- if (env->next == NULL)
- break ;
- }
- return (i);
- }
- void ft_putlist(t_list *elem)
- {
- if (elem->content_size == 8)
- ft_putendl(elem->content);
- }
- int delenv(t_list *env, char *name)
- {
- if (ft_strcmp(env->content, name) == 61)
- return (1);
- else if (env->next != NULL)
- if (delenv(env->next, name) == 1)
- env->next = env->next->next;
- return (0);
- }
- //setenv
- /*
- else
- {
- if (get_tenv(name[0]) != NULL)
- if (delenv(g_lenv, name[0]) == 1)
- *g_lenv = *g_lenv->next;
- ft_lstadd(&g_lenv, ft_lstnew(namevalue, 8));
- }*/
- //unsetenv
- /* else
- {
- if (delenv(g_lenv, name) == 1)
- *g_lenv = *g_lenv->next;
- }*/
|