diff --git a/42sh/Makefile b/42sh/Makefile index 8ac4b6c4..30072292 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,14 +6,14 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/16 23:02:12 by jhalford ### ########.fr # +# Updated: 2017/03/17 14:37:09 by gwojda ### ########.fr # # # # **************************************************************************** # NAME = 42sh CC = gcc -FLAGS = -Wall -Wextra -Werror -fvisibility=hidden +FLAGS = -Wall -Wextra -Werror -g D_FLAGS = -g DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/src/line-editing/control_features.c b/42sh/src/line-editing/control_features.c index 44f1b08f..df2a351a 100644 --- a/42sh/src/line-editing/control_features.c +++ b/42sh/src/line-editing/control_features.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ -/* Updated: 2017/03/17 12:20:31 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:32:16 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,6 +41,7 @@ int ft_control_d(char **str, size_t *pos) int ft_control_c(char **str, size_t *pos) { + set_exitstatus(1, 1); if (*str) ft_current_str(*str, *pos); ft_strdel(str); diff --git a/42sh/src/line-editing/get_key.c b/42sh/src/line-editing/get_key.c index fa130e54..7c974d2c 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 12:15:58 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 15:11:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,52 +38,60 @@ t_key g_key[] = {0 , 0 }, }; -static void init_read_stdin(char **str, size_t *pos) +static void init_read_stdin(char ***str, size_t **pos) { - if (*str) + *pos = &data_singleton()->line.pos; + *str = &data_singleton()->line.input; + 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()); signal(SIGWINCH, sigwinch_resize); } +static int read_stdin(int *ret, int *j) +{ + *j = 0; + *ret = 0; + if (read(0, ret, sizeof(int)) < 0) + return (-1); + return (1); +} + +static int press_enter(char **input, char **str) +{ + *input = *str; + return (0); +} + int ft_read_stdin(char **input) { - int ret; - int j; + int ret; + int j; + char **str; + size_t *pos; - init_read_stdin(&data_singleton()->line.input, &data_singleton()->line.pos); + init_read_stdin(&str, &pos); while (42) { - ret = 0; - j = 0; - read(0, &ret, sizeof(int)); - if (ft_completion(ret, &data_singleton()->line.input, - &data_singleton()->line.pos)) + if (read_stdin(&ret, &j) < 0) + return (-1); + if (ft_completion(ret, str, pos)) continue ; while (g_key[j].value && g_key[j].value != ret) ++j; - if (g_key[j].value) - { - if ((ret = g_key[j].f(&data_singleton()->line.input, - &data_singleton()->line.pos))) - return (ret); - } - else if (ft_isprint(ret)) - ft_print(ret, &data_singleton()->line.input, - &data_singleton()->line.pos); - else if (ret == 10) - { - *input = data_singleton()->line.input; - return (0); - } - else if (ft_isascii(ret) == 0) - ft_read_it(ret, &data_singleton()->line.pos, - &data_singleton()->line.input); + if (g_key[j].value && (ret = g_key[j].f(str, pos))) + return (ret); + else if (!g_key[j].value && ft_isprint(ret)) + ft_print(ret, str, pos); + else if (!g_key[j].value && ret == 10) + return (press_enter(input, str)); + else if (!g_key[j].value && ft_isascii(ret) == 0) + ft_read_it(ret, pos, str); } } diff --git a/42sh/src/line-editing/init_history.c b/42sh/src/line-editing/init_history.c index c6a9b24e..b6859052 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 13:52:05 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 14:35:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,21 +39,16 @@ void ft_init_history(void) return ; path = ft_str3join(home, "/", ".42sh_history"); if ((fd = open(path, O_RDONLY)) < 0) - { - free(path); - return ; - } + return (free(path)); while (get_next_line(fd, &str) > 0) { if (ft_str_is_print(str) && *str) ft_push_back_history(&data_singleton()->line.list_beg, ft_create_history_list(str)); - else - corrupt = CORRUPT; + else if (!corrupt) + ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home); free(str); } - if (corrupt) - ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home); free(path); free(str); close(fd); diff --git a/42sh/src/line-editing/move_to_word.c b/42sh/src/line-editing/move_to_word.c index 47c46fe9..dade6941 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 11:49:18 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:33:43 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,8 +74,7 @@ int ft_found_prev_word(char **str, size_t *pos) ft_puttermcaps("cd"); *pos -= 2; ft_get_beggin(*str, pos); - if (!*pos && (*str)[*pos] == '\n') - ++(*pos); + (!*pos && (*str)[*pos] == '\n') ? ++(*pos) : 0; ft_current_str(*str, *pos); ft_get_next_str(*str, pos); ++(*pos); diff --git a/42sh/src/line-editing/print_and_del.c b/42sh/src/line-editing/print_and_del.c index 7415c5cc..0999701b 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 12:19:23 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 12:32:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,7 +54,7 @@ static void ft_suppr_2(char **str, size_t *i, size_t tmp) ft_strdel(str); } -int ft_suppr(char **str, size_t *pos) +int ft_suppr(char **str, size_t *pos) { size_t tmp; char boolean; @@ -82,7 +82,7 @@ int ft_suppr(char **str, size_t *pos) return (0); } -int ft_del(char **str, size_t *pos) +int ft_del(char **str, size_t *pos) { size_t tmp; diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 4b767c2b..cc134418 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 12:20:12 by gwojda ### ########.fr */ +/* Updated: 2017/03/17 14:56:35 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ int readline(int has_prompt, char **input) 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)