diff --git a/42sh/Makefile b/42sh/Makefile index cf13eb2e..aa57f27a 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/23 00:25:53 by ariard ### ########.fr # +# Updated: 2017/03/23 00:29:22 by ariard ### ########.fr # # # # **************************************************************************** # @@ -267,8 +267,12 @@ line_editing/print_and_del.c\ line_editing/queue.c\ line_editing/readline.c\ line_editing/resize.c\ +line_editing/underline_end.c\ line_editing/underline_function.c\ +line_editing/underline_home.c\ +line_editing/underline_left.c\ line_editing/underline_reset.c\ +line_editing/underline_right.c\ main/data_exit.c\ main/data_init.c\ main/data_singleton.c\ diff --git a/42sh/includes/ft_curs.h b/42sh/includes/ft_curs.h index d411b2c5..8d0bf2eb 100644 --- a/42sh/includes/ft_curs.h +++ b/42sh/includes/ft_curs.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 16:34:51 by sbenning #+# #+# */ -/* Updated: 2017/03/20 12:33:06 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 00:03:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ typedef struct s_curs t_curs; ** Cursor data : cursor's coordonate and windows size */ -struct s_curs +struct s_curs { int co; int li; diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index ef7dbaea..38113343 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/22 22:16:17 by ariard ### ########.fr */ +/* Updated: 2017/03/23 00:30:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,7 +53,7 @@ # define TOUCHE_F5 892427035 # define TOUCHE_F6 925981467 -# define SIZE_LINE 16000 +# define SIZE_LINE 16384 # define CORRUPT 1 @@ -127,11 +127,14 @@ int ft_nb_of_line(char *str, size_t pos); int ft_get_size_prev(char *str, size_t pos); void sigwinch_resize(int sig); size_t ft_hist_len(void); -void underline_right(char **str, size_t *pos, size_t pos_ref); -void underline_left(char **str, size_t *pos, size_t pos_ref); + +int underline_right(char **str, size_t *pos, size_t pos_ref); +int underline_left(char **str, size_t *pos, size_t pos_ref); +void underline_home(char **str, size_t *pos, size_t pos_ref); +void underline_end(char **str, size_t *pos, size_t pos_ref); +void underline_check_end_of_line(char *str, size_t pos); void reset_term(char **str, size_t *pos); void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp); -int reset_term_hard(void); int ft_read_stdin(char **input); diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 3c978f2d..0af3c493 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 17:22:51 by ariard #+# #+# */ -/* Updated: 2017/03/22 22:25:58 by ariard ### ########.fr */ +/* Updated: 2017/03/23 00:32:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/sstr/ft_sstrfree.c b/42sh/libft/src/sstr/ft_sstrfree.c index 1e10d105..7855228d 100644 --- a/42sh/libft/src/sstr/ft_sstrfree.c +++ b/42sh/libft/src/sstr/ft_sstrfree.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:53:36 by jhalford #+# #+# */ -/* Updated: 2017/01/11 14:42:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 23:19:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/sstr/ft_sstrstr.c b/42sh/libft/src/sstr/ft_sstrstr.c index 7170a6e6..d6618563 100644 --- a/42sh/libft/src/sstr/ft_sstrstr.c +++ b/42sh/libft/src/sstr/ft_sstrstr.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:29:54 by ariard #+# #+# */ -/* Updated: 2017/03/21 18:14:45 by ariard ### ########.fr */ +/* Updated: 2017/03/22 21:54:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/str/ft_atoi.c b/42sh/libft/src/str/ft_atoi.c index b583a198..546c58f6 100644 --- a/42sh/libft/src/str/ft_atoi.c +++ b/42sh/libft/src/str/ft_atoi.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:36:22 by wescande ### ########.fr */ +/* Updated: 2017/03/22 22:21:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/str/ft_strdupchr.c b/42sh/libft/src/str/ft_strdupchr.c index aee98aaf..3fd5d0d5 100644 --- a/42sh/libft/src/str/ft_strdupchr.c +++ b/42sh/libft/src/str/ft_strdupchr.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:01:15 by ariard #+# #+# */ -/* Updated: 2017/03/21 15:43:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 23:12:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/str/ft_strlenchr.c b/42sh/libft/src/str/ft_strlenchr.c index 34882af2..1ea82cfa 100644 --- a/42sh/libft/src/str/ft_strlenchr.c +++ b/42sh/libft/src/str/ft_strlenchr.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 16:10:54 by ariard #+# #+# */ -/* Updated: 2017/03/07 11:30:02 by ariard ### ########.fr */ +/* Updated: 2017/03/22 22:12:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index 77072563..9bdb8261 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,103 +6,60 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/17 18:54:00 by ariard #+# #+# */ -/* Updated: 2017/03/21 18:08:31 by ariard ### ########.fr */ +/* Updated: 2017/03/22 22:26:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -#define MATHERR_0 "math : invalid number of arguments" -#define MATHERR_1 "math : invalid variable name" -#define MATHERR_2 "math : invalid operator" -#define MATHERR_3 "math : invalid operand" -#define MATHERR_4 "math : division by 0" +#define MATHERR_0 "usage: math variable operator(+-/*%) operand" +#define MATHERR_2 "math: %c: invalid operator" +#define MATHERR_3 "math: %s: operand must be digits only" +#define MATHERR_4 "math: division by 0" +#define MATHERR_5 "math: modulo by 0" -static int init_math(char **var, char **value, char **operator, - char **operand) -{ - *var = NULL; - *value = NULL; - *operator = NULL; - *operand = NULL; - return (0); -} - -static int get_value(char *var, char **value) -{ - char *temp; - char *esc; - int ret; - - esc = ft_strnew((ft_strlen(var) >> 3) + 1); - ret = word_is_assignment((char *[]) {var, (esc + 1)}); - ft_strdel(&esc); - if (!ret) - return (SH_ERR(MATHERR_1)); - temp = ft_sstrstr(data_singleton()->local_var, var); - if (temp) - { - temp += ft_strlenchr(temp, '=') + 1; - *value = ft_strdup(temp); - if (!(ft_stris(*value, &ft_isdigit))) - { - ft_strdel(value); - *value = ft_itoa(0); - } - } - else - *value = ft_itoa(0); - return (0); -} - -static int do_math(char **value, char *operator, char *operand) +static char *do_math(char *value, char operator, char *operand) { long ope1; long ope2; - ope1 = ft_atoi(*value); - if (operand) - ope2 = ft_atoi(operand); - else - ope2 = 0; - if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) - return (SH_ERR(MATHERR_4)); - else - { - ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; - ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; - ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; - ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; - ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; - } - ft_strdel(value); - *value = ft_itoa(ope1); - return (0); + ope1 = ft_atoi(value); + ope2 = ft_atoi(operand); + DG("value %s -> %i", value, ope1); + DG("operand %s -> %i", operand, ope2); + if ((operator == '/') && ope2 == 0) + return (SH_ERR(MATHERR_4) ? NULL : NULL); + if ((operator == '%') && ope2 == 0) + return (SH_ERR(MATHERR_5) ? NULL : NULL); + ope1 = (operator == '+') ? ope1 + ope2 : ope1; + ope1 = (operator == '-') ? ope1 - ope2 : ope1; + ope1 = (operator == '/') ? ope1 / ope2 : ope1; + ope1 = (operator == '*') ? ope1 * ope2 : ope1; + ope1 = (operator == '%') ? ope1 % ope2 : ope1; + DG("output=%s (%i)", ft_itoa(ope1), ope1); + return (ft_itoa(ope1)); } int builtin_math(const char *path, char *const av[], char *const envp[]) { - char *var; char *value; - char *operator; + char operator; char *operand; (void)path; (void)envp; if (!av || !av[1] || !av[2] || !av[3] || av[4]) return (SH_ERR(MATHERR_0)); - init_math(&var, &value, &operator, &operand); - var = av[1]; - if (get_value(var, &value)) - return (1); - operator = av[2]; - if (ft_strlen(operator) != 1 || !(ft_strchr("+-/*%", operator[0]))) - return (SH_ERR(MATHERR_2)); + value = ft_getenv(data_singleton()->local_var, av[1]); + operator = av[2][0]; + if (!(ft_strchr("+-/*%", operator))) + return (SH_ERR(MATHERR_2, operator)); operand = av[3]; if (!ft_stris(operand, &ft_isdigit)) - return (SH_ERR(MATHERR_3)); - if (do_math(&value, operator, operand)) + return (SH_ERR(MATHERR_3, operand)); + if (!(value = do_math(value, operator, operand))) return (1); - builtin_setenv("setenv", (char *[]){"local", var, value, 0}, NULL); + builtin_setenv("setenv", (char *[]){"math", av[1], value, 0}, NULL); + ft_strdel(&value); return (0); } diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index a00dd611..8cd00b78 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/22 16:21:49 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 22:08:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/completion/c_match_glob.c b/42sh/src/completion/c_match_glob.c index 016473cb..43d2cf9c 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/22 14:51:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/23 00:06:08 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -76,7 +76,7 @@ static int c_check_glob(char **ss_glob, char *current_word, str = data_singleton()->line.input; free(current_word); free(glob_echap); - if (!*ss_glob || !**ss_glob || + if (!ss_glob || !*ss_glob || !**ss_glob || !ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob))) { ft_sstrfree(ss_glob); diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index 756ea439..ec5599be 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/03/21 19:14:31 by ariard ### ########.fr */ +/* Updated: 2017/03/22 21:50:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index a95f54c2..9fb93b0e 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/22 18:27:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 21:48:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 617a704d..4c63ea9e 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -6,36 +6,28 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ -/* Updated: 2017/03/22 23:05:47 by ariard ### ########.fr */ +/* Updated: 2017/03/23 00:30:46 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int set_var(char *stream, char **var, char **value) -{ - *var = ft_strdupchr(stream, '='); - stream += ft_strlenchr(stream, '=') + 1; - *value = ft_strdup(stream); - return (0); -} - int exec_var(t_btree **ast) { t_astnode *node; char **av; char *var; char *value; + char *equal; node = (*ast)->item; - av = token_to_argv(node->data.cmd.token, 1); - set_var(av[0], &var, &value); - if (ft_getenv(data_singleton()->env, var)) - node = NULL; - else - builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL); - ft_strdel(&var); - ft_strdel(&value); - ft_tabdel(&av); + if (!(av = token_to_argv(node->data.cmd.token, 1))) + return (0); + var = av[0]; + if ((equal = ft_strchr(av[0], '='))) + *equal = 0; + value = equal ? equal + 1 : NULL; + builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL); + ft_sstrfree(av); return (0); } diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index 5b829c78..e5e662ec 100644 --- a/42sh/src/exec/node_copy.c +++ b/42sh/src/exec/node_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ -/* Updated: 2017/03/21 18:44:57 by ariard ### ########.fr */ +/* Updated: 2017/03/22 21:50:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_cmd.c b/42sh/src/exec/pfree_cmd.c index 2047d654..58ebe736 100644 --- a/42sh/src/exec/pfree_cmd.c +++ b/42sh/src/exec/pfree_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ -/* Updated: 2017/03/20 16:29:37 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 23:17:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_list.c b/42sh/src/exec/pfree_list.c index 3f1be691..966344e2 100644 --- a/42sh/src/exec/pfree_list.c +++ b/42sh/src/exec/pfree_list.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:37:04 by wescande #+# #+# */ -/* Updated: 2017/03/22 22:18:41 by ariard ### ########.fr */ +/* Updated: 2017/03/23 00:31:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_case.c b/42sh/src/exec/pset_case.c index 0a3441d2..c439fb2e 100644 --- a/42sh/src/exec/pset_case.c +++ b/42sh/src/exec/pset_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/22 22:10:45 by ariard ### ########.fr */ +/* Updated: 2017/03/23 00:31:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_bquote.c b/42sh/src/lexer/lexer_bquote.c index 084db882..e16cba63 100644 --- a/42sh/src/lexer/lexer_bquote.c +++ b/42sh/src/lexer/lexer_bquote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */ -/* Updated: 2017/03/17 21:01:50 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 23:59:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,10 @@ int lexer_bquote(t_list **alst, t_lexer *lexer) if (get_lexer_stack(*lexer) != BQUOTE) push(&lexer->stack, lexer->state); else - lexer->state = pop(&lexer->stack) == DQUOTE ? DQUOTE : DEFAULT; + { + lexer->state = pop(&lexer->stack) && + get_lexer_stack(*lexer) == DQUOTE ? DQUOTE : DEFAULT; + } } else if (lexer->str[lexer->pos] == '\\' && (back = 1)) { diff --git a/42sh/src/lexer/lexer_dquote.c b/42sh/src/lexer/lexer_dquote.c index f4df5b90..1786990d 100644 --- a/42sh/src/lexer/lexer_dquote.c +++ b/42sh/src/lexer/lexer_dquote.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 18:36:58 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:08:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 23:56:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line_editing/copy_cut_paste.c b/42sh/src/line_editing/copy_cut_paste.c index 23411367..37ba5f96 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/22 21:14:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 23:53:57 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,13 +27,15 @@ int ft_x(char **str, size_t *pos) ret = 0; if (read(STDIN, &ret, sizeof(int)) < 0) return (-1); - if ((*str)[*pos] == '\n') - return (reset_term_hard()); - if (ret == FLECHE_GAUCHE) - underline_left(str, pos, pos_ref); - else if (ret == FLECHE_DROITE) - underline_right(str, pos, pos_ref); - else + if (ret == FLECHE_GAUCHE && !underline_left(str, pos, pos_ref)) + return (0); + else if (ret == FLECHE_DROITE && !underline_right(str, pos, pos_ref)) + return (0); + else if (ret == TOUCHE_HOME) + underline_home(str, pos, pos_ref); + else if (ret == TOUCHE_END) + underline_end(str, pos, pos_ref); + else if (ret != FLECHE_DROITE && ret != FLECHE_GAUCHE) break ; } if (data_singleton()->line.copy_tmp && *data_singleton()->line.copy_tmp) @@ -56,13 +58,15 @@ int ft_c(char **str, size_t *pos) ret = 0; if (read(STDIN, &ret, sizeof(int)) < 0) return (-1); - if ((*str)[*pos] == '\n') - return (reset_term_hard()); - if (ret == FLECHE_GAUCHE) - underline_left(str, pos, pos_ref); - else if (ret == FLECHE_DROITE) - underline_right(str, pos, pos_ref); - else + if (ret == FLECHE_GAUCHE && !underline_left(str, pos, pos_ref)) + return (0); + else if (ret == FLECHE_DROITE && !underline_right(str, pos, pos_ref)) + return (0); + else if (ret == TOUCHE_HOME) + underline_home(str, pos, pos_ref); + else if (ret == TOUCHE_END) + underline_end(str, pos, pos_ref); + else if (ret != FLECHE_DROITE && ret != FLECHE_GAUCHE) break ; } reset_term(str, pos); diff --git a/42sh/src/line_editing/underline_end.c b/42sh/src/line_editing/underline_end.c new file mode 100644 index 00000000..c43e9ce5 --- /dev/null +++ b/42sh/src/line_editing/underline_end.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* underline_end.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/22 23:18:15 by gwojda #+# #+# */ +/* Updated: 2017/03/22 23:42:27 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void underline_end(char **str, size_t *pos, size_t pos_ref) +{ + size_t pos_tmp; + + pos_tmp = *pos; + if ((*str)[pos_tmp] == '\n') + { + underline_right(str, pos, pos_ref); + ++pos_tmp; + } + while ((*str)[pos_tmp] && (*str)[pos_tmp] != '\n') + { + underline_right(str, pos, pos_ref); + ++pos_tmp; + } + if ((*str)[pos_tmp] == '\n') + { + underline_left(str, pos, pos_ref); + --pos_tmp; + } +} diff --git a/42sh/src/line_editing/underline_function.c b/42sh/src/line_editing/underline_function.c index 5412e6af..34c0f318 100644 --- a/42sh/src/line_editing/underline_function.c +++ b/42sh/src/line_editing/underline_function.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 20:55:24 by gwojda #+# #+# */ -/* Updated: 2017/03/22 21:28:31 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 22:59:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static void underline_check_end_of_line(char *str, size_t pos) +void underline_check_end_of_line(char *str, size_t pos) { if (!str) return ; @@ -22,61 +22,3 @@ static void underline_check_end_of_line(char *str, size_t pos) ft_puttermcaps("le"); } } - -void underline_right(char **str, size_t *pos, size_t pos_ref) -{ - if (!(*pos < ft_strlen(*str))) - return ; - if (*pos >= pos_ref) - { - ft_puttermcaps("mr"); - data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()-> - line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); - ft_putchar((*str)[*pos]); - ft_puttermcaps("me"); - ++(data_singleton()->line.pos_tmp); - ++(*pos); - underline_check_end_of_line(*str, *pos); - } - else - { - data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()-> - line.copy_tmp, data_singleton()->line.pos_tmp); - ft_putchar((*str)[*pos]); - if (data_singleton()->line.pos_tmp) - --(data_singleton()->line.pos_tmp); - ++(*pos); - underline_check_end_of_line(*str, *pos); - } -} - -void underline_left(char **str, size_t *pos, size_t pos_ref) -{ - if (!*pos) - return ; - if (*pos > pos_ref) - { - --(*pos); - ft_putchar('\b'); - ft_putchar((*str)[*pos]); - underline_check_end_of_line(*str, *pos + 1); - ft_putchar('\b'); - data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()-> - line.copy_tmp, data_singleton()->line.pos_tmp); - if (data_singleton()->line.pos_tmp) - --(data_singleton()->line.pos_tmp); - } - else - { - data_singleton()->line.pos_tmp = 0; - --(*pos); - ft_putchar('\b'); - ft_puttermcaps("mr"); - data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()-> - line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); - ft_putchar((*str)[*pos]); - underline_check_end_of_line(*str, *pos + 1); - ft_puttermcaps("me"); - ft_putchar('\b'); - } -} diff --git a/42sh/src/line_editing/underline_home.c b/42sh/src/line_editing/underline_home.c new file mode 100644 index 00000000..0c6fe355 --- /dev/null +++ b/42sh/src/line_editing/underline_home.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* underline_home.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/22 23:11:05 by gwojda #+# #+# */ +/* Updated: 2017/03/22 23:44:44 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void underline_home(char **str, size_t *pos, size_t pos_ref) +{ + size_t pos_tmp; + + pos_tmp = *pos; + if ((*str)[pos_tmp] == '\n') + { + underline_left(str, pos, pos_ref); + --pos_tmp; + } + while ((pos_tmp && (*str)[pos_tmp] != '\n') + && (pos_tmp + 1 > 0 && (*str)[pos_tmp - 1] != '\n')) + { + underline_left(str, pos, pos_ref); + --pos_tmp; + } + *pos = pos_tmp; +} diff --git a/42sh/src/line_editing/underline_left.c b/42sh/src/line_editing/underline_left.c new file mode 100644 index 00000000..0d3cd41a --- /dev/null +++ b/42sh/src/line_editing/underline_left.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* underline_left.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/22 22:54:28 by gwojda #+# #+# */ +/* Updated: 2017/03/22 23:08:58 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int reset_term_hard(void) +{ + ft_putstr(data_singleton()->line.copy_tmp); + ft_putnc('\b', ft_strlen(data_singleton()->line.copy_tmp)); + ft_strdel(&data_singleton()->line.copy_tmp); + data_singleton()->line.pos_tmp = 0; + return (0); +} + +static void left_abs(char **str, size_t *pos) +{ + --(*pos); + ft_putchar('\b'); + data_singleton()->line.pos_tmp = 0; + ft_puttermcaps("mr"); + data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()-> + line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); + ft_putchar((*str)[*pos]); + underline_check_end_of_line(*str, *pos + 1); + ft_puttermcaps("me"); + ft_putchar('\b'); +} + +static void left_mv_back(char **str, size_t *pos) +{ + --(*pos); + ft_putchar('\b'); + ft_putchar((*str)[*pos]); + underline_check_end_of_line(*str, *pos + 1); + data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()-> + line.copy_tmp, data_singleton()->line.pos_tmp); + if (data_singleton()->line.pos_tmp) + --(data_singleton()->line.pos_tmp); + ft_putchar('\b'); +} + +int underline_left(char **str, size_t *pos, size_t pos_ref) +{ + if (!*pos) + return (1); + if ((*str)[*pos - 1] == '\n') + return (reset_term_hard()); + if (*pos > pos_ref) + left_mv_back(str, pos); + else + left_abs(str, pos); + return (1); +} diff --git a/42sh/src/line_editing/underline_reset.c b/42sh/src/line_editing/underline_reset.c index bddcf88c..6fd150a5 100644 --- a/42sh/src/line_editing/underline_reset.c +++ b/42sh/src/line_editing/underline_reset.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 21:14:07 by gwojda #+# #+# */ -/* Updated: 2017/03/22 21:16:24 by gwojda ### ########.fr */ +/* Updated: 2017/03/22 23:40:39 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void reset_term(char **str, size_t *pos) { - size_t pos_ref; + size_t pos_ref; pos_ref = *pos; if (*pos) @@ -26,39 +26,30 @@ void reset_term(char **str, size_t *pos) ft_current_str(*str, *pos); ft_get_next_str(*str, pos); ft_putnc('\b', *pos - pos_ref); - (*pos) = pos_ref; + (*pos) = pos_ref + (((*str)[*pos]) ? 1 : 0); } void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp) { - size_t pos_ref; + size_t pos_ref; pos_ref = *pos; if (!data_singleton()->line.pos_tmp) pos_ref += ft_strlen(data_singleton()->line.copy_tmp); + if (*pos) + { + --(*pos); + ft_get_beggin_with_curs(*str, pos); + } while (*copy_tmp) { --pos_ref; *str = ft_remove_imput(*str, pos_ref); ++copy_tmp; } - if (*pos) - { - --(*pos); - ft_get_beggin_with_curs(*str, pos); - } ft_puttermcaps("cd"); ft_current_str(*str, *pos); ft_get_next_str(*str, pos); ft_putnc('\b', *pos - pos_ref); - (*pos) = pos_ref; -} - -int reset_term_hard(void) -{ - ft_putnc('\b', ft_strlen(data_singleton()->line.copy_tmp)); - ft_putstr(data_singleton()->line.copy_tmp); - ft_strdel(&data_singleton()->line.copy_tmp); - data_singleton()->line.pos_tmp = 0; - return (0); + (*pos) = pos_ref + (((*str)[*pos]) ? 1 : 0); } diff --git a/42sh/src/line_editing/underline_right.c b/42sh/src/line_editing/underline_right.c new file mode 100644 index 00000000..85ba5b41 --- /dev/null +++ b/42sh/src/line_editing/underline_right.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* underline_right.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/22 22:50:52 by gwojda #+# #+# */ +/* Updated: 2017/03/22 23:00:32 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int reset_term_hard(void) +{ + ft_putnc('\b', ft_strlen(data_singleton()->line.copy_tmp)); + ft_putstr(data_singleton()->line.copy_tmp); + ft_strdel(&data_singleton()->line.copy_tmp); + data_singleton()->line.pos_tmp = 0; + return (0); +} + +static void right_abs(char **str, size_t *pos) +{ + ft_puttermcaps("mr"); + data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()-> + line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); + ft_putchar((*str)[*pos]); + ft_puttermcaps("me"); + ++(data_singleton()->line.pos_tmp); + ++(*pos); + underline_check_end_of_line(*str, *pos); +} + +static void right_mv_back(char **str, size_t *pos) +{ + data_singleton()->line.copy_tmp = ft_remove_imput(data_singleton()-> + line.copy_tmp, data_singleton()->line.pos_tmp); + ft_putchar((*str)[*pos]); + if (data_singleton()->line.pos_tmp) + --(data_singleton()->line.pos_tmp); + ++(*pos); + underline_check_end_of_line(*str, *pos); +} + +int underline_right(char **str, size_t *pos, size_t pos_ref) +{ + if (!(*pos < ft_strlen(*str))) + return (1); + if ((*str)[*pos] == '\n') + return (reset_term_hard()); + if (*pos >= pos_ref) + right_abs(str, pos); + else + right_mv_back(str, pos); + return (1); +} diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a5774ca6..69fedd03 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/22 22:18:05 by ariard ### ########.fr */ +/* Updated: 2017/03/23 00:28:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,6 +66,7 @@ int main(int ac, char **av) t_btree *ast; g_argv = av; + DG("----------------"); setlocale(LC_ALL, ""); if (shell_init(ac, av) != 0) return (1);