correction des heredocs + corrections de quelques bugs mineurs sur l'edition de ligne (le gain de ligne a peut-etre entrainé des bugs que j'ai raté)

This commit is contained in:
gwojda 2017-02-05 17:13:26 +01:00
parent c77af3da9f
commit 1afdd9528b
13 changed files with 230 additions and 283 deletions

View file

@ -6,7 +6,7 @@
/* 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/04 18:26:59 by gwojda ### ########.fr */ /* Updated: 2017/02/05 12:40:21 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -101,32 +101,28 @@ static int ft_brackets(char c)
void ft_check_line(void) void ft_check_line(void)
{ {
int i; int i;
char *str;
short status; short status;
i = 0; i = -1;
status = 0; status = 0;
str = STR;
ft_reset_tab((char *)g_brackets.tabl); ft_reset_tab((char *)g_brackets.tabl);
g_brackets.pos = 0; g_brackets.pos = 0;
if (!str) if (!STR)
return ; return ;
while (str[i]) while (STR[++i])
{ {
if (IS_BSLASH & status) if (IS_BSLASH & status)
status = status ^ IS_BSLASH; status = status ^ IS_BSLASH;
else else
{ {
ft_check_this_char_quotes(str[i], &status); ft_check_this_char_quotes(STR[i], &status);
if (!status && ft_brackets(str[i])) if (!status && ft_brackets(STR[i]))
return ; return ;
} }
++i;
} }
if (g_brackets.pos && g_brackets.tabl[0] == '(') if (g_brackets.pos && g_brackets.tabl[0] == '(')
status = status | IS_BRACKET; status = status | IS_BRACKET;
else if (g_brackets.pos && g_brackets.tabl[0] == '{') else if (g_brackets.pos && g_brackets.tabl[0] == '{')
status = status | IS_ACCOLADE; status = status | IS_ACCOLADE;
if (status) (status) ? ft_read_more(status) : 0;
ft_read_more(status);
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */ /* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */
/* Updated: 2017/02/03 16:10:54 by gwojda ### ########.fr */ /* Updated: 2017/02/05 16:48:20 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,15 +21,15 @@ int ft_completion(int ret)
if (((ret != TOUCHE_TAB && ret != 10) if (((ret != TOUCHE_TAB && ret != 10)
|| (ret == 10)) && !(data_singleton()->comp)) || (ret == 10)) && !(data_singleton()->comp))
return (0); return (0);
tmp = data_singleton()->line.pos; tmp = POS;
if (data_singleton()->comp || ret == TOUCHE_TAB) if (data_singleton()->comp || ret == TOUCHE_TAB)
boolean = completion(ret); boolean = completion(ret);
if (boolean || ret == 10) if (boolean || ret == 10)
{ {
ft_puttermcaps("cd"); ft_puttermcaps("cd");
ft_current_str(data_singleton()->line.input, tmp); ft_current_str(STR, tmp);
ft_get_next_str(data_singleton()->line.input, &tmp); ft_get_next_str(STR, &tmp);
data_singleton()->line.pos = tmp; POS = tmp;
} }
return (1); return (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/03 18:27:23 by gwojda ### ########.fr */ /* Updated: 2017/02/05 16:49:10 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,17 +22,12 @@ void ft_buff_f6(void)
void ft_control_d(void) void ft_control_d(void)
{ {
char **str; if (!STR || STR[0] == '\0')
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (!(*str) || (*str)[0] == '\0')
{ {
ft_putstr("exit\n"); 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
ft_puttermcaps("bl"); ft_puttermcaps("bl");
@ -40,13 +35,8 @@ void ft_control_d(void)
void ft_control_c(void) void ft_control_c(void)
{ {
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
ft_putchar('\n'); ft_putchar('\n');
ft_prompt(); ft_prompt();
ft_strdel(str); ft_strdel(&STR);
*pos = 0; POS = 0;
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
/* Updated: 2017/02/04 14:55:05 by gwojda ### ########.fr */ /* Updated: 2017/02/05 17:07:12 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,48 +41,40 @@ void ft_v(void)
size_t tmp_pos; size_t tmp_pos;
int i; int i;
char *tmp; char *tmp;
char **str;
size_t *pos;
tmp = data_singleton()->line.copy_tmp; tmp = data_singleton()->line.copy_tmp;
str = &STR;
pos = &POS;
i = -1; i = -1;
tmp_pos = *pos; tmp_pos = POS;
if (!*str || !tmp) if (!STR || !tmp)
return ; return ;
while (tmp[++i]) while (tmp[++i])
*str = ft_realloc_imput(*str, tmp[i], *pos + i); STR = ft_realloc_imput(STR, tmp[i], POS + i);
if (*pos) if (POS)
{ {
--(*pos); --POS;
ft_get_beggin_with_curs(*str, pos); ft_get_beggin_with_curs(STR, &POS);
} }
ft_current_str(*str, *pos); ft_current_str(STR, POS);
ft_get_next_str(*str, pos); ft_get_next_str(STR, &POS);
ft_putnc('\b', *pos - tmp_pos); ft_putnc('\b', POS - tmp_pos);
(*pos) = tmp_pos; POS = tmp_pos;
} }
void ft_x(void) void ft_x(void)
{ {
int i; int i;
char **tmp; char **tmp;
char **str;
size_t *pos;
tmp = &data_singleton()->line.copy_tmp; tmp = &data_singleton()->line.copy_tmp;
str = &STR; if (!STR)
pos = &POS;
if (!*str)
return ; return ;
if (*tmp) if (*tmp)
ft_strdel(tmp); ft_strdel(tmp);
*tmp = ft_strdupi_space(&(*str)[(*pos)]); *tmp = ft_strdupi_space(&STR[POS]);
i = ft_strlen(*tmp); i = ft_strlen(*tmp);
while (i >= 0) while (i >= 0)
{ {
*str = ft_remove_imput(*str, *pos + i); STR = ft_remove_imput(STR, POS + i);
--i; --i;
} }
ft_puttermcaps("cd"); ft_puttermcaps("cd");
@ -91,13 +83,9 @@ void ft_x(void)
void ft_c(void) void ft_c(void)
{ {
char *tmp; char *tmp;
char **str;
size_t *pos;
tmp = data_singleton()->line.copy_tmp; tmp = data_singleton()->line.copy_tmp;
str = &STR;
pos = &POS;
if (tmp) if (tmp)
ft_strdel(&tmp); ft_strdel(&tmp);
tmp = ft_strdupi_space((*str) + (*pos)); tmp = ft_strdupi_space(STR + POS);
} }

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/04 15:39:49 by gwojda ### ########.fr */ /* Updated: 2017/02/05 16:57:57 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -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/04 15:17:19 by gwojda ### ########.fr */ /* Updated: 2017/02/05 16:57:51 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -58,76 +58,70 @@ static void ft_found_prev_word_2(int i, char *str, size_t *pos)
void ft_found_prev_word(void) void ft_found_prev_word(void)
{ {
int i; int i;
char *str;
size_t *pos;
i = 0; i = 0;
str = STR; if (!POS || !STR)
pos = &POS;
if (!*pos || !str)
return ; return ;
ft_init_prev_word(pos, str); ft_init_prev_word(&POS, STR);
if (*pos >= 1 && str[*pos - 1] == '\n') if (POS >= 1 && STR[POS - 1] == '\n')
{
if (POS - 1 == 0)
{ {
ft_puttermcaps("cd"); ft_puttermcaps("cd");
if (*pos >= 2) --POS;
(*pos) -= 2; return ;
ft_get_beggin(str, pos); }
ft_current_str(str, *pos); ft_puttermcaps("cd");
ft_get_next_str(str, pos); POS -= 2;
++(*pos); ft_get_beggin(STR, &POS);
if (!POS && STR[POS] == '\n')
++POS;
ft_current_str(STR, POS);
ft_get_next_str(STR, &POS);
++POS;
} }
else else
ft_found_prev_word_2(i, str, pos); ft_found_prev_word_2(i, STR, &POS);
} }
static void ft_found_next_word_2(void) static void ft_found_next_word_2(void)
{ {
char *str; if (POS)
size_t *pos;
str = STR;
pos = &POS;
if (*pos)
{ {
--(*pos); --POS;
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(STR, &POS);
} }
ft_puttermcaps("cd"); ft_puttermcaps("cd");
ft_get_next_str(str, pos); ft_get_next_str(STR, &POS);
(*pos) += (*pos) ? 2 : 1; POS += (POS || STR[0] != '\n') ? 2 : 1;
ft_current_str(str, *pos); ft_current_str(STR, POS);
ft_get_next_str(str, pos); ft_get_next_str(STR, &POS);
if (!str[*pos]) if (!STR[POS])
--(*pos); --POS;
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(STR, &POS);
} }
void ft_found_next_word(void) void ft_found_next_word(void)
{ {
int i; int i;
char *str;
size_t *pos;
i = 0; i = 0;
str = STR; if (!STR)
pos = &POS;
if (!str)
return ; 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]);
++i; ++i;
} }
if (str[*pos] == '\n') if (STR[POS] == '\n')
ft_found_next_word_2(); ft_found_next_word_2();
else else
{ {
while (str[i + *pos] && str[i + *pos] != '\n' && str[i + *pos] != ' ') while (STR[i + POS] && STR[i + POS] != '\n' && STR[i + POS] != ' ')
{ {
ft_putchar(str[i + *pos]); ft_putchar(STR[i + POS]);
++i; ++i;
} }
*pos += i; POS += i;
} }
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */ /* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
/* Updated: 2017/02/04 15:34:10 by gwojda ### ########.fr */ /* Updated: 2017/02/05 17:07:43 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,106 +20,93 @@ int ft_put(int nb)
void ft_end(void) void ft_end(void)
{ {
char *str; if (!STR)
size_t *pos;
str = STR;
pos = &POS;
if (!str)
return ; return ;
if (*pos) if (POS)
{ {
--(*pos); --POS;
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(STR, &POS);
} }
ft_puttermcaps("cd"); ft_puttermcaps("cd");
while (str[*pos]) while (STR[POS])
++(*pos); ++POS;
ft_get_beggin(str, pos); ft_get_beggin(STR, &POS);
ft_current_str(str, *pos); ft_current_str(STR, POS);
ft_get_next_str(str, pos); ft_get_next_str(STR, &POS);
} }
void ft_home(void) void ft_home(void)
{ {
char *str; if (!STR)
size_t *pos;
str = STR;
pos = &POS;
if (!str)
return ; return ;
if (*pos) if (POS)
{ {
--(*pos); --POS;
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(STR, &POS);
if (str[*pos + 1] == '\n') if (STR[POS + 1] == '\n')
ft_puttermcaps("nd"); ft_puttermcaps("nd");
} }
ft_puttermcaps("cd"); ft_puttermcaps("cd");
*pos = 0; POS = 0;
ft_current_str(str, *pos); ft_current_str(STR, POS);
ft_get_next_str(str, pos); ft_get_next_str(STR, &POS);
ft_check_end_of_line(str, *pos); ft_check_end_of_line(STR, POS);
if (!str[*pos]) if (!STR[POS])
--(*pos); --POS;
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(STR, &POS);
} }
void ft_move_right(void) void ft_move_right(void)
{ {
size_t tmp; size_t tmp;
size_t *pos;
pos = &POS; if (ft_strlen(STR) <= POS)
if (ft_strlen(STR) <= *pos)
return ; return ;
if (STR[*pos] == '\n') if (STR[POS] == '\n')
{ {
if (*pos) if (POS)
{ {
tmp = *pos - 1; tmp = POS - 1;
ft_get_beggin_with_curs(STR, &tmp); ft_get_beggin_with_curs(STR, &tmp);
} }
ft_puttermcaps("cd"); ft_puttermcaps("cd");
++(*pos); ++POS;
ft_current_str(STR, *pos); ft_current_str(STR, POS);
ft_get_next_str(STR, pos); ft_get_next_str(STR, &POS);
(*pos) = (!STR[*pos]) ? *pos - 1 : *pos; POS = (!STR[POS]) ? POS - 1 : POS;
ft_get_beggin_with_curs(STR, pos); ft_get_beggin_with_curs(STR, &POS);
} }
else else
{ {
ft_putchar(STR[*pos]); ft_putchar(STR[POS]);
++(*pos); ++POS;
} }
} }
void ft_move_left(void) void ft_move_left(void)
{ {
size_t *pos; if (!POS)
pos = &POS;
if (!*pos)
return ; return ;
if (STR[*pos - 1] == '\n') if (STR[POS - 1] == '\n')
{ {
if (*pos - 1 == 0) if (POS - 1 == 0)
{ {
ft_puttermcaps("cd"); ft_puttermcaps("cd");
--(*pos); --POS;
return ; return ;
} }
ft_puttermcaps("cd"); ft_puttermcaps("cd");
(*pos) -= 2; POS -= 2;
ft_get_beggin(STR, pos); ft_get_beggin(STR, &POS);
ft_current_str(STR, *pos); if (!POS && STR[POS] == '\n')
ft_get_next_str(STR, pos); ++POS;
++(*pos); ft_current_str(STR, POS);
ft_get_next_str(STR, &POS);
++POS;
} }
else else
{ {
ft_puttermcaps("le"); ft_puttermcaps("le");
--(*pos); --POS;
} }
} }

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/03 18:15:07 by gwojda ### ########.fr */ /* Updated: 2017/02/05 12:21:21 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,13 +19,39 @@ char *ft_get_next_word(char *str)
j = 0; j = 0;
k = 0; k = 0;
while (str[j] && str[j] == ' ') while (str[j] && (str[j] == ' ' || str[j] == '\n'))
++j; ++j;
while (str[j + k] && str[j + k] != ' ') while (str[j + k] && str[j + k] != ' ' && str[j + k] != '\n')
++k; ++k;
return (ft_strndup(str + j, k)); return (ft_strndup(str + j, k));
} }
static void ft_after_retline(char *str, int *i)
{
while (str[*i] && str[*i] != '\n')
++(*i);
if (str[*i] == '\n')
++(*i);
}
static int ft_is_keyword(char *str, char *end)
{
int i;
int j;
i = 0;
while (str[i])
{
ft_after_retline(str, &i);
j = 0;
while (str[i + j] && str[i + j] != '\n')
++j;
if (str[i] && ft_strncmp(str + i, end, j) == 0)
return (0);
}
return (1);
}
static void ft_check_heredoc_2(char **str, char *end) static void ft_check_heredoc_2(char **str, char *end)
{ {
char boolean; char boolean;
@ -67,7 +93,12 @@ void ft_check_heredoc(char **str)
if ((*str)[i] == '<' && !ft_strncmp(*str + i, "<<", 2)) if ((*str)[i] == '<' && !ft_strncmp(*str + i, "<<", 2))
{ {
if ((*str)[i + 1] == '<' && (*str)[i + 2]) if ((*str)[i + 1] == '<' && (*str)[i + 2])
{
end = ft_get_next_word(*str + i + 2); end = ft_get_next_word(*str + i + 2);
if (ft_is_keyword(*str, end))
ft_check_heredoc_2(str, end);
free(end);
}
else else
return ; return ;
} }
@ -75,6 +106,4 @@ void ft_check_heredoc(char **str)
} }
if (!end) if (!end)
return ; return ;
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/02/02 15:22:19 by gwojda #+# #+# */ /* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
/* Updated: 2017/02/04 15:20:49 by gwojda ### ########.fr */ /* Updated: 2017/02/05 17:00:18 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,18 +14,15 @@
static void ft_clear_before_history(char **str) static void ft_clear_before_history(char **str)
{ {
size_t *pos;
pos = &POS;
if (*str) if (*str)
{ {
if (*pos) if (POS)
{ {
--(*pos); --POS;
ft_get_beggin_with_curs(*str, pos); ft_get_beggin_with_curs(*str, &POS);
} }
ft_puttermcaps("cd"); ft_puttermcaps("cd");
*pos = 0; POS = 0;
ft_strdel(str); ft_strdel(str);
} }
} }
@ -33,53 +30,45 @@ static void ft_clear_before_history(char **str)
void ft_history_down(void) void ft_history_down(void)
{ {
t_list_history *head; t_list_history *head;
char **str;
size_t *pos;
str = &STR;
pos = &POS;
head = data_singleton()->line.list_cur; head = data_singleton()->line.list_cur;
if (!head) if (!head)
return ; return ;
ft_clear_before_history(str); ft_clear_before_history(&STR);
if (head->next) if (head->next)
head = head->next; head = head->next;
if (!head->str) if (!head->str)
*str = NULL; STR = NULL;
else else
*str = ft_strdup(head->str); STR = ft_strdup(head->str);
if (*str) if (STR)
ft_current_str(*str, *pos); ft_current_str(STR, POS);
if (*str) if (STR)
*pos = ft_strlen_next(*str, *pos); POS = ft_strlen_next(STR, POS);
else else
*pos = 0; POS = 0;
data_singleton()->line.list_cur = head; data_singleton()->line.list_cur = head;
} }
void ft_history_up(void) void ft_history_up(void)
{ {
t_list_history *head; t_list_history *head;
char **str;
size_t *pos;
str = &STR;
pos = &POS;
head = data_singleton()->line.list_cur; head = data_singleton()->line.list_cur;
if (!head) if (!head)
return ; return ;
ft_clear_before_history(str); ft_clear_before_history(&STR);
if (head->prev) if (head->prev)
head = head->prev; head = head->prev;
if (!head->str) if (!head->str)
*str = NULL; STR = NULL;
else else
*str = ft_strdup(head->str); STR = ft_strdup(head->str);
if (*str) if (STR)
ft_current_str(*str, *pos); ft_current_str(STR, POS);
if (*str) if (STR)
*pos = ft_strlen_next(*str, *pos); POS = ft_strlen_next(STR, POS);
else else
*pos = 0; POS = 0;
data_singleton()->line.list_cur = head; data_singleton()->line.list_cur = head;
} }

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/04 15:35:25 by gwojda ### ########.fr */ /* Updated: 2017/02/05 16:58:43 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -72,24 +72,22 @@ static void ft_history_parsing_2(void)
void ft_history_parsing(void) void ft_history_parsing(void)
{ {
char *str;
int i; int i;
char boolean; char boolean;
i = 0; i = 0;
boolean = 0; boolean = 0;
str = data_singleton()->line.input; if (!STR)
if (!str)
return ; return ;
while (str && str[i]) while (STR && STR[i])
{ {
if (str[i] == '!') if (STR[i] == '!')
{ {
boolean = 1; boolean = 1;
if (!ft_history_parsing_3(str, &i)) if (!ft_history_parsing_3(STR, &i))
boolean = 0; boolean = 0;
} }
str = data_singleton()->line.input; 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/09 13:21:40 by gwojda #+# #+# */ /* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
/* Updated: 2017/02/04 16:35:33 by gwojda ### ########.fr */ /* Updated: 2017/02/05 17:01:51 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,26 +41,22 @@ static void ft_up_2(size_t *pos, char *str)
void ft_up(void) void ft_up(void)
{ {
int i; int i;
char *str;
size_t *pos;
i = 0; i = 0;
str = data_singleton()->line.input; if (!STR || !POS)
pos = &data_singleton()->line.pos;
if (!str || !*pos)
return ; return ;
if (str[*pos - 1] == '\n') if (STR[POS - 1] == '\n')
{ {
ft_puttermcaps("cd"); ft_puttermcaps("cd");
if (*pos >= 2) if (POS >= 2)
(*pos) -= 2; POS -= 2;
ft_get_beggin(str, pos); ft_get_beggin(STR, &POS);
ft_current_str(str, *pos); ft_current_str(STR, POS);
ft_get_next_str(str, pos); ft_get_next_str(STR, &POS);
++(*pos); ++POS;
} }
else else
ft_up_2(pos, str); ft_up_2(&POS, STR);
} }
static void ft_down_2(size_t *pos, char *str) static void ft_down_2(size_t *pos, char *str)
@ -84,24 +80,20 @@ void ft_down(void)
{ {
int i; int i;
int len; int len;
char *str;
size_t *pos;
i = 0; i = 0;
str = data_singleton()->line.input; if (!STR)
pos = &data_singleton()->line.pos;
if (!str)
return ; return ;
if (str[*pos] == '\n') if (STR[POS] == '\n')
ft_down_2(pos, str); ft_down_2(&POS, STR);
else else
{ {
len = ft_size_term(); len = ft_size_term();
while (str[i + *pos] && str[i + *pos] != '\n' && --len + 1) while (STR[i + POS] && STR[i + POS] != '\n' && --len + 1)
{ {
ft_putchar(str[i + *pos]); ft_putchar(STR[i + POS]);
++i; ++i;
} }
*pos += i; POS += i;
} }
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */ /* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
/* Updated: 2017/02/02 15:10:50 by gwojda ### ########.fr */ /* Updated: 2017/02/05 17:08:58 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,21 +26,17 @@ int ft_found_next_char(char *str, size_t i)
void ft_print(int ret) void ft_print(int ret)
{ {
int j; int j;
char **str;
size_t *i;
j = 0; j = 0;
str = &data_singleton()->line.input; STR = ft_realloc_imput(STR, ret, POS);
i = &data_singleton()->line.pos; while (*(STR + POS + j) && *(STR + POS + j) != '\n')
*str = ft_realloc_imput(*str, ret, *i);
while (*((*str) + *i + j) && *((*str) + *i + j) != '\n')
{ {
ft_putchar(*((*str) + *i + j)); ft_putchar(*(STR + POS + j));
++j; ++j;
} }
ft_check_end_of_line(*str, *i + j); ft_check_end_of_line(STR, POS + j);
ft_putnc('\b', j - 1); ft_putnc('\b', j - 1);
++(*i); ++POS;
} }
void ft_suppr_2(char **str, size_t *i, size_t tmp) void ft_suppr_2(char **str, size_t *i, size_t tmp)
@ -60,53 +56,45 @@ void ft_suppr(void)
{ {
size_t tmp; size_t tmp;
char boolean; char boolean;
char **str;
size_t *i;
str = &data_singleton()->line.input;
i = &data_singleton()->line.pos;
boolean = 0; boolean = 0;
if (*i <= 0) if (POS <= 0)
return ; return ;
if ((*str)[*i - 1] != '\n') if (STR[POS - 1] != '\n')
boolean = 1; boolean = 1;
--(*i); --POS;
tmp = *i; tmp = POS;
if (boolean) if (boolean)
{ {
ft_get_beggin_with_curs(*str, i); ft_get_beggin_with_curs(STR, &POS);
*str = ft_remove_imput((*str), tmp); STR = ft_remove_imput(STR, tmp);
} }
else else
{ {
*str = ft_remove_imput((*str), tmp); STR = ft_remove_imput(STR, tmp);
ft_get_beggin(*str, i); ft_get_beggin(STR, &POS);
} }
ft_suppr_2(str, i, tmp); ft_suppr_2(&STR, &POS, tmp);
} }
void ft_del(void) void ft_del(void)
{ {
size_t tmp; size_t tmp;
char **str;
size_t *i;
str = &data_singleton()->line.input; tmp = POS;
i = &data_singleton()->line.pos; STR = ft_remove_imput(STR, tmp);
tmp = *i; if (!(STR && POS < ft_strlen(STR + 1)))
*str = ft_remove_imput((*str), tmp);
if (!((*str) && (*i) < ft_strlen((*str))))
return ; return ;
if (*i) if (POS)
{ {
--(*i); --POS;
ft_get_beggin_with_curs(*str, i); ft_get_beggin_with_curs(STR, &POS);
} }
ft_puttermcaps("cd"); ft_puttermcaps("cd");
ft_current_str(*str, *i); ft_current_str(STR, POS);
ft_get_next_str(*str, i); ft_get_next_str(STR, &POS);
if ((*str)[*i]) if (STR[POS] && STR[POS] != '\n')
++(*i); ++POS;
ft_putnc('\b', *i - tmp); ft_putnc('\b', POS - tmp);
(*i) = tmp; POS = tmp;
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */ /* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */
/* Updated: 2017/02/04 16:27:34 by gwojda ### ########.fr */ /* Updated: 2017/02/05 17:06:07 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -58,29 +58,25 @@ void ft_change_affichage(void)
void ft_printall(void) void ft_printall(void)
{ {
size_t pos_tmp; size_t pos_tmp;
char *str;
size_t *pos;
int ret; int ret;
str = STR;
pos = &POS;
ret = 0; ret = 0;
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !str) if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !STR)
return ; return ;
ft_clear_window(); ft_clear_window();
ft_prompt(); ft_prompt();
pos_tmp = *pos; pos_tmp = POS;
ft_change_affichage(); ft_change_affichage();
if (*pos) if (POS)
--(*pos); --POS;
ft_get_beggin(str, pos); ft_get_beggin(STR, &POS);
ft_current_str(str, *pos); ft_current_str(STR, POS);
ft_get_next_str(str, pos); ft_get_next_str(STR, &POS);
if (*pos && !str[*pos]) if (POS && !STR[POS])
--(*pos); --POS;
if (*pos) if (POS)
ft_putnc('\b', *pos - pos_tmp + 1); ft_putnc('\b', POS - pos_tmp + 1);
*pos = pos_tmp; POS = pos_tmp;
} }
void ft_get_beggin_with_curs(char *str, size_t *pos) void ft_get_beggin_with_curs(char *str, size_t *pos)