Merging
This commit is contained in:
commit
cb9fe01c3e
32 changed files with 316 additions and 246 deletions
|
|
@ -56,15 +56,14 @@ exec/ast_free.c\
|
|||
exec/exec_ampersand.c\
|
||||
exec/exec_and_if.c\
|
||||
exec/exec_command.c\
|
||||
exec/exec_dgreat.c\
|
||||
exec/exec_great.c\
|
||||
exec/exec_less.c\
|
||||
exec/exec_or_if.c\
|
||||
exec/exec_pipe.c\
|
||||
exec/exec_redir.c\
|
||||
exec/exec_semi.c\
|
||||
exec/ft_exec.c\
|
||||
exec/ft_findexec.c\
|
||||
exec/launch_process.c\
|
||||
exec/process_do_redirection.c\
|
||||
exec/process_redirect.c\
|
||||
exec/process_reset.c\
|
||||
exec/process_setexec.c\
|
||||
|
|
@ -156,6 +155,7 @@ lexer/token_init.c\
|
|||
lexer/token_print.c\
|
||||
line-editing/builtin_history.c\
|
||||
line-editing/check_backslash.c\
|
||||
line-editing/completion.c\
|
||||
line-editing/control_c_and_d.c\
|
||||
line-editing/copy_cut_paste.c\
|
||||
line-editing/ft_split_whitespaces.c\
|
||||
|
|
@ -201,6 +201,7 @@ parser/parse_great.c\
|
|||
parser/parse_greatand.c\
|
||||
parser/parse_less.c\
|
||||
parser/parse_lessand.c\
|
||||
parser/parse_redir.c\
|
||||
parser/parse_separator.c\
|
||||
parser/parse_subshell.c\
|
||||
parser/parse_word.c
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/12 13:18:27 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:01:10 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -47,6 +47,7 @@ struct s_process
|
|||
pid_t pid;
|
||||
int fdin;
|
||||
int fdout;
|
||||
t_list *redirs;
|
||||
int toclose;
|
||||
int status;
|
||||
t_flag attributes;
|
||||
|
|
@ -77,16 +78,14 @@ int exec_ampersand(t_btree **ast);
|
|||
int exec_or_if(t_btree **ast);
|
||||
int exec_and_if(t_btree **ast);
|
||||
int exec_pipe(t_btree **ast);
|
||||
|
||||
int exec_less(t_btree **ast);
|
||||
int exec_great(t_btree **ast);
|
||||
int exec_dgreat(t_btree **ast);
|
||||
int exec_redir(t_btree **ast);
|
||||
int exec_command(t_btree **ast);
|
||||
|
||||
int launch_process(t_process *p);
|
||||
int process_setexec(t_type type, t_process *p);
|
||||
int process_setgroup(t_process *p, pid_t pid);
|
||||
int process_redirect(t_process *p);
|
||||
void process_do_redirection(t_redir *redir);
|
||||
void process_setsig(void);
|
||||
void process_free(void *content, size_t content_size);
|
||||
void process_reset(void);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/03 14:34:31 by alao ### ########.fr */
|
||||
/* Updated: 2017/02/03 15:13:01 by alao ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -52,6 +52,27 @@
|
|||
# define TOUCHE_F5 892427035
|
||||
# define TOUCHE_F6 925981467
|
||||
|
||||
# define PROMPT_QUOTES "quote> "
|
||||
# define PROMPT_DQUOTES "dquote> "
|
||||
# define PROMPT_BQUOTES "bquote> "
|
||||
# define PROMPT_ACCOLADE "cursh> "
|
||||
# define PROMPT_BRACKET "subsh> "
|
||||
# define PROMPT_BSLASH "> "
|
||||
|
||||
# define SIZE_PROMPT_QUOTES 7
|
||||
# define SIZE_PROMPT_DQUOTES 8
|
||||
# define SIZE_PROMPT_BQUOTES 8
|
||||
# define SIZE_PROMPT_ACCOLADE 7
|
||||
# define SIZE_PROMPT_BRACKET 7
|
||||
# define SIZE_PROMPT_BSLASH 2
|
||||
|
||||
# define IS_QUOTES 1 << 0
|
||||
# define IS_BQUOTES 1 << 1
|
||||
# define IS_DQUOTES 1 << 2
|
||||
# define IS_ACCOLADE 1 << 3
|
||||
# define IS_BRACKET 1 << 4
|
||||
# define IS_BSLASH 1 << 5
|
||||
|
||||
# define HIST 1
|
||||
|
||||
# define ERROR_CNTL_R 1
|
||||
|
|
@ -83,8 +104,15 @@ typedef struct s_key
|
|||
void (*f)(void);
|
||||
} t_key;
|
||||
|
||||
extern t_key g_keys[];
|
||||
typedef struct s_prompt_type
|
||||
{
|
||||
char key;
|
||||
int value;
|
||||
char *new_prompt;
|
||||
} t_prompt_type;
|
||||
|
||||
extern t_key g_keys[];
|
||||
extern t_prompt_type g_prompt_tab[];
|
||||
|
||||
void ft_putnc(char c, int n);
|
||||
int ft_nbr_len(int nbr);
|
||||
|
|
@ -110,10 +138,10 @@ void ft_realloc_str_history(char **str, size_t pos, int nb_his, int len);
|
|||
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
||||
long long ft_pow(int nbr, int power);
|
||||
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
||||
void ft_check_backslash(char **str);
|
||||
char *ft_strget_history(char *str);
|
||||
int ft_nb_last_line(char *str, size_t pos);
|
||||
int ft_put(int nb);
|
||||
void ft_check_line(void);
|
||||
|
||||
char *ft_read_stdin(void);
|
||||
void ft_end(void);
|
||||
|
|
@ -140,9 +168,8 @@ void ft_v(void);
|
|||
void ft_history_parsing(void);
|
||||
void ft_read_it(int input, size_t *pos, char **str);
|
||||
int ft_readline(void);
|
||||
int ft_completion(int ret);
|
||||
|
||||
void ft_check_heredoc(char **str);
|
||||
void ft_check_quotes(char **s);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:36:09 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:25:50 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 14:03:15 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:01:51 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,14 +15,6 @@
|
|||
|
||||
# include "minishell.h"
|
||||
|
||||
typedef struct s_parser t_parser;
|
||||
typedef struct s_ld t_ld;
|
||||
typedef struct s_astnode t_astnode;
|
||||
typedef struct s_redir t_redir;
|
||||
typedef union u_astdata t_astdata;
|
||||
typedef union u_word t_word;
|
||||
typedef long long t_type;
|
||||
|
||||
struct s_parser
|
||||
{
|
||||
t_type type;
|
||||
|
|
@ -37,9 +29,10 @@ union u_word
|
|||
|
||||
struct s_redir
|
||||
{
|
||||
t_flag type;
|
||||
int n;
|
||||
int close;
|
||||
t_word word;
|
||||
int close;
|
||||
};
|
||||
|
||||
union u_astdata
|
||||
|
|
@ -60,6 +53,7 @@ extern t_parser g_parser[];
|
|||
|
||||
int ft_parse(t_btree **ast, t_list **token);
|
||||
int parse_separator(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_redir(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_less(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_great(t_btree **ast, t_list **start, t_list **lst);
|
||||
int parse_dless(t_btree **ast, t_list **start, t_list **lst);
|
||||
|
|
|
|||
|
|
@ -6,29 +6,33 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 12:45:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:54:04 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TYPES_H
|
||||
# define TYPES_H
|
||||
|
||||
typedef long long t_type;
|
||||
typedef struct s_line t_line;
|
||||
typedef struct s_comp t_comp;
|
||||
typedef struct s_exec t_exec;
|
||||
typedef struct s_jobc t_jobc;
|
||||
typedef enum e_mode t_mode;
|
||||
typedef struct s_data t_data;
|
||||
|
||||
typedef struct s_data t_data;
|
||||
typedef enum e_qstate t_qstate;
|
||||
|
||||
typedef struct s_job t_job;
|
||||
typedef struct s_jobc t_jobc;
|
||||
typedef struct s_execmap t_execmap;
|
||||
typedef struct s_process t_process;
|
||||
typedef long long t_type;
|
||||
typedef long long t_flag;
|
||||
typedef struct s_line t_line;
|
||||
typedef struct s_comp t_comp;
|
||||
typedef struct s_exec t_exec;
|
||||
typedef struct s_jobc t_jobc;
|
||||
typedef enum e_mode t_mode;
|
||||
|
||||
typedef struct s_parser t_parser;
|
||||
typedef struct s_ld t_ld;
|
||||
typedef struct s_astnode t_astnode;
|
||||
typedef struct s_redir t_redir;
|
||||
typedef union u_astdata t_astdata;
|
||||
typedef union u_word t_word;
|
||||
|
||||
typedef struct s_job t_job;
|
||||
typedef struct s_execmap t_execmap;
|
||||
typedef struct s_process t_process;
|
||||
typedef int (t_execf)(const char *path, char *const argv[], char *const envp[]);
|
||||
|
||||
t_data *data_singleton();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:45:32 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:45:08 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -66,6 +66,7 @@ int exec_command(t_btree **ast)
|
|||
p->av = NULL;
|
||||
p->pid = 0;
|
||||
p->attributes &= ~(PROCESS_STATE_MASK | PROCESS_TYPE_MASK);
|
||||
p->redirs = NULL;
|
||||
btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_dgreat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 18:15:13 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/13 17:13:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
int exec_dgreat(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
int fd;
|
||||
|
||||
node = (*ast)->item;
|
||||
fd = open(node->data.redir.word.word, O_WRONLY | O_APPEND | O_CREAT, 0644);
|
||||
data_singleton()->exec.process.fdout = fd;
|
||||
ft_exec(&(*ast)->left);
|
||||
data_singleton()->exec.process.fdout = STDOUT;
|
||||
btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_less.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/13 17:14:46 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
int exec_less(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
int fd;
|
||||
|
||||
node = (*ast)->item;
|
||||
fd = open(node->data.redir.word.word, O_RDONLY);
|
||||
data_singleton()->exec.process.fdin = fd;
|
||||
/* ft_strappend(&data->exec.process.command, "<"); */
|
||||
/* ft_strappend(&data->exec.process.command, node->data.redir.word.word); */
|
||||
ft_exec(&(*ast)->left);
|
||||
data_singleton()->exec.process.fdin = STDIN;
|
||||
/* data->exec.process.command = NULL; */
|
||||
btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,27 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_great.c :+: :+: :+: */
|
||||
/* exec_redir.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/13 17:14:19 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:58:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
int exec_great(t_btree **ast)
|
||||
int exec_redir(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
int fd;
|
||||
t_process *p;
|
||||
|
||||
p = &data_singleton()->exec.process;
|
||||
node = (*ast)->item;
|
||||
fd = open(node->data.redir.word.word, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||
data_singleton()->exec.process.fdout = fd;
|
||||
node->data.redir.type = node->type;
|
||||
ft_lsteadd(&p->redirs, ft_lstnew(&node->data.redir,sizeof(node->data.redir)));
|
||||
ft_exec(&(*ast)->left);
|
||||
data_singleton()->exec.process.fdout = STDOUT;
|
||||
btree_delone(ast, &ast_free);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:04:50 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:45:05 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,9 +19,7 @@ t_execmap g_execmap[] =
|
|||
{TK_SEMI, &exec_semi},
|
||||
{TK_AMP, &exec_ampersand},
|
||||
{TK_PIPE, &exec_pipe},
|
||||
{TK_LESS, &exec_less},
|
||||
{TK_GREAT, &exec_great},
|
||||
{TK_DGREAT, &exec_dgreat},
|
||||
{TK_REDIR, &exec_redir},
|
||||
{TK_COMMAND | TK_SUBSHELL, &exec_command},
|
||||
{0, 0},
|
||||
};
|
||||
|
|
|
|||
57
42sh/src/exec/process_do_redirection.c
Normal file
57
42sh/src/exec/process_do_redirection.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* process_do_redirection.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 14:55:44 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int fd_is_valid(int fd)
|
||||
{
|
||||
return (fcntl(fd, F_GETFD) != -1 || errno != EBADF);
|
||||
}
|
||||
|
||||
void process_do_redirection(t_redir *redir)
|
||||
{
|
||||
int fdin;
|
||||
int fdout;
|
||||
|
||||
if (redir->type & (TK_GREAT | TK_DGREAT))
|
||||
{
|
||||
fdin = redir->n;
|
||||
fdout = open(redir->word.word, O_WRONLY | O_CREAT
|
||||
| (redir->type & TK_GREAT) ? O_TRUNC : O_APPEND,
|
||||
0644);
|
||||
}
|
||||
else if (redir->type & TK_LESS)
|
||||
{
|
||||
fdin = open(redir->word.word, O_WRONLY | O_TRUNC | O_CREAT, 0644);
|
||||
fdout = redir->n;
|
||||
}
|
||||
else if (redir->type & (TK_LESSAND | TK_GREATAND))
|
||||
{
|
||||
if (redir->close)
|
||||
{
|
||||
close(redir->n);
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
fdin = redir->type & TK_LESSAND ? redir->word.fd : redir->n;
|
||||
fdout = redir->type & TK_LESSAND ? redir->n : redir->word.fd;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: redirection error.", SHELL_NAME);
|
||||
return ;
|
||||
}
|
||||
fd_is_valid(fdout) ? dup2(fdout, fdin) : close(fdin);
|
||||
close(fdout);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 14:31:15 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:46:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,14 @@
|
|||
|
||||
int process_redirect(t_process *p)
|
||||
{
|
||||
t_list *redirs;
|
||||
|
||||
redirs = p->redirs;
|
||||
while (redirs)
|
||||
{
|
||||
process_do_redirection(redirs->content);
|
||||
redirs = redirs->next;
|
||||
}
|
||||
if (p->toclose != STDIN)
|
||||
close(p->toclose);
|
||||
if (p->fdin != STDIN)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:45:25 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:59:25 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,5 +20,6 @@ void process_free(void *content, size_t content_size)
|
|||
p = content;
|
||||
ft_strdel(&p->path);
|
||||
ft_sstrfree(p->av);
|
||||
ft_lstdel(&p->redirs, ft_lst_cfree);
|
||||
free(p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:34:45 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:26:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,30 +6,85 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/26 13:32:52 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/02 16:01:25 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:09:20 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void ft_check_backslash(char **str)
|
||||
t_prompt_type g_prompt_tab[] =
|
||||
{
|
||||
char *tmp1;
|
||||
char *tmp2;
|
||||
{IS_QUOTES ,SIZE_PROMPT_QUOTES ,PROMPT_QUOTES},
|
||||
{IS_BQUOTES ,SIZE_PROMPT_BQUOTES ,PROMPT_BQUOTES},
|
||||
{IS_DQUOTES ,SIZE_PROMPT_DQUOTES ,PROMPT_DQUOTES},
|
||||
{IS_ACCOLADE ,SIZE_PROMPT_ACCOLADE ,PROMPT_ACCOLADE},
|
||||
{IS_BRACKET ,SIZE_PROMPT_BRACKET ,PROMPT_BRACKET},
|
||||
{IS_BSLASH ,SIZE_PROMPT_BSLASH ,PROMPT_BSLASH},
|
||||
{0 ,0 ,0},
|
||||
};
|
||||
|
||||
if (!*str || !**str)
|
||||
return ;
|
||||
if ((*str)[ft_strlen(*str) - 1] == '\\')
|
||||
{
|
||||
ft_putstr("> ");
|
||||
data_singleton()->line.prompt_size = 2;
|
||||
tmp1 = *str;
|
||||
tmp2 = ft_strjoin(tmp1, "\n");
|
||||
free(tmp1);
|
||||
tmp1 = ft_read_stdin();
|
||||
*str = ft_strjoin(tmp2, tmp1);
|
||||
free(tmp1);
|
||||
free(tmp2);
|
||||
ft_putchar('\n');
|
||||
}
|
||||
void ft_read_more(short c)
|
||||
{
|
||||
char *str_tmp;
|
||||
char *str_tmp2;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
str_tmp2 = data_singleton()->line.input;
|
||||
str_tmp = ft_strjoin(str_tmp2, "\n");
|
||||
free(str_tmp2);
|
||||
data_singleton()->line.input = NULL;
|
||||
data_singleton()->line.pos = 0;
|
||||
while (g_prompt_tab[i].key && !(g_prompt_tab[i].key & c))
|
||||
++i;
|
||||
data_singleton()->line.prompt_size = g_prompt_tab[i].value;
|
||||
ft_printf("\n%s", g_prompt_tab[i].new_prompt);
|
||||
str_tmp2 = ft_read_stdin();
|
||||
str_tmp2 = ft_strjoin(str_tmp, data_singleton()->line.input);
|
||||
free(str_tmp);
|
||||
free(data_singleton()->line.input);
|
||||
data_singleton()->line.input = str_tmp2;
|
||||
ft_check_line();
|
||||
}
|
||||
|
||||
void ft_check_this_char(char c, short *status)
|
||||
{
|
||||
int i;
|
||||
char stats[] = {'\'', '`', '\"', '{', '(', '\\', '\0'};
|
||||
|
||||
i = 0;
|
||||
while (stats[i] && stats[i] != c)
|
||||
++i;
|
||||
if (!stats[i])
|
||||
return ;
|
||||
if (((1 << i) & ~(*status)))
|
||||
{
|
||||
if (((1 << i) > *status &&
|
||||
(*status == 0 && !(IS_QUOTES & *status) && (!(IS_DQUOTES & *status))))
|
||||
|| (((1 << i) == IS_BQUOTES) && !(IS_QUOTES & *status)))
|
||||
(*status) = (*status) | (1 << i);
|
||||
}
|
||||
else
|
||||
(*status) = (*status) ^ (1 << i);
|
||||
}
|
||||
|
||||
void ft_check_line(void)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
short status;
|
||||
|
||||
i = 0;
|
||||
status = 0;
|
||||
str = data_singleton()->line.input;
|
||||
while (str[i])
|
||||
{
|
||||
if (IS_BSLASH & status)
|
||||
status = status ^ IS_BSLASH;
|
||||
else
|
||||
ft_check_this_char(str[i], &status);
|
||||
++i;
|
||||
}
|
||||
if (status)
|
||||
ft_read_more(status);
|
||||
}
|
||||
|
|
|
|||
34
42sh/src/line-editing/completion.c
Normal file
34
42sh/src/line-editing/completion.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* completion.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/03 15:03:17 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int ft_completion(int ret)
|
||||
{
|
||||
size_t tmp;
|
||||
|
||||
if ((ret != TOUCHE_TAB && ret != 10)
|
||||
|| (ret == 10 && !(data_singleton()->comp)))
|
||||
return (0);
|
||||
data_singleton()->line.pos = tmp;
|
||||
if (ret == 10)
|
||||
ft_puttermcaps("cd");
|
||||
if (data_singleton()->comp || ret == TOUCHE_TAB)
|
||||
completion(ret);
|
||||
if (ret == 10)
|
||||
{
|
||||
ft_current_str(data_singleton()->line.input, tmp);
|
||||
ft_get_next_str(data_singleton()->line.input, &tmp);
|
||||
data_singleton()->line.pos = tmp;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -6,7 +6,11 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/03 14:54:17 by alao ### ########.fr */
|
||||
/* Updated: 2017/02/03 15:12:38 by alao ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
>>>>>>> 3769f98c9a62c0352e90cbfe380b5377572981b1
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -56,8 +60,8 @@ if (data_singleton()->comp)
|
|||
ret = 0;
|
||||
j = 0;
|
||||
read(0, &ret, sizeof(int));
|
||||
if (data_singleton()->comp || ret == TOUCHE_TAB)
|
||||
completion(ret);
|
||||
if (ft_completion(ret))
|
||||
continue ;
|
||||
while (g_key[j].value && g_key[j].value != ret)
|
||||
++j;
|
||||
if (g_key[j].value)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/19 16:42:54 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/02 15:22:35 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/03 12:08:45 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -73,13 +73,15 @@ void ft_found_prev_word(void)
|
|||
|
||||
void ft_found_next_word(void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
char *str;
|
||||
size_t *pos;
|
||||
|
||||
str = data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
i = 0;
|
||||
if (!str)
|
||||
return ;
|
||||
while (str[i + *pos] && str[i + *pos] == ' ')
|
||||
{
|
||||
ft_putchar(str[i + *pos]);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/02 18:04:16 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/03 11:55:36 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ void ft_history_down(void)
|
|||
str = &data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
head = data_singleton()->line.list_cur;
|
||||
if (!head || !*str)
|
||||
if (!head)
|
||||
return ;
|
||||
if (*str)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/02 16:20:26 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/03 11:57:07 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -59,7 +59,6 @@ static void ft_history_parsing_2(void)
|
|||
data_singleton()->line.input = ft_read_stdin();
|
||||
ft_putchar('\n');
|
||||
data_singleton()->line.opt = data_singleton()->line.opt | ~HIST;
|
||||
ft_check_quotes(&data_singleton()->line.input);
|
||||
ft_check_heredoc(&data_singleton()->line.input);
|
||||
ft_history_parsing();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,88 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* quotes_gest.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/05 12:20:19 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/02 17:53:41 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int ft_check_quotes_num(char *s)
|
||||
{
|
||||
int i;
|
||||
char simp;
|
||||
char doub;
|
||||
|
||||
i = 0;
|
||||
simp = 0;
|
||||
doub = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] == '\'' && ((i && s[i - 1] != '\\') || !i))
|
||||
{
|
||||
simp = 1;
|
||||
++i;
|
||||
while (s[i] && !(s[i] == '\'' && ((i && s[i - 1] != '\\') || !i)))
|
||||
++i;
|
||||
if (s[i] == '\'' && ((i && s[i - 1] != '\\') || !i))
|
||||
simp = 0;
|
||||
}
|
||||
else if (s[i] == '"' && ((i && s[i - 1] != '\\') || !i))
|
||||
{
|
||||
doub = 1;
|
||||
++i;
|
||||
while (s[i] && !(s[i] == '"' && ((i && s[i - 1] != '\\') || !i)))
|
||||
++i;
|
||||
if (s[i] == '"' && ((i && s[i - 1] != '\\') || !i))
|
||||
doub = 0;
|
||||
}
|
||||
if (s[i])
|
||||
++i;
|
||||
}
|
||||
if (doub)
|
||||
return (2);
|
||||
else if (simp)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_check_quotes(char **s)
|
||||
{
|
||||
int ret;
|
||||
char *tmp;
|
||||
char *tmp2;
|
||||
int prompt_size_mem;
|
||||
t_list_history *head;
|
||||
|
||||
head = data_singleton()->line.list_beg;
|
||||
if (!*s)
|
||||
return ;
|
||||
while ((ret = (ft_check_quotes_num(*s))))
|
||||
{
|
||||
if (ret == 1)
|
||||
ft_putstr("squote> ");
|
||||
else if (ret == 2)
|
||||
ft_putstr("dquote> ");
|
||||
tmp = *s;
|
||||
*s = ft_strjoin(*s, "\n");
|
||||
ft_strdel(&tmp);
|
||||
tmp = *s;
|
||||
prompt_size_mem = data_singleton()->line.prompt_size;
|
||||
data_singleton()->line.input = NULL;
|
||||
data_singleton()->line.pos = 0;
|
||||
tmp2 = ft_read_stdin();
|
||||
data_singleton()->line.prompt_size = prompt_size_mem;
|
||||
ft_putchar('\n');
|
||||
if (!tmp2)
|
||||
continue ;
|
||||
*s = ft_strjoin(tmp, tmp2);
|
||||
data_singleton()->line.input = *s;
|
||||
ft_strdel(&tmp);
|
||||
ft_strdel(&tmp2);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
|
||||
/* Updated: 2017/01/25 19:07:39 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/03 11:40:10 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -61,6 +61,7 @@ void ft_read_it(int input, size_t *pos, char **str)
|
|||
return ;
|
||||
ft_read_it_2(input, t);
|
||||
ft_read_it_3(str, t, pos, &j);
|
||||
ft_putstr((*str) + (*pos) - j);
|
||||
// ft_current_str((*str) + (*pos) - j, *pos);
|
||||
// ft_get_next_str((*str) + (*pos) - j, pos);
|
||||
ft_putnc('\b', ft_strlen((*str)) - ((*pos)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/02 18:03:23 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/03 12:33:51 by gwojda ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -82,10 +82,9 @@ int ft_readline(void)
|
|||
data_singleton()->line.pos = 0;
|
||||
ft_prompt();
|
||||
data_singleton()->line.input = ft_read_stdin();
|
||||
ft_check_line();
|
||||
ft_putchar('\n');
|
||||
ft_check_quotes(&data_singleton()->line.input);
|
||||
ft_check_heredoc(&data_singleton()->line.input);
|
||||
ft_check_backslash(&data_singleton()->line.input);
|
||||
ft_history_parsing();
|
||||
if (data_singleton()->line.input)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/19 16:26:35 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:44:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -29,6 +29,7 @@ int data_init(void)
|
|||
data->exec.process.fdout = STDOUT;
|
||||
data->exec.process.pid = 0;
|
||||
data->exec.process.attributes = PROCESS_PIPESTART | PROCESS_PIPEEND;
|
||||
data->exec.process.redirs = NULL;
|
||||
|
||||
data->exec.aol_status = NULL;
|
||||
data->exec.aol_search = 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:45:17 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 18:57:56 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/02 15:45:33 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 13:43:00 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,12 +18,7 @@ t_parser g_parser[] =
|
|||
{TK_AND_IF | TK_OR_IF, &parse_separator},
|
||||
{TK_AMP, &parse_separator},
|
||||
{TK_PIPE, &parse_separator},
|
||||
{TK_LESS, &parse_less},
|
||||
{TK_GREAT, &parse_great},
|
||||
{TK_DLESS, &parse_dless},
|
||||
{TK_DGREAT, &parse_dgreat},
|
||||
{TK_LESSAND, &parse_lessand},
|
||||
{TK_GREATAND, &parse_greatand},
|
||||
{TK_REDIR, &parse_redir},
|
||||
{TK_SUBSHELL, &parse_subshell},
|
||||
{TK_WORD, &parse_word},
|
||||
{0, 0},
|
||||
|
|
@ -48,8 +43,7 @@ int ft_parse(t_btree **ast, t_list **start)
|
|||
if ((lst = ft_lst_find(*start, &g_parser[i].type, &token_cmp_type)))
|
||||
{
|
||||
if (g_parser[i].f)
|
||||
(*g_parser[i].f)(ast, start, &lst);
|
||||
return (0);
|
||||
return ((*g_parser[i].f)(ast, start, &lst));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 14:44:12 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/02 19:02:52 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/01/10 14:45:50 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:07:03 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 16:37:58 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:09:50 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ int parse_greatand(t_btree **ast, t_list **start, t_list **lst)
|
|||
node->type = TK_GREATAND;
|
||||
tok = (*lst)->content;
|
||||
and = ft_strchr(tok->data, '&');
|
||||
node->data.redir.n = *tok->data == '>' ? 1 : ft_atoi(tok->data);
|
||||
node->data.redir.word.fd = ft_atoi(and + 1);
|
||||
node->data.redir.close =
|
||||
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
|
||||
/* Updated: 2016/12/01 16:37:54 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/03 14:07:55 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ int parse_lessand(t_btree **ast, t_list **start, t_list **lst)
|
|||
node->type = TK_LESSAND;
|
||||
tok = (*lst)->content;
|
||||
and = ft_strchr(tok->data, '&');
|
||||
node->data.redir.n = *tok->data == '<' ? 1 : ft_atoi(tok->data);
|
||||
node->data.redir.word.fd = ft_atoi(and + 1);
|
||||
node->data.redir.close =
|
||||
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
|
||||
|
|
|
|||
34
42sh/src/parser/parse_redir.c
Normal file
34
42sh/src/parser/parse_redir.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parse_redir.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/02 18:58:27 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 13:58:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser.h"
|
||||
|
||||
int parse_redir(t_btree **ast, t_list **start, t_list **lst)
|
||||
{
|
||||
t_token *tok;
|
||||
|
||||
tok = (*lst)->content;
|
||||
if (tok->type == TK_LESS)
|
||||
return (parse_less(ast, start, lst));
|
||||
else if (tok->type == TK_GREAT)
|
||||
return (parse_great(ast, start, lst));
|
||||
else if (tok->type == TK_DLESS)
|
||||
return (parse_dless(ast, start, lst));
|
||||
else if (tok->type == TK_DGREAT)
|
||||
return (parse_dgreat(ast, start, lst));
|
||||
else if (tok->type == TK_LESSAND)
|
||||
return (parse_lessand(ast, start, lst));
|
||||
else if (tok->type == TK_GREATAND)
|
||||
return (parse_greatand(ast, start, lst));
|
||||
else
|
||||
return (-42);
|
||||
}
|
||||
Loading…
Reference in a new issue