fix export =""
This commit is contained in:
62
.gitignore
vendored
62
.gitignore
vendored
@ -1,62 +0,0 @@
|
|||||||
# Prerequisites
|
|
||||||
*.d
|
|
||||||
.tonotdo
|
|
||||||
|
|
||||||
|
|
||||||
minishell
|
|
||||||
minishell_bonus
|
|
||||||
.minishellrc
|
|
||||||
objs/
|
|
||||||
.tmp*
|
|
||||||
out
|
|
||||||
minishell_tester/
|
|
||||||
|
|
||||||
# Object files
|
|
||||||
*.o
|
|
||||||
*.ko
|
|
||||||
*.obj
|
|
||||||
*.elf
|
|
||||||
|
|
||||||
# Linker output
|
|
||||||
*.ilk
|
|
||||||
*.map
|
|
||||||
*.exp
|
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Libraries
|
|
||||||
*.lib
|
|
||||||
*.a
|
|
||||||
*.la
|
|
||||||
*.lo
|
|
||||||
|
|
||||||
# Shared objects (inc. Windows DLLs)
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.so.*
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
*.exe
|
|
||||||
*.out
|
|
||||||
*.app
|
|
||||||
*.i*86
|
|
||||||
*.x86_64
|
|
||||||
*.hex
|
|
||||||
|
|
||||||
# Debug files
|
|
||||||
*.dSYM/
|
|
||||||
*.su
|
|
||||||
*.idb
|
|
||||||
*.pdb
|
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
|
||||||
*.mod*
|
|
||||||
*.cmd
|
|
||||||
.tmp_versions/
|
|
||||||
modules.order
|
|
||||||
Module.symvers
|
|
||||||
Mkfile.old
|
|
||||||
dkms.conf
|
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/26 10:52:17 by marde-vr ### ########.fr */
|
/* Updated: 2024/04/26 16:06:09 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ int export_invalid_identifier(char *arg, char *name)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_env *set_env(t_env *env, char *name, char *value, int append)
|
t_env *set_env(t_env *env, char *name, char *value, int flags)
|
||||||
{
|
{
|
||||||
t_env *tmp;
|
t_env *tmp;
|
||||||
|
|
||||||
@ -31,12 +31,12 @@ t_env *set_env(t_env *env, char *name, char *value, int append)
|
|||||||
if (!ft_strcmp(name, tmp->name))
|
if (!ft_strcmp(name, tmp->name))
|
||||||
{
|
{
|
||||||
free(name);
|
free(name);
|
||||||
if (!*value)
|
if (!*value && !(flags & 0b10))
|
||||||
{
|
{
|
||||||
free(value);
|
free(value);
|
||||||
return (env);
|
return (env);
|
||||||
}
|
}
|
||||||
if (append)
|
if (flags & 0b1)
|
||||||
value = ft_strjoin_free(tmp->value, value, 2);
|
value = ft_strjoin_free(tmp->value, value, 2);
|
||||||
if (!value)
|
if (!value)
|
||||||
return (env);
|
return (env);
|
||||||
@ -49,7 +49,7 @@ t_env *set_env(t_env *env, char *name, char *value, int append)
|
|||||||
return (env_add_back(env, name, value));
|
return (env_add_back(env, name, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
t_env *export_set_env(t_env *env, char *name, char *value, int append)
|
t_env *export_set_env(t_env *env, char *name, char *value, int flags)
|
||||||
{
|
{
|
||||||
if (!value || !name)
|
if (!value || !name)
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ t_env *export_set_env(t_env *env, char *name, char *value, int append)
|
|||||||
ft_printf_fd(2, "minishell: malloc failed");
|
ft_printf_fd(2, "minishell: malloc failed");
|
||||||
return (env);
|
return (env);
|
||||||
}
|
}
|
||||||
return (set_env(env, name, value, append));
|
return (set_env(env, name, value, flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
int export_var(t_token *cmd, t_env *env)
|
int export_var(t_token *cmd, t_env *env)
|
||||||
@ -67,20 +67,25 @@ int export_var(t_token *cmd, t_env *env)
|
|||||||
char *name;
|
char *name;
|
||||||
char *value;
|
char *value;
|
||||||
int len;
|
int len;
|
||||||
int append;
|
int flags;
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
arg = cmd->value;
|
arg = cmd->value;
|
||||||
while (arg[len] && arg[len] != '=' && arg[len] != '+')
|
while (arg[len] && arg[len] != '=' && arg[len] != '+')
|
||||||
len++;
|
len++;
|
||||||
name = ft_substr(arg, 0, len);
|
name = ft_substr(arg, 0, len);
|
||||||
append = arg[len] == '+';
|
flags = arg[len] == '+';
|
||||||
if (arg[len] == '=' || (arg[len] == '+' && arg[len + 1] == '='))
|
if (arg[len] == '+' && arg[len + 1] == '=')
|
||||||
len += 1 + (arg[len] == '+');
|
len++;
|
||||||
|
if (arg[len] == '=')
|
||||||
|
{
|
||||||
|
flags += 0b10;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
if (!name || !check_var_name(name) || arg[len] == '+')
|
if (!name || !check_var_name(name) || arg[len] == '+')
|
||||||
return (export_invalid_identifier(arg, name));
|
return (export_invalid_identifier(arg, name));
|
||||||
value = ft_strdup(arg + len);
|
value = ft_strdup(arg + len);
|
||||||
env = export_set_env(env, name, value, append);
|
env = export_set_env(env, name, value, flags);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user