changement du squelette (passage a un tableau de pointeur sur fonction) - pas encore tout resté

This commit is contained in:
gwojda 2017-02-02 19:07:32 +01:00
parent 7265a6c340
commit 7fb9aa2da5
22 changed files with 490 additions and 425 deletions

View file

@ -144,12 +144,14 @@ 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/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\
line-editing/get_touch.c\ line-editing/get_touch.c\
line-editing/get_touch_toolz.c\ line-editing/get_touch_toolz.c\
line-editing/get_touch_toolz_2.c\ line-editing/get_touch_toolz_2.c\
line-editing/heredoc.c\ line-editing/heredoc.c\
line-editing/history.c\
line-editing/history_parsing.c\ line-editing/history_parsing.c\
line-editing/history_parsing_toolz.c\ line-editing/history_parsing_toolz.c\
line-editing/history_parsing_toolz_2.c\ line-editing/history_parsing_toolz_2.c\

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* builtin.h :+: :+: :+: */ /* builtin.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */ /* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */
/* Updated: 2017/01/21 18:42:34 by jhalford ### ########.fr */ /* Updated: 2017/02/02 19:07:01 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,5 +27,6 @@ int builtin_unsetenv(const char *path, char *const argv[], char *const envp[]);
int builtin_jobs(const char *path, char *const av[], char *const envp[]); int builtin_jobs(const char *path, char *const av[], char *const envp[]);
int builtin_fg(const char *path, char *const av[], char *const envp[]); int builtin_fg(const char *path, char *const av[], char *const envp[]);
int builtin_bg(const char *path, char *const av[], char *const envp[]); int builtin_bg(const char *path, char *const av[], char *const envp[]);
int builtin_history(const char *path, char *const av[], char *const envp[]);
#endif #endif

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/02 13:23:12 by gwojda ### ########.fr */ /* Updated: 2017/02/02 18:28:44 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,6 +38,7 @@
# define TOUCHE_CTRL_C 3 # define TOUCHE_CTRL_C 3
# define TOUCHE_CTRL_D 4 # define TOUCHE_CTRL_D 4
# define TOUCHE_CTRL_R 18 # define TOUCHE_CTRL_R 18
# define TOUCHE_SUPPR 127
# define TOUCHE_HOME 4741915 # define TOUCHE_HOME 4741915
# define TOUCHE_END 4610843 # define TOUCHE_END 4610843
# define TOUCHE_TAB 9 # define TOUCHE_TAB 9
@ -65,84 +66,82 @@ typedef struct s_list_history
typedef struct s_line typedef struct s_line
{ {
char *input; char *input;
char *copy_tmp;
size_t pos;
int prompt_size; int prompt_size;
int list_size; int list_size;
char opt; char opt;
t_list_history *list_end; t_list_history *list_end;
t_list_history *list_cur;
t_list_history *list_beg; t_list_history *list_beg;
} t_line; } t_line;
void ft_add_in_history_file(char *str); typedef struct s_key
int builtin_history(const char *path, char *const av[], char *const envp[]); {
void ft_check_backslash(char **str); int value;
char *ft_strget_history(char *str); void (*f)(void);
void ft_surch_in_history(char **str, size_t *pos); } t_key;
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
void ft_move_right(size_t *pos, char *str); extern t_key g_keys[];
void ft_move_left(size_t *pos, char *str);
int ft_put(int nb);
void ft_end(char *str, size_t *pos); void ft_putnc(char c, int n);
void ft_home(char *str, size_t *pos);
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
void ft_realloc_str_history(char **str, size_t pos
, int nb_his, int len);
char *ft_strdupi_w(char const *s);
void ft_history_parsing();
void ft_check_heredoc(char **str);
void ft_history_builtin(void);
int ft_nbr_len(int nbr); int ft_nbr_len(int nbr);
int ft_found_next_char(char *str, size_t i); void ft_puttermcaps(char *str);
void ft_check_end_of_line(char *str, size_t pos);
void ft_printall(char *str, size_t *pos);
void ft_get_beggin_with_curs(char *str, size_t *pos); void ft_get_beggin_with_curs(char *str, size_t *pos);
void ft_history(char **str, int ret, t_list_history **head, size_t *pos); void ft_check_end_of_line(char *str, size_t pos);
void ft_suppr(char **str, size_t *i); int ft_size_term(void);
void ft_del(char **str, size_t *i); void ft_add_in_history_file(char *str);
void ft_get_beggin(char *str, size_t *pos);
void ft_get_next_str(char *str, size_t *pos);
void ft_putall_current_str(char *str, size_t *pos);
void ft_current_str(char *str, size_t pos); void ft_current_str(char *str, size_t pos);
int ft_strlen_next(char *str, size_t pos); int ft_strlen_next(char *str, size_t pos);
void ft_putall_current_str(char *str, size_t *pos); void ft_push_back_history(t_list_history **head, t_list_history *new);
void ft_get_next_str(char *str, size_t *pos); void ft_prompt(void);
void ft_get_beggin(char *str, size_t *pos);
long long ft_pow(int nbr, int power);
char *ft_strndup(char const *s, int n);
char *ft_strdupi(char const *s);
void ft_puttermcaps(char *str);
void ft_putnc(char c, int n);
int ft_size_term(void);
void ft_free_tabstr(char ***env);
int ft_is_whitespaces(char *str);
int ft_get_size_prev(char *str, size_t pos);
int ft_nb_line(char *str, size_t pos);
int ft_get_ind_prev(char *str, size_t pos);
void ft_found_next_word(char *str, size_t *pos);
void ft_move_to_beggin(char *str, size_t *pos);
int ft_nb_last_line(char *str, size_t pos);
void ft_found_prev_word(char *str, size_t *pos);
char *ft_remove_imput(char *str, size_t pos); char *ft_remove_imput(char *str, size_t pos);
char *ft_realloc_imput(char *str, int a, size_t pos); char *ft_realloc_imput(char *str, int a, size_t pos);
int ft_readline(void); char *ft_strdupi(char const *s);
struct termios *ft_stats_term_termcaps(void); char *ft_strndup(char const *s, int n);
struct termios *ft_save_stats_term(void);
void ft_init_line(void);
void ft_read_it(int input, size_t *pos, char **str);
void ft_check_quotes(char **s, t_list_history *head);
int ft_check_quotes_num(char *s);
void ft_print(char **str, int ret, size_t *i);
void ft_move_to_line(int ret, size_t *pos, char *str);
void ft_get_head(t_list_history **head);
void ft_push_back_history(t_list_history **head, t_list_history *new);
t_list_history *ft_create_history_list(char *str); t_list_history *ft_create_history_list(char *str);
void ft_curse_move(char *str); char *ft_strdupi_w(char const *s);
void ft_move_suppr(char *str, size_t pos); void ft_realloc_str_history(char **str, size_t pos, int nb_his, int len);
void ft_move_dell(char *str, size_t pos); void ft_realloc_str_history_2(char **str, size_t pos, char *s);
void ft_move_to_word(int ret, size_t *pos, char *str); long long ft_pow(int nbr, int power);
void ft_move_term(int ret, size_t *pos, char *str); void ft_realloc_str_history_3(char **str, size_t pos, char *s);
void ft_home_end(char *str, int ret, size_t *pos); 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); int ft_put(int nb);
char **ft_split_whitespaces(char const *s);
void ft_cxv(int ret, size_t *pos, char **str); char *ft_read_stdin(void);
char *ft_lecture(t_list_history *head); void ft_end(void);
void ft_prompt(void); void ft_home(void);
void ft_move_right(void);
void ft_move_left(void);
void ft_up(void);
void ft_down(void);
void ft_buff_f6(void);
void ft_control_d(void);
void ft_control_c(void);
void ft_del(void);
void ft_suppr(void);
void ft_print(int ret);
void ft_surch_in_history(void);
void ft_printall(void);
void ft_history_down(void);
void ft_history_up(void);
void ft_found_next_word(void);
void ft_found_prev_word(void);
void ft_c(void);
void ft_x(void);
void ft_v(void);
void ft_history_parsing(void);
void ft_read_it(int input, size_t *pos, char **str);
int ft_readline(void);
void ft_check_heredoc(char **str);
void ft_check_quotes(char **s);
#endif #endif

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/02 11:11:11 by gwojda ### ########.fr */ /* Updated: 2017/02/02 16:01:25 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,7 +26,7 @@ void ft_check_backslash(char **str)
tmp1 = *str; tmp1 = *str;
tmp2 = ft_strjoin(tmp1, "\n"); tmp2 = ft_strjoin(tmp1, "\n");
free(tmp1); free(tmp1);
tmp1 = ft_lecture(data_singleton()->line.list_beg); tmp1 = ft_read_stdin();
*str = ft_strjoin(tmp2, tmp1); *str = ft_strjoin(tmp2, tmp1);
free(tmp1); free(tmp1);
free(tmp2); free(tmp2);

View file

@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* control_c_and_d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
/* Updated: 2017/02/02 16:43:15 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_buff_f6(void)
{
int ret;
ret = 0;
read(0, &ret, sizeof(int));
}
void ft_control_d(void)
{
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (!(*str) || (*str)[0] == '\0')
builtin_exit(NULL, (char*[]){"exit", NULL}, NULL);
else if (*pos < ft_strlen(*str))
ft_del();
else
ft_puttermcaps("bl");
}
void ft_control_c(void)
{
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
ft_putchar('\n');
ft_prompt();
ft_strdel(str);
*pos = 0;
}

View file

@ -6,37 +6,12 @@
/* 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/01 15:16:33 by gwojda ### ########.fr */ /* Updated: 2017/02/02 16:10:51 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static void ft_v(char *tmp, size_t *pos, char **str)
{
size_t tmp_pos;
int i;
i = 0;
tmp_pos = *pos;
if (!tmp)
return ;
while (tmp[i])
{
*str = ft_realloc_imput(*str, tmp[i], *pos + i);
++i;
}
if (*pos)
{
--(*pos);
ft_get_beggin_with_curs(*str, pos);
}
ft_current_str(*str, *pos);
ft_get_next_str(*str, pos);
ft_putnc('\b', *pos - tmp_pos);
(*pos) = tmp_pos;
}
static char *ft_strdupi_space(char const *s) static char *ft_strdupi_space(char const *s)
{ {
int i; int i;
@ -61,10 +36,49 @@ static char *ft_strdupi_space(char const *s)
return (str); return (str);
} }
static void ft_x(char **tmp, size_t *pos, char **str) void ft_v(void)
{ {
int i; size_t tmp_pos;
int i;
char *tmp;
char **str;
size_t *pos;
tmp = data_singleton()->line.copy_tmp;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
i = 0;
tmp_pos = *pos;
if (!*str || !tmp)
return ;
while (tmp[i])
{
*str = ft_realloc_imput(*str, tmp[i], *pos + i);
++i;
}
if (*pos)
{
--(*pos);
ft_get_beggin_with_curs(*str, pos);
}
ft_current_str(*str, *pos);
ft_get_next_str(*str, pos);
ft_putnc('\b', *pos - tmp_pos);
(*pos) = tmp_pos;
}
void ft_x(void)
{
int i;
char **tmp;
char **str;
size_t *pos;
tmp = &data_singleton()->line.copy_tmp;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (!*str)
return ;
if (*tmp) if (*tmp)
ft_strdel(tmp); ft_strdel(tmp);
*tmp = ft_strdupi_space(&(*str)[(*pos)]); *tmp = ft_strdupi_space(&(*str)[(*pos)]);
@ -77,20 +91,16 @@ static void ft_x(char **tmp, size_t *pos, char **str)
ft_puttermcaps("cd"); ft_puttermcaps("cd");
} }
void ft_cxv(int ret, size_t *pos, char **str) void ft_c(void)
{ {
static char *tmp = NULL; char *tmp;
char **str;
size_t *pos;
if (!*str) tmp = data_singleton()->line.copy_tmp;
return ; str = &data_singleton()->line.input;
if (ret == TOUCHE_OPT_X) pos = &data_singleton()->line.pos;
ft_x(&tmp, pos, str); if (tmp)
else if (ret == TOUCHE_OPT_C) ft_strdel(&tmp);
{ tmp = ft_strdupi_space((*str) + (*pos));
if (tmp)
ft_strdel(&tmp);
tmp = ft_strdupi_space((*str) + (*pos));
}
else if (ret == TOUCHE_OPT_V)
ft_v(tmp, pos, str);
} }

View file

@ -6,114 +6,64 @@
/* 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 11:34:22 by gwojda ### ########.fr */ /* Updated: 2017/02/02 18:27:07 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int ft_lecture_3(int ret, char **str, size_t *i) t_key g_key[] =
{ {
if (ret == 127 && (*i) > 0) {FLECHE_HAUT , &ft_history_up },
ft_suppr(str, i); {FLECHE_BAS , &ft_history_down },
else if (ret == TOUCHE_DELETE && (*str) && (*i) < ft_strlen((*str))) {FLECHE_GAUCHE , &ft_move_left },
ft_del(str, i); {FLECHE_DROITE , &ft_move_right },
else if (ret == TOUCHE_HOME) {TOUCHE_DELETE , &ft_del },
ft_home(*str, i); {TOUCHE_CTRL_C , &ft_control_c },
else if (ret == TOUCHE_END) {TOUCHE_CTRL_D , &ft_control_d },
ft_end(*str, i); {TOUCHE_CTRL_R , &ft_history_parsing },
else {TOUCHE_SUPPR , &ft_suppr },
return (0); {TOUCHE_HOME , &ft_home },
return (1); {TOUCHE_END , &ft_end },
} {TOUCHE_OPT_UP , &ft_up },
{TOUCHE_OPT_DOWN , &ft_down },
{TOUCHE_OPT_LEFT , &ft_found_prev_word },
{TOUCHE_OPT_RIGHT , &ft_found_next_word },
{TOUCHE_OPT_C , &ft_c },
{TOUCHE_OPT_V , &ft_v },
{TOUCHE_OPT_X , &ft_x },
{TOUCHE_F5 , &ft_printall },
{TOUCHE_F6 , &ft_buff_f6 },
{0 , 0 },
};
static int ft_lecture_2(int ret, char **str, size_t *i) char *ft_read_stdin(void)
{ {
if (ret == TOUCHE_F5) int ret;
ft_printall(*str, i); int j;
else if (ret == TOUCHE_OPT_LEFT || ret == TOUCHE_OPT_RIGHT)
ft_move_to_word(ret, i, *str);
else if (ret == TOUCHE_OPT_X || ret == TOUCHE_OPT_C
|| ret == TOUCHE_OPT_V)
ft_cxv(ret, i, str);
else if (ret == FLECHE_DROITE)
ft_move_right(i, *str);
else if (ret == FLECHE_GAUCHE)
ft_move_left(i, *str);
else if (ret == TOUCHE_OPT_UP || ret == TOUCHE_OPT_DOWN)
ft_move_to_line(ret, i, *str);
else if (ft_isprint(ret))
ft_print(str, ret, i);
else
return (0);
return (1);
}
char *ft_lecture(t_list_history *head) if (data_singleton()->line.input)
{
char *str;
int ret;
size_t i;
str = NULL;
if (data_singleton()->line.opt & HIST)
str = data_singleton()->line.input;
i = 0;
if (str)
{ {
ft_current_str(str, i); ft_current_str(data_singleton()->line.input, data_singleton()->line.pos);
ft_get_next_str(str, &i); ft_get_next_str(data_singleton()->line.input, &data_singleton()->line.pos);
if (str[i]) if (data_singleton()->line.input[data_singleton()->line.pos])
++i; ++(data_singleton()->line.pos);
} }
while (42) while (42)
{ {
ret = 0; ret = 0;
j = 0;
read(0, &ret, sizeof(int)); read(0, &ret, sizeof(int));
if (ret == TOUCHE_F6 && read(0, &ret, sizeof(int)) > 0) while (g_key[j].value && g_key[j].value != ret)
continue ; ++j;
if (ret == TOUCHE_CTRL_R) if (g_key[j].value)
{ g_key[j].f();
ft_surch_in_history(&str, &i); else if (ft_isprint(ret))
continue ; ft_print(ret);
}
/*
** if (ret == TOUCHE_TAB)
** ret = ft_completion(&str, &i);
*/
if (ret == TOUCHE_CTRL_D)
{
if (!str || str[0] == '\0')
exit(0);
else if (i < ft_strlen(str))
ft_del(&str, &i);
else
ft_puttermcaps("bl");
}
if (ret == TOUCHE_CTRL_C)
{
ft_putchar('\n');
ft_prompt();
ft_strdel(&str);
i = 0;
}
if (ft_lecture_2(ret, &str, &i))
continue ;
else if (ret == FLECHE_BAS || ret == FLECHE_HAUT)
{
if (!head)
continue ;
ft_history(&str, ret, &head, &i);
if (str)
i = ft_strlen_next(str, i);
else
i = 0;
}
else if (ft_lecture_3(ret, &str, &i))
continue ;
else if (ret == 10) else if (ret == 10)
return (str); return (data_singleton()->line.input);
else if (ft_isascii(ret) == 0) else if (ft_isascii(ret) == 0)
ft_read_it(ret, &i, &str); ft_read_it(ret, &data_singleton()->line.pos,
&data_singleton()->line.input);
} }
} }

