merge completion

This commit is contained in:
gwojda 2017-03-10 17:45:53 +01:00
commit e43f743d4c
54 changed files with 332 additions and 207 deletions

View file

@ -67,6 +67,7 @@ exec/bad_fd.c\
exec/error_badidentifier.c\
exec/exec_ampersand.c\
exec/exec_and_if.c\
exec/exec_bang.c\
exec/exec_case_branch.c\
exec/exec_elif.c\
exec/exec_else.c\
@ -270,6 +271,7 @@ main/main.c\
main/shell_get_avdata.c\
main/shell_get_opts.c\
main/shell_init.c\
parser/add_bang.c\
parser/add_case.c\
parser/add_cmd.c\
parser/add_condition.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/10 17:42:32 by gwojda ### ########.fr */
/* Updated: 2017/03/10 17:45:43 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -217,5 +217,6 @@ int exec_else(t_btree **ast);
int exec_var(t_btree **ast);
int exec_case_branch(t_btree **ast);
int exec_math(t_btree **ast);
int exec_bang(t_btree **ast);
#endif

View file

@ -100,7 +100,7 @@ void expand_home(t_glob *gl, char *str);
void expand_var(t_glob *tglob);
void expand_home(t_glob *gl, char *str);
int match_pattern(t_glob *tglob, char *str, char *full_word);
int dir_research(t_glob *tglob, char *p, char *pat, int rec);
int dir_research(t_glob *tglob, char *p, char *pat, int rec, int first);
char **gen_tab(const char *pat, const unsigned char *esc,
const unsigned char *esc2, int dup);
char **ft_strsplit_spe(const char *str,

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/08 20:06:47 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:57:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@
# define JOB_NOTIFIED (1 << 0)
# define JOB_BG (1 << 1)
# define JOB_IS_BG(j) (j & JOB_BG)
# define JOB_IS_FG(j) (!JOB_IS_BG(j))

View file

@ -122,6 +122,8 @@ int add_pipe(t_btree **ast, t_list **lst);
int add_var(t_btree **ast, t_list **lst);
int add_null(t_btree **ast, t_list **lst);
int add_ionumber(t_btree **ast, t_list **lst);
int add_bang(t_btree **ast, t_list **lst);
int add_bang_sep(t_btree **ast, t_list **lst);
int isloop(t_btree **ast, t_list **lst);
int isloop_condition(t_btree **ast, t_list **lst);
@ -142,6 +144,8 @@ int isnull(t_btree **ast, t_list **list);
int isionumber(t_btree **ast, t_list **lst);
int ismath(t_btree **ast, t_list **lst);
int ismath_expr(t_btree **ast, t_list **lst);
int isbang(t_btree **ast, t_list **lst);
int isbang_sep(t_btree **ast, t_list **lst);
int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast);

View file

@ -64,7 +64,7 @@ int bt_read_parse(t_read *data, char **av)
i++;
}
data->names = av[i] ? av + i : NULL;
DG("read_opts: %b", data->opts);
// DG("read_opts: %b", data->opts);
DG("\ndelim=%c\nnchars=%i\nprompt=%s\ntimeout=%i\nfd=%i",
data->delim, data->nchars, data->prompt, data->timeout, data->fd);
return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
/* Updated: 2017/03/08 16:46:12 by jhalford ### ########.fr */
/* Updated: 2017/03/10 15:36:48 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,6 +20,7 @@ int exec_ampersand(t_btree **ast)
return (exec_semi(ast));
exec = &data_singleton()->exec;
push(&exec->op_stack, TK_AMP);
exec->job.attrs |= JOB_BG;
ft_exec(&(*ast)->left);
exec->attrs &= ~EXEC_AOL_MASK;
exec->job.attrs &= ~JOB_BG;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:18:41 by jhalford ### ########.fr */
/* Updated: 2017/03/10 14:26:32 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

25
42sh/src/exec/exec_bang.c Normal file
View file

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_bang.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/10 14:46:27 by ariard #+# #+# */
/* Updated: 2017/03/10 15:51:37 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int exec_bang(t_btree **ast)
{
t_exec *exec;
exec = &data_singleton()->exec;
push(&exec->op_stack, TK_BANG);
ft_exec(&(*ast)->left);
ft_exec(&(*ast)->right);
set_exitstatus(ft_atoi(ft_getenv(data_singleton()->env, "?")) ? 0 : 1, 1);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/10 11:58:54 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:58:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,16 +24,13 @@ int exec_leaf(t_btree **ast)
{
DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]);
job_addprocess(&p);
DG("[BG:%i]", JOB_IS_BG(job->attrs));
if (IS_PIPEEND(p))
{
if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0);
else
put_job_in_background(job, 0);
job->pgid = 0;
}
}
if (p.fdout != STDOUT)
close(p.fdout);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
/* Updated: 2017/03/10 13:13:49 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:49:14 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,15 +20,13 @@ int exec_reset(void)
/* exec->fd_save[0] = 1;//fcntl(STDIN, F_DUPFD_CLOEXEC); */
/* exec->fd_save[1] = 1;//fcntl(STDOUT, F_DUPFD_CLOEXEC); */
/* exec->fd_save[2] = 1;//fcntl(STDERR, F_DUPFD_CLOEXEC); */
DG("check 0");
if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1)
ft_dprintf(2, "{red}%s: internal fcntl error errno=%i %s{eoc}\n", SHELL_NAME, errno);
DG("check 1");
if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1)
ft_dprintf(2, "{red}%s: internal fcntl error errno=%i %s{eoc}\n", SHELL_NAME, errno);
if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1)
ft_dprintf(2, "{red}%s: internal fcntl error errno=%i %s{eoc}\n", SHELL_NAME, errno);
DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]);
if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i %s{eoc}\n", SHELL_NAME, errno);
if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i %s{eoc}\n", SHELL_NAME, errno);
if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i %s{eoc}\n", SHELL_NAME, errno);
/* DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]); */
exec->op_stack = NULL;
exec->fdin = STDIN;
exec->attrs = 0;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
/* Updated: 2017/03/08 16:41:45 by jhalford ### ########.fr */
/* Updated: 2017/03/10 14:55:05 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,16 +6,18 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */
/* Updated: 2017/03/06 16:58:38 by jhalford ### ########.fr */
/* Updated: 2017/03/10 13:59:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int fd_is_valid(int fd, int has_flag)
int fd_is_valid(int fd, int has_mode)
{
int flags;
int fd_flags;
int fd_modes;
flags = fcntl(fd, F_GETFD);
return ((flags != -1 || errno != EBADF) && flags & has_flag);
fd_modes = fcntl(fd, F_GETFL);
fd_flags = fcntl(fd, F_GETFD);
return ((fd_flags != -1 || errno != EBADF) && fd_modes & has_mode);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
/* Updated: 2017/03/08 11:57:19 by jhalford ### ########.fr */
/* Updated: 2017/03/10 15:45:12 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,6 +31,7 @@ t_itof g_execmap[] =
{TK_ASSIGNEMENT_WORD, &exec_var},
{MATH, &exec_math},
{SUBSHELL, &exec_leaf},
{TK_BANG, &exec_bang},
{CMD, &exec_leaf},
{0, 0},
};

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
/* Updated: 2017/03/08 15:07:47 by wescande ### ########.fr */
/* Updated: 2017/03/10 17:08:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/03/10 11:58:53 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:50:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,9 +40,12 @@ int launch_process(t_process *p)
{
DG("gonna reset fds");
process_resetfds(p);
return (-1);
return (1);
}
p->pid = pid;
process_setgroup(p, pid);
/* process_resetfds(p); */
if (p->fdout != STDOUT)
close(p->fdout);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
/* Updated: 2017/03/08 15:18:36 by wescande ### ########.fr */
/* Updated: 2017/03/10 17:09:14 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/10 12:51:05 by jhalford ### ########.fr */
/* Updated: 2017/03/10 17:09:04 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2017/03/09 15:14:43 by jhalford ### ########.fr */
/* Updated: 2017/03/10 15:31:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,6 +51,7 @@ int process_redirect(t_process *p)
}
redirs = redirs->next;
}
DG("redirecting [%i:%i] [%i]", p->fdin, p->fdout, p->to_close);
if (p->to_close != STDIN)
close(p->to_close);
if (p->fdin != STDIN)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/09 14:51:23 by jhalford #+# #+# */
/* Updated: 2017/03/10 13:09:25 by jhalford ### ########.fr */
/* Updated: 2017/03/10 14:35:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
/* Updated: 2017/03/09 14:28:39 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:51:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,8 +23,7 @@ int process_setgroup(t_process *p, pid_t pid)
if (!SH_HAS_JOBC(data->opts))
return (0);
j = &data->exec.job;
if (!j->pgid)
j->pgid = pid ? pid : getpid();
/* DG("setpgid(%i, %i)", pid, j->pgid); */
setpgid(pid, j->pgid);
if (pid == 0 && JOB_IS_FG(j->attrs))
tcsetpgrp(STDIN, j->pgid);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
/* Updated: 2017/03/06 16:54:43 by jhalford ### ########.fr */
/* Updated: 2017/03/10 14:31:24 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,14 +17,14 @@ int redirect_greatand(t_redir *redir)
int fdold;
int fdnew;
if (ft_strcmp(redir->word, "-"))
if (ft_strcmp(redir->word, "-") == 0)
{
close(redir->n);
return (0);
}
if (!ft_stris(redir->word, ft_isdigit))
{
ft_dprintf(2, "%s: %s: can only be digits", SHELL_NAME, redir->word);
ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n", SHELL_NAME, redir->word);
return (1);
}
fdold = ft_atoi(redir->word);
@ -33,9 +33,10 @@ int redirect_greatand(t_redir *redir)
return (0);
if (fdold > 9)
return (bad_fd(fdold));
if (fd_is_valid(fdold, O_RDONLY))
if (fd_is_valid(fdold, O_RDONLY | O_RDWR))
dup2_close(fdold, fdnew);
else
return (bad_fd(fdold));
close(fdnew);
/* return (bad_fd(fdold)); */
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */
/* Updated: 2017/03/06 16:53:29 by jhalford ### ########.fr */
/* Updated: 2017/03/10 14:00:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,14 +17,14 @@ int redirect_lessand(t_redir *redir)
int fdold;
int fdnew;
if (ft_strcmp(redir->word, "-"))
if (ft_strcmp(redir->word, "-") == 0)
{
close(redir->n);
return (0);
}
if (!ft_stris(redir->word, ft_isdigit))
{
ft_dprintf(2, "%s: %s: can only be digits", SHELL_NAME, redir->word);
ft_dprintf(2, "{red}%s: %s: can only be digits{eoc}\n", SHELL_NAME, redir->word);
return (1);
}
fdold = ft_atoi(redir->word);
@ -33,9 +33,10 @@ int redirect_lessand(t_redir *redir)
return (0);
if (fdold > 9)
return (bad_fd(fdold));
if (fd_is_valid(fdold, O_WRONLY))
if (fd_is_valid(fdold, O_WRONLY | O_RDWR))
dup2_close(fdold, fdnew);
else
return (bad_fd(fdold));
close(fdnew);
/* return (bad_fd(fdold)); */
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/08 16:46:51 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:22:00 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,10 +28,11 @@ int set_process(t_process *p, t_btree *ast)
return (1);
fds[PIPE_WRITE] = STDOUT;
fds[PIPE_READ] = STDIN;
if (op == TK_AMP)
exec->job.attrs |= JOB_BG;
else if (op == TK_PIPE)
if (op == TK_PIPE)
{
pipe(fds);
DG("[%i] -> PIPE -> [%i]", fds[PIPE_WRITE], fds[PIPE_READ]);
}
p->fdin = exec->fdin;
p->to_close = fds[PIPE_READ];
p->fdout = fds[PIPE_WRITE];

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:19:50 by wescande #+# #+# */
/* Updated: 2017/03/08 14:59:17 by wescande ### ########.fr */
/* Updated: 2017/03/10 14:32:31 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:10 by wescande #+# #+# */
/* Updated: 2017/03/08 14:58:54 by wescande ### ########.fr */
/* Updated: 2017/03/10 14:32:22 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
/* Updated: 2017/03/08 23:46:06 by ariard ### ########.fr */
/* Updated: 2017/03/08 23:46:06 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,51 +14,83 @@
#define BUF_SIZE 1024
/*static char *manage_output(int *fds)
{
int ret;
char buf[BUF_SIZE + 1];
char *output;
{
int ret;
char buf[BUF_SIZE + 1];
char *output;
output = NULL;
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0)
{
buf[ret] = 0;
ft_strappend(&output, buf);
}
close(fds[PIPE_READ]);
return (output);
}
*/
static t_btree *gen_t_btree(const char *command)
{
t_btree *ast;
t_astnode item;
int len;
unsigned char *esc;
ft_bzero(&item, sizeof(t_astnode));
item.type = SUBSHELL;
ast = btree_create_node(&item, sizeof(t_astnode));
ft_bzero(&item, sizeof(t_astnode));
item.type = CMD;
len = ft_strlen(command);
esc = ft_memalloc((len >> 3) + 1);
ft_ld_pushfront(&item.data.cmd.token, gen_tab(command, esc, esc, 1));
ast->right = btree_create_node(&item, sizeof(t_astnode));
return (ast);
}
char *command_getoutput(char *command)
{
t_btree *ast;
char *output;
char buf[BUF_SIZE + 1];
t_exec *exec;
t_process p;
int ret;
int pid;
return (NULL);
output = NULL;
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0)
exec = &data_singleton()->exec;
DG("%p exec ?", exec);
DG("\033[38;5;46mbefore");
ast = gen_t_btree(command);
DG();
if (set_process(&p, ast))
return (NULL);
DG();
if (!(pid = launch_subshell(&p)))
return (NULL);
waitpid(pid, &ret, WUNTRACED);
DG();
// exec_leaf(&ast);
/*
DG();
set_process(&p, ast);
DG();
launch_process(&p);
DG();
close(p.fdout);*/
DG();
while ((ret = read(exec->fdin, buf, BUF_SIZE)) > 0)
{
buf[ret] = 0;
ft_strappend(&output, buf);
}
close(fds[PIPE_READ]);
DG();
close(exec->fdin);
DG("done with %s\033[0m", output);
return (output);
}
*/
char *command_getoutput(char *command)
{
return (ft_strdup(command));
/* int fds[2]; */
/* t_btree *ast; */
/* t_astnode item; */
/* char *output; */
/* char buf[BUF_SIZE + 1]; */
/* int ret; */
/* t_exec *exec; */
/* output = NULL; */
/* exec = &data_singleton()->exec; */
/* item.type = SUBSHELL; */
/* item.data.sstr = malloc(4 * sizeof(char *)); */
/* item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]); */
/* item.data.sstr[1] = ft_strdup("-c"); */
/* item.data.sstr[2] = ft_strdup(command); */
/* item.data.sstr[3] = NULL; */
/* ast = btree_create_node(&item, sizeof(item)); */
/* pipe(fds); */
/* exec->process.fdout = fds[PIPE_WRITE]; */
/* exec_command(&ast); */
/* exec->process.fdout = STDOUT; */
/* close(fds[PIPE_WRITE]); */
/* while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE))) */
/* { */
/* buf[ret] = 0; */
/* ft_strappend(&output, buf); */
/* } */
/* close(fds[PIPE_READ]); */
/* return (output); */
}

