This commit is contained in:
Jack Halford 2017-03-22 17:17:14 +01:00
commit 9a8c3ebe64
13 changed files with 47 additions and 43 deletions

View file

@ -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" #include "minishell.h"
#define ENV_USAGE "env [-i] [name=value]... [utility [argument...]]" #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], '/') ? if (!(path = ft_strchr(data.av_data[0], '/') ?
ft_strdup(data.av_data[0]) : ft_hash(data.av_data[0])) ft_strdup(data.av_data[0]) : ft_hash(data.av_data[0]))
|| access(path, F_OK) != 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); stat(path, &buf);
if (S_ISDIR(buf.st_mode) || access(path, X_OK) != 0) 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); execve(path, data.av_data, data.custom_env);
} }
waitpid(pid, &status, 0); waitpid(pid, &status, 0);

View file

@ -6,13 +6,13 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ /* 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" #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) static int assign_var(char *const av[], char ***env)
{ {

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */ /* 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); return (str);
} }
/* /*
** Seek the current word. ** Seek the current word.
*/ */

View file

@ -6,7 +6,7 @@
/* 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/21 20:59:57 by ariard ### ########.fr */ /* Updated: 2017/03/22 16:22:34 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* 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->fdout = fds[PIPE_WRITE];
p->pid = 0; p->pid = 0;
exec->fdin = fds[PIPE_READ]; exec->fdin = fds[PIPE_READ];
if (!ast) if (ast)
return (0); p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir,
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir,
&redir_copy); &redir_copy);
return (process_set_spec(p, ast)); return ((!ast) ? 0 : process_set_spec(p, ast));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ /* 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; (void)envp;
if (!SH_HAS_JOBC(data_singleton()->opts)) 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); return (-1);
} }
jobc = &data_singleton()->jobc; 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))) if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))
job_run(jlist->content, 1); job_run(jlist->content, 1);
else else
ft_dprintf(2, "{red}fg: job not found: [%i]{eoc}\n", id); SH_ERR("{red}fg: job not found: [%i]", id);
} }
else 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))) else if ((jlist = ft_lst_find(jobc->first_job, &rank[1], job_cmp_id)))
job_run(jlist->content, 1); job_run(jlist->content, 1);
else else
ft_dprintf(2, "{red}fg: no current job{eoc}\n"); SH_ERR("fg: no current job");
} }
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/19 14:24:38 by wescande #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -34,9 +34,7 @@ int do_lexer_routine(t_list **token, char *stream)
ltoken = ft_lstlast(*token); ltoken = ft_lstlast(*token);
if (lexer_lex(*token ? &ltoken : token, &data->lexer) < 0) if (lexer_lex(*token ? &ltoken : token, &data->lexer) < 0)
exit(1); exit(1);
if (get_lexer_stack(data->lexer) > 2) if ((get_lexer_stack(data->lexer) > 2) || (get_reserved_words(*token)))
return (1);
if (get_reserved_words(*token))
return (1); return (1);
keep_last_type(&last, *token); keep_last_type(&last, *token);
data->lexer.state = DEFAULT; data->lexer.state = DEFAULT;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 19:12:50 by ariard #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 16:15:34 by ariard #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ /* 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; int i;
char *tmp; char *tmp;
tmp = data_singleton()->line.copy_tmp;
i = -1; i = -1;
tmp_pos = *pos; tmp_pos = *pos;
tmp = data_singleton()->line.copy_tmp;
if (!*str || !tmp) if (!*str || !tmp)
return (0); return (0);
while (tmp[++i]) while (tmp[++i])
{ {
if (ft_strlen(*str) > SIZE_LINE) if (ft_strlen(*str) > SIZE_LINE)
break ; break ;
if (!(*str = ft_realloc_imput(*str, tmp[i], *pos + i))) *str = ft_realloc_imput(*str, tmp[i], *pos + i);
return (-1);
} }
if (*pos) if (*pos)
{ {

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ /* 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 (!SH_IS_INTERACTIVE(data_singleton()->opts))
{ {
if ((ret = get_next_line(data_singleton()->fd, input)) >= 0) if ((ret = get_next_line(data_singleton()->fd, input)) >= 0)
{
DG("returning %i", !ret);
return (!ret); return (!ret);
}
return (ret); return (ret);
} }
readline_init(has_prompt); readline_init(has_prompt);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ /* 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,7 +94,7 @@ t_list *is_already_func(t_btree **new)
while (tmp && ret) while (tmp && ret)
{ {
if ((ast = tmp->content) && !*ast) if ((ast = tmp->content) && !*ast)
break; break ;
old_name = token_to_argv(((t_astnode *) old_name = token_to_argv(((t_astnode *)
(*ast)->item)->data.cmd.token, 1); (*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]
@ -117,7 +117,7 @@ int add_one_func(t_btree **ast, t_list **lst)
func_ast = btree_map(*ast, &node_copy); func_ast = btree_map(*ast, &node_copy);
if ((old_func = is_already_func(&func_ast))) if ((old_func = is_already_func(&func_ast)))
ft_lst_delif(&data_singleton()->lst_func, 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))); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
return (0); return (0);
} }