confclit ok

This commit is contained in:
Antoine Riard 2017-03-23 00:32:41 +01:00
commit a281d4e514
29 changed files with 297 additions and 213 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 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/queue.c\
line_editing/readline.c\ line_editing/readline.c\
line_editing/resize.c\ line_editing/resize.c\
line_editing/underline_end.c\
line_editing/underline_function.c\ line_editing/underline_function.c\
line_editing/underline_home.c\
line_editing/underline_left.c\
line_editing/underline_reset.c\ line_editing/underline_reset.c\
line_editing/underline_right.c\
main/data_exit.c\ main/data_exit.c\
main/data_init.c\ main/data_init.c\
main/data_singleton.c\ main/data_singleton.c\

View file

@ -6,7 +6,7 @@
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */ /* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 16:34:51 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 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_F5 892427035
# define TOUCHE_F6 925981467 # define TOUCHE_F6 925981467
# define SIZE_LINE 16000 # define SIZE_LINE 16384
# define CORRUPT 1 # 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); int ft_get_size_prev(char *str, size_t pos);
void sigwinch_resize(int sig); void sigwinch_resize(int sig);
size_t ft_hist_len(void); 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_term(char **str, size_t *pos);
void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp); void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp);
int reset_term_hard(void);
int ft_read_stdin(char **input); int ft_read_stdin(char **input);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 17:22:51 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:53:36 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:29:54 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:21 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:01:15 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <marvin@42.fr> +#+ +:+ +#+ */ /* By: ariard <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 16:10:54 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,103 +6,60 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/17 18:54:00 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" #include "minishell.h"
#define MATHERR_0 "math : invalid number of arguments" #define MATHERR_0 "usage: math variable operator(+-/*%) operand"
#define MATHERR_1 "math : invalid variable name" #define MATHERR_2 "math: %c: invalid operator"
#define MATHERR_2 "math : invalid operator" #define MATHERR_3 "math: %s: operand must be digits only"
#define MATHERR_3 "math : invalid operand"
#define MATHERR_4 "math: division by 0" #define MATHERR_4 "math: division by 0"
#define MATHERR_5 "math: modulo by 0"
static int init_math(char **var, char **value, char **operator, static char *do_math(char *value, char operator, char *operand)
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)
{ {
long ope1; long ope1;
long ope2; long ope2;
ope1 = ft_atoi(*value); ope1 = ft_atoi(value);
if (operand)
ope2 = ft_atoi(operand); ope2 = ft_atoi(operand);
else DG("value %s -> %i", value, ope1);
ope2 = 0; DG("operand %s -> %i", operand, ope2);
if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) if ((operator == '/') && ope2 == 0)
return (SH_ERR(MATHERR_4)); return (SH_ERR(MATHERR_4) ? NULL : NULL);
else if ((operator == '%') && ope2 == 0)
{ return (SH_ERR(MATHERR_5) ? NULL : NULL);
ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; ope1 = (operator == '+') ? ope1 + ope2 : ope1;
ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; ope1 = (operator == '-') ? ope1 - ope2 : ope1;
ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; ope1 = (operator == '/') ? ope1 / ope2 : ope1;
ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; ope1 = (operator == '*') ? ope1 * ope2 : ope1;
ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; ope1 = (operator == '%') ? ope1 % ope2 : ope1;
} DG("output=%s (%i)", ft_itoa(ope1), ope1);
ft_strdel(value); return (ft_itoa(ope1));
*value = ft_itoa(ope1);
return (0);
} }
int builtin_math(const char *path, char *const av[], char *const envp[]) int builtin_math(const char *path, char *const av[], char *const envp[])
{ {
char *var;
char *value; char *value;
char *operator; char operator;
char *operand; char *operand;
(void)path; (void)path;
(void)envp; (void)envp;
if (!av || !av[1] || !av[2] || !av[3] || av[4]) if (!av || !av[1] || !av[2] || !av[3] || av[4])
return (SH_ERR(MATHERR_0)); return (SH_ERR(MATHERR_0));
init_math(&var, &value, &operator, &operand); value = ft_getenv(data_singleton()->local_var, av[1]);
var = av[1]; operator = av[2][0];
if (get_value(var, &value)) if (!(ft_strchr("+-/*%", operator)))
return (1); return (SH_ERR(MATHERR_2, operator));
operator = av[2];
if (ft_strlen(operator) != 1 || !(ft_strchr("+-/*%", operator[0])))
return (SH_ERR(MATHERR_2));
operand = av[3]; operand = av[3];
if (!ft_stris(operand, &ft_isdigit)) if (!ft_stris(operand, &ft_isdigit))
return (SH_ERR(MATHERR_3)); return (SH_ERR(MATHERR_3, operand));
if (do_math(&value, operator, operand)) if (!(value = do_math(value, operator, operand)))
return (1); 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); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 17:20:01 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; str = data_singleton()->line.input;
free(current_word); free(current_word);
free(glob_echap); 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_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob)))
{ {
ft_sstrfree(ss_glob); ft_sstrfree(ss_glob);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 11:50:51 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,36 +6,28 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:12:05 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" #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) int exec_var(t_btree **ast)
{ {
t_astnode *node; t_astnode *node;
char **av; char **av;
char *var; char *var;
char *value; char *value;
char *equal;
node = (*ast)->item; node = (*ast)->item;
av = token_to_argv(node->data.cmd.token, 1); if (!(av = token_to_argv(node->data.cmd.token, 1)))
set_var(av[0], &var, &value); return (0);
if (ft_getenv(data_singleton()->env, var)) var = av[0];
node = NULL; if ((equal = ft_strchr(av[0], '=')))
else *equal = 0;
value = equal ? equal + 1 : NULL;
builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL); builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL);
ft_strdel(&var); ft_sstrfree(av);
ft_strdel(&value);
ft_tabdel(&av);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:38:36 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:58:02 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:37:04 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:36:04 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 22:03:48 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) if (get_lexer_stack(*lexer) != BQUOTE)
push(&lexer->stack, lexer->state); push(&lexer->stack, lexer->state);
else 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)) else if (lexer->str[lexer->pos] == '\\' && (back = 1))
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:58 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 12:45:06 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; ret = 0;
if (read(STDIN, &ret, sizeof(int)) < 0) if (read(STDIN, &ret, sizeof(int)) < 0)
return (-1); return (-1);
if ((*str)[*pos] == '\n') if (ret == FLECHE_GAUCHE && !underline_left(str, pos, pos_ref))
return (reset_term_hard()); return (0);
if (ret == FLECHE_GAUCHE) else if (ret == FLECHE_DROITE && !underline_right(str, pos, pos_ref))
underline_left(str, pos, pos_ref); return (0);
else if (ret == FLECHE_DROITE) else if (ret == TOUCHE_HOME)
underline_right(str, pos, pos_ref); underline_home(str, pos, pos_ref);
else else if (ret == TOUCHE_END)
underline_end(str, pos, pos_ref);
else if (ret != FLECHE_DROITE && ret != FLECHE_GAUCHE)
break ; break ;
} }
if (data_singleton()->line.copy_tmp && *data_singleton()->line.copy_tmp) 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; ret = 0;
if (read(STDIN, &ret, sizeof(int)) < 0) if (read(STDIN, &ret, sizeof(int)) < 0)
return (-1); return (-1);
if ((*str)[*pos] == '\n') if (ret == FLECHE_GAUCHE && !underline_left(str, pos, pos_ref))
return (reset_term_hard()); return (0);
if (ret == FLECHE_GAUCHE) else if (ret == FLECHE_DROITE && !underline_right(str, pos, pos_ref))
underline_left(str, pos, pos_ref); return (0);
else if (ret == FLECHE_DROITE) else if (ret == TOUCHE_HOME)
underline_right(str, pos, pos_ref); underline_home(str, pos, pos_ref);
else else if (ret == TOUCHE_END)
underline_end(str, pos, pos_ref);
else if (ret != FLECHE_DROITE && ret != FLECHE_GAUCHE)
break ; break ;
} }
reset_term(str, pos); reset_term(str, pos);

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* underline_end.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
}

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 20:55:24 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" #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) if (!str)
return ; return ;
@ -22,61 +22,3 @@ static void underline_check_end_of_line(char *str, size_t pos)
ft_puttermcaps("le"); 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');
}
}

View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* underline_home.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}

View file

@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* underline_left.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 21:14:07 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,7 +26,7 @@ void reset_term(char **str, size_t *pos)
ft_current_str(*str, *pos); ft_current_str(*str, *pos);
ft_get_next_str(*str, pos); ft_get_next_str(*str, pos);
ft_putnc('\b', *pos - pos_ref); 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) void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp)
@ -36,29 +36,20 @@ void reset_and_remove_term(char **str, size_t *pos, char *copy_tmp)
pos_ref = *pos; pos_ref = *pos;
if (!data_singleton()->line.pos_tmp) if (!data_singleton()->line.pos_tmp)
pos_ref += ft_strlen(data_singleton()->line.copy_tmp); pos_ref += ft_strlen(data_singleton()->line.copy_tmp);
if (*pos)
{
--(*pos);
ft_get_beggin_with_curs(*str, pos);
}
while (*copy_tmp) while (*copy_tmp)
{ {
--pos_ref; --pos_ref;
*str = ft_remove_imput(*str, pos_ref); *str = ft_remove_imput(*str, pos_ref);
++copy_tmp; ++copy_tmp;
} }
if (*pos)
{
--(*pos);
ft_get_beggin_with_curs(*str, pos);
}
ft_puttermcaps("cd"); ft_puttermcaps("cd");
ft_current_str(*str, *pos); ft_current_str(*str, *pos);
ft_get_next_str(*str, pos); ft_get_next_str(*str, pos);
ft_putnc('\b', *pos - pos_ref); ft_putnc('\b', *pos - pos_ref);
(*pos) = pos_ref; (*pos) = pos_ref + (((*str)[*pos]) ? 1 : 0);
}
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);
} }

View file

@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* underline_right.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 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; t_btree *ast;
g_argv = av; g_argv = av;
DG("----------------");
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
if (shell_init(ac, av) != 0) if (shell_init(ac, av) != 0)
return (1); return (1);