dev: don't use t_variable where don't make sense *
also fix unset builtin
This commit is contained in:
parent
f9f9562a40
commit
f578b5311b
4 changed files with 17 additions and 20 deletions
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/27 13:43:21 by mcolonna #+# #+# */
|
/* 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;
|
} t_variable;
|
||||||
|
|
||||||
// Set a variable to a new value.
|
// 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.
|
// Get the value of a variable from its name.
|
||||||
const char *variables_get(t_list *variables, const char *name);
|
const char *variables_get(t_list *variables, const char *name);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */
|
/* 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)
|
static int unset_builtin(t_env *env, t_call call)
|
||||||
{
|
{
|
||||||
t_variable var;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
var.value = "";
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (call.argv[++i])
|
while (call.argv[++i])
|
||||||
{
|
variables_set(env->variables, call.argv[i], "");
|
||||||
var.name = call.argv[++i];
|
|
||||||
variables_set(env->variables, var);
|
|
||||||
}
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */
|
/* 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(
|
static bool parse_variable_set_command(
|
||||||
t_parsing_args *args, const char *command, t_list *variables)
|
t_parsing_args *args, const char *command, t_list *variables)
|
||||||
{
|
{
|
||||||
t_variable var;
|
const char *name;
|
||||||
|
const char *value;
|
||||||
|
|
||||||
streamstr_init(&args->stream, command);
|
streamstr_init(&args->stream, command);
|
||||||
skip_blank(&args->stream);
|
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);
|
read_only(args, &var.name, SYMBOL_CHARS);
|
||||||
if (str_len(var.name) == 0 || stream_pop(&args->stream) != '=')
|
if (str_len(var.name) == 0 || stream_pop(&args->stream) != '=')
|
||||||
return (false);
|
return (false);
|
||||||
var.value = read_string(args, "<>|/");
|
value = read_string(args, "<>|/");
|
||||||
if (args->r.error)
|
if (args->r.error)
|
||||||
return (false);
|
return (false);
|
||||||
if (!var.value)
|
if (!value)
|
||||||
var.value = "";
|
value = "";
|
||||||
skip_blank(&args->stream);
|
skip_blank(&args->stream);
|
||||||
if (stream_read(&args->stream))
|
if (stream_read(&args->stream))
|
||||||
return (false);
|
return (false);
|
||||||
variables_set(variables, var);
|
variables_set(variables, name, value);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 13:47:40 by mcolonna #+# #+# */
|
/* 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);
|
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 = (
|
variables_find(variables, name)->value = (
|
||||||
str_dup(fatal_error, variables->mc, var.value));
|
str_dup(fatal_error, variables->mc, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *variables_get(t_list *variables, const char *name)
|
const char *variables_get(t_list *variables, const char *name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue