quoting + backslash + backquotes + parentheses + accolades revu : normalement ca marche. On va tenter d'ajouter la completion
This commit is contained in:
parent
f4efbdd313
commit
c0918e8e6b
10 changed files with 156 additions and 36 deletions
|
|
@ -143,6 +143,7 @@ lexer/token_init.c\
|
||||||
lexer/token_print.c\
|
lexer/token_print.c\
|
||||||
line-editing/builtin_history.c\
|
line-editing/builtin_history.c\
|
||||||
line-editing/check_backslash.c\
|
line-editing/check_backslash.c\
|
||||||
|
line-editing/completion.c\
|
||||||
line-editing/control_c_and_d.c\
|
line-editing/control_c_and_d.c\
|
||||||
line-editing/copy_cut_paste.c\
|
line-editing/copy_cut_paste.c\
|
||||||
line-editing/ft_split_whitespaces.c\
|
line-editing/ft_split_whitespaces.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 18:28:44 by gwojda ### ########.fr */
|
/* Updated: 2017/02/03 15:04:38 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -52,6 +52,27 @@
|
||||||
# define TOUCHE_F5 892427035
|
# define TOUCHE_F5 892427035
|
||||||
# define TOUCHE_F6 925981467
|
# 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 HIST 1
|
||||||
|
|
||||||
# define ERROR_CNTL_R 1
|
# define ERROR_CNTL_R 1
|
||||||
|
|
@ -82,8 +103,15 @@ typedef struct s_key
|
||||||
void (*f)(void);
|
void (*f)(void);
|
||||||
} t_key;
|
} 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);
|
void ft_putnc(char c, int n);
|
||||||
int ft_nbr_len(int nbr);
|
int ft_nbr_len(int nbr);
|
||||||
|
|
@ -109,10 +137,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);
|
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
||||||
long long ft_pow(int nbr, int power);
|
long long ft_pow(int nbr, int power);
|
||||||
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
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);
|
char *ft_strget_history(char *str);
|
||||||
int ft_nb_last_line(char *str, size_t pos);
|
int ft_nb_last_line(char *str, size_t pos);
|
||||||
int ft_put(int nb);
|
int ft_put(int nb);
|
||||||
|
void ft_check_line(void);
|
||||||
|
|
||||||
char *ft_read_stdin(void);
|
char *ft_read_stdin(void);
|
||||||
void ft_end(void);
|
void ft_end(void);
|
||||||
|
|
@ -139,9 +167,8 @@ void ft_v(void);
|
||||||
void ft_history_parsing(void);
|
void ft_history_parsing(void);
|
||||||
void ft_read_it(int input, size_t *pos, char **str);
|
void ft_read_it(int input, size_t *pos, char **str);
|
||||||
int ft_readline(void);
|
int ft_readline(void);
|
||||||
|
int ft_completion(int ret);
|
||||||
|
|
||||||
void ft_check_heredoc(char **str);
|
void ft_check_heredoc(char **str);
|
||||||
void ft_check_quotes(char **s);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,30 +6,85 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 13:32:52 by gwojda #+# #+# */
|
/* 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"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_check_backslash(char **str)
|
t_prompt_type g_prompt_tab[] =
|
||||||
{
|
{
|
||||||
char *tmp1;
|
{IS_QUOTES ,SIZE_PROMPT_QUOTES ,PROMPT_QUOTES},
|
||||||
char *tmp2;
|
{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)
|
void ft_read_more(short c)
|
||||||
return ;
|
{
|
||||||
if ((*str)[ft_strlen(*str) - 1] == '\\')
|
char *str_tmp;
|
||||||
{
|
char *str_tmp2;
|
||||||
ft_putstr("> ");
|
int i;
|
||||||
data_singleton()->line.prompt_size = 2;
|
|
||||||
tmp1 = *str;
|
i = 0;
|
||||||
tmp2 = ft_strjoin(tmp1, "\n");
|
str_tmp2 = data_singleton()->line.input;
|
||||||
free(tmp1);
|
str_tmp = ft_strjoin(str_tmp2, "\n");
|
||||||
tmp1 = ft_read_stdin();
|
free(str_tmp2);
|
||||||
*str = ft_strjoin(tmp2, tmp1);
|
data_singleton()->line.input = NULL;
|
||||||
free(tmp1);
|
data_singleton()->line.pos = 0;
|
||||||
free(tmp2);
|
while (g_prompt_tab[i].key && !(g_prompt_tab[i].key & c))
|
||||||
ft_putchar('\n');
|
++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,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/02 18:27:07 by gwojda ### ########.fr */
|
/* Updated: 2017/02/03 14:46:22 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -54,6 +54,8 @@ char *ft_read_stdin(void)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
j = 0;
|
j = 0;
|
||||||
read(0, &ret, sizeof(int));
|
read(0, &ret, sizeof(int));
|
||||||
|
if (ft_completion(ret))
|
||||||
|
continue ;
|
||||||
while (g_key[j].value && g_key[j].value != ret)
|
while (g_key[j].value && g_key[j].value != ret)
|
||||||
++j;
|
++j;
|
||||||
if (g_key[j].value)
|
if (g_key[j].value)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:42:54 by gwojda #+# #+# */
|
/* 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)
|
void ft_found_next_word(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
char *str;
|
||||||
size_t *pos;
|
size_t *pos;
|
||||||
|
|
||||||
str = data_singleton()->line.input;
|
str = data_singleton()->line.input;
|
||||||
pos = &data_singleton()->line.pos;
|
pos = &data_singleton()->line.pos;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
if (!str)
|
||||||
|
return ;
|
||||||
while (str[i + *pos] && str[i + *pos] == ' ')
|
while (str[i + *pos] && str[i + *pos] == ' ')
|
||||||
{
|
{
|
||||||
ft_putchar(str[i + *pos]);
|
ft_putchar(str[i + *pos]);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
|
/* 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;
|
str = &data_singleton()->line.input;
|
||||||
pos = &data_singleton()->line.pos;
|
pos = &data_singleton()->line.pos;
|
||||||
head = data_singleton()->line.list_cur;
|
head = data_singleton()->line.list_cur;
|
||||||
if (!head || !*str)
|
if (!head)
|
||||||
return ;
|
return ;
|
||||||
if (*str)
|
if (*str)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
/* 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();
|
data_singleton()->line.input = ft_read_stdin();
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
data_singleton()->line.opt = data_singleton()->line.opt | ~HIST;
|
data_singleton()->line.opt = data_singleton()->line.opt | ~HIST;
|
||||||
ft_check_quotes(&data_singleton()->line.input);
|
|
||||||
ft_check_heredoc(&data_singleton()->line.input);
|
ft_check_heredoc(&data_singleton()->line.input);
|
||||||
ft_history_parsing();
|
ft_history_parsing();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
|
/* 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 ;
|
return ;
|
||||||
ft_read_it_2(input, t);
|
ft_read_it_2(input, t);
|
||||||
ft_read_it_3(str, t, pos, &j);
|
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)));
|
ft_putnc('\b', ft_strlen((*str)) - ((*pos)));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/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;
|
data_singleton()->line.pos = 0;
|
||||||
ft_prompt();
|
ft_prompt();
|
||||||
data_singleton()->line.input = ft_read_stdin();
|
data_singleton()->line.input = ft_read_stdin();
|
||||||
|
ft_check_line();
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
ft_check_quotes(&data_singleton()->line.input);
|
|
||||||
ft_check_heredoc(&data_singleton()->line.input);
|
ft_check_heredoc(&data_singleton()->line.input);
|
||||||
ft_check_backslash(&data_singleton()->line.input);
|
|
||||||
ft_history_parsing();
|
ft_history_parsing();
|
||||||
if (data_singleton()->line.input)
|
if (data_singleton()->line.input)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue