core: merge
This commit is contained in:
2
env/env.h
vendored
2
env/env.h
vendored
@ -1,5 +1,6 @@
|
||||
#ifndef ENV_H
|
||||
# define ENV_H
|
||||
# include <stdbool.h>
|
||||
# include "../libftx/libft/list.h"
|
||||
# include "../data/data.h"
|
||||
|
||||
@ -7,6 +8,7 @@ typedef struct s_env
|
||||
{
|
||||
char *key;
|
||||
char *value;
|
||||
bool original;
|
||||
} t_env;
|
||||
|
||||
char *ft_env_filler(t_data *data, const char *str);
|
||||
|
6
env/env1.c
vendored
6
env/env1.c
vendored
@ -6,7 +6,7 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/02/23 13:34:41 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/03/09 19:01:05 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -48,7 +48,7 @@ char *get_value_by_key(char *key, t_list **head)
|
||||
return (((t_env *)current->content)->value);
|
||||
current = current->next;
|
||||
}
|
||||
return ("");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int set_value_by_key(char *key, char *value, t_list **head)
|
||||
@ -80,6 +80,7 @@ int create_value_by_key(char *key, char *value, t_list **head)
|
||||
return (1);
|
||||
content->key = key;
|
||||
content->value = value;
|
||||
content->original = 0;
|
||||
add_sort(head, content);
|
||||
return (0);
|
||||
}
|
||||
@ -104,6 +105,7 @@ t_list **init_env(char **env)
|
||||
return (NULL);
|
||||
var->key = get_key(env[i]);
|
||||
var->value = get_value(env[i]);
|
||||
var->original = 1;
|
||||
add_sort(head, var);
|
||||
}
|
||||
return (head);
|
||||
|
5
env/env2.c
vendored
5
env/env2.c
vendored
@ -1,11 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* env2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 17:22:01 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/02/17 17:24:57 by erey-bet ### ########.fr */
|
||||
/* Created: 2023/03/09 19:59:03 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/03/09 19:59:10 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
29
env/env3.c
vendored
29
env/env3.c
vendored
@ -6,7 +6,7 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/02/28 12:46:33 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/03/09 19:58:55 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -43,19 +43,22 @@ int create_value_by_key_dup(char *key, char *value, t_list **env)
|
||||
char *key_dup;
|
||||
char *value_dup;
|
||||
|
||||
if (set_value_by_key(key, value, env) == 0)
|
||||
return (0);
|
||||
key_dup = ft_strdup(key);
|
||||
if (key_dup == NULL)
|
||||
{
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
return (1);
|
||||
}
|
||||
value_dup = ft_strdup(value);
|
||||
if (value_dup == NULL)
|
||||
if (value != NULL)
|
||||
{
|
||||
free(key);
|
||||
ft_eprintf("minishell: malloc failed\n");
|
||||
return (1);
|
||||
value_dup = ft_strdup(value);
|
||||
if (value_dup == NULL)
|
||||
{
|
||||
free(key);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
value_dup = value;
|
||||
if (create_value_by_key(key_dup, value_dup, env))
|
||||
return (1);
|
||||
return (0);
|
||||
@ -89,9 +92,13 @@ int possible_key(char *key)
|
||||
|
||||
i = -1;
|
||||
if (ft_isdigit(key[i + 1]))
|
||||
return (0);
|
||||
while (key[++i])
|
||||
return (0);
|
||||
while (key[++i + 1])
|
||||
if (!ft_isalnum(key[i]) && key[i] != '_')
|
||||
return (0);
|
||||
if (key[i] == '+')
|
||||
return (2);
|
||||
else if (!ft_isalnum(key[i]) && key[i] != '_')
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user