Merge branch 'master' of https://github.com/jzck/42sh
This commit is contained in:
commit
9a8c3ebe64
13 changed files with 47 additions and 43 deletions
|
|
@ -1,3 +1,15 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_env.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/22 16:21:12 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
#define ENV_USAGE "env [-i] [name=value]... [utility [argument...]]"
|
||||
|
|
@ -51,10 +63,10 @@ int builtin_env(const char *path,
|
|||
if (!(path = ft_strchr(data.av_data[0], '/') ?
|
||||
ft_strdup(data.av_data[0]) : ft_hash(data.av_data[0]))
|
||||
|| access(path, F_OK) != 0)
|
||||
exit (SH_ERR(ENV_NOFILE, data.av_data[0]));
|
||||
exit(SH_ERR(ENV_NOFILE, data.av_data[0]));
|
||||
stat(path, &buf);
|
||||
if (S_ISDIR(buf.st_mode) || access(path, X_OK) != 0)
|
||||
exit (SH_ERR(ENV_NOPERM, data.av_data[0]));
|
||||
exit(SH_ERR(ENV_NOPERM, data.av_data[0]));
|
||||
execve(path, data.av_data, data.custom_env);
|
||||
}
|
||||
waitpid(pid, &status, 0);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/21 18:11:31 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:21:49 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
#define SETERR_0 "%s: %s: invalid variable name"
|
||||
#define SETERR_0 "%s: %s: invalid variable name"
|
||||
|
||||
static int assign_var(char *const av[], char ***env)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
|
||||
/* Updated: 2017/03/22 16:02:25 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:20:03 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -40,7 +40,6 @@ static char *c_strdupi(char *s, int (*f)(char))
|
|||
return (str);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Seek the current word.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/21 20:59:57 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:22:34 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached\n"
|
||||
#define FUNCERR_0 SHELL_NAME ":maximum nested function level reached\n"
|
||||
|
||||
int plaunch_function(t_process *p)
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ int plaunch_function(t_process *p)
|
|||
func_lvl += ft_strlenchr(func_lvl, '=') + 1;
|
||||
if ((value = ft_atoi(func_lvl)) >= 199)
|
||||
{
|
||||
ft_strdel(&temp);
|
||||
ft_strdel(&temp);
|
||||
return (SH_ERR(FUNCERR_0));
|
||||
}
|
||||
value += 1;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/20 20:41:48 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:24:18 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -67,9 +67,8 @@ int process_set(t_process *p, t_btree *ast)
|
|||
p->fdout = fds[PIPE_WRITE];
|
||||
p->pid = 0;
|
||||
exec->fdin = fds[PIPE_READ];
|
||||
if (!ast)
|
||||
return (0);
|
||||
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir,
|
||||
if (ast)
|
||||
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir,
|
||||
&redir_copy);
|
||||
return (process_set_spec(p, ast));
|
||||
return ((!ast) ? 0 : process_set_spec(p, ast));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/20 14:42:22 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:30:05 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ int builtin_fg(const char *path, char *const av[], char *const envp[])
|
|||
(void)envp;
|
||||
if (!SH_HAS_JOBC(data_singleton()->opts))
|
||||
{
|
||||
ft_dprintf(2, "{red}fg: %s{eoc}\n", SH_MSG_NOJOBC);
|
||||
SH_ERR("fg: %s", SH_MSG_NOJOBC);
|
||||
return (-1);
|
||||
}
|
||||
jobc = &data_singleton()->jobc;
|
||||
|
|
@ -33,7 +33,7 @@ int builtin_fg(const char *path, char *const av[], char *const envp[])
|
|||
if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
|
||||
job_run(jlist->content, 1);
|
||||
else
|
||||
ft_dprintf(2, "{red}fg: job not found: [%i]{eoc}\n", id);
|
||||
SH_ERR("{red}fg: job not found: [%i]", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -42,7 +42,7 @@ int builtin_fg(const char *path, char *const av[], char *const envp[])
|
|||
else if ((jlist = ft_lst_find(jobc->first_job, &rank[1], job_cmp_id)))
|
||||
job_run(jlist->content, 1);
|
||||
else
|
||||
ft_dprintf(2, "{red}fg: no current job{eoc}\n");
|
||||
SH_ERR("fg: no current job");
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/19 14:24:38 by wescande #+# #+# */
|
||||
/* Updated: 2017/03/20 16:44:31 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:37:46 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,11 +21,11 @@ int do_lexer_routine(t_list **token, char *stream)
|
|||
data = data_singleton();
|
||||
if (data->lexer.state == HEREDOC)
|
||||
ft_strappend(&data->lexer.str, (char[]){'\n', 0});
|
||||
if (data->parser.state == UNDEFINED && !isrw_delim(last))
|
||||
if (data->parser.state == UNDEFINED && !isrw_delim(last))
|
||||
ft_strappend(&data->lexer.str, (char[]){';', 0});
|
||||
else if (data->parser.state == UNDEFINED && last != 0)
|
||||
ft_strappend(&data->lexer.str, (char[]){' ', 0});
|
||||
if (data->lexer.state == HEREDOC || (data->parser.state == UNDEFINED
|
||||
if (data->lexer.state == HEREDOC || (data->parser.state == UNDEFINED
|
||||
&& last != 0))
|
||||
data->lexer.pos++;
|
||||
ft_strappend(&data->lexer.str, stream);
|
||||
|
|
@ -34,9 +34,7 @@ int do_lexer_routine(t_list **token, char *stream)
|
|||
ltoken = ft_lstlast(*token);
|
||||
if (lexer_lex(*token ? <oken : token, &data->lexer) < 0)
|
||||
exit(1);
|
||||
if (get_lexer_stack(data->lexer) > 2)
|
||||
return (1);
|
||||
if (get_reserved_words(*token))
|
||||
if ((get_lexer_stack(data->lexer) > 2) || (get_reserved_words(*token)))
|
||||
return (1);
|
||||
keep_last_type(&last, *token);
|
||||
data->lexer.state = DEFAULT;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/20 16:01:29 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:38:44 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ static int recognization_rvwords(t_token *pv_tk, t_token *at_tk)
|
|||
|| pv_tk->type == TK_FI || pv_tk->type == TK_THEN
|
||||
|| 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_LBRACE || pv_tk->type == TK_UNTIL)
|
||||
|| (pv_tk->type == TK_PAREN_CLOSE && at_tk->type == TK_PAREN_OPEN));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/20 19:12:50 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/20 19:12:51 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:38:33 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int isrw_delim(t_type type)
|
||||
int isrw_delim(t_type type)
|
||||
{
|
||||
return (type == TK_NEWLINE || type == TK_AMP
|
||||
|| type == TK_SEMI || type == TK_PIPE
|
||||
|| type == TK_WHILE || type == TK_UNTIL
|
||||
|| type == TK_WHILE || type == TK_UNTIL
|
||||
|| type == TK_DONE || type == TK_RBRACE
|
||||
|| type == TK_DO || type == TK_IF
|
||||
|| type == TK_FI || type == TK_THEN
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/20 16:15:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/20 16:25:06 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:38:19 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,4 +19,4 @@ int keep_last_type(t_type *last, t_list *token)
|
|||
if (!(tmp = ft_lstlast(token)))
|
||||
return ((*last = 0));
|
||||
return (*last = ((t_token *)tmp->content)->type);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/21 18:11:14 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:49:08 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -43,17 +43,16 @@ int ft_v(char **str, size_t *pos)
|
|||
int i;
|
||||
char *tmp;
|
||||
|
||||
tmp = data_singleton()->line.copy_tmp;
|
||||
i = -1;
|
||||
tmp_pos = *pos;
|
||||
tmp = data_singleton()->line.copy_tmp;
|
||||
if (!*str || !tmp)
|
||||
return (0);
|
||||
while (tmp[++i])
|
||||
{
|
||||
if (ft_strlen(*str) > SIZE_LINE)
|
||||
break ;
|
||||
if (!(*str = ft_realloc_imput(*str, tmp[i], *pos + i)))
|
||||
return (-1);
|
||||
*str = ft_realloc_imput(*str, tmp[i], *pos + i);
|
||||
}
|
||||
if (*pos)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/20 21:19:20 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:49:30 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,10 +21,7 @@ int readline(int has_prompt, char **input)
|
|||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||
{
|
||||
if ((ret = get_next_line(data_singleton()->fd, input)) >= 0)
|
||||
{
|
||||
DG("returning %i", !ret);
|
||||
return (!ret);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
readline_init(has_prompt);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/21 20:01:37 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/22 16:52:57 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -94,10 +94,10 @@ t_list *is_already_func(t_btree **new)
|
|||
while (tmp && ret)
|
||||
{
|
||||
if ((ast = tmp->content) && !*ast)
|
||||
break;
|
||||
break ;
|
||||
old_name = token_to_argv(((t_astnode *)
|
||||
(*ast)->item)->data.cmd.token, 1);
|
||||
ret = (new_name && new_name[0] && old_name && old_name[0]
|
||||
ret = (new_name && new_name[0] && old_name && old_name[0]
|
||||
&& !ft_strcmp(new_name[0], old_name[0])) ? 0 : 1;
|
||||
ft_tabdel(&old_name);
|
||||
tmp = tmp->next;
|
||||
|
|
@ -117,7 +117,7 @@ int add_one_func(t_btree **ast, t_list **lst)
|
|||
func_ast = btree_map(*ast, &node_copy);
|
||||
if ((old_func = is_already_func(&func_ast)))
|
||||
ft_lst_delif(&data_singleton()->lst_func,
|
||||
old_func->content, &ft_addrcmp, &tree_func_free);
|
||||
old_func->content, &ft_addrcmp, &tree_func_free);
|
||||
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue