[ADD] export with "name=value" syntax

This commit is contained in:
mcolonna 2024-06-28 14:51:09 +02:00
parent 532b4e959f
commit b72be8973e

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/25 13:28:29 by jschaft #+# #+# */
/* Updated: 2024/06/28 14:26:05 by mcolonna ### ########.fr */
/* Updated: 2024/06/28 14:50:17 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,11 +15,29 @@
// TODO 'name=value' notation
int export_builtin(t_env *env, t_call call)
{
int i;
int i;
char *name;
char *value;
char **splitted;
const t_memclass mc = mem_subclass(fatal_error, env->mc_global);
i = 0;
while (call.argv[++i])
variables_export(env->variables, call.argv[i]);
{
if (char_isin('=', call.argv[i]))
{
splitted = str_split(fatal_error, mc, call.argv[i], "=");
name = splitted[0];
value = splitted[1];
if (!value)
value = "";
variables_set(env->variables, name, value);
}
else
name = call.argv[i];
variables_export(env->variables, name);
}
mem_freeall(mc);
return (0);
}