dev: don't use t_variable where don't make sense *

also fix unset builtin
This commit is contained in:
mcolonna 2024-06-28 13:15:05 +02:00
parent f9f9562a40
commit f578b5311b
4 changed files with 17 additions and 20 deletions

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 13:43:21 by mcolonna #+# #+# */
/* Updated: 2024/06/27 14:43:36 by mcolonna ### ########.fr */
/* Updated: 2024/06/28 13:10:43 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,7 +20,8 @@ typedef struct s_variable
} t_variable;
// Set a variable to a new value.
void variables_set(t_list *variables, const t_variable var);
void variables_set(t_list *variables, const char *name,
const char *value);
// Get the value of a variable from its name.
const char *variables_get(t_list *variables, const char *name);

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */
/* Updated: 2024/06/28 13:05:59 by mcolonna ### ########.fr */
/* Updated: 2024/06/28 13:12:49 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,16 +14,11 @@
static int unset_builtin(t_env *env, t_call call)
{
t_variable var;
int i;
var.value = "";
i = 0;
while (call.argv[++i])
{
var.name = call.argv[++i];
variables_set(env->variables, var);
}
variables_set(env->variables, call.argv[i], "");
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */
/* Updated: 2024/06/27 14:52:32 by mcolonna ### ########.fr */
/* Updated: 2024/06/28 13:14:15 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -53,23 +53,24 @@ static int heredoc(t_memclass mc, int *readfd, const char *eof)
static bool parse_variable_set_command(
t_parsing_args *args, const char *command, t_list *variables)
{
t_variable var;
const char *name;
const char *value;
streamstr_init(&args->stream, command);
skip_blank(&args->stream);
var.name = str_dup(fatal_error, args->mc, "");
name = str_dup(fatal_error, args->mc, "");
read_only(args, &var.name, SYMBOL_CHARS);
if (str_len(var.name) == 0 || stream_pop(&args->stream) != '=')
return (false);
var.value = read_string(args, "<>|/");
value = read_string(args, "<>|/");
if (args->r.error)
return (false);
if (!var.value)
var.value = "";
if (!value)
value = "";
skip_blank(&args->stream);
if (stream_read(&args->stream))
return (false);
variables_set(variables, var);
variables_set(variables, name, value);
return (true);
}

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */
/* Updated: 2024/06/27 13:47:39 by mcolonna ### ########.fr */
/* Updated: 2024/06/28 13:11:41 by mcolonna ### ########.fr */
/* */
/* ************************************************************************** */
@ -53,10 +53,10 @@ static t_variable *variables_find(t_list *variables, const char *name)
return (r);
}
void variables_set(t_list *variables, const t_variable var)
void variables_set(t_list *variables, const char *name, const char *value)
{
variables_find(variables, var.name)->value = (
str_dup(fatal_error, variables->mc, var.value));
variables_find(variables, name)->value = (
str_dup(fatal_error, variables->mc, value));
}
const char *variables_get(t_list *variables, const char *name)