oubli while_clause and tk_paren_open close #188

This commit is contained in:
Antoine Riard 2017-03-24 19:18:39 +01:00
commit 9f1fe08fe3
17 changed files with 95 additions and 40 deletions

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/04 16:31:18 by wescande #+# #+# */
/* Updated: 2017/03/23 03:18:41 by wescande ### ########.fr */
/* Updated: 2017/03/24 18:38:35 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,7 +62,7 @@ typedef struct s_bquote
*/
char **glob(char *str, unsigned char *esc,
unsigned char *dbl_esc, int do_match);
void esc_print(char *str, unsigned char *esc);
void esc_print(int fd, char *str, unsigned char *esc);
int word_is_assignment(char **content);
void *tab_esc_copy(void *content);
char *get_output(char *command);

View file

@ -141,6 +141,7 @@ sstr/ft_sstrcat.c\
sstr/ft_sstrdel.c\
sstr/ft_sstrdup.c\
sstr/ft_sstrfree.c\
sstr/ft_sstrmerge.c\
sstr/ft_sstrprint.c\
sstr/ft_sstrprint_fd.c\
sstr/ft_sstrsort.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/18 13:16:25 by jhalford #+# #+# */
/* Updated: 2017/03/07 11:35:11 by ariard ### ########.fr */
/* Updated: 2017/03/24 17:46:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@ void ft_sstrsort(char **list, int (*cmp)());
void ft_sstrprint(char **list, char sep);
void ft_sstrprint_fd(int fd, char **list, char sep);
char **ft_sstrdup(char **list);
char **ft_sstrmerge(char **s1, char **s2);
void ft_sstrdel(char **sstr, int index);
void ft_sstrfree(char **sstr);
char *ft_sstrcat(char **sstr, char sep);

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sstrmerge.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 17:40:50 by jhalford #+# #+# */
/* Updated: 2017/03/24 18:05:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_sstrmerge(char **s1, char **s2)
{
char **out;
out = ft_sstrdup(s1);
if (!s2)
return (out);
while (*s2)
{
out = ft_sstradd(out, *s2);
s2++;
}
return (out);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 16:20:31 by gwojda #+# #+# */
/* Updated: 2017/03/24 15:11:42 by jhalford ### ########.fr */
/* Updated: 2017/03/24 17:59:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,11 +18,11 @@
t_cliopts g_env_opts[] =
{
{'i', NULL, BT_ENV_LI, 0, bt_env_geti},
{'i', NULL, BT_ENV_LI, 0, NULL},
{0, 0, 0, 0, 0},
};
int bt_env_geti(char ***av, t_env_data *data)
int bt_env_getcustom(char ***av, t_env_data *data)
{
if (!av || !*av || !data)
return (1);
@ -31,7 +31,6 @@ int bt_env_geti(char ***av, t_env_data *data)
data->custom_env = ft_sstradd(data->custom_env, **av);
++(*av);
}
--(*av);
return (0);
}
@ -39,9 +38,19 @@ static int bt_env_parse(t_env_data *data, char **av)
{
data->flag = 0;
data->av_data = NULL;
data->custom_env = NULL;
DG();
if (cliopts_get(av, g_env_opts, data))
return (1);
DG();
data->custom_env = NULL;
bt_env_getcustom(&data->av_data, data);
DG();
if (!(data->flag & BT_ENV_LI))
{
DG("no -i");
data->custom_env = ft_sstrmerge(data_singleton()->env, data->custom_env);
}
DG();
return (0);
}
@ -55,11 +64,18 @@ int builtin_env(const char *path,
(void)envp;
if (bt_env_parse(&data, (char**)argv))
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));
return (ft_perror("env") && SH_ERR("usage: %s", ENV_USAGE));
DG();
if (!*data.av_data)
{
DG();
ft_sstrprint(data.custom_env, '\n');
ft_putchar('\n');
return (0);
}
else if ((pid = fork()) == 0)
{
DG();
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)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
/* Updated: 2017/03/24 14:06:48 by jhalford ### ########.fr */
/* Updated: 2017/03/24 18:23:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,6 +18,7 @@ int exec_reset_job(t_job *job)
job->pgid = 0;
job->attrs = 0;
job->first_process = NULL;
tcgetattr(STDIN, &job->tmodes);
return (0);
}
@ -31,12 +32,11 @@ int exec_reset(void)
jobc = &data_singleton()->jobc;
i = -1;
while (++i < 10)
exec->fd_save[i] = fcntl(i, F_DUPFD_CLOEXEC, 10);
exec->fd_save[i] = fcntl(i, F_DUPFD, 10);
exec->op_stack = NULL;
exec->fdin = STDIN;
exec->attrs = 0;
exec_reset_job(&exec->job);
tcgetattr(STDIN, &exec->job.tmodes);
jobc->first_job = NULL;
jobc->current_id = 1;
return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:05:28 by jhalford ### ########.fr */
/* Updated: 2017/03/24 17:28:45 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,7 @@ int mark_process_status(pid_t pid, int status)
{
t_list *plist;
t_process *p;
int signo;
if ((plist = job_getprocess(pid)))
{
@ -26,8 +27,11 @@ int mark_process_status(pid_t pid, int status)
else
{
p->state = PROCESS_COMPLETED;
if (WIFSIGNALED(status) && WTERMSIG(status) != SIGPIPE)
ft_dprintf(2, "%s\n", strsignal((WTERMSIG(status))));
if (WIFSIGNALED(status) && (signo = WTERMSIG(status)))
{
if (signo != SIGPIPE && signo != SIGINT)
ft_dprintf(2, "%s\n", strsignal(signo));
}
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
/* Updated: 2017/03/24 14:56:32 by wescande ### ########.fr */
/* Updated: 2017/03/24 18:22:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -41,7 +41,10 @@ int process_launch(t_process *p)
if (process_redirect(p))
set_exitstatus(1, 1);
else
{
exec_reset();
p->map.launch(p);
}
shell_resetfds();
shell_resetsig();
process_free(p, 0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
/* Updated: 2017/03/24 17:22:28 by gwojda ### ########.fr */
/* Updated: 2017/03/24 18:25:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,6 @@ int redirect_great(t_redir *redir)
if ((fdold = open(redir->word,
O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
exit(1);
dup2(fdold, fdnew);
dup2_close(fdold, fdnew);
return (0);
}

View file

@ -6,13 +6,13 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 15:38:14 by jhalford #+# #+# */
/* Updated: 2017/03/15 18:12:49 by jhalford ### ########.fr */
/* Updated: 2017/03/24 18:39:17 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void esc_print(char *str, unsigned char *esc)
void esc_print(int fd, char *str, unsigned char *esc)
{
char *cur;
@ -20,10 +20,10 @@ void esc_print(char *str, unsigned char *esc)
while (*cur)
{
if (is_char_esc(esc, str, cur))
ft_printf("\\%c", *cur);
ft_dprintf(fd, "\\%c", *cur);
else
ft_printf("%c", *cur);
ft_dprintf(fd, "%c", *cur);
++cur;
}
ft_printf("\n");
ft_dprintf(fd, "\n");
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 16:09:27 by wescande #+# #+# */
/* Updated: 2017/03/07 12:07:53 by wescande ### ########.fr */
/* Updated: 2017/03/24 18:42:15 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,12 +32,12 @@ static void insert_var(t_glob *gl, char *pos, char *name, char *content)
gl->pat = ft_strjoinf(ft_strjoin(s1, content), s2, 1);
new_esc = calc_expand_esc(gl->esc, ft_strlen(s1),
(int[2]){ft_strlen(content), 1},
(int[2]){delta, ft_strlen(s2)});
(int[2]){delta - 1, ft_strlen(s2)});
ft_memdel((void **)&gl->esc);
gl->esc = new_esc;
new_esc = calc_expand_esc(gl->esc2, ft_strlen(s1),
(int[2]){ft_strlen(content), 1},
(int[2]){delta, ft_strlen(s2)});
(int[2]){delta - 1, ft_strlen(s2)});
ft_memdel((void **)&gl->esc2);
gl->esc2 = new_esc;
ft_strdel(&s1);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/03/24 15:39:48 by jhalford ### ########.fr */
/* Updated: 2017/03/24 18:17:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -66,12 +66,9 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[])
(void)path;
(void)envp;
do_job_notification();
if (!SH_HAS_JOBC(data_singleton()->opts))
{
SH_ERR("jobs: %s", SH_MSG_NOJOBC);
return (1);
}
return (SH_ERR("jobs: %s", SH_MSG_NOJOBC));
do_job_notification();
ft_bzero(&data, sizeof(t_data_template));
if (cliopts_get((char**)av, g_jobs_opts, &data))
return (ft_perror("jobs"));

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:10:38 by jhalford #+# #+# */
/* Updated: 2017/03/24 17:22:36 by gwojda ### ########.fr */
/* Updated: 2017/03/24 18:24:43 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 11:37:40 by jhalford #+# #+# */
/* Updated: 2017/03/24 17:22:42 by gwojda ### ########.fr */
/* Updated: 2017/03/24 18:24:56 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,7 +25,6 @@ void job_hup_all(void)
while (jlist)
{
job = jlist->content;
builtin_jobs(NULL, NULL, NULL);
if (job->pgid != 1)
kill(-job->pgid, SIGHUP);
jlist = jlist->next;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */
/* Updated: 2017/03/10 15:08:14 by jhalford ### ########.fr */
/* Updated: 2017/03/24 17:24:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,6 @@ int put_job_in_background(t_job *j, int cont)
{
if (cont)
if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed");
SH_ERR("kill(): %s", strerror(errno));
return (0);
}

View file

@ -17,6 +17,7 @@ void data_exit(void)
t_data *data;
data = data_singleton();
ft_strdel(&data->line.input);
ft_strdel(&data->binary);
ft_sstrfree(data->env);
ft_sstrfree(data->local_var);

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 18:58:30 by ariard ### ########.fr */
/* Updated: 2017/03/24 19:18:27 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +23,10 @@ static int do_readline_routine(char **stream)
|| data->parser.state == UNDEFINED || data->lexer.state == HEREDOC);
ret = readline(has_prompt, stream);
if (ret == -1)
{
ft_strdel(stream);
exit(1);
}
if (ret == 1 && data->parser.state == UNDEFINED)
error_eof();
return (ret);
@ -50,6 +53,8 @@ static int handle_instruction(t_list **token, t_btree **ast)
else if (ret > 0)
break ;
}
/* btree_print(3, *ast, ft_putast); */
/* exit(1); */
if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
exit(1);
else if (data->parser.state != SUCCESS)