norme builtin

This commit is contained in:
gwojda 2017-03-20 14:39:20 +01:00
parent 5b5a4442e2
commit 3c39c485cb
5 changed files with 89 additions and 90 deletions

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* bt_read_term.c :+: :+: :+: */ /* bt_read_term.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */ /* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
/* Updated: 2017/03/15 21:23:41 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:23:46 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */ /* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */
/* Updated: 2017/03/19 17:43:24 by wescande ### ########.fr */ /* Updated: 2017/03/20 14:38:06 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -86,7 +86,8 @@ static int env_treat_flag(char ***custom_env, char *const *arg[])
return (0); return (0);
} }
int builtin_env(const char *path, char *const argv[], char *const envp[]) int builtin_env(const char *path, char *const argv[],
char *const envp[])
{ {
char **env; char **env;

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */ /* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */
/* Updated: 2017/03/18 11:46:32 by gwojda ### ########.fr */ /* Updated: 2017/03/20 14:37:26 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static t_cliopts export_opts[] = static t_cliopts g_export_opts[] =
{ {
{'p', NULL, BT_EXPORT_LP, 0, NULL}, {'p', NULL, BT_EXPORT_LP, 0, NULL},
{0, NULL, 0, 0, NULL}, {0, NULL, 0, 0, NULL},
@ -44,23 +44,20 @@ int builtin_export(
(void)envp; (void)envp;
(void)path; (void)path;
data.flag = 0; data.flag = 0;
if (cliopts_get((char**)av, export_opts, &data)) if (cliopts_get((char**)av, g_export_opts, &data))
ft_perror(); ft_perror();
if (data.flag & BT_EXPORT_LP) if (data.flag & BT_EXPORT_LP)
return (bt_export_print()); return (bt_export_print());
av = data.av_data; av = data.av_data;
while (*av) while (*av)
{ {
if ((equal = ft_strchr(*av, '='))) equal = ft_strchr(*av, '=');
{ if (equal)
*equal = 0; *equal = 0;
builtin_setenv("internal", (char*[]){"global", *av, equal + 1}, NULL);
}
else else
{
equal = ft_getenv(data_singleton()->local_var, *av); equal = ft_getenv(data_singleton()->local_var, *av);
equal ? equal++ : equal;
builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL); builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL);
}
builtin_unsetenv("internal", (char*[]){"local", *av, NULL}, NULL); builtin_unsetenv("internal", (char*[]){"local", *av, NULL}, NULL);
av++; av++;
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/17 18:54:00 by ariard #+# #+# */ /* Created: 2017/03/17 18:54:00 by ariard #+# #+# */
/* Updated: 2017/03/17 19:59:42 by ariard ### ########.fr */ /* Updated: 2017/03/20 14:23:26 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -110,6 +110,7 @@ int builtin_math(const char *path, char *const av[], char *const envp[])
return (error_msg(MATHERR_3)); return (error_msg(MATHERR_3));
if (do_math(&value, operator, operand) == -1) if (do_math(&value, operator, operand) == -1)
return (-1); return (-1);
builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var); builtin_setenv("setenv", (char *[]){"local", var, value, 0},
data_singleton()->local_var);
return (0); return (0);
} }

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* builtin_read.c :+: :+: :+: */ /* builtin_read.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
/* Updated: 2017/03/20 08:31:25 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:24:19 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */