From a40169e77b5da3ffa1fdd87fd9cdda0576f7949d Mon Sep 17 00:00:00 2001 From: gwojda Date: Fri, 17 Mar 2017 12:21:25 +0100 Subject: [PATCH] changement edition de line -> STR et POS vous nous manquez --- 42sh/includes/ft_readline.h | 54 +++++++------- 42sh/src/completion/c_match_glob.c | 2 +- 42sh/src/completion/c_match_update.c | 5 +- 42sh/src/history/history.c | 46 ++++++------ 42sh/src/history/history_parsing.c | 10 +-- 42sh/src/history/surch_in_history.c | 35 ++++----- 42sh/src/line-editing/completion.c | 20 +++--- 42sh/src/line-editing/control_features.c | 33 +++++---- 42sh/src/line-editing/copy_cut_paste.c | 38 +++++----- 42sh/src/line-editing/get_key.c | 30 ++++---- 42sh/src/line-editing/home_end.c | 48 ++++++------- 42sh/src/line-editing/init_line.c | 8 +-- .../lib_line_editing/tool_line_2.c | 30 ++++---- 42sh/src/line-editing/move_left_and_right.c | 54 +++++++------- 42sh/src/line-editing/move_to_word.c | 71 ++++++++++--------- 42sh/src/line-editing/move_up_and_down.c | 36 +++++----- 42sh/src/line-editing/print_and_del.c | 60 ++++++++-------- 42sh/src/line-editing/readline.c | 7 +- 42sh/src/line-editing/resize.c | 6 +- 19 files changed, 301 insertions(+), 292 deletions(-) diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 86450201..f580c181 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:54:02 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:17:52 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,8 +57,8 @@ # define CORRUPT 1 -# define STR data_singleton()->line.input -# define POS data_singleton()->line.pos +//# define STR data_singleton()->line.input +//# define POS data_singleton()->line.pos # define ERROR_CNTL_R 1 @@ -87,7 +87,7 @@ typedef struct s_line typedef struct s_key { int value; - int (*f)(void); + int (*f)(char **str, size_t *pos); } t_key; extern t_key g_keys[]; @@ -132,32 +132,32 @@ size_t ft_hist_len(void); int ft_read_stdin(char **input); -int ft_end(void); -int ft_home(void); -int ft_move_right(void); -int ft_move_left(void); -int ft_up(void); -int ft_down(void); -int ft_buff_f6(void); -int ft_control_d(void); -int ft_control_c(void); -int ft_control_l(void); -int ft_del(void); -int ft_suppr(void); -int ft_print(int ret); -int ft_surch_in_history(void); -int ft_printall(void); -int ft_history_down(void); -int ft_history_up(void); -int ft_found_next_word(void); -int ft_found_prev_word(void); -int ft_c(void); -int ft_x(void); -int ft_v(void); +int ft_end(char **str, size_t *pos); +int ft_home(char **str, size_t *pos); +int ft_move_right(char **str, size_t *pos); +int ft_move_left(char **str, size_t *pos); +int ft_up(char **str, size_t *pos); +int ft_down(char **str, size_t *pos); +int ft_buff_f6(char **str, size_t *pos); +int ft_control_d(char **str, size_t *pos); +int ft_control_c(char **str, size_t *pos); +int ft_control_l(char **str, size_t *pos); +int ft_del(char **str, size_t *pos); +int ft_suppr(char **str, size_t *pos); +int ft_surch_in_history(char **str, size_t *pos); +int ft_printall(char **str, size_t *pos); +int ft_history_down(char **str, size_t *pos); +int ft_history_up(char **str, size_t *pos); +int ft_found_next_word(char **str, size_t *pos); +int ft_found_prev_word(char **str, size_t *pos); +int ft_c(char **str, size_t *pos); +int ft_x(char **str, size_t *pos); +int ft_v(char **str, size_t *pos); int ft_read_it(int input, size_t *pos, char **str); +int ft_print(int ret, char **str, size_t *pos); int readline(int prompt, char **input); -int ft_completion(int ret); +int ft_completion(int ret, char **str, size_t *pos); struct termios *ft_save_termios(int save); diff --git a/42sh/src/completion/c_match_glob.c b/42sh/src/completion/c_match_glob.c index d7720fce..4e85779f 100644 --- a/42sh/src/completion/c_match_glob.c +++ b/42sh/src/completion/c_match_glob.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */ -/* Updated: 2017/03/16 08:39:09 by alao ### ########.fr */ +/* Updated: 2017/03/17 11:20:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_match_update.c b/42sh/src/completion/c_match_update.c index e18f456e..bbbee3b2 100644 --- a/42sh/src/completion/c_match_update.c +++ b/42sh/src/completion/c_match_update.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 12:03:30 by alao #+# #+# */ -/* Updated: 2017/03/16 10:21:03 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:03:26 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,7 +59,8 @@ int c_rematch(t_comp *c, long int keypress) c_clear(data_singleton()); else if (c->lst == c->lst->next) return (1); - ft_print(keypress); + ft_print(keypress, &data_singleton()->line.input, + &data_singleton()->line.pos); return (1); } else diff --git a/42sh/src/history/history.c b/42sh/src/history/history.c index c901b8fc..29fa0548 100644 --- a/42sh/src/history/history.c +++ b/42sh/src/history/history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:48:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:09:42 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,63 +16,63 @@ static void ft_clear_before_history(char **str) { if (*str) { - if (POS) + if (data_singleton()->line.pos) { - --POS; - ft_get_beggin_with_curs(*str, &POS); + --data_singleton()->line.pos; + ft_get_beggin_with_curs(*str, &data_singleton()->line.pos); } ft_puttermcaps("cd"); - POS = 0; + data_singleton()->line.pos = 0; ft_strdel(str); } } -int ft_history_down(void) +int ft_history_down(char **str, size_t *pos) { t_list_history *head; head = data_singleton()->line.list_cur; if (!head) return (0); - ft_clear_before_history(&STR); + ft_clear_before_history(str); if (head->next) head = head->next; if (!head->str) - STR = NULL; + *str = NULL; else - if (!(STR = ft_strdup(head->str))) + if (!(*str = ft_strdup(head->str))) return (-1); - if (STR) - ft_current_str(STR, POS); - if (STR) - POS = ft_strlen_next(STR, POS); + if (*str) + ft_current_str(*str, *pos); + if (*str) + *pos = ft_strlen_next(*str, *pos); else - POS = 0; + *pos = 0; data_singleton()->line.list_cur = head; return (0); } -int ft_history_up(void) +int ft_history_up(char **str, size_t *pos) { t_list_history *head; head = data_singleton()->line.list_cur; if (!head) return (0); - ft_clear_before_history(&STR); + ft_clear_before_history(str); if (head->prev) head = head->prev; if (!head->str) - STR = NULL; + *str = NULL; else - if (!(STR = ft_strdup(head->str))) + if (!(*str = ft_strdup(head->str))) return (-1); - if (STR) - ft_current_str(STR, POS); - if (STR) - POS = ft_strlen_next(STR, POS); + if (*str) + ft_current_str(*str, *pos); + if (*str) + *pos = ft_strlen_next(*str, *pos); else - POS = 0; + *pos = 0; data_singleton()->line.list_cur = head; return (0); } diff --git a/42sh/src/history/history_parsing.c b/42sh/src/history/history_parsing.c index 85dc9ef5..9bdffdd6 100644 --- a/42sh/src/history/history_parsing.c +++ b/42sh/src/history/history_parsing.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:48:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:10:17 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,14 +67,14 @@ int ft_history_parsing(int has_prompt, char **input) i = 0; boolean = 0; - if (!STR) + if (!data_singleton()->line.input) return (0); - while (STR && STR[i]) + while (data_singleton()->line.input && data_singleton()->line.input[i]) { - if (STR[i] == '!') + if (data_singleton()->line.input[i] == '!') { boolean = 1; - if (!ft_history_parsing_3(STR, &i)) + if (!ft_history_parsing_3(data_singleton()->line.input, &i)) boolean = 0; else break ; diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index cbbea74e..d3fbffc7 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:48:06 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:12:19 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,34 +35,37 @@ static int ft_surch_and_realloc(char **str, char **str_srch, static void ft_give_new_prompt(char *str_srch, size_t srch_pos) { - ft_clear_prompt(&POS, srch_pos); + ft_clear_prompt(&data_singleton()->line.pos, srch_pos); data_singleton()->line.prompt_size = 21; if (str_srch) ft_printf("\033[35m(reverse-i-search)`\033[32m%s\033[35m': \033[37m", str_srch); else ft_putstr("\033[35m(reverse-i-search)`': \033[37m"); - if (STR) + if (data_singleton()->line.input) { - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); + ft_current_str(data_singleton()->line.input, + data_singleton()->line.pos); + ft_get_next_str(data_singleton()->line.input, + &data_singleton()->line.pos); } } -static void ft_modify_str(char *str_srch, size_t srch_pos) +static void ft_modify_str(char *str_srch, size_t srch_pos, char **str, + size_t *pos) { - ft_clear_prompt(&POS, srch_pos); + ft_clear_prompt(pos, srch_pos); data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> "); - if (STR) + if (*str) { - STR = ft_strdup(STR); - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); + *str = ft_strdup(*str); + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); } free(str_srch); } -int ft_surch_in_history(void) +int ft_surch_in_history(char **str, size_t *pos) { char *str_srch; int ret; @@ -70,7 +73,7 @@ int ft_surch_in_history(void) srch_pos = 0; str_srch = NULL; - (STR) ? ft_strdel(&STR) : 0; + (*str) ? ft_strdel(str) : 0; while (42) { ft_give_new_prompt(str_srch, srch_pos); @@ -78,7 +81,7 @@ int ft_surch_in_history(void) read(0, &ret, sizeof(int)); if (ft_isprint(ret)) { - if (ft_surch_and_realloc(&STR, &str_srch, ret, &srch_pos) < 0) + if (ft_surch_and_realloc(str, &str_srch, ret, &srch_pos) < 0) return (-1); } else if (ret == 127 && srch_pos) @@ -86,11 +89,11 @@ int ft_surch_in_history(void) --srch_pos; str_srch = ft_remove_imput(str_srch, srch_pos); ft_puttermcaps("le"); - STR = (!*str_srch) ? NULL : ft_strget_history(str_srch); + *str = (!*str_srch) ? NULL : ft_strget_history(str_srch); } else if (ret != 127) break ; } - ft_modify_str(str_srch, srch_pos); + ft_modify_str(str_srch, srch_pos, str, pos); return (0); } diff --git a/42sh/src/line-editing/completion.c b/42sh/src/line-editing/completion.c index b9d12e3a..18470e74 100644 --- a/42sh/src/line-editing/completion.c +++ b/42sh/src/line-editing/completion.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:45:06 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:13:41 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ static size_t ft_strleni_w(char *str, size_t pos, char c) size_t len; len = 0; - if (!STR) + if (!str) return (0); while (str[pos] && str[pos] != c) { @@ -27,7 +27,7 @@ static size_t ft_strleni_w(char *str, size_t pos, char c) return (len); } -int ft_completion(int ret) +int ft_completion(int ret, char **str, size_t *pos) { size_t tmp; size_t pos_tmp; @@ -35,8 +35,8 @@ int ft_completion(int ret) char boolean; boolean = 0; - pos_tmp = POS; - right = ft_strleni_w(STR, POS, '\n'); + pos_tmp = *pos; + right = ft_strleni_w(*str, *pos, '\n'); if (((ret != TOUCHE_TAB && ret != 10) || (ret == 10)) && !(data_singleton()->comp)) return (0); @@ -45,13 +45,13 @@ int ft_completion(int ret) if (boolean || ret == 10) { (pos_tmp) ? --pos_tmp : ft_puttermcaps("nd"); - ft_get_beggin_with_curs(STR, &pos_tmp); + ft_get_beggin_with_curs(*str, &pos_tmp); tmp = pos_tmp; ft_puttermcaps("cd"); - ft_current_str(STR, tmp); - ft_get_next_str(STR, &tmp); + ft_current_str(*str, tmp); + ft_get_next_str(*str, &tmp); ft_putnc('\b', right); - POS = ft_strleni_w(STR, pos_tmp, '\n') - right; + *pos = ft_strleni_w(*str, pos_tmp, '\n') - right; } - return (0); + return (1); } diff --git a/42sh/src/line-editing/control_features.c b/42sh/src/line-editing/control_features.c index 2298d32f..44f1b08f 100644 --- a/42sh/src/line-editing/control_features.c +++ b/42sh/src/line-editing/control_features.c @@ -6,54 +6,53 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:45:20 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:20:31 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_buff_f6(void) +int ft_buff_f6(char **str, size_t *pos) { int ret; ret = 0; + (void)str; + (void)pos; if (read(0, &ret, sizeof(int)) < 0) return (-1); return (0); } -int ft_control_d(void) +int ft_control_d(char **str, size_t *pos) { - if (!STR || STR[0] == '\0') + if (!*str || (*str)[0] == '\0') { ft_putstr("exit\n"); builtin_exit(NULL, (char*[]){"exit", NULL}, NULL); data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> "); } - else if (POS < ft_strlen(STR)) - ft_del(); + else if (*pos < ft_strlen(*str)) + ft_del(str, pos); else ft_puttermcaps("bl"); return (0); } -int ft_control_c(void) +int ft_control_c(char **str, size_t *pos) { -/* if (STR) - ft_current_str(STR, POS); - ft_putchar('\n'); - set_exitstatus(1, 1); - ft_prompt();*/ - ft_strdel(&STR); - POS = 0; + if (*str) + ft_current_str(*str, *pos); + ft_strdel(str); + *pos = 0; return (42); } -int ft_control_l(void) +int ft_control_l(char **str, size_t *pos) { ft_clear_window(); ft_prompt(); - ft_strdel(&STR); - POS = 0; + ft_strdel(str); + *pos = 0; return (0); } diff --git a/42sh/src/line-editing/copy_cut_paste.c b/42sh/src/line-editing/copy_cut_paste.c index bd137eb3..8e7e330a 100644 --- a/42sh/src/line-editing/copy_cut_paste.c +++ b/42sh/src/line-editing/copy_cut_paste.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:58:09 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 11:56:42 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,7 @@ static char *ft_strdupi_space(char const *s) return (str); } -int ft_v(void) +int ft_v(char **str, size_t *pos) { size_t tmp_pos; int i; @@ -45,40 +45,40 @@ int ft_v(void) tmp = data_singleton()->line.copy_tmp; i = -1; - tmp_pos = POS; - if (!STR || !tmp) + tmp_pos = *pos; + if (!*str || !tmp) return (0); while (tmp[++i]) - if (!(STR = ft_realloc_imput(STR, tmp[i], POS + i))) + if (!(*str = ft_realloc_imput(*str, tmp[i], *pos + i))) return (-1); - if (POS) + if (*pos) { - --POS; - ft_get_beggin_with_curs(STR, &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; + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + ft_putnc('\b', *pos - tmp_pos); + *pos = tmp_pos; return (0); } -int ft_x(void) +int ft_x(char **str, size_t *pos) { int i; char **tmp; tmp = &data_singleton()->line.copy_tmp; - if (!STR) + if (!*str) return (0); if (*tmp) ft_strdel(tmp); - if (!(*tmp = ft_strdupi_space(&STR[POS]))) + if (!(*tmp = ft_strdupi_space(&(*str)[*pos]))) return (-1); i = ft_strlen(*tmp); while (i >= 0) { - if (!(STR = ft_remove_imput(STR, POS + i))) + if (!(*str = ft_remove_imput(*str, *pos + i))) return (-1); --i; } @@ -86,16 +86,16 @@ int ft_x(void) return (0); } -int ft_c(void) +int ft_c(char **str, size_t *pos) { char **tmp; - if (!STR) + if (!*str) return (0); tmp = &data_singleton()->line.copy_tmp; if (*tmp) ft_strdel(tmp); - if (!(*tmp = ft_strdupi_space(STR + POS))) + if (!(*tmp = ft_strdupi_space(*str + *pos))) return (-1); return (0); } diff --git a/42sh/src/line-editing/get_key.c b/42sh/src/line-editing/get_key.c index 065754f0..fa130e54 100644 --- a/42sh/src/line-editing/get_key.c +++ b/42sh/src/line-editing/get_key.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:49:59 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:15:58 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,14 +38,14 @@ t_key g_key[] = {0 , 0 }, }; -static void init_read_stdin(void) +static void init_read_stdin(char **str, size_t *pos) { - if (STR) + if (*str) { - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); - if (STR[POS]) - ++(POS); + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + if ((*str)[*pos]) + ++(*pos); } if (data_singleton()->comp) c_clear(data_singleton()); @@ -57,29 +57,33 @@ int ft_read_stdin(char **input) int ret; int j; - init_read_stdin(); + init_read_stdin(&data_singleton()->line.input, &data_singleton()->line.pos); while (42) { ret = 0; j = 0; read(0, &ret, sizeof(int)); - if (ft_completion(ret)) + if (ft_completion(ret, &data_singleton()->line.input, + &data_singleton()->line.pos)) continue ; while (g_key[j].value && g_key[j].value != ret) ++j; if (g_key[j].value) { - if ((ret = g_key[j].f())) + if ((ret = g_key[j].f(&data_singleton()->line.input, + &data_singleton()->line.pos))) return (ret); } else if (ft_isprint(ret)) - ft_print(ret); + ft_print(ret, &data_singleton()->line.input, + &data_singleton()->line.pos); else if (ret == 10) { - *input = STR; + *input = data_singleton()->line.input; return (0); } else if (ft_isascii(ret) == 0) - ft_read_it(ret, &POS, &STR); + ft_read_it(ret, &data_singleton()->line.pos, + &data_singleton()->line.input); } } diff --git a/42sh/src/line-editing/home_end.c b/42sh/src/line-editing/home_end.c index b9dff034..3f3fbe99 100644 --- a/42sh/src/line-editing/home_end.c +++ b/42sh/src/line-editing/home_end.c @@ -6,48 +6,48 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/14 11:13:24 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:46:05 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 11:54:33 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_end(void) +int ft_end(char **str, size_t *pos) { - if (!STR) + if (!*str) return (0); - if (POS) + if (*pos) { - --POS; - ft_get_beggin_with_curs(STR, &POS); + --(*pos); + ft_get_beggin_with_curs(*str, pos); } ft_puttermcaps("cd"); - while (STR[POS]) - ++POS; - ft_get_beggin(STR, &POS); - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); + while ((*str)[*pos]) + ++(*pos); + ft_get_beggin(*str, pos); + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); return (0); } -int ft_home(void) +int ft_home(char **str, size_t *pos) { - if (!STR) + if (!*str) return (0); - if (POS) + if (*pos) { - --POS; - ft_get_beggin_with_curs(STR, &POS); - if (STR[POS + 1] == '\n') + --(*pos); + ft_get_beggin_with_curs(*str, pos); + if ((*str)[*pos + 1] == '\n') ft_puttermcaps("nd"); } ft_puttermcaps("cd"); - POS = 0; - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); - ft_check_end_of_line(STR, POS); - if (!STR[POS]) - --POS; - ft_get_beggin_with_curs(STR, &POS); + *pos = 0; + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + ft_check_end_of_line(*str, *pos); + if (!(*str)[*pos]) + --(*pos); + ft_get_beggin_with_curs(*str, pos); return (0); } diff --git a/42sh/src/line-editing/init_line.c b/42sh/src/line-editing/init_line.c index 3631a3fc..13d1eb55 100644 --- a/42sh/src/line-editing/init_line.c +++ b/42sh/src/line-editing/init_line.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:34:44 by gwojda #+# #+# */ -/* Updated: 2017/03/16 15:32:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 12:16:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,10 +36,10 @@ void readline_init(int has_prompt) beg = 1; } ft_init_termios(); - if (STR) - ft_strdel(&STR); + if (data_singleton()->line.input) + ft_strdel(&data_singleton()->line.input); data_singleton()->line.list_cur = data_singleton()->line.list_beg; - POS = 0; + data_singleton()->line.pos = 0; has_prompt ? ft_prompt() : ft_putstr("> "); data_singleton()->line.is_prompt = has_prompt ? 1 : 0; } diff --git a/42sh/src/line-editing/lib_line_editing/tool_line_2.c b/42sh/src/line-editing/lib_line_editing/tool_line_2.c index 07f7b1ed..2703ce09 100644 --- a/42sh/src/line-editing/lib_line_editing/tool_line_2.c +++ b/42sh/src/line-editing/lib_line_editing/tool_line_2.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:58:40 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:17:07 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,35 +39,35 @@ void ft_change_affichage(void) ft_putstr("\033[31m"); ft_puttermcaps("cd"); ft_puttermcaps("sc"); - ft_putstr(STR); + ft_putstr(data_singleton()->line.input); ft_read_tmp(); ft_puttermcaps("rc"); ft_puttermcaps("cd"); ft_putstr("\033[37m"); } -int ft_printall(void) +int ft_printall(char **str, size_t *pos) { size_t pos_tmp; int ret; ret = 0; - if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !STR) + if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !*str) return (0); ft_clear_window(); ft_prompt(); - pos_tmp = POS; + pos_tmp = *pos; ft_change_affichage(); - if (POS) - --POS; - ft_get_beggin(STR, &POS); - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); - if (POS && !STR[POS]) - --POS; - if (POS) - ft_putnc('\b', POS - pos_tmp + 1); - POS = pos_tmp; + if (*pos) + --(*pos); + ft_get_beggin(*str, pos); + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + if (*pos && !(*str)[*pos]) + --(*pos); + if (*pos) + ft_putnc('\b', *pos - pos_tmp + 1); + *pos = pos_tmp; return (0); } diff --git a/42sh/src/line-editing/move_left_and_right.c b/42sh/src/line-editing/move_left_and_right.c index 70055250..6e95a076 100644 --- a/42sh/src/line-editing/move_left_and_right.c +++ b/42sh/src/line-editing/move_left_and_right.c @@ -6,65 +6,65 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:46:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 11:51:32 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int ft_move_right(void) +int ft_move_right(char **str, size_t *pos) { size_t tmp; - if (ft_strlen(STR) <= POS) + if (ft_strlen(*str) <= *pos) return (0); - if (STR[POS] == '\n') + if ((*str)[*pos] == '\n') { - if (POS) + if (*pos) { - tmp = POS - 1; - ft_get_beggin_with_curs(STR, &tmp); + tmp = *pos - 1; + ft_get_beggin_with_curs(*str, &tmp); } ft_puttermcaps("cd"); - ++POS; - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); - POS = (!STR[POS]) ? POS - 1 : POS; - ft_get_beggin_with_curs(STR, &POS); + ++(*pos); + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + *pos = (!(*str)[*pos]) ? *pos - 1 : *pos; + ft_get_beggin_with_curs(*str, pos); } else { - ft_putchar(STR[POS]); - ++POS; + ft_putchar((*str)[*pos]); + ++(*pos); } return (0); } -int ft_move_left(void) +int ft_move_left(char **str, size_t *pos) { - if (!POS) + if (!*pos) return (0); - if (STR[POS - 1] == '\n') + if ((*str)[*pos - 1] == '\n') { - if (POS - 1 == 0) + if (*pos - 1 == 0) { ft_puttermcaps("cd"); - --POS; + --(*pos); return (0); } ft_puttermcaps("cd"); - POS -= 2; - ft_get_beggin(STR, &POS); - if (!POS && STR[POS] == '\n') - ++POS; - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); - ++POS; + *pos -= 2; + ft_get_beggin(*str, pos); + if (!*pos && (*str)[*pos] == '\n') + ++(*pos); + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + ++(*pos); } else { ft_puttermcaps("le"); - --POS; + --(*pos); } return (0); } diff --git a/42sh/src/line-editing/move_to_word.c b/42sh/src/line-editing/move_to_word.c index cf68ec30..47c46fe9 100644 --- a/42sh/src/line-editing/move_to_word.c +++ b/42sh/src/line-editing/move_to_word.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/14 11:12:09 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:46:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 11:49:18 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,75 +55,76 @@ static void ft_found_prev_word_2(int i, char *str, size_t *pos) (*pos) -= i; } -int ft_found_prev_word(void) +int ft_found_prev_word(char **str, size_t *pos) { int i; i = 0; - if (!POS || !STR) + if (!*pos || !*str) return (0); - ft_init_prev_word(&POS, STR); - if (POS >= 1 && STR[POS - 1] == '\n') + ft_init_prev_word(pos, *str); + if (*pos >= 1 && (*str)[*pos - 1] == '\n') { - if (POS - 1 == 0) + if (*pos - 1 == 0) { ft_puttermcaps("cd"); - --POS; + --(*pos); return (0); } ft_puttermcaps("cd"); - POS -= 2; - ft_get_beggin(STR, &POS); - if (!POS && STR[POS] == '\n') - ++POS; - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); - ++POS; + *pos -= 2; + ft_get_beggin(*str, pos); + if (!*pos && (*str)[*pos] == '\n') + ++(*pos); + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + ++(*pos); } else - ft_found_prev_word_2(i, STR, &POS); + ft_found_prev_word_2(i, *str, pos); return (0); } -static void ft_found_next_word_2(void) +static void ft_found_next_word_2(char **str, size_t *pos) { - if (POS) + if (*pos) { - --POS; - ft_get_beggin_with_curs(STR, &POS); + --(*pos); + ft_get_beggin_with_curs(*str, pos); } ft_puttermcaps("cd"); - ft_get_next_str(STR, &POS); - POS += (POS || STR[0] != '\n') ? 2 : 1; - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); - if (!STR[POS]) - --POS; - ft_get_beggin_with_curs(STR, &POS); + ft_get_next_str(*str, pos); + *pos += (*pos || (*str)[0] != '\n') ? 2 : 1; + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + if (!(*str)[*pos]) + --(*pos); + ft_get_beggin_with_curs(*str, pos); } -int ft_found_next_word(void) +int ft_found_next_word(char **str, size_t *pos) { int i; i = 0; - if (!STR) + if (!*str) return (0); - 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; } - if (STR[POS] == '\n') - ft_found_next_word_2(); + if ((*str)[*pos] == '\n') + ft_found_next_word_2(str, pos); 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; } - POS += i; + *pos += i; } return (0); } diff --git a/42sh/src/line-editing/move_up_and_down.c b/42sh/src/line-editing/move_up_and_down.c index 43dbd192..f72088a7 100644 --- a/42sh/src/line-editing/move_up_and_down.c +++ b/42sh/src/line-editing/move_up_and_down.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:46:55 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 11:44:08 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,22 +38,22 @@ static void ft_up_2(size_t *pos, char *str) (*pos) -= i; } -int ft_up(void) +int ft_up(char **str, size_t *pos) { - if (!STR || !POS) + if (!*str || !*pos) return (0); - if (STR[POS - 1] == '\n') + if ((*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; + if (*pos >= 2) + *pos -= 2; + ft_get_beggin(*str, pos); + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + ++(*pos); } else - ft_up_2(&POS, STR); + ft_up_2(pos, *str); return (0); } @@ -74,25 +74,25 @@ static void ft_down_2(size_t *pos, char *str) ft_get_beggin_with_curs(str, pos); } -int ft_down(void) +int ft_down(char **str, size_t *pos) { int i; int len; i = 0; - if (!STR) + if (!*str) return (0); - if (STR[POS] == '\n') - ft_down_2(&POS, STR); + if ((*str)[*pos] == '\n') + ft_down_2(pos, *str); else { 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; } - POS += i; + *pos += i; } return (0); } diff --git a/42sh/src/line-editing/print_and_del.c b/42sh/src/line-editing/print_and_del.c index 250f4901..7415c5cc 100644 --- a/42sh/src/line-editing/print_and_del.c +++ b/42sh/src/line-editing/print_and_del.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:47:11 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:19:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,21 +23,21 @@ int ft_found_next_char(char *str, size_t i) return (0); } -int ft_print(int ret) +int ft_print(int ret, char **str, size_t *pos) { int j; j = 0; - if (!(STR = ft_realloc_imput(STR, ret, POS))) + if (!(*str = ft_realloc_imput(*str, ret, *pos))) return (-1); - while (*(STR + POS + j) && *(STR + POS + j) != '\n') + while (*(*str + *pos + j) && *(*str + *pos + j) != '\n') { - ft_putchar(*(STR + POS + j)); + ft_putchar(*(*str + *pos + j)); ++j; } - ft_check_end_of_line(STR, POS + j); + ft_check_end_of_line(*str, *pos + j); ft_putnc('\b', j - 1); - ++POS; + ++(*pos); return (0); } @@ -54,54 +54,54 @@ static void ft_suppr_2(char **str, size_t *i, size_t tmp) ft_strdel(str); } -int ft_suppr(void) +int ft_suppr(char **str, size_t *pos) { size_t tmp; char boolean; boolean = 0; - if (POS <= 0) + if (*pos <= 0) return (0); - if (STR[POS - 1] != '\n') + if ((*str)[*pos - 1] != '\n') boolean = 1; - --POS; - tmp = POS; + --(*pos); + tmp = *pos; if (boolean) { - ft_get_beggin_with_curs(STR, &POS); - if (!(STR = ft_remove_imput(STR, tmp))) + ft_get_beggin_with_curs(*str, pos); + if (!(*str = ft_remove_imput(*str, tmp))) return (-1); } else { - if (!(STR = ft_remove_imput(STR, tmp))) + if (!(*str = ft_remove_imput(*str, tmp))) return (-1); - ft_get_beggin(STR, &POS); + ft_get_beggin(*str, pos); } - ft_suppr_2(&STR, &POS, tmp); + ft_suppr_2(str, pos, tmp); return (0); } -int ft_del(void) +int ft_del(char **str, size_t *pos) { size_t tmp; - tmp = POS; - if (!(STR = ft_remove_imput(STR, tmp))) + tmp = *pos; + if (!(*str = ft_remove_imput(*str, tmp))) return (-1); - if (!(STR && POS < ft_strlen(STR) + 1)) + if (!(*str && *pos < ft_strlen(*str) + 1)) return (0); - if (POS) + if (*pos) { - --POS; - ft_get_beggin_with_curs(STR, &POS); + --(*pos); + ft_get_beggin_with_curs(*str, pos); } ft_puttermcaps("cd"); - ft_current_str(STR, POS); - ft_get_next_str(STR, &POS); - if (STR[POS] && STR[POS] != '\n') - ++POS; - ft_putnc('\b', POS - tmp); - POS = tmp; + ft_current_str(*str, *pos); + ft_get_next_str(*str, pos); + if ((*str)[*pos] && (*str)[*pos] != '\n') + ++(*pos); + ft_putnc('\b', *pos - tmp); + *pos = tmp; return (0); } diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 40fa882e..4b767c2b 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/17 10:54:25 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:20:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,9 @@ int readline(int has_prompt, char **input) ret = ft_read_stdin(input); if (ret < 0) return (ret); - if (STR) - ft_current_str(STR, POS); + if (data_singleton()->line.input) + ft_current_str(data_singleton()->line.input, + data_singleton()->line.pos); ft_putchar('\n'); if (has_prompt) ret = ft_history_parsing(has_prompt, input); diff --git a/42sh/src/line-editing/resize.c b/42sh/src/line-editing/resize.c index 8d6042e8..ee04c914 100644 --- a/42sh/src/line-editing/resize.c +++ b/42sh/src/line-editing/resize.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 10:56:08 by gwojda #+# #+# */ -/* Updated: 2017/03/15 14:25:51 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 11:23:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,8 @@ void sigwinch_resize(int sig) c_term_resize(data_singleton()->comp); ft_puttermcaps("cl"); data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> "); - ft_putall_current_str(STR, &pos_tmp); - ft_putnc('\b', pos_tmp - POS); + ft_putall_current_str(data_singleton()->line.input, &pos_tmp); + ft_putnc('\b', pos_tmp - data_singleton()->line.pos); c_dispatcher(data_singleton()); } }