View file

@ -21,40 +21,44 @@ int is_directory(const char *path)
}
static void dir_list_content(t_glob *gl, char **str, char *pat,
int recursive)
int recursive)
{
char *path_tmp;
char *path;
if (str[1][0] != '.')
{
if (*str[0] == '/' && !*(str[0] + 1))
path_tmp = ft_strjoin(str[0], str[1]);
path = ft_strjoin(str[0], str[1]);
else
path_tmp = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1);
path = ft_strjoinf(ft_strjoin(str[0], "/"), str[1], 1);
if (recursive)
dir_research(gl, path_tmp, pat, recursive);
dir_research(gl, path, pat, recursive, 0);
gl->pat = pat;
if (match_pattern(gl, str[1], path_tmp))
if (match_pattern(gl, str[1], path))
{
gl->found = 1;
ft_ld_pushfront(&gl->match_tmp, ft_strdup(path_tmp + gl->cur_dir * 2 *
(path_tmp[0] == '.' && path_tmp[1] == '/')));
ft_ld_pushfront(&gl->match_tmp, ft_strdup(path + gl->cur_dir * 2 *
(path[0] == '.' && path[1] == '/')));
}
gl->pat = pat;
ft_strdel(&path_tmp);
ft_strdel(&path);
}
}
int dir_research(t_glob *gl, char *p,
char *pat, int recursive)
char *pat, int recursive, int first)
{
DIR *dir;
struct dirent *in;
if (!pat)
if (!*pat)
{
gl->found = 1;
ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p, "/"));
if (!first)
ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 *
(p[0] == '.' && p[1] == '/'), "/"));
else
ft_ld_pushfront(&gl->match_tmp, ft_strdup(""));
return (0);
}
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))

