This commit is contained in:
gwojda 2017-03-23 16:29:48 +01:00
parent 809791f46e
commit 061daad09c
12 changed files with 75 additions and 61 deletions

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/23 11:45:05 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:16:57 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -88,7 +88,14 @@ typedef struct s_key
int (*f)(char **str, size_t *pos); int (*f)(char **str, size_t *pos);
} t_key; } t_key;
typedef struct s_cpy
{
int value;
int (*f)(char **str, size_t *pos, size_t pos_ref);
} t_cpy;
extern t_key g_keys[]; extern t_key g_keys[];
extern t_cpy g_cpy[];
void ft_reset_tab(char *tabl); void ft_reset_tab(char *tabl);
void ft_putnc(char c, int n); void ft_putnc(char c, int n);
@ -130,13 +137,13 @@ size_t ft_hist_len(void);
int underline_right(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); int underline_left(char **str, size_t *pos, size_t pos_ref);
void underline_home(char **str, size_t *pos, size_t pos_ref); int underline_home(char **str, size_t *pos, size_t pos_ref);
void underline_end(char **str, size_t *pos, size_t pos_ref); int underline_end(char **str, size_t *pos, size_t pos_ref);
int underline_down(char **str, size_t *pos, size_t pos_ref);
int underline_up(char **str, size_t *pos, size_t pos_ref);
void underline_check_end_of_line(char *str, size_t pos); 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);
void underline_down(char **str, size_t *pos, size_t pos_ref);
void underline_up(char **str, size_t *pos, size_t pos_ref);
int ft_read_stdin(char **input); int ft_read_stdin(char **input);

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* job_control.h :+: :+: :+: */ /* job_control.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/22 17:24:08 by jhalford ### ########.fr */ /* Updated: 2017/03/23 16:13:56 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/16 22:17:10 by alao #+# #+# */ /* Created: 2017/02/16 22:17:10 by alao #+# #+# */
/* Updated: 2017/03/22 18:23:04 by alao ### ########.fr */ /* Updated: 2017/03/23 16:11:29 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,7 +21,7 @@ static size_t ft_strxchr(char *str, char c)
size_t rt; size_t rt;
rt = 0; rt = 0;
while(*str) while (*str)
{ {
if (*str == c) if (*str == c)
rt++; rt++;
@ -34,7 +34,7 @@ static size_t ft_strxchr(char *str, char c)
** Add escape char \ for char to_escape. ** Add escape char \ for char to_escape.
*/ */
char *ft_add_escape(char *str, char to_escape) char *ft_add_escape(char *str, char to_escape)
{ {
char *rt; char *rt;
int i; int i;
@ -65,7 +65,7 @@ char *ft_add_escape(char *str, char to_escape)
** Support: Return the size of a char**. ** Support: Return the size of a char**.
*/ */
int ft_sstrlen(char **s) int ft_sstrlen(char **s)
{ {
int i; int i;
@ -79,7 +79,7 @@ int ft_sstrlen(char **s)
** Support: Tranform a char** as char* with char*sep in between. ** Support: Tranform a char** as char* with char*sep in between.
*/ */
char *ft_sstrtostr(char **s, char *sep) char *ft_sstrtostr(char **s, char *sep)
{ {
char *tmp; char *tmp;
char *tmp2; char *tmp2;

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:52:07 by alao #+# #+# */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */
/* Updated: 2017/03/23 15:42:30 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:12:05 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,6 +33,7 @@ void c_lst_id(t_comp *c)
break ; break ;
} }
} }
/* /*
** Add the matching element to the list ** Add the matching element to the list
*/ */

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* get_lexer_stack2.c :+: :+: :+: */ /* get_lexer_stack2.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/23 15:15:46 by jhalford #+# #+# */ /* Created: 2017/03/23 15:15:46 by jhalford #+# #+# */
/* Updated: 2017/03/23 15:19:00 by jhalford ### ########.fr */ /* Updated: 2017/03/23 16:12:26 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,4 +18,3 @@ int get_lexer_stack2(t_lexer lexer)
return (0); return (0);
return (*(int*)lexer.stack->next->content); return (*(int*)lexer.stack->next->content);
} }

View file

@ -6,16 +6,28 @@
/* 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/23 11:44:51 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:28:01 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
t_cpy g_cpy[] =
{
{FLECHE_GAUCHE , &underline_left },
{FLECHE_DROITE , &underline_right },
{FLECHE_HAUT , &underline_up },
{FLECHE_BAS , &underline_down },
{TOUCHE_HOME , &underline_home },
{TOUCHE_END , &underline_end },
{0 , 0 },
};
int ft_x(char **str, size_t *pos) int ft_x(char **str, size_t *pos)
{ {
int ret;
size_t pos_ref; size_t pos_ref;
int ret;
int i;
pos_ref = *pos; pos_ref = *pos;
ft_strdel(&data_singleton()->line.copy_tmp); ft_strdel(&data_singleton()->line.copy_tmp);
@ -25,21 +37,14 @@ int ft_x(char **str, size_t *pos)
while (42) while (42)
{ {
ret = 0; ret = 0;
i = 0;
if (read(STDIN, &ret, sizeof(int)) < 0) if (read(STDIN, &ret, sizeof(int)) < 0)
return (-1); return (-1);
if (ret == FLECHE_GAUCHE && !underline_left(str, pos, pos_ref)) while (g_cpy[i].value && g_cpy[i].value != ret)
return (0); ++i;
else if (ret == FLECHE_DROITE && !underline_right(str, pos, pos_ref)) if (g_cpy[i].value && (ret = g_cpy[i].f(str, pos, pos_ref)))
return (0); return (ret);
else if (ret == TOUCHE_HOME) else
underline_home(str, pos, pos_ref);
else if (ret == TOUCHE_END)
underline_end(str, pos, pos_ref);
else if (ret == FLECHE_HAUT)
underline_up(str, pos, pos_ref);
else if (ret == FLECHE_BAS)
underline_down(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)
@ -49,8 +54,9 @@ int ft_x(char **str, size_t *pos)
int ft_c(char **str, size_t *pos) int ft_c(char **str, size_t *pos)
{ {
int ret;
size_t pos_ref; size_t pos_ref;
int ret;
int i;
pos_ref = *pos; pos_ref = *pos;
ft_strdel(&data_singleton()->line.copy_tmp); ft_strdel(&data_singleton()->line.copy_tmp);
@ -60,21 +66,14 @@ int ft_c(char **str, size_t *pos)
while (42) while (42)
{ {
ret = 0; ret = 0;
i = 0;
if (read(STDIN, &ret, sizeof(int)) < 0) if (read(STDIN, &ret, sizeof(int)) < 0)
return (-1); return (-1);
if (ret == FLECHE_GAUCHE && !underline_left(str, pos, pos_ref)) while (g_cpy[i].value && g_cpy[i].value != ret)
return (0); ++i;
else if (ret == FLECHE_DROITE && !underline_right(str, pos, pos_ref)) if (g_cpy[i].value && (ret = g_cpy[i].f(str, pos, pos_ref)))
return (0); return (ret);
else if (ret == TOUCHE_HOME) else if (!g_cpy[i].value)
underline_home(str, pos, pos_ref);
else if (ret == TOUCHE_END)
underline_end(str, pos, pos_ref);
else if (ret == FLECHE_HAUT)
underline_up(str, pos, pos_ref);
else if (ret == FLECHE_BAS)
underline_down(str, pos, pos_ref);
else if (ret != FLECHE_DROITE && ret != FLECHE_GAUCHE)
break ; break ;
} }
reset_term(str, pos); reset_term(str, pos);

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/23 11:43:40 by gwojda #+# #+# */ /* Created: 2017/03/23 11:43:40 by gwojda #+# #+# */
/* Updated: 2017/03/23 11:45:20 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:21:46 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
void underline_down(char **str, size_t *pos, size_t pos_ref) int underline_down(char **str, size_t *pos, size_t pos_ref)
{ {
size_t pos_tmp; size_t pos_tmp;
int i; int i;
@ -36,4 +36,5 @@ void underline_down(char **str, size_t *pos, size_t pos_ref)
underline_left(str, pos, pos_ref); underline_left(str, pos, pos_ref);
--pos_tmp; --pos_tmp;
} }
return (0);
} }

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 23:18:15 by gwojda #+# #+# */ /* Created: 2017/03/22 23:18:15 by gwojda #+# #+# */
/* Updated: 2017/03/22 23:42:27 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:21:53 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
void underline_end(char **str, size_t *pos, size_t pos_ref) int underline_end(char **str, size_t *pos, size_t pos_ref)
{ {
size_t pos_tmp; size_t pos_tmp;
@ -32,4 +32,5 @@ void underline_end(char **str, size_t *pos, size_t pos_ref)
underline_left(str, pos, pos_ref); underline_left(str, pos, pos_ref);
--pos_tmp; --pos_tmp;
} }
return (0);
} }

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 23:11:05 by gwojda #+# #+# */ /* Created: 2017/03/22 23:11:05 by gwojda #+# #+# */
/* Updated: 2017/03/22 23:44:44 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:22:01 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
void underline_home(char **str, size_t *pos, size_t pos_ref) int underline_home(char **str, size_t *pos, size_t pos_ref)
{ {
size_t pos_tmp; size_t pos_tmp;
@ -29,4 +29,5 @@ void underline_home(char **str, size_t *pos, size_t pos_ref)
--pos_tmp; --pos_tmp;
} }
*pos = pos_tmp; *pos = pos_tmp;
return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 22:54:28 by gwojda #+# #+# */ /* Created: 2017/03/22 22:54:28 by gwojda #+# #+# */
/* Updated: 2017/03/22 23:08:58 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:25:19 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,7 +18,7 @@ static int reset_term_hard(void)
ft_putnc('\b', ft_strlen(data_singleton()->line.copy_tmp)); ft_putnc('\b', ft_strlen(data_singleton()->line.copy_tmp));
ft_strdel(&data_singleton()->line.copy_tmp); ft_strdel(&data_singleton()->line.copy_tmp);
data_singleton()->line.pos_tmp = 0; data_singleton()->line.pos_tmp = 0;
return (0); return (1);
} }
static void left_abs(char **str, size_t *pos) static void left_abs(char **str, size_t *pos)
@ -27,10 +27,12 @@ static void left_abs(char **str, size_t *pos)
ft_putchar('\b'); ft_putchar('\b');
data_singleton()->line.pos_tmp = 0; data_singleton()->line.pos_tmp = 0;
ft_puttermcaps("mr"); ft_puttermcaps("mr");
ft_putstr("\x1b[38;5;196m");
data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()-> data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()->
line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp);
ft_putchar((*str)[*pos]); ft_putchar((*str)[*pos]);
underline_check_end_of_line(*str, *pos + 1); underline_check_end_of_line(*str, *pos + 1);
ft_putstr("\033[22;37m");
ft_puttermcaps("me"); ft_puttermcaps("me");
ft_putchar('\b'); ft_putchar('\b');
} }
@ -51,12 +53,12 @@ static void left_mv_back(char **str, size_t *pos)
int underline_left(char **str, size_t *pos, size_t pos_ref) int underline_left(char **str, size_t *pos, size_t pos_ref)
{ {
if (!*pos) if (!*pos)
return (1); return (0);
if ((*str)[*pos - 1] == '\n') if ((*str)[*pos - 1] == '\n')
return (reset_term_hard()); return (reset_term_hard());
if (*pos > pos_ref) if (*pos > pos_ref)
left_mv_back(str, pos); left_mv_back(str, pos);
else else
left_abs(str, pos); left_abs(str, pos);
return (1); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 22:50:52 by gwojda #+# #+# */ /* Created: 2017/03/22 22:50:52 by gwojda #+# #+# */
/* Updated: 2017/03/23 10:59:04 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:25:34 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,15 +18,17 @@ static int reset_term_hard(void)
ft_putstr(data_singleton()->line.copy_tmp); ft_putstr(data_singleton()->line.copy_tmp);
ft_strdel(&data_singleton()->line.copy_tmp); ft_strdel(&data_singleton()->line.copy_tmp);
data_singleton()->line.pos_tmp = 0; data_singleton()->line.pos_tmp = 0;
return (0); return (1);
} }
static void right_abs(char **str, size_t *pos) static void right_abs(char **str, size_t *pos)
{ {
ft_puttermcaps("mr"); ft_puttermcaps("mr");
ft_putstr("\x1b[38;5;196m");
data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()-> data_singleton()->line.copy_tmp = ft_realloc_imput(data_singleton()->
line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp); line.copy_tmp, (*str)[*pos], data_singleton()->line.pos_tmp);
ft_putchar((*str)[*pos]); ft_putchar((*str)[*pos]);
ft_putstr("\033[22;37m");
ft_puttermcaps("me"); ft_puttermcaps("me");
++(data_singleton()->line.pos_tmp); ++(data_singleton()->line.pos_tmp);
++(*pos); ++(*pos);
@ -47,12 +49,12 @@ static void right_mv_back(char **str, size_t *pos)
int underline_right(char **str, size_t *pos, size_t pos_ref) int underline_right(char **str, size_t *pos, size_t pos_ref)
{ {
if (!(*pos < ft_strlen(*str))) if (!(*pos < ft_strlen(*str)))
return (1); return (0);
if ((*str)[*pos] == '\n') if ((*str)[*pos] == '\n')
return (reset_term_hard()); return (reset_term_hard());
if (*pos >= pos_ref) if (*pos >= pos_ref)
right_abs(str, pos); right_abs(str, pos);
else else
right_mv_back(str, pos); right_mv_back(str, pos);
return (1); return (0);
} }

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/23 11:35:48 by gwojda #+# #+# */ /* Created: 2017/03/23 11:35:48 by gwojda #+# #+# */
/* Updated: 2017/03/23 11:39:49 by gwojda ### ########.fr */ /* Updated: 2017/03/23 16:22:12 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
void underline_up(char **str, size_t *pos, size_t pos_ref) int underline_up(char **str, size_t *pos, size_t pos_ref)
{ {
size_t pos_tmp; size_t pos_tmp;
int i; int i;
@ -33,4 +33,5 @@ void underline_up(char **str, size_t *pos, size_t pos_ref)
--i; --i;
} }
*pos = pos_tmp; *pos = pos_tmp;
return (0);
} }