diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index 399d81cd..b2b62c12 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/16 09:14:30 by alao ### ########.fr */ +/* Updated: 2017/03/17 17:23:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index f580c181..4282c854 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 12:17:52 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 17:24:03 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -106,7 +106,7 @@ 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_push_back_history( - t_list_history **head, t_list_history *new); + 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); diff --git a/42sh/src/completion/c_clear.c b/42sh/src/completion/c_clear.c index 2e1dc33b..5378d72b 100644 --- a/42sh/src/completion/c_clear.c +++ b/42sh/src/completion/c_clear.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 11:37:43 by alao #+# #+# */ -/* Updated: 2017/03/16 08:27:50 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:46:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_init.c b/42sh/src/completion/c_init.c index 7840296e..91039f74 100644 --- a/42sh/src/completion/c_init.c +++ b/42sh/src/completion/c_init.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 11:21:16 by alao #+# #+# */ -/* Updated: 2017/03/16 08:30:52 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:51:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_misc.c b/42sh/src/completion/c_misc.c index 34ee487e..92dd2101 100644 --- a/42sh/src/completion/c_misc.c +++ b/42sh/src/completion/c_misc.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/16 22:17:10 by alao #+# #+# */ -/* Updated: 2017/03/16 08:08:19 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:51:53 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_output.c b/42sh/src/completion/c_output.c index cd73c1f8..e3c207e2 100644 --- a/42sh/src/completion/c_output.c +++ b/42sh/src/completion/c_output.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/03 13:10:38 by alao #+# #+# */ -/* Updated: 2017/03/16 08:48:05 by alao ### ########.fr */ +/* Updated: 2017/03/17 16:48:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_terminal.c b/42sh/src/completion/c_terminal.c index ffc880e2..9719ad0f 100644 --- a/42sh/src/completion/c_terminal.c +++ b/42sh/src/completion/c_terminal.c @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/11 10:44:40 by alao #+# #+# */ -/* Updated: 2017/03/16 09:02:14 by alao ### ########.fr */ +/* Updated: 2017/03/17 17:07:20 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,22 @@ void c_term_clear(t_comp *c) } } +static size_t c_virtual_position(t_comp *c) +{ + char *str; + size_t pos; + size_t virtual_pos; + + pos = c->ircmd; + virtual_pos = pos; + str = data_singleton()->line.input; + while (pos && str[pos] != '\n') + --pos; + if (str[pos] == '\n') + ++pos; + return (virtual_pos - pos); +} + /* ** Move the terminal up by the number of line needed and move it back up to ** the original position. @@ -58,7 +74,7 @@ void c_term_mv_back(t_comp *c) ft_putstr(tgetstr("cr", NULL)); i = 0; lcmd = 0; - c->rcmd ? lcmd += c->ircmd + c->prompt + 1 : 0; + c->rcmd ? lcmd += c_virtual_position(c) + c->prompt + 1 : 0; while (i < lcmd) { ft_putstr(tgetstr("nd", NULL)); diff --git a/42sh/src/history/history.c b/42sh/src/history/history.c index 29fa0548..48be8f6f 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 12:09:42 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 16:05:47 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,9 +39,8 @@ int ft_history_down(char **str, size_t *pos) head = head->next; if (!head->str) *str = NULL; - else - if (!(*str = ft_strdup(head->str))) - return (-1); + else if (!(*str = ft_strdup(head->str))) + return (-1); if (*str) ft_current_str(*str, *pos); if (*str) @@ -64,9 +63,8 @@ int ft_history_up(char **str, size_t *pos) head = head->prev; if (!head->str) *str = NULL; - else - if (!(*str = ft_strdup(head->str))) - return (-1); + else if (!(*str = ft_strdup(head->str))) + return (-1); if (*str) ft_current_str(*str, *pos); if (*str) diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index d3fbffc7..0920de9c 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 12:12:19 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 16:06:09 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -52,7 +52,7 @@ static void ft_give_new_prompt(char *str_srch, size_t srch_pos) } static void ft_modify_str(char *str_srch, size_t srch_pos, char **str, - size_t *pos) + size_t *pos) { ft_clear_prompt(pos, srch_pos); data_singleton()->line.is_prompt ? ft_prompt() : ft_putstr("> "); diff --git a/42sh/src/line-editing/completion.c b/42sh/src/line-editing/completion.c index 18470e74..8a21df39 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 12:13:41 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 17:22:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,7 +51,7 @@ int ft_completion(int ret, char **str, size_t *pos) 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 = pos_tmp + ft_strleni_w(*str, pos_tmp, '\n') - right; } return (1); } diff --git a/42sh/src/line-editing/get_key.c b/42sh/src/line-editing/get_key.c index 7c974d2c..c99659fc 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 15:11:10 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 15:54:45 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,6 +81,7 @@ int ft_read_stdin(char **input) { if (read_stdin(&ret, &j) < 0) return (-1); + DG("key value hex = %x", ret); if (ft_completion(ret, str, pos)) continue ; while (g_key[j].value && g_key[j].value != ret) diff --git a/42sh/src/line-editing/init_history.c b/42sh/src/line-editing/init_history.c index b6859052..4c8f5c57 100644 --- a/42sh/src/line-editing/init_history.c +++ b/42sh/src/line-editing/init_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */ -/* Updated: 2017/03/17 14:35:12 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 16:01:44 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,12 @@ static int ft_str_is_print(char *str) return (1); } +static void corrupt_history(int corrupt, char *home) +{ + if (corrupt) + ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history\n", home); +} + void ft_init_history(void) { int fd; @@ -45,10 +51,11 @@ void ft_init_history(void) if (ft_str_is_print(str) && *str) ft_push_back_history(&data_singleton()->line.list_beg, ft_create_history_list(str)); - else if (!corrupt) - ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home); + else + corrupt = CORRUPT; free(str); } + corrupt_history(corrupt, home); free(path); free(str); close(fd); diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index cc134418..0b84ab3d 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 14:56:35 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 16:10:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,11 +16,12 @@ int readline(int has_prompt, char **input) { int ret; + if (!has_prompt) + data_singleton()->line.prompt_size = 1; if (!SH_IS_INTERACTIVE(data_singleton()->opts)) return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret); readline_init(has_prompt); ret = ft_read_stdin(input); - DG("ret = %s", input); if (ret < 0) return (ret); if (data_singleton()->line.input) diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 12161d0d..cae2ce88 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/16 23:25:46 by ariard ### ########.fr */ +/* Updated: 2017/03/17 17:41:33 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,9 +27,13 @@ int data_init(int ac, char **av) data->local_var = NULL; builtin_setenv(NULL, (char *[]){"local", "IFS", "\n ", 0}, NULL); set_exitstatus(0, 1); - shlvl = ft_itoa(ft_atoi(ft_getenv(data->env, "SHLVL")) + 1); - builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL); - ft_strdel(&shlvl); + shlvl = ft_getenv(data->env, "SHLVL"); + if (shlvl) + { + shlvl = ft_itoa(ft_atoi(shlvl) + 1); + builtin_setenv(NULL, (char *[]){"setenv", "SHLVL", shlvl, 0}, NULL); + ft_strdel(&shlvl); + } data->comp = NULL; data->opts = 0; exec_reset();