View file

@ -13,7 +13,7 @@
#include "minishell.h"
static void expand_all_bquote(t_bquote *me, char *content,
char *ifs)
char *ifs)
{
char *content2;
@ -45,7 +45,8 @@ static void init_expand(t_bquote *me, char *content, int esc)
ifs = esc ? NULL : ft_getenv(data_singleton()->env, "IFS");
content = ft_strtok(content, ifs);
if (!(content2 = ft_strtok(NULL, ifs)))
if (!content || !(content2 = ft_strtok(NULL, ifs)))
{
ft_ld_pushfront(me->wk, gen_tab(ft_strjoinf(ft_strjoin(me->s1, content),
me->s2, 1),
calc_expand_esc(me->esc, ft_strlen(me->s1),
@ -56,6 +57,7 @@ static void init_expand(t_bquote *me, char *content, int esc)
(int[2]){ft_strlen(content), 1},
(int[2]){ft_strlen(me->s1) + ft_strlen(me->mid),
ft_strlen(me->s2)}), 0));
}
else
{
ft_ld_pushfront(me->wk, gen_tab(ft_strjoin(me->s1, content),
@ -72,7 +74,8 @@ static char *get_output(char *command)
char *output;
int len;
output = command_getoutput(command);
if (!(output = command_getoutput(command)))
return (ft_strnew(0));
len = ft_strlen(output);
while (output[--len] == '\n')
output[len] = '\0';
@ -96,7 +99,9 @@ static int search_bquote(t_bquote *me)
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
me->s2 = ft_strdup(me->str + 1);
content = get_output(me->mid);
DG();
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
DG();
ft_strdel(&me->mid);
ft_strdel(&me->s1);
ft_strdel(&me->s2);

View file

@ -96,9 +96,9 @@ char **glob(char *pat, unsigned char *esc,
gl.cur_dir = 1;
gl.pat = CH(gl.m_pat)[0];
if ((gl.esc = UCH(gl.m_pat)[1]) && gl.pat[0] != '/')
dir_research(&gl, ".", gl.pat, 0);
dir_research(&gl, ".", gl.pat, 0, 1);
else
dir_research(&gl, "/", gl.pat + 1, 0);
dir_research(&gl, "/", gl.pat + 1, 0, 1);
if (!gl.found)
ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0]));
else

View file

@ -73,7 +73,7 @@ static int match_star(t_glob *gl, char *str, char *full_word)
if (gl->pat[1] == '*' &&
!is_char_esc(gl->esc, ((char **)gl->m_pat->content)[0], gl->pat + 1))
dir_research(gl, full_word, gl->pat + 1, 1);
dir_research(gl, full_word, gl->pat + 1, 1, 0);
if (!*gl->pat || (*gl->pat == '*' && !*++gl->pat))
return (1);
pat = gl->pat;
@ -119,7 +119,7 @@ int match_pattern(t_glob *gl, char *str, char *full_word)
else if (*gl->pat == '*')
return (match_star(gl, str, full_word));
else if (*gl->pat == '/' && !*str && is_directory(full_word))
dir_research(gl, full_word, gl->pat + 1, 0);
return (dir_research(gl, full_word, gl->pat + 1, 0, 0));
else if (*gl->pat != *str)
return (0);
++str;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
/* Updated: 2017/02/21 20:09:24 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:27:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/03/08 20:16:09 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:45:11 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,7 +29,10 @@ int job_addprocess(t_process *p)
}
job = jobc->first_job->content;
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
/* DG("[BG:%i]", JOB_IS_BG(job->attrs)); */
if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p))
{
job_notify_new(job);
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */
/* Updated: 2017/03/08 18:28:01 by jhalford ### ########.fr */
/* Updated: 2017/03/10 15:36:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
/* Updated: 2017/03/08 18:18:34 by jhalford ### ########.fr */
/* Updated: 2017/03/10 14:40:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
/* Updated: 2017/03/10 12:41:11 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:45:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
/* Updated: 2017/03/08 20:46:24 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:48:38 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,12 +19,15 @@ int job_wait(int id)
t_jobc *jobc;
int status;
DG("job wait [%i]", id);
jobc = &data_singleton()->jobc;
j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
DG("job wait id=[%i], pgid=[%i]", id, j->pgid);
do
{
pid = waitpid(-j->pgid, &status, WUNTRACED);
while (!mark_process_status(pid, status)
DG("pid=[%d]", pid);
}
while (pid > 1 && !mark_process_status(pid, status)
&& !job_is_stopped(id)
&& !job_is_completed(id));
return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
/* Updated: 2017/03/08 20:08:26 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:27:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */
/* Updated: 2017/03/08 20:33:24 by jhalford ### ########.fr */
/* Updated: 2017/03/10 15:08:14 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/08 20:33:21 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:27:05 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,10 @@ int put_job_in_foreground(t_job *j, int cont)
t_jobc *jobc;
jobc = &data_singleton()->jobc;
DG("givving terminal to job [%i]", j->pgid);
tcsetpgrp(STDIN, j->pgid);
/* tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); */
if (cont)
{
tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
@ -26,11 +29,12 @@ int put_job_in_foreground(t_job *j, int cont)
}
job_wait(j->id);
job_remove(j->id);
tcsetpgrp(STDIN, jobc->shell_pgid);
if (SH_HAS_JOBC(data_singleton()->opts))
{
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
/* { */
tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
}
/* } */
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:58 by jhalford #+# #+# */
/* Updated: 2017/03/08 23:34:08 by ariard ### ########.fr */
/* Updated: 2017/03/10 13:45:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/09 00:09:19 by ariard ### ########.fr */
/* Updated: 2017/03/10 15:48:30 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,6 +22,8 @@ int readline(int fd, int prompt, char **input)
}
readline_init(prompt);
*input = ft_read_stdin();
if (STR)
ft_current_str(STR, POS);
ft_putchar('\n');
if (!prompt)
*input = ft_history_parsing();

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/10 12:12:26 by jhalford ### ########.fr */
/* Updated: 2017/03/10 13:48:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/10 13:28:24 by jhalford ### ########.fr */
/* Updated: 2017/03/10 16:20:35 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_bang.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/10 14:57:45 by ariard #+# #+# */
/* Updated: 2017/03/10 15:43:54 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int isbang(t_btree **ast, t_list **lst)
{
t_astnode *node;
(void)lst;
node = NULL;
if (*ast)
{
node = (*ast)->item;
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|| node->type == TK_AMP) && isbang(&(*ast)->right, lst) == 1)
return (1);
if (node->type == TK_BANG && node->full == 0)
return (1);
}
return (0);
}
int isbang_sep(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
token = (*lst)->content;
if (*ast)
{
node = (*ast)->item;
if ((token->type == TK_SEMI || token->type == TK_AMP || token->type == TK_NEWLINE
|| token->type == TK_AND_IF || token->type == TK_OR_IF) && node->type == TK_BANG
&& node->nest == 0)
node->full = 1;
if (token->type == TK_PIPE && node->type == TK_BANG && node->full == 0)
return (1);
}
return (0);
}
int add_bang(t_btree **ast, t_list **lst)
{
t_astnode *node;
t_token *token;
DG("add bang");
token = (*lst)->content;
node = (*ast)->item;
if ((token->type == TK_CASE || token->type == TK_WHILE
|| token->type == TK_IF || token->type == TK_UNTIL || token->type == TK_FOR
|| token->type == SUBSHELL || token->type == TK_LBRACE)
&& node->type == TK_BANG)
node->nest++;
if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI
|| token->type == TK_RBRACE || token->type == TK_PAREN_CLOSE)
&& node->type == TK_BANG && node->nest > 0)
node->nest--;
return (add_cmd(&(*ast)->right, lst));
}
int add_bang_sep(t_btree **ast, t_list **lst)
{
return (add_sep(&(*ast)->right, lst));
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
/* Updated: 2017/03/07 22:46:00 by ariard ### ########.fr */
/* Updated: 2017/03/09 20:00:19 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,7 +32,6 @@ int iscase_pattern(t_btree **ast, t_list **lst)
t_astnode *node;
t_token *token;
// DG(" add pattern");
node = NULL;
token = (*lst)->content;
if (*ast)
@ -90,7 +89,6 @@ int add_pattern(t_btree **ast, t_list **lst)
t_token *token;
char **my_tab;
DG("add pattern");
token = (*lst)->content;
node = (*ast)->item;
if ((my_tab = (char **)malloc(sizeof(char *) * 4)))

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/09 19:44:51 by ariard ### ########.fr */
/* Updated: 2017/03/10 15:22:44 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,6 +31,7 @@ t_distrostree g_distrostree[] =
{&isfunc_name, &add_null},
{&isfunc, &add_func_cmd},
{&isionumber, &add_ionumber},
{&isbang, &add_bang},
{&isnull, &add_null},
};
@ -71,7 +72,7 @@ int add_cmd(t_btree **ast, t_list **lst)
int i;
i = -1;
while (++i < 17)
while (++i < 18)
if (g_distrostree[i].test(ast, lst) == 1)
{
DG("add : %d", i);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/03/10 13:19:14 by jhalford ### ########.fr */
/* Updated: 2017/03/10 13:45:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
/* Updated: 2017/03/07 22:46:57 by ariard ### ########.fr */
/* Updated: 2017/03/10 15:43:01 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,10 +29,11 @@ int add_sep(t_btree **ast, t_list **lst)
return (add_subshell_sep(ast, lst));
else if (isfunc(ast, lst))
return (add_func_sep(ast, lst));
else if (isbang_sep(ast, lst))
return (add_bang_sep(ast, lst));
if (!*ast)
gen_node(ast);
token = (*lst)->content;
//watch != TK_DO
new_node = NULL;
gen_node(&new_node);
join_ast(ast, &new_node);

View file

@ -58,6 +58,8 @@ t_aggrematch g_aggrematch[] =
{TK_RBRACE, CMD_SUPERIOR, BRACE_CLAUSE, TK_LBRACE},
{TK_AND_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR},
{TK_OR_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR},
{TK_AND_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE},
{TK_OR_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE},
//watch this
{SEPARATOR_OP, MATH_SUP, CMD_SUPERIOR, MATH_SUP},
{SEPARATOR_OP, CMD_SUPERIOR, SEPARATOR, 0},
@ -142,7 +144,7 @@ t_aggrematch g_aggrematch[] =
{IO_REDIRECT, TK_PAREN_OPEN, CMD_PREFIX, 0},
{IO_REDIRECT, TK_LBRACE, CMD_PREFIX, 0},
{IO_REDIRECT, COMPLETE_COMMANDS, CMD_PREFIX, 0},
{IO_REDIRECT, TK_BANG, CMD_PREFIX, 0},
{IO_REDIRECT, TK_BANG, CMD_PREFIX, TK_BANG},
{IO_REDIRECT, SEPARATOR_OP, CMD_PREFIX, 0},
{IO_REDIRECT, NEWLINE_LIST, CMD_PREFIX, 0},
{REDIRECT_LIST, COMPOUND_COMMAND, COMPOUND_COMMAND, COMPOUND_COMMAND},
@ -156,7 +158,7 @@ t_aggrematch g_aggrematch[] =
{CMD_PREFIX, TK_PAREN_OPEN, SIMPLE_COMMAND, 0},
{CMD_PREFIX, TK_LBRACE, SIMPLE_COMMAND, 0},
{CMD_PREFIX, COMPLETE_COMMANDS, SIMPLE_COMMAND, 0},
{CMD_PREFIX, TK_BANG, SIMPLE_COMMAND, 0},
{CMD_PREFIX, TK_BANG, SIMPLE_COMMAND, TK_BANG},
{CMD_PREFIX, SEPARATOR_OP, SIMPLE_COMMAND, 0},
{CMD_PREFIX, NEWLINE_LIST, SIMPLE_COMMAND, 0},
@ -166,7 +168,7 @@ t_aggrematch g_aggrematch[] =
{CMD_NAME, TK_PAREN_OPEN, CMD_SUPERIOR, 0},
{CMD_NAME, TK_LBRACE, CMD_SUPERIOR, 0},
{CMD_NAME, COMPLETE_COMMANDS, CMD_SUPERIOR, 0},
{CMD_NAME, TK_BANG, CMD_SUPERIOR, 0},
{CMD_NAME, TK_BANG, CMD_SUPERIOR, TK_BANG},
{CMD_NAME, SEPARATOR_OP, CMD_SUPERIOR, 0},
{CMD_NAME, NEWLINE_LIST, CMD_SUPERIOR, 0},
{CMD_NAME, TK_WHILE, CMD_SUPERIOR, 0},
@ -224,7 +226,7 @@ t_aggrematch g_aggrematch[] =
{AND_OR_MINOR, TK_LBRACE, AND_OR_MAJOR, 0},
{AND_OR_MINOR, COMPLETE_COMMANDS, AND_OR_MAJOR, 0},
{AND_OR_MINOR, AND_OR_MAJOR, AND_OR_MAJOR, 0},
{AND_OR_MINOR, TK_BANG, AND_OR_MAJOR, 0},
{AND_OR_MINOR, TK_BANG, AND_OR_MAJOR, TK_BANG},
{COMMAND, SEQUENCE, PIPE_SEMI_SEQUENCE, 0},
// watch
{COMMAND, COMPOUND_LIST, PIPE_SEMI_SEQUENCE, 0},
@ -237,11 +239,11 @@ t_aggrematch g_aggrematch[] =
{COMMAND, TK_THEN, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, TK_ELIF, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, TK_ELSE, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, TK_BANG},
{COMMAND, SEPARATOR_OP, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, NEWLINE_LIST, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, LINEBREAK, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, TK_BANG},
{COMMAND, TK_PAREN_OPEN, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, TK_LBRACE, PIPE_SEMI_SEQUENCE, 0},
{COMMAND, COMPLETE_COMMANDS, PIPE_SEMI_SEQUENCE, 0},
@ -258,11 +260,11 @@ t_aggrematch g_aggrematch[] =
{COMPOUND_COMMAND, TK_THEN, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, TK_ELIF, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, TK_ELSE, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, TK_BANG, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, TK_BANG, PIPE_CLOSE_SEQUENCE, TK_BANG},
{COMPOUND_COMMAND, SEPARATOR_OP, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, NEWLINE_LIST, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, LINEBREAK, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, TK_BANG, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, TK_BANG, PIPE_CLOSE_SEQUENCE, TK_BANG},
{COMPOUND_COMMAND, TK_PAREN_OPEN, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, TK_LBRACE, PIPE_CLOSE_SEQUENCE, 0},
{COMPOUND_COMMAND, COMPLETE_COMMANDS, PIPE_CLOSE_SEQUENCE, 0},
@ -275,7 +277,7 @@ t_aggrematch g_aggrematch[] =
{END_COMMAND, TK_WHILE, PIPE_SEQUENCE, 0},
{END_COMMAND, TK_UNTIL, PIPE_SEQUENCE, 0},
{END_COMMAND, LINEBREAK, PIPE_SEQUENCE, 0},
{END_COMMAND, TK_BANG, PIPE_SEQUENCE, 0},
{END_COMMAND, TK_BANG, PIPE_SEQUENCE, TK_BANG},
{END_COMMAND, TK_PAREN_OPEN, PIPE_SEQUENCE, 0},
{END_COMMAND, TK_LBRACE, PIPE_SEQUENCE, 0},
{END_COMMAND, COMPLETE_COMMANDS, PIPE_SEQUENCE, 0},
@ -321,7 +323,7 @@ t_aggrematch g_aggrematch[] =
{PIPELINE, COMPOUND_LIST, AND_OR, 0},
{PIPELINE, CASE_LIST_NS, AND_OR, 0},
{PIPELINE, LINEBREAK, AND_OR, 0},
{PIPELINE, TK_BANG, AND_OR, 0},
{PIPELINE, TK_BANG, AND_OR, TK_BANG},
{PIPELINE, TK_PAREN_OPEN, AND_OR, 0},
{PIPELINE, TK_LBRACE, AND_OR, 0},
{PIPELINE, COMPLETE_COMMANDS, AND_OR, 0},
@ -346,7 +348,7 @@ t_aggrematch g_aggrematch[] =
{AND_OR, SEPARATOR_OP, LIST, LIST},
{AND_OR, NEWLINE_LIST, LIST, 0},
{AND_OR, LINEBREAK, LIST, 0},
{AND_OR, TK_BANG, LIST, 0},
{AND_OR, TK_BANG, LIST, TK_BANG},
{AND_OR, TK_LBRACE, LIST, 0},
{AND_OR, COMPLETE_COMMANDS, LIST, 0},
{LIST, NEWLINE_LIST, COMPLETE_COMMAND, 0},
@ -368,21 +370,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
return (1);
i = 0;
head = (*stack)->content;
DG("aggregate head %s && sym %s",
read_state(*head), read_state(*new_sym));
// DG("aggregate head %s && sym %s",
// read_state(*head), read_state(*new_sym));
while (g_aggrematch[i].top)
{
if (*new_sym == g_aggrematch[i].top
&& MATCH_STACK(*head, g_aggrematch[i].under))
{
DG("MATCH : %s", read_state(g_aggrematch[i].new_sym));
// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym));
*new_sym = g_aggrematch[i].new_sym;
if (g_aggrematch[i].erase_sym)
{
pop_stack(stack, g_aggrematch[i].erase_sym);
head = (*stack)->content;
DG("stack after pop: %s", read_state(*head));
// DG("stack after pop: %s", read_state(*head));
}
if (eval_sym(stack, *new_sym))
{

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/03/09 19:45:53 by ariard ### ########.fr */
/* Updated: 2017/03/10 15:34:58 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,7 @@ t_treematch g_treematch[] =
{
{TK_WORD, &add_cmd},
{TK_PIPE, &add_sep},
{TK_BANG, &add_sep},
{TK_BANG, &add_cmd},
{TK_SEMI, &add_sep},
{TK_GREAT, &add_cmd},
{TK_LESS, &add_cmd},

View file

@ -36,7 +36,6 @@ t_stackmatch g_stackmatch[] =
{TK_IO_NUMBER, TK_PAREN_OPEN},
{TK_IO_NUMBER, TK_LBRACE},
{TK_IO_NUMBER, COMPLETE_COMMANDS},
{TK_IO_NUMBER, TK_BANG},
{TK_IO_NUMBER, SEPARATOR_OP},
{TK_IO_NUMBER, NEWLINE_LIST},
{TK_IO_NUMBER, PIPE_SEMI_SEQUENCE},
@ -47,9 +46,10 @@ t_stackmatch g_stackmatch[] =
{TK_IO_NUMBER, AND_OR_MAJOR},
{TK_AND_IF, AND_OR},
{TK_AND_IF, CMD_SUPERIOR},
{TK_AND_IF, PIPE_SEMI_SEQUENCE},
{TK_OR_IF, AND_OR},
{TK_OR_IF, CMD_SUPERIOR},
{TK_OR_IF, AND_OR},
{TK_OR_IF, PIPE_SEMI_SEQUENCE},
{TK_DSEMI, LINEBREAK},
{TK_DSEMI, TK_BANG},
{TK_DSEMI, COMPLETE_COMMANDS},
@ -67,7 +67,6 @@ t_stackmatch g_stackmatch[] =
{TK_LESS, CMD_WORD},
{TK_LESS, CMD_NAME},
{TK_LESS, LINEBREAK},
{TK_LESS, TK_BANG},
{TK_LESS, TK_PAREN_OPEN},
{TK_LESS, TK_LBRACE},
{TK_LESS, COMPLETE_COMMANDS},
@ -91,7 +90,6 @@ t_stackmatch g_stackmatch[] =
{TK_GREAT, TK_PAREN_OPEN},
{TK_GREAT, TK_LBRACE},
{TK_GREAT, COMPLETE_COMMANDS},
{TK_GREAT, TK_BANG},
{TK_GREAT, SEPARATOR_OP},
{TK_GREAT, NEWLINE_LIST},
{TK_GREAT, PIPE_SEMI_SEQUENCE},
@ -109,7 +107,6 @@ t_stackmatch g_stackmatch[] =
{TK_DLESS, CMD_WORD},
{TK_DLESS, CMD_NAME},
{TK_DLESS, LINEBREAK},
{TK_DLESS, TK_BANG},
{TK_DLESS, TK_PAREN_OPEN},
{TK_DLESS, TK_LBRACE},
{TK_DLESS, COMPLETE_COMMANDS},
@ -123,28 +120,6 @@ t_stackmatch g_stackmatch[] =
{TK_DLESS, CMD_SUPERIOR},
{TK_DLESS, AND_OR_MAJOR},
{TK_DLESSDASH, TK_IO_NUMBER},
{TK_DLESSDASH, REDIRECT_LIST},
{TK_DLESSDASH, CMD_SUFFIX},
{TK_DLESSDASH, CMD_PREFIX},
{TK_DLESSDASH, CMD_WORD},
{TK_DLESSDASH, CMD_NAME},
{TK_DLESSDASH, LINEBREAK},
{TK_DLESSDASH, TK_BANG},
{TK_DLESSDASH, TK_PAREN_OPEN},
{TK_DLESSDASH, TK_LBRACE},
{TK_DLESSDASH, COMPLETE_COMMANDS},
{TK_DLESSDASH, TK_BANG},
{TK_DLESSDASH, TK_BANG},
{TK_DLESSDASH, SEPARATOR_OP},
{TK_DLESSDASH, NEWLINE_LIST},
{TK_DLESSDASH, PIPE_SEMI_SEQUENCE},
{TK_DLESSDASH, PIPE_CLOSE_SEQUENCE},
{TK_DLESSDASH, SEQUENCE},
// watch !
{TK_DLESSDASH, CMD_SUPERIOR},
{TK_DLESSDASH, AND_OR_MAJOR},
{TK_DGREAT, TK_IO_NUMBER},
{TK_DGREAT, REDIRECT_LIST},
{TK_DGREAT, CMD_SUFFIX},
@ -156,8 +131,6 @@ t_stackmatch g_stackmatch[] =
{TK_DGREAT, TK_PAREN_OPEN},
{TK_DGREAT, TK_LBRACE},
{TK_DGREAT, COMPLETE_COMMANDS},
{TK_DGREAT, TK_BANG},
{TK_DGREAT, TK_BANG},
{TK_DGREAT, SEPARATOR_OP},
{TK_DGREAT, NEWLINE_LIST},
{TK_DGREAT, PIPE_SEMI_SEQUENCE},
@ -178,8 +151,6 @@ t_stackmatch g_stackmatch[] =
{TK_LESSAND, TK_PAREN_OPEN},
{TK_LESSAND, TK_LBRACE},
{TK_LESSAND, COMPLETE_COMMANDS},
{TK_LESSAND, TK_BANG},
{TK_LESSAND, TK_BANG},
{TK_LESSAND, SEPARATOR_OP},
{TK_LESSAND, NEWLINE_LIST},
{TK_LESSAND, PIPE_SEMI_SEQUENCE},
@ -200,8 +171,6 @@ t_stackmatch g_stackmatch[] =
{TK_GREATAND, TK_PAREN_OPEN},
{TK_GREATAND, TK_LBRACE},
{TK_GREATAND, COMPLETE_COMMANDS},
{TK_LESSAND, TK_BANG},
{TK_GREATAND, TK_BANG},
{TK_GREATAND, SEPARATOR_OP},
{TK_GREATAND, NEWLINE_LIST},
{TK_GREATAND, PIPE_SEMI_SEQUENCE},
@ -217,7 +186,6 @@ t_stackmatch g_stackmatch[] =
{TK_IF, TK_PAREN_OPEN},
{TK_IF, TK_LBRACE},
{TK_IF, COMPLETE_COMMANDS},
{TK_IF, TK_BANG},
{TK_IF, SEPARATOR_OP},
{TK_IF, NEWLINE_LIST},
{TK_IF, SEQUENCE},
@ -260,7 +228,6 @@ t_stackmatch g_stackmatch[] =
{TK_CASE, TK_PAREN_OPEN},
{TK_CASE, TK_LBRACE},
{TK_CASE, COMPLETE_COMMANDS},
{TK_CASE, TK_BANG},
{TK_CASE, TK_DO},
{TK_CASE, TK_THEN},
{TK_CASE, TK_PAREN_CLOSE},
@ -281,10 +248,8 @@ t_stackmatch g_stackmatch[] =
{TK_IN, NAME},
{TK_ESAC, CASE_LIST_NS},
{TK_ESAC, LINEBREAK},
{TK_ESAC, TK_BANG},
{TK_ESAC, TK_IN},
{TK_WHILE, LINEBREAK},
{TK_WHILE, TK_BANG},
{TK_WHILE, TK_PAREN_OPEN},
{TK_WHILE, TK_LBRACE},
{TK_WHILE, COMPLETE_COMMANDS},
@ -306,7 +271,6 @@ t_stackmatch g_stackmatch[] =
{TK_WHILE, TK_THEN},
{TK_WHILE, COMPLETE_CONDITION},
{TK_UNTIL, LINEBREAK},
{TK_UNTIL, TK_BANG},
{TK_UNTIL, TK_PAREN_OPEN},
{TK_UNTIL, TK_LBRACE},
{TK_UNTIL, COMPLETE_COMMANDS},
@ -332,8 +296,6 @@ t_stackmatch g_stackmatch[] =
{TK_FOR, TK_PAREN_OPEN},
{TK_FOR, TK_LBRACE},
{TK_FOR, COMPLETE_COMMANDS},
{TK_FOR, TK_BANG},
{TK_FOR, TK_BANG},
{TK_FOR, SEPARATOR_OP},
{TK_FOR, NEWLINE_LIST},
{TK_FOR, SEQUENCE},
@ -354,7 +316,6 @@ t_stackmatch g_stackmatch[] =
{TK_LBRACE, LINEBREAK},
{TK_LBRACE, TK_BANG},
{TK_LBRACE, TK_LBRACE},
{TK_LBRACE, TK_BANG},
{TK_LBRACE, SEPARATOR_OP},
{TK_LBRACE, NEWLINE_LIST},
{TK_LBRACE, SEQUENCE},
@ -836,7 +797,6 @@ t_stackmatch g_stackmatch[] =
{IF_CLAUSE, TK_PAREN_OPEN},
{IF_CLAUSE, TK_LBRACE},
{IF_CLAUSE, COMPLETE_COMMANDS},
{IF_CLAUSE, TK_BANG},
{IF_CLAUSE, SEPARATOR_OP},
{IF_CLAUSE, NEWLINE_LIST},
{IF_CLAUSE, SEQUENCE},
@ -856,7 +816,6 @@ t_stackmatch g_stackmatch[] =
{IF_CLAUSE, COMPLETE_CONDITION},
{IF_CLAUSE, AND_OR_MAJOR},
{BRACE_CLAUSE, LINEBREAK},
{BRACE_CLAUSE, TK_BANG},
{BRACE_CLAUSE, TK_PAREN_OPEN},
{BRACE_CLAUSE, TK_LBRACE},
{BRACE_CLAUSE, COMPLETE_COMMANDS},
@ -889,7 +848,6 @@ t_stackmatch g_stackmatch[] =
{CASE_CLAUSE, TK_PAREN_OPEN},
{CASE_CLAUSE, TK_LBRACE},
{CASE_CLAUSE, COMPLETE_COMMANDS},
{CASE_CLAUSE, TK_BANG},
{CASE_CLAUSE, SEPARATOR_OP},
{CASE_CLAUSE, NEWLINE_LIST},
{CASE_CLAUSE, SEQUENCE},
@ -1012,7 +970,6 @@ t_stackmatch g_stackmatch[] =
{COMMAND, COMPOUND_LIST},
{COMMAND, CASE_LIST_NS},
{COMMAND, COMPLETE_CONDITION},
{COMMAND, TK_BANG},
{COMMAND, SEPARATOR_OP},
{COMMAND, NEWLINE_LIST},
{COMMAND, SEQUENCE},
@ -1042,8 +999,6 @@ t_stackmatch g_stackmatch[] =
{PIPE_SEQUENCE, TK_PAREN_OPEN},
{PIPE_SEQUENCE, TK_LBRACE},
{PIPE_SEQUENCE, COMPLETE_COMMANDS},
{PIPE_SEQUENCE, TK_BANG},
{PIPE_SEQUENCE, TK_BANG},
{PIPE_SEQUENCE, SEPARATOR_OP},
{PIPE_SEQUENCE, NEWLINE_LIST},
{PIPE_SEQUENCE, AND_OR_MAJOR},
@ -1192,7 +1147,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
if (!*stack)
return (1);
head = (*stack)->content;
DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
i = 0;
while (g_stackmatch[i].top)
{

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
/* Updated: 2017/03/10 13:26:15 by jhalford ### ########.fr */
/* Updated: 2017/03/10 13:33:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
/* Updated: 2017/03/09 15:25:25 by ariard ### ########.fr */
/* Updated: 2017/03/10 14:44:52 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,8 @@
char *read_state(t_sym current)
{
if (current == TK_BANG)
return ("TK_BANG");
if (current == OPEN_FUNC)
return ("OPEN_FUNC");
if (current == CLOSE_FUNC)