heredoc - historique avec point d'exclamation - sortie plus propre avec control D - historique ne prend plus en compte deux commandes consecutives egales

This commit is contained in:
gwojda 2017-02-03 18:38:22 +01:00
parent 12d069d26b
commit 86fc221cb4
9 changed files with 41 additions and 24 deletions

View file

@ -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/03 16:27:48 by jhalford ### ########.fr */ /* Updated: 2017/02/03 16:36:20 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,12 +66,12 @@
# define SIZE_PROMPT_BRACKET 7 # define SIZE_PROMPT_BRACKET 7
# define SIZE_PROMPT_BSLASH 2 # define SIZE_PROMPT_BSLASH 2
# define IS_QUOTES 1 << 0 # define IS_QUOTES (1 << 0)
# define IS_BQUOTES 1 << 1 # define IS_BQUOTES (1 << 1)
# define IS_DQUOTES 1 << 2 # define IS_DQUOTES (1 << 2)
# define IS_ACCOLADE 1 << 3 # define IS_ACCOLADE (1 << 3)
# define IS_BRACKET 1 << 4 # define IS_BRACKET (1 << 4)
# define IS_BSLASH 1 << 5 # define IS_BSLASH (1 << 5)
# define HIST 1 # define HIST 1

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ /* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
/* Updated: 2017/02/02 16:43:15 by gwojda ### ########.fr */ /* Updated: 2017/02/03 18:27:23 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,7 +28,10 @@ void ft_control_d(void)
str = &data_singleton()->line.input; str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos; pos = &data_singleton()->line.pos;
if (!(*str) || (*str)[0] == '\0') if (!(*str) || (*str)[0] == '\0')
{
ft_putstr("exit\n");
builtin_exit(NULL, (char*[]){"exit", NULL}, NULL); builtin_exit(NULL, (char*[]){"exit", NULL}, NULL);
}
else if (*pos < ft_strlen(*str)) else if (*pos < ft_strlen(*str))
ft_del(); ft_del();
else else

View file

@ -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/03 15:24:37 by gwojda ### ########.fr */ /* Updated: 2017/02/03 18:00:09 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/24 15:52:34 by gwojda #+# #+# */ /* Created: 2017/01/24 15:52:34 by gwojda #+# #+# */
/* Updated: 2017/02/02 16:09:42 by gwojda ### ########.fr */ /* Updated: 2017/02/03 18:15:07 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,6 +41,8 @@ static void ft_check_heredoc_2(char **str, char *end)
*str = ft_strjoin(*str, "\n"); *str = ft_strjoin(*str, "\n");
free(tmp); free(tmp);
tmp = *str; tmp = *str;
data_singleton()->line.input = NULL;
data_singleton()->line.pos = 0;
tmp2 = ft_read_stdin(); tmp2 = ft_read_stdin();
if (!ft_strcmp(end, tmp2)) if (!ft_strcmp(end, tmp2))
boolean = 1; boolean = 1;
@ -74,4 +76,5 @@ void ft_check_heredoc(char **str)
if (!end) if (!end)
return ; return ;
ft_check_heredoc_2(str, end); ft_check_heredoc_2(str, end);
free(end);
} }

View file

@ -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/03 11:57:07 by gwojda ### ########.fr */ /* Updated: 2017/02/03 17:57:21 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,7 @@
static int ft_history_parsing_4(char *str, int *i) static int ft_history_parsing_4(char *str, int *i)
{ {
int tmp;
if (!ft_strncmp("!!", str + *i, 2)) if (!ft_strncmp("!!", str + *i, 2))
{ {
ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2); ft_realloc_str_history(&(data_singleton()->line.input), *i, 0, 2);
@ -22,9 +23,10 @@ static int ft_history_parsing_4(char *str, int *i)
} }
else if (ft_isdigit(str[(*i) + 1])) else if (ft_isdigit(str[(*i) + 1]))
{ {
tmp = ft_nbr_len(ft_atoi(str + *i + 1));
ft_realloc_str_history(&(data_singleton()->line.input), *i, ft_realloc_str_history(&(data_singleton()->line.input), *i,
ft_atoi(str + (*i) + 1), ft_nbr_len(ft_atoi(str + *i + 1)) + 1); ft_atoi(str + (*i) + 1), ft_nbr_len(ft_atoi(str + *i + 1)) + 1);
(*i) += ft_nbr_len(ft_atoi(str + *i + 1)); (*i) += tmp;
return (1); return (1);
} }
return (0); return (0);
@ -32,14 +34,16 @@ static int ft_history_parsing_4(char *str, int *i)
static int ft_history_parsing_3(char *str, int *i) static int ft_history_parsing_3(char *str, int *i)
{ {
int tmp;
if (ft_history_parsing_4(str, i)) if (ft_history_parsing_4(str, i))
return (1); return (1);
else if (str[*i + 1] == '-') else if (str[*i + 1] == '-' && ft_isdigit(str[*i + 2]))
{ {
tmp = ft_nbr_len(ft_atoi(str + *i + 2));
ft_realloc_str_history(&(data_singleton()->line.input), *i, ft_realloc_str_history(&(data_singleton()->line.input), *i,
data_singleton()->line.list_size - ft_atoi(str + *i + 2), data_singleton()->line.list_size - ft_atoi(str + *i + 2),
ft_nbr_len(ft_atoi(str + *i + 2)) + 2); ft_nbr_len(ft_atoi(str + *i + 2)) + 2);
(*i) += ft_nbr_len(ft_atoi(str + *i + 2) + 1); i += tmp;
} }
else if (str[*i + 1] == '?') else if (str[*i + 1] == '?')
ft_realloc_str_history_3(&(data_singleton()->line.input), *i, ft_realloc_str_history_3(&(data_singleton()->line.input), *i,
@ -54,6 +58,7 @@ static int ft_history_parsing_3(char *str, int *i)
static void ft_history_parsing_2(void) static void ft_history_parsing_2(void)
{ {
data_singleton()->line.pos = 0;
data_singleton()->line.opt = data_singleton()->line.opt | HIST; data_singleton()->line.opt = data_singleton()->line.opt | HIST;
ft_prompt(); ft_prompt();
data_singleton()->line.input = ft_read_stdin(); data_singleton()->line.input = ft_read_stdin();
@ -74,7 +79,7 @@ void ft_history_parsing(void)
str = data_singleton()->line.input; str = data_singleton()->line.input;
if (!str) if (!str)
return ; return ;
while (str[i]) while (str && str[i])
{ {
if (str[i] == '!') if (str[i] == '!')
{ {
@ -82,6 +87,7 @@ void ft_history_parsing(void)
if (!ft_history_parsing_3(str, &i)) if (!ft_history_parsing_3(str, &i))
boolean = 0; boolean = 0;
} }
str = data_singleton()->line.input;
++i; ++i;
} }
if (boolean) if (boolean)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */ /* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */
/* Updated: 2017/01/25 14:41:29 by gwojda ### ########.fr */ /* Updated: 2017/02/03 17:03:23 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,7 +40,6 @@ void ft_realloc_str_history(char **str, size_t pos, int nb_his, int len)
if (!*str) if (!*str)
return ; return ;
new_str = ft_strndup(*str, pos); new_str = ft_strndup(*str, pos);
ft_printf("\n\npos = %d\n\n", len);
new_str3 = ft_nget_histo(nb_his); new_str3 = ft_nget_histo(nb_his);
if (new_str3) if (new_str3)
{ {

View file

@ -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/02/03 11:40:10 by gwojda ### ########.fr */ /* Updated: 2017/02/03 18:24:47 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -52,8 +52,10 @@ void ft_read_it(int input, size_t *pos, char **str)
{ {
int j; int j;
char t[5]; char t[5];
size_t pos_tmp;
j = 0; j = 0;
pos_tmp = *pos;
if (input == TOUCHE_DELETE || input < 0 || input == 892427035 || if (input == TOUCHE_DELETE || input < 0 || input == 892427035 ||
input == 126 || input == 993090331 || input == 925981467 || input == 126 || input == 993090331 || input == 925981467 ||
input == 21298 || input == 892427035 || input == 8270395 || input == 21298 || input == 892427035 || input == 8270395 ||
@ -61,7 +63,9 @@ 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_current_str((*str) + (*pos) - j, *pos); *pos = pos_tmp;
// ft_get_next_str((*str) + (*pos) - j, pos); ft_current_str((*str), *pos);
ft_putnc('\b', ft_strlen((*str)) - ((*pos))); ft_get_next_str((*str), pos);
ft_putnc('\b', *pos - (pos_tmp + j) + 1);
*pos = (pos_tmp + j);
} }

View file

@ -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/03 16:23:38 by jhalford ### ########.fr */ /* Updated: 2017/02/03 18:36:18 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -86,7 +86,8 @@ int ft_readline(void)
ft_putchar('\n'); ft_putchar('\n');
ft_check_heredoc(&data_singleton()->line.input); ft_check_heredoc(&data_singleton()->line.input);
ft_history_parsing(); ft_history_parsing();
if (data_singleton()->line.input) if (data_singleton()->line.input && (!data_singleton()->line.list_beg ||
ft_strcmp(data_singleton()->line.list_beg->prev->str, data_singleton()->line.input)))
{ {
ft_push_back_history(&data_singleton()->line.list_beg, ft_push_back_history(&data_singleton()->line.list_beg,
ft_create_history_list(data_singleton()->line.input)); ft_create_history_list(data_singleton()->line.input));

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 18:20:23 by gwojda #+# #+# */ /* Created: 2017/01/20 18:20:23 by gwojda #+# #+# */
/* Updated: 2017/02/01 15:27:31 by gwojda ### ########.fr */ /* Updated: 2017/02/03 17:50:48 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -37,6 +37,7 @@ void ft_putall_current_str(char *str, size_t *pos)
while (str[(*pos) + len] && str[(*pos) + len] != '\n') while (str[(*pos) + len] && str[(*pos) + len] != '\n')
++len; ++len;
write(1, str + *pos, len); write(1, str + *pos, len);
ft_check_end_of_line(str, *pos + len);
} }
void ft_current_str(char *str, size_t pos) void ft_current_str(char *str, size_t pos)