#issue160 : chapeau wescande

This commit is contained in:
Antoine Riard 2017-03-23 03:17:31 +01:00
parent a281d4e514
commit 5e5e0769ba
6 changed files with 91 additions and 25 deletions

View file

@ -6,14 +6,14 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/23 00:29:22 by ariard ### ########.fr # # Updated: 2017/03/23 00:55:25 by ariard ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
NAME = 42sh NAME = 42sh
CC = gcc CC = gcc
FLAGS = -Wall -Wextra -Werror -fvisibility=hidden -fsanitize=address FLAGS = -Wall -Wextra -Werror #-fvisibility=hidden #-fsanitize=address
D_FLAGS = -g D_FLAGS = -g
DELTA = $$(echo "$$(tput cols)-47"|bc) DELTA = $$(echo "$$(tput cols)-47"|bc)

63
42sh/log Normal file
View file

@ -0,0 +1,63 @@
env lvl 2
env lvl 3
env lvl 4
env lvl 5
env lvl 6
env lvl 7
env lvl 8
env lvl 7
env lvl 8
env lvl 9
env lvl 6
env lvl 7
env lvl 8
env lvl 9
env lvl 8
env lvl 9
env lvl 10
env lvl 5
env lvl 6
env lvl 7
env lvl 8
env lvl 9
env lvl 8
env lvl 9
env lvl 10
env lvl 7
env lvl 8
env lvl 9
env lvl 10
env lvl 9
env lvl 10
env lvl 11
env lvl 4
env lvl 5
env lvl 6
env lvl 7
env lvl 8
env lvl 9
env lvl 8
env lvl 9
env lvl 10
env lvl 7
env lvl 8
env lvl 9
env lvl 10
env lvl 9
env lvl 10
env lvl 11
env lvl 6
env lvl 7
env lvl 8
env lvl 9
env lvl 10
env lvl 9
env lvl 10
env lvl 11
env lvl 8
env lvl 9
env lvl 10
env lvl 11
env lvl 10
env lvl 11
env lvl 12

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/22 22:26:37 by jhalford ### ########.fr */ /* Updated: 2017/03/23 01:08:14 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
/* Updated: 2017/03/23 00:30:46 by ariard ### ########.fr */ /* Updated: 2017/03/23 00:51:22 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,8 +21,10 @@ int exec_var(t_btree **ast)
char *equal; char *equal;
node = (*ast)->item; node = (*ast)->item;
DG("before");
if (!(av = token_to_argv(node->data.cmd.token, 1))) if (!(av = token_to_argv(node->data.cmd.token, 1)))
return (0); return (0);
DG("after");
var = av[0]; var = av[0];
if ((equal = ft_strchr(av[0], '='))) if ((equal = ft_strchr(av[0], '=')))
*equal = 0; *equal = 0;

View file

@ -6,36 +6,34 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/22 19:37:08 by jhalford ### ########.fr */ /* Updated: 2017/03/23 03:15:20 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached" #define FUNCERR_0 ":maximum nested function level reached"
#define FUNC_LVL 200
int plaunch_function(t_process *p) int plaunch_function(t_process *p)
{ {
char *temp; static int protection= 0;
char *func_lvl;
int value;
func_lvl = ft_sstrstr(data_singleton()->env, "FUNC_LVL"); if (ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) > 10)
if ((temp = func_lvl)) return(SH_ERR(FUNCERR_0));
{
func_lvl += ft_strlenchr(func_lvl, '=') + 1; if (protection >= FUNC_LVL)
if ((value = ft_atoi(func_lvl)) >= 199) return(SH_ERR(FUNCERR_0));
{ protection++;
ft_strdel(&temp);
return (SH_ERR(FUNCERR_0)); // jack faut qu on parle
}
value += 1;
}
else
value = 0;
builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL",
ft_itoa(value), 0}, NULL); ft_itoa(ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) + 1),
NULL}, NULL);
ft_exec(&p->data.function.content); ft_exec(&p->data.function.content);
builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "0", 0}, NULL); builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL",
ft_itoa(ft_atoi(ft_getenv(data_singleton()->env, "FUNC_LVL")) - 1),
NULL}, NULL);
protection--;
return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/22 15:55:07 by jhalford ### ########.fr */ /* Updated: 2017/03/23 03:16:08 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,6 +66,9 @@ int data_init(int ac, char **av)
data->lst_func = NULL; data->lst_func = NULL;
lexer_init(&data->lexer); lexer_init(&data->lexer);
parser_init(&data->parser); parser_init(&data->parser);
if (!ft_getenv(data_singleton()->env, "FUNC_LVL"))
builtin_setenv("setenv", (char *[]){"env", "FUNC_LVL", "-1",
NULL}, NULL);
if ((term_name = ft_getenv(data->env, "TERM")) == NULL) if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
{ {
term_name = "dumb"; term_name = "dumb";