View file

@ -6,61 +6,108 @@
/* 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 11:41:52 by gwojda ### ########.fr */ /* Updated: 2017/02/02 15:22:35 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
void ft_history_2(char **str, int ret, t_list_history **head void ft_found_prev_word(void)
, size_t *pos)
{ {
if (*str) int i;
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
i = 0;
if (!*pos)
return ;
if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' '))
{
ft_puttermcaps("le");
--(*pos);
}
while ((int)*pos - i - 1 > 0 && str[*pos - i - 1] == ' ')
{
ft_puttermcaps("le");
++i;
}
(*pos) = (i && str[*pos - i] == '\n') ? *pos - i + 1 : *pos - i;
i = 0;
if (*pos >= 1 && str[*pos - 1] == '\n')
{
ft_puttermcaps("cd");
if (*pos >= 2)
(*pos) -= 2;
ft_get_beggin(str, pos);
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
++(*pos);
}
else
{
if (*pos && !(str[*pos] == '\n' || str[*pos] == ' '))
{
ft_puttermcaps("le");
--(*pos);
}
while (*pos - i && (str[*pos - i] == '\n' || str[*pos - i] == ' '))
{
ft_puttermcaps("le");
++i;
}
while (*pos - i && str[*pos - i] != '\n' && str[*pos - i] != ' ')
{
ft_puttermcaps("le");
++i;
}
if (str[*pos - i] == '\n' || str[*pos - i] == ' ')
{
ft_puttermcaps("nd");
++(*pos);
}
(*pos) -= i;
}
}
void ft_found_next_word(void)
{
int i;
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
i = 0;
while (str[i + *pos] && str[i + *pos] == ' ')
{
ft_putchar(str[i + *pos]);
++i;
}
if (str[*pos] == '\n')
{ {
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; ft_get_next_str(str, pos);
ft_strdel(str); (*pos) += (*pos) ? 2 : 1;
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
if (!str[*pos])
--(*pos);
ft_get_beggin_with_curs(str, pos);
} }
if (ret == FLECHE_BAS) else
{ {
if ((*head)->next) while (str[i + *pos] && str[i + *pos] != '\n' && str[i + *pos] != ' ')
(*head) = (*head)->next; {
if (!(*head)->str) ft_putchar(str[i + *pos]);
*str = NULL; ++i;
else }
*str = ft_strdup((*head)->str); *pos += i;
if (*str)
ft_current_str(*str, *pos);
} }
} }
void ft_history(char **str, int ret, t_list_history **head, size_t *pos)
{
ft_history_2(str, ret, head, pos);
if (ret == FLECHE_HAUT)
{
if ((*head)->prev)
(*head) = (*head)->prev;
if (!(*head)->str)
*str = NULL;
else
*str = ft_strdup((*head)->str);
if (*str)
ft_current_str(*str, *pos);
}
}
void ft_move_to_word(int ret, size_t *pos, char *str)
{
if (!str)
return ;
if (ret == TOUCHE_OPT_LEFT)
ft_found_prev_word(str, pos);
else if (ret == TOUCHE_OPT_RIGHT)
ft_found_next_word(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:43:58 by gwojda #+# #+# */ /* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
/* Updated: 2017/02/02 11:34:34 by gwojda ### ########.fr */ /* Updated: 2017/02/02 17:54:27 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,8 +18,13 @@ int ft_put(int nb)
return (1); return (1);
} }
void ft_end(char *str, size_t *pos) void ft_end(void)
{ {
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (!str) if (!str)
return ; return ;
if (*pos) if (*pos)
@ -35,8 +40,13 @@ void ft_end(char *str, size_t *pos)
ft_get_next_str(str, pos); ft_get_next_str(str, pos);
} }
void ft_home(char *str, size_t *pos) void ft_home(void)
{ {
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (!str) if (!str)
return ; return ;
if (*pos) if (*pos)
@ -56,10 +66,14 @@ void ft_home(char *str, size_t *pos)
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(str, pos);
} }
void ft_move_right(size_t *pos, char *str) void ft_move_right(void)
{ {
size_t tmp; size_t tmp;
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (ft_strlen(str) <= *pos) if (ft_strlen(str) <= *pos)
return ; return ;
if (str[*pos] == '\n') if (str[*pos] == '\n')
@ -84,8 +98,13 @@ void ft_move_right(size_t *pos, char *str)
} }
} }
void ft_move_left(size_t *pos, char *str) void ft_move_left(void)
{ {
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (!*pos) if (!*pos)
return ; return ;
if (str[*pos - 1] == '\n') if (str[*pos - 1] == '\n')
@ -96,7 +115,6 @@ void ft_move_left(size_t *pos, char *str)
--(*pos); --(*pos);
return ; return ;
} }
printf("here\n\n");
ft_puttermcaps("cd"); ft_puttermcaps("cd");
(*pos) -= 2; (*pos) -= 2;
ft_get_beggin(str, pos); ft_get_beggin(str, 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/01/25 16:03:11 by gwojda ### ########.fr */ /* Updated: 2017/02/02 16:09:42 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,7 +41,7 @@ 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;
tmp2 = ft_lecture(data_singleton()->line.list_beg); tmp2 = ft_read_stdin();
if (!ft_strcmp(end, tmp2)) if (!ft_strcmp(end, tmp2))
boolean = 1; boolean = 1;
*str = ft_strjoin(tmp, tmp2); *str = ft_strjoin(tmp, tmp2);

View file

@ -0,0 +1,87 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* history.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_history_down(void)
{
t_list_history *head;
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
head = data_singleton()->line.list_cur;
if (!head || !*str)
return ;
if (*str)
{
if (*pos)
{
--(*pos);
ft_get_beggin_with_curs(*str, pos);
}
ft_puttermcaps("cd");
*pos = 0;
ft_strdel(str);
}
if (head->next)
head = head->next;
if (!head->str)
*str = NULL;
else
*str = ft_strdup(head->str);
if (*str)
ft_current_str(*str, *pos);
if (*str)
*pos = ft_strlen_next(*str, *pos);
else
*pos = 0;
data_singleton()->line.list_cur = head;
}
void ft_history_up(void)
{
t_list_history *head;
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
head = data_singleton()->line.list_cur;
if (!head)
return ;
if (*str)
{
if (*pos)
{
--(*pos);
ft_get_beggin_with_curs(*str, pos);
}
ft_puttermcaps("cd");
*pos = 0;
ft_strdel(str);
}
if (head->prev)
head = head->prev;
if (!head->str)
*str = NULL;
else
*str = ft_strdup(head->str);
if (*str)
ft_current_str(*str, *pos);
if (*str)
*pos = ft_strlen_next(*str, *pos);
else
*pos = 0;
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/01/25 20:05:40 by gwojda ### ########.fr */ /* Updated: 2017/02/02 16:20:26 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -56,12 +56,10 @@ static void ft_history_parsing_2(void)
{ {
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_lecture( data_singleton()->line.input = ft_read_stdin();
data_singleton()->line.list_beg);
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_quotes(&data_singleton()->line.input);
data_singleton()->line.list_beg);
ft_check_heredoc(&data_singleton()->line.input); ft_check_heredoc(&data_singleton()->line.input);
ft_history_parsing(); ft_history_parsing();
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ /* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */
/* Updated: 2017/01/24 15:19:04 by gwojda ### ########.fr */ /* Updated: 2017/02/02 16:08:01 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,12 +49,3 @@ void ft_push_back_history(t_list_history **head, t_list_history *new)
new->next = (*head); new->next = (*head);
(*head)->prev = new; (*head)->prev = new;
} }
void ft_get_head(t_list_history **head)
{
if (head && *head)
{
while ((*head)->next && (*head)->next->str)
(*head) = (*head)->next;
}
}

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/01/25 16:40:09 by gwojda ### ########.fr */ /* Updated: 2017/02/02 15:07:08 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,11 +38,17 @@ static void ft_up_2(size_t *pos, char *str)
(*pos) -= i; (*pos) -= i;
} }
static void ft_up(size_t *pos, char *str) void ft_up(void)
{ {
int i; int i;
char *str;
size_t *pos;
i = 0; i = 0;
str = data_singleton()->line.input;
pos = &data_singleton()->line.pos;
if (!str)
return ;
if (str[*pos - 1] == '\n') if (str[*pos - 1] == '\n')
{ {
ft_puttermcaps("cd"); ft_puttermcaps("cd");
@ -73,12 +79,18 @@ static void ft_down_2(size_t *pos, char *str)
ft_get_beggin_with_curs(str, pos); ft_get_beggin_with_curs(str, pos);
} }
static void ft_down(size_t *pos, char *str) 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;
pos = &data_singleton()->line.pos;
if (!str)
return ;
if (str[*pos] == '\n') if (str[*pos] == '\n')
ft_down_2(pos, str); ft_down_2(pos, str);
else else
@ -92,13 +104,3 @@ static void ft_down(size_t *pos, char *str)
*pos += i; *pos += i;
} }
} }
void ft_move_to_line(int ret, size_t *pos, char *str)
{
if (!str)
return ;
if (ret == TOUCHE_OPT_UP)
ft_up(pos, str);
else if (ret == TOUCHE_OPT_DOWN)
ft_down(pos, str);
}

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 11:12:29 by gwojda ### ########.fr */ /* Updated: 2017/02/02 15:10:50 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,11 +23,15 @@ int ft_found_next_char(char *str, size_t i)
return (0); return (0);
} }
void ft_print(char **str, int ret, size_t *i) void ft_print(int ret)
{ {
int j; int j;
char **str;
size_t *i;
j = 0; j = 0;
str = &data_singleton()->line.input;
i = &data_singleton()->line.pos;
*str = ft_realloc_imput(*str, ret, *i); *str = ft_realloc_imput(*str, ret, *i);
while (*((*str) + *i + j) && *((*str) + *i + j) != '\n') while (*((*str) + *i + j) && *((*str) + *i + j) != '\n')
{ {
@ -52,12 +56,18 @@ void ft_suppr_2(char **str, size_t *i, size_t tmp)
ft_strdel(str); ft_strdel(str);
} }
void ft_suppr(char **str, size_t *i) 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)
return ;
if ((*str)[*i - 1] != '\n') if ((*str)[*i - 1] != '\n')
boolean = 1; boolean = 1;
--(*i); --(*i);
@ -75,12 +85,18 @@ void ft_suppr(char **str, size_t *i)
ft_suppr_2(str, i, tmp); ft_suppr_2(str, i, tmp);
} }
void ft_del(char **str, size_t *i) void ft_del(void)
{ {
size_t tmp; size_t tmp;
char **str;
size_t *i;
str = &data_singleton()->line.input;
i = &data_singleton()->line.pos;
tmp = *i; tmp = *i;
*str = ft_remove_imput((*str), tmp); *str = ft_remove_imput((*str), tmp);
if (!((*str) && (*i) < ft_strlen((*str))))
return ;
if (*i) if (*i)
{ {
--(*i); --(*i);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/05 12:20:19 by gwojda #+# #+# */ /* Created: 2017/01/05 12:20:19 by gwojda #+# #+# */
/* Updated: 2017/01/25 16:50:14 by gwojda ### ########.fr */ /* Updated: 2017/02/02 17:53:41 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -51,13 +51,15 @@ int ft_check_quotes_num(char *s)
return (0); return (0);
} }
void ft_check_quotes(char **s, t_list_history *head) void ft_check_quotes(char **s)
{ {
int ret; int ret;
char *tmp; char *tmp;
char *tmp2; char *tmp2;
int prompt_size_mem; int prompt_size_mem;
t_list_history *head;
head = data_singleton()->line.list_beg;
if (!*s) if (!*s)
return ; return ;
while ((ret = (ft_check_quotes_num(*s)))) while ((ret = (ft_check_quotes_num(*s))))
@ -71,12 +73,15 @@ void ft_check_quotes(char **s, t_list_history *head)
ft_strdel(&tmp); ft_strdel(&tmp);
tmp = *s; tmp = *s;
prompt_size_mem = data_singleton()->line.prompt_size; prompt_size_mem = data_singleton()->line.prompt_size;
tmp2 = ft_lecture(head); data_singleton()->line.input = NULL;
data_singleton()->line.pos = 0;
tmp2 = ft_read_stdin();
data_singleton()->line.prompt_size = prompt_size_mem; data_singleton()->line.prompt_size = prompt_size_mem;
ft_putchar('\n'); ft_putchar('\n');
if (!tmp2) if (!tmp2)
continue ; continue ;
*s = ft_strjoin(tmp, tmp2); *s = ft_strjoin(tmp, tmp2);
data_singleton()->line.input = *s;
ft_strdel(&tmp); ft_strdel(&tmp);
ft_strdel(&tmp2); ft_strdel(&tmp2);
} }

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/02 14:38:30 by jhalford ### ########.fr */ /* Updated: 2017/02/02 18:03:23 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,6 +15,8 @@
void ft_init_line(void) void ft_init_line(void)
{ {
data_singleton()->line.input = NULL; data_singleton()->line.input = NULL;
data_singleton()->line.copy_tmp = NULL;
data_singleton()->line.pos = 0;
data_singleton()->line.prompt_size = 0; data_singleton()->line.prompt_size = 0;
data_singleton()->line.list_size = 0; data_singleton()->line.list_size = 0;
data_singleton()->line.list_end = NULL; data_singleton()->line.list_end = NULL;
@ -76,11 +78,12 @@ int ft_readline(void)
return (-1); return (-1);
if (data_singleton()->line.input) if (data_singleton()->line.input)
ft_strdel(&data_singleton()->line.input); ft_strdel(&data_singleton()->line.input);
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
data_singleton()->line.pos = 0;
ft_prompt(); ft_prompt();
data_singleton()->line.input = ft_lecture(data_singleton()->line.list_beg); data_singleton()->line.input = ft_read_stdin();
ft_putchar('\n'); ft_putchar('\n');
ft_check_quotes(&data_singleton()->line.input, ft_check_quotes(&data_singleton()->line.input);
data_singleton()->line.list_beg);
ft_check_heredoc(&data_singleton()->line.input); ft_check_heredoc(&data_singleton()->line.input);
ft_check_backslash(&data_singleton()->line.input); ft_check_backslash(&data_singleton()->line.input);
ft_history_parsing(); ft_history_parsing();

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
/* Updated: 2017/01/26 14:01:53 by gwojda ### ########.fr */ /* Updated: 2017/02/02 15:16:42 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,12 +32,16 @@ void ft_surch_and_realloc(char **str, char **str_srch, int ret, size_t *srch_pos
*str = ft_strget_history(*str_srch); *str = ft_strget_history(*str_srch);
} }
void ft_surch_in_history(char **str, size_t *pos) void ft_surch_in_history(void)
{ {
char *str_srch; char *str_srch;
int ret; int ret;
size_t srch_pos; size_t srch_pos;
char **str;
size_t *pos;
str = &data_singleton()->line.input;
pos = &data_singleton()->line.pos;
srch_pos = 0; srch_pos = 0;
str_srch = NULL; str_srch = NULL;
if (*str) if (*str)

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/01 15:24:50 by gwojda ### ########.fr */ /* Updated: 2017/02/02 14:16:24 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,11 +24,15 @@ static void ft_clear_window()
execve("/usr/bin/clear", tab_str, data_singleton()->env); execve("/usr/bin/clear", tab_str, data_singleton()->env);
} }
void ft_printall(char *str, size_t *pos) void ft_printall(void)
{ {
size_t pos_tmp; size_t pos_tmp;
int ret; int ret;
char *str;
size_t *pos;
str = data_singleton()->line.input;
pos = &data_singleton()->line.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 ;

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */ /* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */
/* Updated: 2017/01/20 18:54:46 by gwojda ### ########.fr */ /* Updated: 2017/02/02 16:22:47 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,35 +24,6 @@ void ft_putnc(char c, int n)
} }
} }
void ft_free_tabstr(char ***env)
{
int i;
i = 0;
while ((*env)[i])
{
free((*env)[i]);
++i;
}
free(*env);
env = NULL;
}
int ft_is_whitespaces(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] != '\t' || str[i] != ' ')
return (1);
++i;
}
return (0);
}
char *ft_strndup(char const *s, int n) char *ft_strndup(char const *s, int n)
{ {
int i; int i;

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */ /* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */
/* Updated: 2017/02/02 13:31:57 by gwojda ### ########.fr */ /* Updated: 2017/02/02 16:04:55 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */ /* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */
/* Updated: 2017/02/02 11:46:55 by gwojda ### ########.fr */ /* Updated: 2017/02/02 14:29:34 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,95 +49,3 @@ char *ft_remove_imput(char *str, size_t pos)
free(new_str); free(new_str);
return (new_str2); return (new_str2);
} }
void ft_found_prev_word(char *str, size_t *pos)
{
int i;
i = 0;
if (!*pos)
return ;
if (str[*pos - 1] != '\n' && !(str[*pos] == '\n' || str[*pos] == ' '))
{
ft_puttermcaps("le");
--(*pos);
}
while ((int)*pos - i - 1 > 0 && str[*pos - i - 1] == ' ')
{
ft_puttermcaps("le");
++i;
}
(*pos) = (i && str[*pos - i] == '\n') ? *pos - i + 1 : *pos - i;
i = 0;
if (*pos >= 1 && str[*pos - 1] == '\n')
{
ft_puttermcaps("cd");
if (*pos >= 2)
(*pos) -= 2;
ft_get_beggin(str, pos);
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
++(*pos);
}
else
{
if (*pos && !(str[*pos] == '\n' || str[*pos] == ' '))
{
ft_puttermcaps("le");
--(*pos);
}
while (*pos - i && (str[*pos - i] == '\n' || str[*pos - i] == ' '))
{
ft_puttermcaps("le");
++i;
}
while (*pos - i && str[*pos - i] != '\n' && str[*pos - i] != ' ')
{
ft_puttermcaps("le");
++i;
}
if (str[*pos - i] == '\n' || str[*pos - i] == ' ')
{
ft_puttermcaps("nd");
++(*pos);
}
(*pos) -= i;
}
}
void ft_found_next_word(char *str, size_t *pos)
{
int i;
i = 0;
while (str[i + *pos] && str[i + *pos] == ' ')
{
ft_putchar(str[i + *pos]);
++i;
}
if (str[*pos] == '\n')
{
if (*pos)
{
--(*pos);
ft_get_beggin_with_curs(str, pos);
}
ft_puttermcaps("cd");
ft_get_next_str(str, pos);
(*pos) += (*pos) ? 2 : 1;
ft_current_str(str, *pos);
ft_get_next_str(str, pos);
if (!str[*pos])
--(*pos);
ft_get_beggin_with_curs(str, pos);
}
else
{
while (str[i + *pos] && str[i + *pos] != '\n' && str[i + *pos] != ' ')
{
ft_putchar(str[i + *pos]);
++i;
}
*pos += i;
}
}