changement edition de ligne

This commit is contained in:
gwojda 2017-03-16 17:18:01 +01:00
parent 3da58bcb52
commit 037f968183
18 changed files with 191 additions and 165 deletions

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/03/16 15:13:25 by jhalford ### ########.fr */
/* Updated: 2017/03/16 17:08:59 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -60,8 +60,6 @@
# define STR data_singleton()->line.input
# define POS data_singleton()->line.pos
# define HIST 1
# define ERROR_CNTL_R 1
typedef struct s_list_history
@ -89,7 +87,7 @@ typedef struct s_line
typedef struct s_key
{
int value;
void (*f)(void);
int (*f)(void);
} t_key;
extern t_key g_keys[];
@ -132,30 +130,32 @@ int ft_get_size_prev(char *str, size_t pos);
void sigwinch_resize(int sig);
size_t ft_hist_len(void);
char *ft_read_stdin(void);
void ft_end(void);
void ft_home(void);
void ft_move_right(void);
void ft_move_left(void);
void ft_up(void);
void ft_down(void);
void ft_buff_f6(void);
void ft_control_d(void);
void ft_control_c(void);
void ft_control_l(void);
void ft_del(void);
void ft_suppr(void);
void ft_print(int ret);
void ft_surch_in_history(void);
void ft_printall(void);
void ft_history_down(void);
void ft_history_up(void);
void ft_found_next_word(void);
void ft_found_prev_word(void);
void ft_c(void);
void ft_x(void);
void ft_v(void);
void ft_read_it(int input, size_t *pos, char **str);
int ft_read_stdin(char **input);
int ft_end(void);
int ft_home(void);
int ft_move_right(void);
int ft_move_left(void);
int ft_up(void);
int ft_down(void);
int ft_buff_f6(void);
int ft_control_d(void);
int ft_control_c(void);
int ft_control_l(void);
int ft_del(void);
int ft_suppr(void);
int ft_print(int ret);
int ft_surch_in_history(void);
int ft_printall(void);
int ft_history_down(void);
int ft_history_up(void);
int ft_found_next_word(void);
int ft_found_prev_word(void);
int ft_c(void);
int ft_x(void);
int ft_v(void);
int ft_read_it(int input, size_t *pos, char **str);
int readline(int prompt, char **input);
int ft_completion(int ret);
@ -165,7 +165,7 @@ char *ft_strdupi_w(char const *s);
void ft_add_str_in_history(char *str);
void ft_init_history(void);
char *ft_history_parsing(void);
int ft_history_parsing(int has_prompt, char **input);
struct termios *ft_save_termios(int save);
void ft_init_termios(void);
void readline_init(int prompt);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
/* Updated: 2017/02/16 16:12:59 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:00:08 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,20 +27,21 @@ static void ft_clear_before_history(char **str)
}
}
void ft_history_down(void)
int ft_history_down(void)
{
t_list_history *head;
head = data_singleton()->line.list_cur;
if (!head)
return ;
return (1);
ft_clear_before_history(&STR);
if (head->next)
head = head->next;
if (!head->str)
STR = NULL;
else
STR = ft_strdup(head->str);
if (!(STR = ft_strdup(head->str)))
return (-1);
if (STR)
ft_current_str(STR, POS);
if (STR)
@ -48,22 +49,24 @@ void ft_history_down(void)
else
POS = 0;
data_singleton()->line.list_cur = head;
return (1);
}
void ft_history_up(void)
int ft_history_up(void)
{
t_list_history *head;
head = data_singleton()->line.list_cur;
if (!head)
return ;
return (1);
ft_clear_before_history(&STR);
if (head->prev)
head = head->prev;
if (!head->str)
STR = NULL;
else
STR = ft_strdup(head->str);
if (!(STR = ft_strdup(head->str)))
return (-1);
if (STR)
ft_current_str(STR, POS);
if (STR)
@ -71,4 +74,5 @@ void ft_history_up(void)
else
POS = 0;
data_singleton()->line.list_cur = head;
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
/* Updated: 2017/03/16 12:39:45 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:09:02 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -60,18 +60,7 @@ static int ft_history_parsing_3(char *str, int *i)
return (1);
}
static void ft_history_parsing_2(void)
{
data_singleton()->line.pos = 0;
data_singleton()->line.opt = data_singleton()->line.opt | HIST;
ft_prompt();
data_singleton()->line.input = ft_read_stdin();
ft_putchar('\n');
data_singleton()->line.opt = data_singleton()->line.opt | ~HIST;
ft_history_parsing();
}
char *ft_history_parsing(void)
int ft_history_parsing(int has_prompt, char **input)
{
int i;
char boolean;
@ -79,7 +68,7 @@ char *ft_history_parsing(void)
i = 0;
boolean = 0;
if (!STR)
return (STR);
return (1);
while (STR && STR[i])
{
if (STR[i] == '!')
@ -93,6 +82,6 @@ char *ft_history_parsing(void)
++i;
}
if (boolean)
ft_history_parsing_2();
return (STR);
return (readline(has_prompt, input));
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
/* Updated: 2017/03/16 11:53:55 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:12:05 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,12 +23,14 @@ static void ft_clear_prompt(size_t *pos, size_t srch_pos)
ft_puttermcaps("cd");
}
static void ft_surch_and_realloc(char **str, char **str_srch,
static int ft_surch_and_realloc(char **str, char **str_srch,
int ret, size_t *srch_pos)
{
*str_srch = ft_realloc_imput(*str_srch, ret, *srch_pos);
if (!(*str_srch = ft_realloc_imput(*str_srch, ret, *srch_pos)))
return (-1);
++(*srch_pos);
*str = ft_strget_history(*str_srch);
return (1);
}
static void ft_give_new_prompt(char *str_srch, size_t srch_pos)
@ -60,7 +62,7 @@ static void ft_modify_str(char *str_srch, size_t srch_pos)
free(str_srch);
}
void ft_surch_in_history(void)
int ft_surch_in_history(void)
{
char *str_srch;
int ret;
@ -75,7 +77,10 @@ void ft_surch_in_history(void)
ret = 0;
read(0, &ret, sizeof(int));
if (ft_isprint(ret))
ft_surch_and_realloc(&STR, &str_srch, ret, &srch_pos);
{
if (ft_surch_and_realloc(&STR, &str_srch, ret, &srch_pos) < 0)
return (-1);
}
else if (ret == 127 && srch_pos)
{
--srch_pos;
@ -87,4 +92,5 @@ void ft_surch_in_history(void)
break ;
}
ft_modify_str(str_srch, srch_pos);
return (1);
}

View file

@ -6,21 +6,23 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
/* Updated: 2017/03/16 14:05:00 by jhalford ### ########.fr */
/* Updated: 2017/03/16 16:45:43 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_buff_f6(void)
int ft_buff_f6(void)
{
int ret;
ret = 0;
read(0, &ret, sizeof(int));
if (read(0, &ret, sizeof(int)) < 0)
return (-1);
return (1);
}
void ft_control_d(void)
int ft_control_d(void)
{
if (!STR || STR[0] == '\0')
{
@ -32,23 +34,26 @@ void ft_control_d(void)
ft_del();
else
ft_puttermcaps("bl");
return (1);
}
void ft_control_c(void)
int ft_control_c(void)
{
if (STR)
/* if (STR)
ft_current_str(STR, POS);
ft_putchar('\n');
set_exitstatus(1, 1);
ft_prompt();
ft_prompt();*/
ft_strdel(&STR);
POS = 0;
return (42);
}
void ft_control_l(void)
int ft_control_l(void)
{
ft_clear_window();
ft_prompt();
ft_strdel(&STR);
POS = 0;
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
/* Updated: 2017/03/09 11:48:13 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:12:40 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,8 @@ static char *ft_strdupi_space(char const *s)
++i;
if (s[i] == '\n')
++i;
str = (char *)malloc(sizeof(char) * (i + 1));
if (!(str = (char *)malloc(sizeof(char) * (i + 1))))
return (NULL);
if (str)
{
str[i] = '\0';
@ -36,7 +37,7 @@ static char *ft_strdupi_space(char const *s)
return (str);
}
void ft_v(void)
int ft_v(void)
{
size_t tmp_pos;
int i;
@ -46,9 +47,10 @@ void ft_v(void)
i = -1;
tmp_pos = POS;
if (!STR || !tmp)
return ;
return (1);
while (tmp[++i])
STR = ft_realloc_imput(STR, tmp[i], POS + i);
if (!(STR = ft_realloc_imput(STR, tmp[i], POS + i)))
return (-1);
if (POS)
{
--POS;
@ -58,36 +60,42 @@ void ft_v(void)
ft_get_next_str(STR, &POS);
ft_putnc('\b', POS - tmp_pos);
POS = tmp_pos;
return (1);
}
void ft_x(void)
int ft_x(void)
{
int i;
char **tmp;
tmp = &data_singleton()->line.copy_tmp;
if (!STR)
return ;
return (1);
if (*tmp)
ft_strdel(tmp);
*tmp = ft_strdupi_space(&STR[POS]);
if (!(*tmp = ft_strdupi_space(&STR[POS])))
return (-1);
i = ft_strlen(*tmp);
while (i >= 0)
{
STR = ft_remove_imput(STR, POS + i);
if (!(STR = ft_remove_imput(STR, POS + i)))
return (-1);
--i;
}
ft_puttermcaps("cd");
return (1);
}
void ft_c(void)
int ft_c(void)
{
char **tmp;
if (!STR)
return ;
return (1);
tmp = &data_singleton()->line.copy_tmp;
if (*tmp)
ft_strdel(tmp);
*tmp = ft_strdupi_space(STR + POS);
if (!(*tmp = ft_strdupi_space(STR + POS)))
return (-1);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
/* Updated: 2017/03/16 10:38:23 by gwojda ### ########.fr */
/* Updated: 2017/03/16 16:43:35 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -92,6 +92,8 @@ static int ft_currend_dir(void)
return (ft_strlen(currend_dir + 1));
}
//Une fois nouveau prompt avec git fait -> protection des pointeurs/malloc a faire ici !
void ft_prompt(void)
{
int ret;

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
/* Updated: 2017/03/16 10:34:04 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:13:48 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,7 +38,7 @@ t_key g_key[] =
{0 , 0 },
};
static void ft_is_str(void)
static void init_read_stdin(void)
{
if (STR)
{
@ -47,17 +47,17 @@ static void ft_is_str(void)
if (STR[POS])
++(POS);
}
if (data_singleton()->comp)
c_clear(data_singleton());
signal(SIGWINCH, sigwinch_resize);
}
char *ft_read_stdin(void)
int ft_read_stdin(char **input)
{
int ret;
int j;
ft_is_str();
if (data_singleton()->comp)
c_clear(data_singleton());
signal(SIGWINCH, sigwinch_resize);
init_read_stdin();
while (42)
{
ret = 0;
@ -68,11 +68,17 @@ char *ft_read_stdin(void)
while (g_key[j].value && g_key[j].value != ret)
++j;
if (g_key[j].value)
g_key[j].f();
{
if ((ret = g_key[j].f()) != 1)
return (ret);
}
else if (ft_isprint(ret))
ft_print(ret);
else if (ret == 10)
return (STR);
{
*input = STR;
return (1);
}
else if (ft_isascii(ret) == 0)
ft_read_it(ret, &POS, &STR);
}

View file

@ -6,16 +6,16 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/14 11:13:24 by gwojda #+# #+# */
/* Updated: 2017/02/14 11:13:47 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:14:07 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_end(void)
int ft_end(void)
{
if (!STR)
return ;
return (1);
if (POS)
{
--POS;
@ -27,12 +27,13 @@ void ft_end(void)
ft_get_beggin(STR, &POS);
ft_current_str(STR, POS);
ft_get_next_str(STR, &POS);
return (1);
}
void ft_home(void)
int ft_home(void)
{
if (!STR)
return ;
return (1);
if (POS)
{
--POS;
@ -48,4 +49,5 @@ void ft_home(void)
if (!STR[POS])
--POS;
ft_get_beggin_with_curs(STR, &POS);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */
/* Updated: 2017/03/09 11:09:59 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:15:07 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,14 +46,14 @@ void ft_change_affichage(void)
ft_putstr("\033[37m");
}
void ft_printall(void)
int ft_printall(void)
{
size_t pos_tmp;
int ret;
ret = 0;
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !STR)
return ;
return (1);
ft_clear_window();
ft_prompt();
pos_tmp = POS;
@ -68,6 +68,7 @@ void ft_printall(void)
if (POS)
ft_putnc('\b', POS - pos_tmp + 1);
POS = pos_tmp;
return (1);
}
void ft_get_beggin_with_curs(char *str, size_t *pos)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */
/* Updated: 2017/03/04 18:52:22 by ariard ### ########.fr */
/* Updated: 2017/03/16 16:37:39 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,7 +30,8 @@ char *ft_strndup(char const *s, int n)
char *str;
i = 0;
str = (char *)malloc(sizeof(char) * (n + 1));
if (!(str = (char *)malloc(sizeof(char) * (n + 1))))
return (NULL);
if (str)
{
while (i < n)
@ -43,28 +44,6 @@ char *ft_strndup(char const *s, int n)
return (str);
}
char *ft_strdupi(char const *s)
{
int i;
char *str;
i = 0;
while (s[i] && s[i] != ';' && s[i] != '>' && s[i] != '<'
&& ft_strncmp(s + i, "||", 2))
i++;
str = (char *)malloc(sizeof(char) * (i + 1));
if (str)
{
str[i--] = '\0';
while (i >= 0)
{
str[i] = s[i];
i--;
}
}
return (str);
}
void ft_reset_tab(char *tabl)
{
int i;

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */
/* Updated: 2017/03/09 12:07:09 by gwojda ### ########.fr */
/* Updated: 2017/03/16 16:39:24 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,10 +25,13 @@ char *ft_realloc_imput(char *str, int a, size_t pos)
new_str = ft_strdup(tmp);
return (new_str);
}
str_tmp = ft_strndup(str, pos);
new_str = ft_strjoin(str_tmp, tmp);
if (!(str_tmp = ft_strndup(str, pos)))
return (NULL);
if (!(new_str = ft_strjoin(str_tmp, tmp)))
return (NULL);
free(str_tmp);
str_tmp = ft_strjoin(new_str, str + pos);
if (!(str_tmp = ft_strjoin(new_str, str + pos)))
return (NULL);
free(new_str);
free(str);
return (str_tmp);
@ -41,8 +44,10 @@ char *ft_remove_imput(char *str, size_t pos)
if (!str)
return (str);
new_str = ft_strndup(str, pos);
new_str2 = ft_strjoin(new_str, &str[pos + 1]);
if (!(new_str = ft_strndup(str, pos)))
return (NULL);
if (!(new_str2 = ft_strjoin(new_str, &str[pos + 1])))
return (NULL);
free(str);
free(new_str);
return (new_str2);

View file

@ -6,18 +6,18 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
/* Updated: 2017/02/14 11:15:38 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:15:21 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_move_right(void)
int ft_move_right(void)
{
size_t tmp;
if (ft_strlen(STR) <= POS)
return ;
return (1);
if (STR[POS] == '\n')
{
if (POS)
@ -37,19 +37,20 @@ void ft_move_right(void)
ft_putchar(STR[POS]);
++POS;
}
return (1);
}
void ft_move_left(void)
int ft_move_left(void)
{
if (!POS)
return ;
return (1);
if (STR[POS - 1] == '\n')
{
if (POS - 1 == 0)
{
ft_puttermcaps("cd");
--POS;
return ;
return (1);
}
ft_puttermcaps("cd");
POS -= 2;
@ -65,4 +66,5 @@ void ft_move_left(void)
ft_puttermcaps("le");
--POS;
}
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/14 11:12:09 by gwojda #+# #+# */
/* Updated: 2017/02/14 11:12:19 by gwojda ### ########.fr */
/* Updated: 2017/03/16 16:48:48 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,13 +55,13 @@ static void ft_found_prev_word_2(int i, char *str, size_t *pos)
(*pos) -= i;
}
void ft_found_prev_word(void)
int ft_found_prev_word(void)
{
int i;
i = 0;
if (!POS || !STR)
return ;
return (1);
ft_init_prev_word(&POS, STR);
if (POS >= 1 && STR[POS - 1] == '\n')
{
@ -69,7 +69,7 @@ void ft_found_prev_word(void)
{
ft_puttermcaps("cd");
--POS;
return ;
return (1);
}
ft_puttermcaps("cd");
POS -= 2;
@ -82,6 +82,7 @@ void ft_found_prev_word(void)
}
else
ft_found_prev_word_2(i, STR, &POS);
return (1);
}
static void ft_found_next_word_2(void)
@ -101,13 +102,13 @@ static void ft_found_next_word_2(void)
ft_get_beggin_with_curs(STR, &POS);
}
void ft_found_next_word(void)
int ft_found_next_word(void)
{
int i;
i = 0;
if (!STR)
return ;
return (1);
while (STR[i + POS] && STR[i + POS] == ' ')
{
ft_putchar(STR[i + POS]);
@ -124,4 +125,5 @@ void ft_found_next_word(void)
}
POS += i;
}
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
/* Updated: 2017/03/16 10:31:54 by gwojda ### ########.fr */
/* Updated: 2017/03/16 16:49:34 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,10 +38,10 @@ static void ft_up_2(size_t *pos, char *str)
(*pos) -= i;
}
void ft_up(void)
int ft_up(void)
{
if (!STR || !POS)
return ;
return (1);
if (STR[POS - 1] == '\n')
{
ft_puttermcaps("cd");
@ -54,6 +54,7 @@ void ft_up(void)
}
else
ft_up_2(&POS, STR);
return (1);
}
static void ft_down_2(size_t *pos, char *str)
@ -73,14 +74,14 @@ static void ft_down_2(size_t *pos, char *str)
ft_get_beggin_with_curs(str, pos);
}
void ft_down(void)
int ft_down(void)
{
int i;
int len;
i = 0;
if (!STR)
return ;
return (1);
if (STR[POS] == '\n')
ft_down_2(&POS, STR);
else
@ -93,4 +94,5 @@ void ft_down(void)
}
POS += i;
}
return (1);
}

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
/* Updated: 2017/02/07 15:27:48 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:15:41 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_found_next_char(char *str, size_t i)
int ft_found_next_char(char *str, size_t i)
{
while (str[i])
{
@ -23,12 +23,13 @@ int ft_found_next_char(char *str, size_t i)
return (0);
}
void ft_print(int ret)
int ft_print(int ret)
{
int j;
j = 0;
STR = ft_realloc_imput(STR, ret, POS);
if (!(STR = ft_realloc_imput(STR, ret, POS)))
return (-1);
while (*(STR + POS + j) && *(STR + POS + j) != '\n')
{
ft_putchar(*(STR + POS + j));
@ -37,9 +38,10 @@ void ft_print(int ret)
ft_check_end_of_line(STR, POS + j);
ft_putnc('\b', j - 1);
++POS;
return (1);
}
void ft_suppr_2(char **str, size_t *i, size_t tmp)
static void ft_suppr_2(char **str, size_t *i, size_t tmp)
{
ft_puttermcaps("cd");
ft_current_str(*str, *i);
@ -52,14 +54,14 @@ void ft_suppr_2(char **str, size_t *i, size_t tmp)
ft_strdel(str);
}
void ft_suppr(void)
int ft_suppr(void)
{
size_t tmp;
char boolean;
boolean = 0;
if (POS <= 0)
return ;
return (1);
if (STR[POS - 1] != '\n')
boolean = 1;
--POS;
@ -67,24 +69,28 @@ void ft_suppr(void)
if (boolean)
{
ft_get_beggin_with_curs(STR, &POS);
STR = ft_remove_imput(STR, tmp);
if (!(STR = ft_remove_imput(STR, tmp)))
return (-1);
}
else
{
STR = ft_remove_imput(STR, tmp);
if (!(STR = ft_remove_imput(STR, tmp)))
return (-1);
ft_get_beggin(STR, &POS);
}
ft_suppr_2(&STR, &POS, tmp);
return (1);
}
void ft_del(void)
int ft_del(void)
{
size_t tmp;
tmp = POS;
STR = ft_remove_imput(STR, tmp);
if (!(STR = ft_remove_imput(STR, tmp)))
return (-1);
if (!(STR && POS < ft_strlen(STR) + 1))
return ;
return (1);
if (POS)
{
--POS;
@ -97,4 +103,5 @@ void ft_del(void)
++POS;
ft_putnc('\b', POS - tmp);
POS = tmp;
return (1);
}

View file

@ -6,13 +6,13 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
/* Updated: 2017/02/18 13:58:29 by gwojda ### ########.fr */
/* Updated: 2017/03/16 17:15:56 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void ft_read_it_3(char **str, char t[5], size_t *pos, int *j)
static int ft_read_it_3(char **str, char t[5], size_t *pos, int *j)
{
int i;
@ -23,12 +23,14 @@ static void ft_read_it_3(char **str, char t[5], size_t *pos, int *j)
{
if (t[i] && ft_isprint(t[i]))
{
*str = ft_realloc_imput(*str, t[i], *pos);
if (!(*str = ft_realloc_imput(*str, t[i], *pos)))
return (-1);
++(*pos);
++(*j);
}
++i;
}
return (1);
}
static void ft_read_it_2(int input, char t[5])
@ -48,7 +50,7 @@ static void ft_read_it_2(int input, char t[5])
t[4] = '\0';
}
void ft_read_it(int input, size_t *pos, char **str)
int ft_read_it(int input, size_t *pos, char **str)
{
int j;
char t[5];
@ -60,14 +62,16 @@ void ft_read_it(int input, size_t *pos, char **str)
input == 126 || input == 993090331 || input == 925981467 ||
input == 21298 || input == 892427035 || input == 8270395 || input ==
942758683 || input == 993090331 || input == 18489 || input == 17977)
return ;
return (1);
ft_read_it_2(input, t);
ft_read_it_3(str, t, pos, &j);
if (ft_read_it_3(str, t, pos, &j) < 0)
return (-1);
if (!*str)
return ;
return (1);
*pos = pos_tmp;
ft_current_str((*str), *pos);
ft_get_next_str((*str), pos);
ft_putnc('\b', *pos - (pos_tmp + j));
*pos = (pos_tmp + j);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/16 15:22:11 by jhalford ### ########.fr */
/* Updated: 2017/03/16 17:08:28 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,13 +19,15 @@ int readline(int has_prompt, char **input)
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret);
readline_init(has_prompt);
*input = ft_read_stdin();
ret = ft_read_stdin(input);
if (ret <= 0)
return (ret);
if (STR)
ft_current_str(STR, POS);
ft_putchar('\n');
if (has_prompt)
*input = ft_history_parsing();
ret = ft_history_parsing(has_prompt, input);
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
return (-1);
return (0);
return (ret);
}