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"
#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);

View file

@ -6,7 +6,7 @@
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -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.
*/

View file

@ -6,7 +6,7 @@
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -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);
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));
}

View file

@ -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);
}

View file

@ -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 */
/* */
/* ************************************************************************** */
@ -34,9 +34,7 @@ int do_lexer_routine(t_list **token, char *stream)
ltoken = ft_lstlast(*token);
if (lexer_lex(*token ? &ltoken : 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;

View file

@ -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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -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 */
/* */
/* ************************************************************************** */

View file

@ -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)
{

View file

@ -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);

View file

@ -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,7 +94,7 @@ 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]