changement du squelette (passage a un tableau de pointeur sur fonction) - pas encore tout resté
This commit is contained in:
parent
7265a6c340
commit
7fb9aa2da5
22 changed files with 490 additions and 425 deletions
|
|
@ -144,12 +144,14 @@ lexer/token_init.c\
|
|||
lexer/token_print.c\
|
||||
line-editing/builtin_history.c\
|
||||
line-editing/check_backslash.c\
|
||||
line-editing/control_c_and_d.c\
|
||||
line-editing/copy_cut_paste.c\
|
||||
line-editing/ft_split_whitespaces.c\
|
||||
line-editing/get_touch.c\
|
||||
line-editing/get_touch_toolz.c\
|
||||
line-editing/get_touch_toolz_2.c\
|
||||
line-editing/heredoc.c\
|
||||
line-editing/history.c\
|
||||
line-editing/history_parsing.c\
|
||||
line-editing/history_parsing_toolz.c\
|
||||
line-editing/history_parsing_toolz_2.c\
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* builtin.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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_fg(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
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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_D 4
|
||||
# define TOUCHE_CTRL_R 18
|
||||
# define TOUCHE_SUPPR 127
|
||||
# define TOUCHE_HOME 4741915
|
||||
# define TOUCHE_END 4610843
|
||||
# define TOUCHE_TAB 9
|
||||
|
|
@ -65,84 +66,82 @@ typedef struct s_list_history
|
|||
typedef struct s_line
|
||||
{
|
||||
char *input;
|
||||
char *copy_tmp;
|
||||
size_t pos;
|
||||
int prompt_size;
|
||||
int list_size;
|
||||
char opt;
|
||||
t_list_history *list_end;
|
||||
t_list_history *list_cur;
|
||||
t_list_history *list_beg;
|
||||
} t_line;
|
||||
|
||||
void ft_add_in_history_file(char *str);
|
||||
int builtin_history(const char *path, char *const av[], char *const envp[]);
|
||||
void ft_check_backslash(char **str);
|
||||
char *ft_strget_history(char *str);
|
||||
void ft_surch_in_history(char **str, size_t *pos);
|
||||
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
||||
void ft_move_right(size_t *pos, char *str);
|
||||
void ft_move_left(size_t *pos, char *str);
|
||||
int ft_put(int nb);
|
||||
void ft_end(char *str, size_t *pos);
|
||||
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);
|
||||
typedef struct s_key
|
||||
{
|
||||
int value;
|
||||
void (*f)(void);
|
||||
} t_key;
|
||||
|
||||
extern t_key g_keys[];
|
||||
|
||||
|
||||
void ft_putnc(char c, int n);
|
||||
int ft_nbr_len(int nbr);
|
||||
int ft_found_next_char(char *str, size_t i);
|
||||
void ft_check_end_of_line(char *str, size_t pos);
|
||||
void ft_printall(char *str, size_t *pos);
|
||||
void ft_puttermcaps(char *str);
|
||||
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_suppr(char **str, size_t *i);
|
||||
void ft_del(char **str, size_t *i);
|
||||
void ft_check_end_of_line(char *str, size_t pos);
|
||||
int ft_size_term(void);
|
||||
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);
|
||||
int ft_strlen_next(char *str, size_t pos);
|
||||
void ft_putall_current_str(char *str, size_t *pos);
|
||||
void ft_get_next_str(char *str, size_t *pos);
|
||||
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);
|
||||
void ft_push_back_history(t_list_history **head, t_list_history *new);
|
||||
void ft_prompt(void);
|
||||
char *ft_remove_imput(char *str, size_t pos);
|
||||
char *ft_realloc_imput(char *str, int a, size_t pos);
|
||||
int ft_readline(void);
|
||||
struct termios *ft_stats_term_termcaps(void);
|
||||
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);
|
||||
char *ft_strdupi(char const *s);
|
||||
char *ft_strndup(char const *s, int n);
|
||||
t_list_history *ft_create_history_list(char *str);
|
||||
void ft_curse_move(char *str);
|
||||
void ft_move_suppr(char *str, size_t pos);
|
||||
void ft_move_dell(char *str, size_t pos);
|
||||
void ft_move_to_word(int ret, size_t *pos, char *str);
|
||||
void ft_move_term(int ret, size_t *pos, char *str);
|
||||
void ft_home_end(char *str, int ret, size_t *pos);
|
||||
char *ft_strdupi_w(char const *s);
|
||||
void ft_realloc_str_history(char **str, size_t pos, int nb_his, int len);
|
||||
void ft_realloc_str_history_2(char **str, size_t pos, char *s);
|
||||
long long ft_pow(int nbr, int power);
|
||||
void ft_realloc_str_history_3(char **str, size_t pos, char *s);
|
||||
void ft_check_backslash(char **str);
|
||||
char *ft_strget_history(char *str);
|
||||
int ft_nb_last_line(char *str, size_t pos);
|
||||
int ft_put(int nb);
|
||||
char **ft_split_whitespaces(char const *s);
|
||||
void ft_cxv(int ret, size_t *pos, char **str);
|
||||
char *ft_lecture(t_list_history *head);
|
||||
void ft_prompt(void);
|
||||
|
||||
char *ft_read_stdin(void);
|
||||
void ft_end(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
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
tmp2 = ft_strjoin(tmp1, "\n");
|
||||
free(tmp1);
|
||||
tmp1 = ft_lecture(data_singleton()->line.list_beg);
|
||||
tmp1 = ft_read_stdin();
|
||||
*str = ft_strjoin(tmp2, tmp1);
|
||||
free(tmp1);
|
||||
free(tmp2);
|
||||
|
|
|
|||
49
42sh/src/line-editing/control_c_and_d.c
Normal file
49
42sh/src/line-editing/control_c_and_d.c
Normal 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;
|
||||
}
|
||||
|
|
@ -6,37 +6,12 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -61,10 +36,49 @@ static char *ft_strdupi_space(char const *s)
|
|||
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)
|
||||
ft_strdel(tmp);
|
||||
*tmp = ft_strdupi_space(&(*str)[(*pos)]);
|
||||
|
|
@ -77,20 +91,16 @@ static void ft_x(char **tmp, size_t *pos, char **str)
|
|||
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)
|
||||
return ;
|
||||
if (ret == TOUCHE_OPT_X)
|
||||
ft_x(&tmp, pos, str);
|
||||
else if (ret == TOUCHE_OPT_C)
|
||||
{
|
||||
if (tmp)
|
||||
ft_strdel(&tmp);
|
||||
tmp = ft_strdupi_space((*str) + (*pos));
|
||||
}
|
||||
else if (ret == TOUCHE_OPT_V)
|
||||
ft_v(tmp, pos, str);
|
||||
tmp = data_singleton()->line.copy_tmp;
|
||||
str = &data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
if (tmp)
|
||||
ft_strdel(&tmp);
|
||||
tmp = ft_strdupi_space((*str) + (*pos));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,114 +6,64 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
static int ft_lecture_3(int ret, char **str, size_t *i)
|
||||
t_key g_key[] =
|
||||
{
|
||||
if (ret == 127 && (*i) > 0)
|
||||
ft_suppr(str, i);
|
||||
else if (ret == TOUCHE_DELETE && (*str) && (*i) < ft_strlen((*str)))
|
||||
ft_del(str, i);
|
||||
else if (ret == TOUCHE_HOME)
|
||||
ft_home(*str, i);
|
||||
else if (ret == TOUCHE_END)
|
||||
ft_end(*str, i);
|
||||
else
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
{FLECHE_HAUT , &ft_history_up },
|
||||
{FLECHE_BAS , &ft_history_down },
|
||||
{FLECHE_GAUCHE , &ft_move_left },
|
||||
{FLECHE_DROITE , &ft_move_right },
|
||||
{TOUCHE_DELETE , &ft_del },
|
||||
{TOUCHE_CTRL_C , &ft_control_c },
|
||||
{TOUCHE_CTRL_D , &ft_control_d },
|
||||
{TOUCHE_CTRL_R , &ft_history_parsing },
|
||||
{TOUCHE_SUPPR , &ft_suppr },
|
||||
{TOUCHE_HOME , &ft_home },
|
||||
{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)
|
||||
ft_printall(*str, i);
|
||||
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);
|
||||
}
|
||||
int ret;
|
||||
int j;
|
||||
|
||||
char *ft_lecture(t_list_history *head)
|
||||
{
|
||||
char *str;
|
||||
int ret;
|
||||
size_t i;
|
||||
|
||||
str = NULL;
|
||||
if (data_singleton()->line.opt & HIST)
|
||||
str = data_singleton()->line.input;
|
||||
i = 0;
|
||||
if (str)
|
||||
if (data_singleton()->line.input)
|
||||
{
|
||||
ft_current_str(str, i);
|
||||
ft_get_next_str(str, &i);
|
||||
if (str[i])
|
||||
++i;
|
||||
ft_current_str(data_singleton()->line.input, data_singleton()->line.pos);
|
||||
ft_get_next_str(data_singleton()->line.input, &data_singleton()->line.pos);
|
||||
if (data_singleton()->line.input[data_singleton()->line.pos])
|
||||
++(data_singleton()->line.pos);
|
||||
}
|
||||
while (42)
|
||||
{
|
||||
ret = 0;
|
||||
j = 0;
|
||||
read(0, &ret, sizeof(int));
|
||||
if (ret == TOUCHE_F6 && read(0, &ret, sizeof(int)) > 0)
|
||||
continue ;
|
||||
if (ret == TOUCHE_CTRL_R)
|
||||
{
|
||||
ft_surch_in_history(&str, &i);
|
||||
continue ;
|
||||
}
|
||||
/*
|
||||
** 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 ;
|
||||
while (g_key[j].value && g_key[j].value != ret)
|
||||
++j;
|
||||
if (g_key[j].value)
|
||||
g_key[j].f();
|
||||
else if (ft_isprint(ret))
|
||||
ft_print(ret);
|
||||
else if (ret == 10)
|
||||
return (str);
|
||||
return (data_singleton()->line.input);
|
||||
else if (ft_isascii(ret) == 0)
|
||||
ft_read_it(ret, &i, &str);
|
||||
ft_read_it(ret, &data_singleton()->line.pos,
|
||||
&data_singleton()->line.input);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,61 +6,108 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
void ft_history_2(char **str, int ret, t_list_history **head
|
||||
, size_t *pos)
|
||||
void ft_found_prev_word(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
--(*pos);
|
||||
ft_get_beggin_with_curs(*str, pos);
|
||||
ft_get_beggin_with_curs(str, pos);
|
||||
}
|
||||
ft_puttermcaps("cd");
|
||||
*pos = 0;
|
||||
ft_strdel(str);
|
||||
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);
|
||||
}
|
||||
if (ret == FLECHE_BAS)
|
||||
else
|
||||
{
|
||||
if ((*head)->next)
|
||||
(*head) = (*head)->next;
|
||||
if (!(*head)->str)
|
||||
*str = NULL;
|
||||
else
|
||||
*str = ft_strdup((*head)->str);
|
||||
if (*str)
|
||||
ft_current_str(*str, *pos);
|
||||
while (str[i + *pos] && str[i + *pos] != '\n' && str[i + *pos] != ' ')
|
||||
{
|
||||
ft_putchar(str[i + *pos]);
|
||||
++i;
|
||||
}
|
||||
*pos += i;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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)
|
||||
return ;
|
||||
if (*pos)
|
||||
|
|
@ -35,8 +40,13 @@ void ft_end(char *str, size_t *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)
|
||||
return ;
|
||||
if (*pos)
|
||||
|
|
@ -56,10 +66,14 @@ void ft_home(char *str, size_t *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;
|
||||
char *str;
|
||||
size_t *pos;
|
||||
|
||||
str = data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
if (ft_strlen(str) <= *pos)
|
||||
return ;
|
||||
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)
|
||||
return ;
|
||||
if (str[*pos - 1] == '\n')
|
||||
|
|
@ -96,7 +115,6 @@ void ft_move_left(size_t *pos, char *str)
|
|||
--(*pos);
|
||||
return ;
|
||||
}
|
||||
printf("here\n\n");
|
||||
ft_puttermcaps("cd");
|
||||
(*pos) -= 2;
|
||||
ft_get_beggin(str, pos);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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");
|
||||
free(tmp);
|
||||
tmp = *str;
|
||||
tmp2 = ft_lecture(data_singleton()->line.list_beg);
|
||||
tmp2 = ft_read_stdin();
|
||||
if (!ft_strcmp(end, tmp2))
|
||||
boolean = 1;
|
||||
*str = ft_strjoin(tmp, tmp2);
|
||||
|
|
|
|||
87
42sh/src/line-editing/history.c
Normal file
87
42sh/src/line-editing/history.c
Normal 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;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
ft_prompt();
|
||||
data_singleton()->line.input = ft_lecture(
|
||||
data_singleton()->line.list_beg);
|
||||
data_singleton()->line.input = ft_read_stdin();
|
||||
ft_putchar('\n');
|
||||
data_singleton()->line.opt = data_singleton()->line.opt | ~HIST;
|
||||
ft_check_quotes(&data_singleton()->line.input,
|
||||
data_singleton()->line.list_beg);
|
||||
ft_check_quotes(&data_singleton()->line.input);
|
||||
ft_check_heredoc(&data_singleton()->line.input);
|
||||
ft_history_parsing();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
(*head)->prev = new;
|
||||
}
|
||||
|
||||
void ft_get_head(t_list_history **head)
|
||||
{
|
||||
if (head && *head)
|
||||
{
|
||||
while ((*head)->next && (*head)->next->str)
|
||||
(*head) = (*head)->next;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
}
|
||||
|
||||
static void ft_up(size_t *pos, char *str)
|
||||
void ft_up(void)
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
size_t *pos;
|
||||
|
||||
i = 0;
|
||||
str = data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
if (!str)
|
||||
return ;
|
||||
if (str[*pos - 1] == '\n')
|
||||
{
|
||||
ft_puttermcaps("cd");
|
||||
|
|
@ -73,12 +79,18 @@ static void ft_down_2(size_t *pos, char *str)
|
|||
ft_get_beggin_with_curs(str, pos);
|
||||
}
|
||||
|
||||
static void ft_down(size_t *pos, char *str)
|
||||
void ft_down(void)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
char *str;
|
||||
size_t *pos;
|
||||
|
||||
i = 0;
|
||||
str = data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
if (!str)
|
||||
return ;
|
||||
if (str[*pos] == '\n')
|
||||
ft_down_2(pos, str);
|
||||
else
|
||||
|
|
@ -92,13 +104,3 @@ static void ft_down(size_t *pos, char *str)
|
|||
*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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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;
|
||||
str = &data_singleton()->line.input;
|
||||
i = &data_singleton()->line.pos;
|
||||
*str = ft_realloc_imput(*str, ret, *i);
|
||||
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);
|
||||
}
|
||||
|
||||
void ft_suppr(char **str, size_t *i)
|
||||
void ft_suppr(void)
|
||||
{
|
||||
size_t tmp;
|
||||
char boolean;
|
||||
char **str;
|
||||
size_t *i;
|
||||
|
||||
str = &data_singleton()->line.input;
|
||||
i = &data_singleton()->line.pos;
|
||||
boolean = 0;
|
||||
if (*i <= 0)
|
||||
return ;
|
||||
if ((*str)[*i - 1] != '\n')
|
||||
boolean = 1;
|
||||
--(*i);
|
||||
|
|
@ -75,12 +85,18 @@ void ft_suppr(char **str, size_t *i)
|
|||
ft_suppr_2(str, i, tmp);
|
||||
}
|
||||
|
||||
void ft_del(char **str, size_t *i)
|
||||
void ft_del(void)
|
||||
{
|
||||
size_t tmp;
|
||||
char **str;
|
||||
size_t *i;
|
||||
|
||||
str = &data_singleton()->line.input;
|
||||
i = &data_singleton()->line.pos;
|
||||
tmp = *i;
|
||||
*str = ft_remove_imput((*str), tmp);
|
||||
if (!((*str) && (*i) < ft_strlen((*str))))
|
||||
return ;
|
||||
if (*i)
|
||||
{
|
||||
--(*i);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
void ft_check_quotes(char **s, t_list_history *head)
|
||||
void ft_check_quotes(char **s)
|
||||
{
|
||||
int ret;
|
||||
char *tmp;
|
||||
char *tmp2;
|
||||
int prompt_size_mem;
|
||||
int ret;
|
||||
char *tmp;
|
||||
char *tmp2;
|
||||
int prompt_size_mem;
|
||||
t_list_history *head;
|
||||
|
||||
head = data_singleton()->line.list_beg;
|
||||
if (!*s)
|
||||
return ;
|
||||
while ((ret = (ft_check_quotes_num(*s))))
|
||||
|
|
@ -71,12 +73,15 @@ void ft_check_quotes(char **s, t_list_history *head)
|
|||
ft_strdel(&tmp);
|
||||
tmp = *s;
|
||||
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;
|
||||
ft_putchar('\n');
|
||||
if (!tmp2)
|
||||
continue ;
|
||||
*s = ft_strjoin(tmp, tmp2);
|
||||
data_singleton()->line.input = *s;
|
||||
ft_strdel(&tmp);
|
||||
ft_strdel(&tmp2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/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)
|
||||
{
|
||||
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.list_size = 0;
|
||||
data_singleton()->line.list_end = NULL;
|
||||
|
|
@ -76,11 +78,12 @@ int ft_readline(void)
|
|||
return (-1);
|
||||
if (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();
|
||||
data_singleton()->line.input = ft_lecture(data_singleton()->line.list_beg);
|
||||
data_singleton()->line.input = ft_read_stdin();
|
||||
ft_putchar('\n');
|
||||
ft_check_quotes(&data_singleton()->line.input,
|
||||
data_singleton()->line.list_beg);
|
||||
ft_check_quotes(&data_singleton()->line.input);
|
||||
ft_check_heredoc(&data_singleton()->line.input);
|
||||
ft_check_backslash(&data_singleton()->line.input);
|
||||
ft_history_parsing();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
void ft_surch_in_history(char **str, size_t *pos)
|
||||
void ft_surch_in_history(void)
|
||||
{
|
||||
char *str_srch;
|
||||
int ret;
|
||||
size_t srch_pos;
|
||||
char **str;
|
||||
size_t *pos;
|
||||
|
||||
str = &data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
srch_pos = 0;
|
||||
str_srch = NULL;
|
||||
if (*str)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
void ft_printall(char *str, size_t *pos)
|
||||
void ft_printall(void)
|
||||
{
|
||||
size_t pos_tmp;
|
||||
int ret;
|
||||
char *str;
|
||||
size_t *pos;
|
||||
|
||||
str = data_singleton()->line.input;
|
||||
pos = &data_singleton()->line.pos;
|
||||
ret = 0;
|
||||
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !str)
|
||||
return ;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
int i;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue