This commit is contained in:
wescande 2017-03-24 15:55:14 +01:00
commit 7644c06f4f
26 changed files with 60 additions and 140 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/24 12:02:21 by gwojda ### ########.fr #
# Updated: 2017/03/24 14:53:07 by ariard ### ########.fr #
# #
# **************************************************************************** #
@ -66,7 +66,6 @@ completion/c_terminal.c\
completion/completion.c\
exec/ast_free.c\
exec/bad_fd.c\
exec/error_badidentifier.c\
exec/exec_ampersand.c\
exec/exec_and_if.c\
exec/exec_bang.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/23 16:27:10 by ariard ### ########.fr */
/* Updated: 2017/03/24 14:47:12 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -166,8 +166,6 @@ void *redir_copy(void *data);
void redir_free(void *data, size_t content_size);
char **token_to_argv(t_ld *ld, int do_match);
int error_badidentifier(char *name);
t_btree *is_function(t_process *p);
/*

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/23 16:13:56 by gwojda ### ########.fr */
/* Updated: 2017/03/24 15:07:50 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 15:34:21 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:05:04 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:11:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -41,6 +41,6 @@ extern int g_errnum;
extern char **g_argv;
int error_set(int n, ...);
int ft_perror(void);
int ft_perror(char *utility);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:04:04 by jhalford #+# #+# */
/* Updated: 2017/03/20 15:50:08 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:02:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -97,7 +97,10 @@ int cliopts_get(char **av, t_cliopts opt_map[], void *data)
while (av && *av)
{
if (ft_strcmp(*av, "--") == 0)
return (0);
{
av++;
break ;
}
else if ((*av)[0] == '-' && (*av)[1] == '-')
{
if (cliopts_parse_long(&av, opt_map, data))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 16:47:00 by jhalford #+# #+# */
/* Updated: 2017/03/15 20:45:41 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:36:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,8 +37,8 @@ int error_set(int n, ...)
return (g_errnum);
}
int ft_perror(void)
int ft_perror(char *utility)
{
ft_dprintf(2, "{red}%s: %s{eoc}\n", g_argv[0], g_errmsg);
ft_dprintf(2, "{red}%s: %s{eoc}\n", utility ? utility : g_argv[0], g_errmsg);
return (g_errnum);
}

View file

@ -1,63 +0,0 @@
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

@ -1,5 +1,8 @@
case van in
( "bus" ) echo Hello world ;;
( "velo" ) echo Comment va ;;
( "van" ) ls ;;
( "van" ) case tutu in
( toto ) pwd ;;
( tutu ) ls ;;
esac ;;
esac

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
/* Updated: 2017/03/22 17:17:28 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:11:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,7 +55,7 @@ int builtin_env(const char *path,
(void)envp;
if (bt_env_parse(&data, (char**)argv))
return (ft_perror() && SH_ERR("usage: %s", ENV_USAGE) ? 0 : 0);
return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE) ? 0 : 0);
else if (!*data.av_data)
return (builtin_setenv(NULL, (char*[]){"setenv", 0}, NULL));
else if ((pid = fork()) == 0)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */
/* Updated: 2017/03/20 14:44:02 by wescande ### ########.fr */
/* Updated: 2017/03/24 15:11:48 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -45,7 +45,7 @@ int builtin_export(
(void)path;
data.flag = 0;
if (cliopts_get((char**)av, g_export_opts, &data))
ft_perror();
ft_perror("export");
if (data.flag & BT_EXPORT_LP)
return (bt_export_print());
av = data.av_data;

View file

@ -6,14 +6,14 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
/* Updated: 2017/03/22 19:21:49 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:10:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define US_READ "read [-ers] [-u fd] [-t timeout] [-p prompt]"
#define US_READ_1 "[-n nchars] [-d delim] [name ...]"
#define US_READ_1 " [-n nchars] [-d delim] [name ...]"
t_cliopts g_read_opts[] =
{
@ -36,12 +36,12 @@ int bt_read_init(t_read *data, char **av)
data->fd = 0;
data->timeout = 0;
data->input = NULL;
if ((cliopts_get(av, g_read_opts, data)))
return (ft_perror() ? 2 : 2);
if (isatty(STDIN))
data->opts |= BT_READ_INTER;
if (bt_read_terminit(data) < 0)
return (-1);
exit (1);
if ((cliopts_get(av, g_read_opts, data)))
return (ft_perror("read"));
return (0);
}
@ -89,7 +89,8 @@ int bt_read_assign(t_read *data)
tok = ft_strtok(input, ifs);
while (*names)
{
builtin_setenv("setenv", (char*[]){"setenv", *names, tok}, NULL);
if (!(builtin_setenv("setenv", (char*[]){"read", *names, tok}, NULL)))
return (1);
ifs = names[1] ? ifs : NULL;
tok = ft_strtok(NULL, ifs);
names++;
@ -106,16 +107,11 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
(void)envp;
ret = 0;
if ((ret = bt_read_init(&data, (char **)av)) != 0)
;
SH_ERR("usage: %s%s", US_READ, US_READ_1);
else if ((ret = bt_read_loop(&data)))
;
else if (data.input && bt_read_assign(&data))
ret = 1;
if (ret == -1)
exit(1);
if (ret != 0)
SH_ERR("usage: read %s %s\n", US_READ, US_READ_1);
if (ret != 2)
bt_read_exit(&data);
else if (data.input && (ret = bt_read_assign(&data)))
;
bt_read_exit(&data);
return (ret);
}

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* error_badidentifier.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/06 18:03:51 by ariard #+# #+# */
/* Updated: 2017/03/06 18:11:26 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int error_badidentifier(char *name)
{
ft_putstr_fd("`", 2);
ft_putstr(name);
ft_putstr_fd("' not a valid identifier", 2);
return (1);
}

View file

@ -6,12 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/15 00:49:20 by wescande #+# #+# */
/* Updated: 2017/03/22 22:20:02 by ariard ### ########.fr */
/* Updated: 2017/03/24 14:52:00 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#define FORERR_0 ": `%s' not a valid identifier"
int plaunch_for(t_process *p)
{
t_ld *temp;
@ -22,7 +24,7 @@ int plaunch_for(t_process *p)
temp = p->data.d_for.token;
var = ((char **)temp->content)[0];
if (!word_is_assignment(temp->content))
return (error_badidentifier(var));
return (SH_ERR(FORERR_0, var));
i = 0;
av = token_to_argv(temp, 1);
while (av[++i])

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/03/24 14:08:12 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:39:48 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -74,7 +74,7 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[])
}
ft_bzero(&data, sizeof(t_data_template));
if (cliopts_get((char**)av, g_jobs_opts, &data))
return (ft_perror());
return (ft_perror("jobs"));
if (!*data.av_data)
bt_jobs_all(data.flag);
else if (bt_jobs_spec(data.av_data, data.flag))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 11:37:40 by jhalford #+# #+# */
/* Updated: 2017/03/20 20:51:54 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:40:55 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,11 +20,16 @@ void job_hup_all(void)
jobc = &data_singleton()->jobc;
jlist = jobc->first_job;
if (!SH_HAS_JOBC(data_singleton()->opts))
return ;
while (jlist)
{
job = jlist->content;
DG("gonna SIGHUP %i", job->pgid);
builtin_jobs(NULL, NULL, NULL);
if (job->pgid != 1)
kill(-job->pgid, SIGHUP);
DG("after SIGHUP %i", job->pgid);
jlist = jlist->next;
}
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
/* Updated: 2017/03/22 16:38:44 by gwojda ### ########.fr */
/* Updated: 2017/03/24 15:01:55 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,6 +39,7 @@ static int recognization_rvwords(t_token *pv_tk, t_token *at_tk)
|| pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE
|| pv_tk->type == TK_DSEMI || pv_tk->type == TK_PAREN_OPEN
|| pv_tk->type == TK_LBRACE || pv_tk->type == TK_UNTIL)
|| pv_tk->type == TK_PAREN_CLOSE
|| (pv_tk->type == TK_PAREN_CLOSE && at_tk->type == TK_PAREN_OPEN));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
/* Updated: 2017/03/24 14:20:30 by jhalford ### ########.fr */
/* Updated: 2017/03/24 14:51:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,6 @@ t_lexstate get_state_global(t_lexer *lexer)
c = lexer->str[lexer->pos];
cn = lexer->str[lexer->pos + 1];
cl = lexer->pos ? lexer->str[lexer->pos - 1] : 0;
DG("%i : '%c'", lexer->pos, cl);
ret = 0;
if ((ft_is_delim(c) && (ret = DELIM))
|| ((c == '&' || c == ';' || c == '|' || c == '!') && (ret = SEP))

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 19:12:50 by ariard #+# #+# */
/* Updated: 2017/03/23 17:25:03 by ariard ### ########.fr */
/* Updated: 2017/03/24 14:49:17 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */
/* Updated: 2017/03/24 15:48:41 by wescande ### ########.fr */
/* Updated: 2017/03/24 15:55:08 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,6 +27,6 @@ void data_exit(void)
ft_lstdel(&data->lst_func, &tree_func_free);
ft_save_termios(-1);
ft_free_hash_table();
free_history_list(data_singleton()->line.list_beg);
free_history_list(data->line.list_beg);
free(data_singleton());
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/24 14:47:30 by wescande ### ########.fr */
/* Updated: 2017/03/24 15:30:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/22 19:36:07 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:12:31 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -89,7 +89,7 @@ int shell_init(int ac, char **av)
return (-1);
if (cliopts_get(av, g_opts, data))
{
ft_perror();
ft_perror(NULL);
return (SH_ERR("usage: %s", SHELL_USAGE));
}
if (!isatty(STDIN) || *data->av_data)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
/* Updated: 2017/03/22 15:30:25 by ariard ### ########.fr */
/* Updated: 2017/03/24 15:17:40 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,12 +62,12 @@ int add_case_cmd(t_btree **ast, t_list **lst)
node->nest++;
if (token->type == TK_ESAC && (node->type == TK_PAREN_OPEN
|| node->type == TK_CASE) && node->nest > 0)
return ((node->nest--));
node->nest--;
else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN
&& node->nest == 0)
return ((node->full = 1));
else if ((token->type == TK_ESAC)
&& node->nest == 0)
else if ((token->type == TK_ESAC) && node->nest == 0
&& (node->type == TK_CASE || node->type == TK_PAREN_OPEN))
return ((node->full = 1));
else if (token->type == TK_PAREN_CLOSE)
return (0);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/03/23 16:49:18 by ariard ### ########.fr */
/* Updated: 2017/03/24 15:01:36 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -84,7 +84,6 @@ int build_tree(t_btree **ast, t_list **lst)
i = 0;
token = (*lst)->content;
check_cache(token, cache);
DG("new");
while (g_treematch[i].type)
{
if ((isseparator(token, cache) && g_treematch[i].type == token->type))

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
/* Updated: 2017/03/18 19:18:34 by ariard ### ########.fr */
/* Updated: 2017/03/24 15:18:51 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */
/* Updated: 2017/03/21 15:46:51 by jhalford ### ########.fr */
/* Updated: 2017/03/24 15:00:14 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -1 +0,0 @@
5