merge
This commit is contained in:
commit
1dc4a51920
20 changed files with 196 additions and 170 deletions
|
|
@ -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/17 00:02:21 by ariard ### ########.fr */
|
/* Updated: 2017/03/17 10:54:02 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -60,8 +60,6 @@
|
||||||
# define STR data_singleton()->line.input
|
# define STR data_singleton()->line.input
|
||||||
# define POS data_singleton()->line.pos
|
# define POS data_singleton()->line.pos
|
||||||
|
|
||||||
# define HIST 1
|
|
||||||
|
|
||||||
# define ERROR_CNTL_R 1
|
# define ERROR_CNTL_R 1
|
||||||
|
|
||||||
typedef struct s_list_history
|
typedef struct s_list_history
|
||||||
|
|
@ -89,7 +87,7 @@ typedef struct s_line
|
||||||
typedef struct s_key
|
typedef struct s_key
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
void (*f)(void);
|
int (*f)(void);
|
||||||
} t_key;
|
} t_key;
|
||||||
|
|
||||||
extern t_key g_keys[];
|
extern t_key g_keys[];
|
||||||
|
|
@ -132,30 +130,32 @@ 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);
|
||||||
|
|
||||||
char *ft_read_stdin(void);
|
int ft_read_stdin(char **input);
|
||||||
void ft_end(void);
|
|
||||||
void ft_home(void);
|
int ft_end(void);
|
||||||
void ft_move_right(void);
|
int ft_home(void);
|
||||||
void ft_move_left(void);
|
int ft_move_right(void);
|
||||||
void ft_up(void);
|
int ft_move_left(void);
|
||||||
void ft_down(void);
|
int ft_up(void);
|
||||||
void ft_buff_f6(void);
|
int ft_down(void);
|
||||||
void ft_control_d(void);
|
int ft_buff_f6(void);
|
||||||
void ft_control_c(void);
|
int ft_control_d(void);
|
||||||
void ft_control_l(void);
|
int ft_control_c(void);
|
||||||
void ft_del(void);
|
int ft_control_l(void);
|
||||||
void ft_suppr(void);
|
int ft_del(void);
|
||||||
void ft_print(int ret);
|
int ft_suppr(void);
|
||||||
void ft_surch_in_history(void);
|
int ft_print(int ret);
|
||||||
void ft_printall(void);
|
int ft_surch_in_history(void);
|
||||||
void ft_history_down(void);
|
int ft_printall(void);
|
||||||
void ft_history_up(void);
|
int ft_history_down(void);
|
||||||
void ft_found_next_word(void);
|
int ft_history_up(void);
|
||||||
void ft_found_prev_word(void);
|
int ft_found_next_word(void);
|
||||||
void ft_c(void);
|
int ft_found_prev_word(void);
|
||||||
void ft_x(void);
|
int ft_c(void);
|
||||||
void ft_v(void);
|
int ft_x(void);
|
||||||
void ft_read_it(int input, size_t *pos, char **str);
|
int ft_v(void);
|
||||||
|
int ft_read_it(int input, size_t *pos, char **str);
|
||||||
|
|
||||||
int readline(int prompt, char **input);
|
int readline(int prompt, char **input);
|
||||||
int ft_completion(int ret);
|
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_add_str_in_history(char *str);
|
||||||
void ft_init_history(void);
|
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);
|
struct termios *ft_save_termios(int save);
|
||||||
void ft_init_termios(void);
|
void ft_init_termios(void);
|
||||||
void readline_init(int prompt);
|
void readline_init(int prompt);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
|
/* Created: 2017/02/02 15:22:19 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/16 16:12:59 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:48:21 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;
|
t_list_history *head;
|
||||||
|
|
||||||
head = data_singleton()->line.list_cur;
|
head = data_singleton()->line.list_cur;
|
||||||
if (!head)
|
if (!head)
|
||||||
return ;
|
return (0);
|
||||||
ft_clear_before_history(&STR);
|
ft_clear_before_history(&STR);
|
||||||
if (head->next)
|
if (head->next)
|
||||||
head = head->next;
|
head = head->next;
|
||||||
if (!head->str)
|
if (!head->str)
|
||||||
STR = NULL;
|
STR = NULL;
|
||||||
else
|
else
|
||||||
STR = ft_strdup(head->str);
|
if (!(STR = ft_strdup(head->str)))
|
||||||
|
return (-1);
|
||||||
if (STR)
|
if (STR)
|
||||||
ft_current_str(STR, POS);
|
ft_current_str(STR, POS);
|
||||||
if (STR)
|
if (STR)
|
||||||
|
|
@ -48,22 +49,24 @@ void ft_history_down(void)
|
||||||
else
|
else
|
||||||
POS = 0;
|
POS = 0;
|
||||||
data_singleton()->line.list_cur = head;
|
data_singleton()->line.list_cur = head;
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_history_up(void)
|
int ft_history_up(void)
|
||||||
{
|
{
|
||||||
t_list_history *head;
|
t_list_history *head;
|
||||||
|
|
||||||
head = data_singleton()->line.list_cur;
|
head = data_singleton()->line.list_cur;
|
||||||
if (!head)
|
if (!head)
|
||||||
return ;
|
return (0);
|
||||||
ft_clear_before_history(&STR);
|
ft_clear_before_history(&STR);
|
||||||
if (head->prev)
|
if (head->prev)
|
||||||
head = head->prev;
|
head = head->prev;
|
||||||
if (!head->str)
|
if (!head->str)
|
||||||
STR = NULL;
|
STR = NULL;
|
||||||
else
|
else
|
||||||
STR = ft_strdup(head->str);
|
if (!(STR = ft_strdup(head->str)))
|
||||||
|
return (-1);
|
||||||
if (STR)
|
if (STR)
|
||||||
ft_current_str(STR, POS);
|
ft_current_str(STR, POS);
|
||||||
if (STR)
|
if (STR)
|
||||||
|
|
@ -71,4 +74,5 @@ void ft_history_up(void)
|
||||||
else
|
else
|
||||||
POS = 0;
|
POS = 0;
|
||||||
data_singleton()->line.list_cur = head;
|
data_singleton()->line.list_cur = head;
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 12:39:45 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:48:34 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -60,18 +60,7 @@ static int ft_history_parsing_3(char *str, int *i)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_history_parsing_2(void)
|
int ft_history_parsing(int has_prompt, char **input)
|
||||||
{
|
|
||||||
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 i;
|
int i;
|
||||||
char boolean;
|
char boolean;
|
||||||
|
|
@ -79,7 +68,7 @@ char *ft_history_parsing(void)
|
||||||
i = 0;
|
i = 0;
|
||||||
boolean = 0;
|
boolean = 0;
|
||||||
if (!STR)
|
if (!STR)
|
||||||
return (STR);
|
return (0);
|
||||||
while (STR && STR[i])
|
while (STR && STR[i])
|
||||||
{
|
{
|
||||||
if (STR[i] == '!')
|
if (STR[i] == '!')
|
||||||
|
|
@ -93,6 +82,6 @@ char *ft_history_parsing(void)
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (boolean)
|
if (boolean)
|
||||||
ft_history_parsing_2();
|
return (readline(has_prompt, input));
|
||||||
return (STR);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
|
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 11:53:55 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:48:06 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,12 +23,14 @@ static void ft_clear_prompt(size_t *pos, size_t srch_pos)
|
||||||
ft_puttermcaps("cd");
|
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)
|
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);
|
++(*srch_pos);
|
||||||
*str = ft_strget_history(*str_srch);
|
*str = ft_strget_history(*str_srch);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_give_new_prompt(char *str_srch, size_t srch_pos)
|
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);
|
free(str_srch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_surch_in_history(void)
|
int ft_surch_in_history(void)
|
||||||
{
|
{
|
||||||
char *str_srch;
|
char *str_srch;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -75,7 +77,10 @@ void ft_surch_in_history(void)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
read(0, &ret, sizeof(int));
|
read(0, &ret, sizeof(int));
|
||||||
if (ft_isprint(ret))
|
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)
|
else if (ret == 127 && srch_pos)
|
||||||
{
|
{
|
||||||
--srch_pos;
|
--srch_pos;
|
||||||
|
|
@ -87,4 +92,5 @@ void ft_surch_in_history(void)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
ft_modify_str(str_srch, srch_pos);
|
ft_modify_str(str_srch, srch_pos);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */
|
/* Created: 2017/02/03 14:15:55 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 10:33:10 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:45:06 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -53,5 +53,5 @@ int ft_completion(int ret)
|
||||||
ft_putnc('\b', right);
|
ft_putnc('\b', right);
|
||||||
POS = ft_strleni_w(STR, pos_tmp, '\n') - right;
|
POS = ft_strleni_w(STR, pos_tmp, '\n') - right;
|
||||||
}
|
}
|
||||||
return (1);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,23 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
|
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 14:05:00 by jhalford ### ########.fr */
|
/* Updated: 2017/03/17 10:45:20 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_buff_f6(void)
|
int ft_buff_f6(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
read(0, &ret, sizeof(int));
|
if (read(0, &ret, sizeof(int)) < 0)
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_control_d(void)
|
int ft_control_d(void)
|
||||||
{
|
{
|
||||||
if (!STR || STR[0] == '\0')
|
if (!STR || STR[0] == '\0')
|
||||||
{
|
{
|
||||||
|
|
@ -32,23 +34,26 @@ void ft_control_d(void)
|
||||||
ft_del();
|
ft_del();
|
||||||
else
|
else
|
||||||
ft_puttermcaps("bl");
|
ft_puttermcaps("bl");
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_control_c(void)
|
int ft_control_c(void)
|
||||||
{
|
{
|
||||||
if (STR)
|
/* if (STR)
|
||||||
ft_current_str(STR, POS);
|
ft_current_str(STR, POS);
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
set_exitstatus(1, 1);
|
set_exitstatus(1, 1);
|
||||||
ft_prompt();
|
ft_prompt();*/
|
||||||
ft_strdel(&STR);
|
ft_strdel(&STR);
|
||||||
POS = 0;
|
POS = 0;
|
||||||
|
return (42);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_control_l(void)
|
int ft_control_l(void)
|
||||||
{
|
{
|
||||||
ft_clear_window();
|
ft_clear_window();
|
||||||
ft_prompt();
|
ft_prompt();
|
||||||
ft_strdel(&STR);
|
ft_strdel(&STR);
|
||||||
POS = 0;
|
POS = 0;
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/09 11:48:13 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:45:37 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,7 +22,8 @@ static char *ft_strdupi_space(char const *s)
|
||||||
++i;
|
++i;
|
||||||
if (s[i] == '\n')
|
if (s[i] == '\n')
|
||||||
++i;
|
++i;
|
||||||
str = (char *)malloc(sizeof(char) * (i + 1));
|
if (!(str = (char *)malloc(sizeof(char) * (i + 1))))
|
||||||
|
return (NULL);
|
||||||
if (str)
|
if (str)
|
||||||
{
|
{
|
||||||
str[i] = '\0';
|
str[i] = '\0';
|
||||||
|
|
@ -36,7 +37,7 @@ static char *ft_strdupi_space(char const *s)
|
||||||
return (str);
|
return (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_v(void)
|
int ft_v(void)
|
||||||
{
|
{
|
||||||
size_t tmp_pos;
|
size_t tmp_pos;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -46,9 +47,10 @@ void ft_v(void)
|
||||||
i = -1;
|
i = -1;
|
||||||
tmp_pos = POS;
|
tmp_pos = POS;
|
||||||
if (!STR || !tmp)
|
if (!STR || !tmp)
|
||||||
return ;
|
return (0);
|
||||||
while (tmp[++i])
|
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)
|
if (POS)
|
||||||
{
|
{
|
||||||
--POS;
|
--POS;
|
||||||
|
|
@ -58,36 +60,42 @@ void ft_v(void)
|
||||||
ft_get_next_str(STR, &POS);
|
ft_get_next_str(STR, &POS);
|
||||||
ft_putnc('\b', POS - tmp_pos);
|
ft_putnc('\b', POS - tmp_pos);
|
||||||
POS = tmp_pos;
|
POS = tmp_pos;
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_x(void)
|
int ft_x(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char **tmp;
|
char **tmp;
|
||||||
|
|
||||||
tmp = &data_singleton()->line.copy_tmp;
|
tmp = &data_singleton()->line.copy_tmp;
|
||||||
if (!STR)
|
if (!STR)
|
||||||
return ;
|
return (0);
|
||||||
if (*tmp)
|
if (*tmp)
|
||||||
ft_strdel(tmp);
|
ft_strdel(tmp);
|
||||||
*tmp = ft_strdupi_space(&STR[POS]);
|
if (!(*tmp = ft_strdupi_space(&STR[POS])))
|
||||||
|
return (-1);
|
||||||
i = ft_strlen(*tmp);
|
i = ft_strlen(*tmp);
|
||||||
while (i >= 0)
|
while (i >= 0)
|
||||||
{
|
{
|
||||||
STR = ft_remove_imput(STR, POS + i);
|
if (!(STR = ft_remove_imput(STR, POS + i)))
|
||||||
|
return (-1);
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_c(void)
|
int ft_c(void)
|
||||||
{
|
{
|
||||||
char **tmp;
|
char **tmp;
|
||||||
|
|
||||||
if (!STR)
|
if (!STR)
|
||||||
return ;
|
return (1);
|
||||||
tmp = &data_singleton()->line.copy_tmp;
|
tmp = &data_singleton()->line.copy_tmp;
|
||||||
if (*tmp)
|
if (*tmp)
|
||||||
ft_strdel(tmp);
|
ft_strdel(tmp);
|
||||||
*tmp = ft_strdupi_space(STR + POS);
|
if (!(*tmp = ft_strdupi_space(STR + POS)))
|
||||||
|
return (-1);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
|
/* 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));
|
return (ft_strlen(currend_dir + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Une fois nouveau prompt avec git fait -> protection des pointeurs/malloc a faire ici !
|
||||||
|
|
||||||
void ft_prompt(void)
|
void ft_prompt(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:28:49 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 10:34:04 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:49:59 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ t_key g_key[] =
|
||||||
{0 , 0 },
|
{0 , 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ft_is_str(void)
|
static void init_read_stdin(void)
|
||||||
{
|
{
|
||||||
if (STR)
|
if (STR)
|
||||||
{
|
{
|
||||||
|
|
@ -47,17 +47,17 @@ static void ft_is_str(void)
|
||||||
if (STR[POS])
|
if (STR[POS])
|
||||||
++(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 ret;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
ft_is_str();
|
init_read_stdin();
|
||||||
if (data_singleton()->comp)
|
|
||||||
c_clear(data_singleton());
|
|
||||||
signal(SIGWINCH, sigwinch_resize);
|
|
||||||
while (42)
|
while (42)
|
||||||
{
|
{
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
@ -68,11 +68,17 @@ char *ft_read_stdin(void)
|
||||||
while (g_key[j].value && g_key[j].value != ret)
|
while (g_key[j].value && g_key[j].value != ret)
|
||||||
++j;
|
++j;
|
||||||
if (g_key[j].value)
|
if (g_key[j].value)
|
||||||
g_key[j].f();
|
{
|
||||||
|
if ((ret = g_key[j].f()))
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
else if (ft_isprint(ret))
|
else if (ft_isprint(ret))
|
||||||
ft_print(ret);
|
ft_print(ret);
|
||||||
else if (ret == 10)
|
else if (ret == 10)
|
||||||
return (STR);
|
{
|
||||||
|
*input = STR;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
else if (ft_isascii(ret) == 0)
|
else if (ft_isascii(ret) == 0)
|
||||||
ft_read_it(ret, &POS, &STR);
|
ft_read_it(ret, &POS, &STR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/14 11:13:24 by gwojda #+# #+# */
|
/* Created: 2017/02/14 11:13:24 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/14 11:13:47 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:46:05 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_end(void)
|
int ft_end(void)
|
||||||
{
|
{
|
||||||
if (!STR)
|
if (!STR)
|
||||||
return ;
|
return (0);
|
||||||
if (POS)
|
if (POS)
|
||||||
{
|
{
|
||||||
--POS;
|
--POS;
|
||||||
|
|
@ -27,12 +27,13 @@ void ft_end(void)
|
||||||
ft_get_beggin(STR, &POS);
|
ft_get_beggin(STR, &POS);
|
||||||
ft_current_str(STR, POS);
|
ft_current_str(STR, POS);
|
||||||
ft_get_next_str(STR, &POS);
|
ft_get_next_str(STR, &POS);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_home(void)
|
int ft_home(void)
|
||||||
{
|
{
|
||||||
if (!STR)
|
if (!STR)
|
||||||
return ;
|
return (0);
|
||||||
if (POS)
|
if (POS)
|
||||||
{
|
{
|
||||||
--POS;
|
--POS;
|
||||||
|
|
@ -48,4 +49,5 @@ void ft_home(void)
|
||||||
if (!STR[POS])
|
if (!STR[POS])
|
||||||
--POS;
|
--POS;
|
||||||
ft_get_beggin_with_curs(STR, &POS);
|
ft_get_beggin_with_curs(STR, &POS);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 19:07:52 by gwojda #+# #+# */
|
/* 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");
|
ft_putstr("\033[37m");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_printall(void)
|
int ft_printall(void)
|
||||||
{
|
{
|
||||||
size_t pos_tmp;
|
size_t pos_tmp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !STR)
|
if (read(0, &ret, sizeof(int)) == -1 || ret != 126 || !STR)
|
||||||
return ;
|
return (1);
|
||||||
ft_clear_window();
|
ft_clear_window();
|
||||||
ft_prompt();
|
ft_prompt();
|
||||||
pos_tmp = POS;
|
pos_tmp = POS;
|
||||||
|
|
@ -68,6 +68,7 @@ void ft_printall(void)
|
||||||
if (POS)
|
if (POS)
|
||||||
ft_putnc('\b', POS - pos_tmp + 1);
|
ft_putnc('\b', POS - pos_tmp + 1);
|
||||||
POS = pos_tmp;
|
POS = pos_tmp;
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_get_beggin_with_curs(char *str, size_t *pos)
|
void ft_get_beggin_with_curs(char *str, size_t *pos)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */
|
/* 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;
|
char *str;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
str = (char *)malloc(sizeof(char) * (n + 1));
|
if (!(str = (char *)malloc(sizeof(char) * (n + 1))))
|
||||||
|
return (NULL);
|
||||||
if (str)
|
if (str)
|
||||||
{
|
{
|
||||||
while (i < n)
|
while (i < n)
|
||||||
|
|
@ -43,28 +44,6 @@ char *ft_strndup(char const *s, int n)
|
||||||
return (str);
|
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)
|
void ft_reset_tab(char *tabl)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/16 16:14:46 by gwojda #+# #+# */
|
/* 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);
|
new_str = ft_strdup(tmp);
|
||||||
return (new_str);
|
return (new_str);
|
||||||
}
|
}
|
||||||
str_tmp = ft_strndup(str, pos);
|
if (!(str_tmp = ft_strndup(str, pos)))
|
||||||
new_str = ft_strjoin(str_tmp, tmp);
|
return (NULL);
|
||||||
|
if (!(new_str = ft_strjoin(str_tmp, tmp)))
|
||||||
|
return (NULL);
|
||||||
free(str_tmp);
|
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(new_str);
|
||||||
free(str);
|
free(str);
|
||||||
return (str_tmp);
|
return (str_tmp);
|
||||||
|
|
@ -41,8 +44,10 @@ char *ft_remove_imput(char *str, size_t pos)
|
||||||
|
|
||||||
if (!str)
|
if (!str)
|
||||||
return (str);
|
return (str);
|
||||||
new_str = ft_strndup(str, pos);
|
if (!(new_str = ft_strndup(str, pos)))
|
||||||
new_str2 = ft_strjoin(new_str, &str[pos + 1]);
|
return (NULL);
|
||||||
|
if (!(new_str2 = ft_strjoin(new_str, &str[pos + 1])))
|
||||||
|
return (NULL);
|
||||||
free(str);
|
free(str);
|
||||||
free(new_str);
|
free(new_str);
|
||||||
return (new_str2);
|
return (new_str2);
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,18 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:43:58 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/14 11:15:38 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:46:27 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void ft_move_right(void)
|
int ft_move_right(void)
|
||||||
{
|
{
|
||||||
size_t tmp;
|
size_t tmp;
|
||||||
|
|
||||||
if (ft_strlen(STR) <= POS)
|
if (ft_strlen(STR) <= POS)
|
||||||
return ;
|
return (0);
|
||||||
if (STR[POS] == '\n')
|
if (STR[POS] == '\n')
|
||||||
{
|
{
|
||||||
if (POS)
|
if (POS)
|
||||||
|
|
@ -37,19 +37,20 @@ void ft_move_right(void)
|
||||||
ft_putchar(STR[POS]);
|
ft_putchar(STR[POS]);
|
||||||
++POS;
|
++POS;
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_move_left(void)
|
int ft_move_left(void)
|
||||||
{
|
{
|
||||||
if (!POS)
|
if (!POS)
|
||||||
return ;
|
return (0);
|
||||||
if (STR[POS - 1] == '\n')
|
if (STR[POS - 1] == '\n')
|
||||||
{
|
{
|
||||||
if (POS - 1 == 0)
|
if (POS - 1 == 0)
|
||||||
{
|
{
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
--POS;
|
--POS;
|
||||||
return ;
|
return (0);
|
||||||
}
|
}
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
POS -= 2;
|
POS -= 2;
|
||||||
|
|
@ -65,4 +66,5 @@ void ft_move_left(void)
|
||||||
ft_puttermcaps("le");
|
ft_puttermcaps("le");
|
||||||
--POS;
|
--POS;
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/14 11:12:09 by gwojda #+# #+# */
|
/* Created: 2017/02/14 11:12:09 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/14 11:12:19 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:46:44 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -55,13 +55,13 @@ static void ft_found_prev_word_2(int i, char *str, size_t *pos)
|
||||||
(*pos) -= i;
|
(*pos) -= i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_found_prev_word(void)
|
int ft_found_prev_word(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!POS || !STR)
|
if (!POS || !STR)
|
||||||
return ;
|
return (0);
|
||||||
ft_init_prev_word(&POS, STR);
|
ft_init_prev_word(&POS, STR);
|
||||||
if (POS >= 1 && STR[POS - 1] == '\n')
|
if (POS >= 1 && STR[POS - 1] == '\n')
|
||||||
{
|
{
|
||||||
|
|
@ -69,7 +69,7 @@ void ft_found_prev_word(void)
|
||||||
{
|
{
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
--POS;
|
--POS;
|
||||||
return ;
|
return (0);
|
||||||
}
|
}
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
POS -= 2;
|
POS -= 2;
|
||||||
|
|
@ -82,6 +82,7 @@ void ft_found_prev_word(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ft_found_prev_word_2(i, STR, &POS);
|
ft_found_prev_word_2(i, STR, &POS);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_found_next_word_2(void)
|
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);
|
ft_get_beggin_with_curs(STR, &POS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_found_next_word(void)
|
int ft_found_next_word(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!STR)
|
if (!STR)
|
||||||
return ;
|
return (0);
|
||||||
while (STR[i + POS] && STR[i + POS] == ' ')
|
while (STR[i + POS] && STR[i + POS] == ' ')
|
||||||
{
|
{
|
||||||
ft_putchar(STR[i + POS]);
|
ft_putchar(STR[i + POS]);
|
||||||
|
|
@ -124,4 +125,5 @@ void ft_found_next_word(void)
|
||||||
}
|
}
|
||||||
POS += i;
|
POS += i;
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
|
/* Created: 2017/01/09 13:21:40 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 10:31:54 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:46:55 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,10 +38,10 @@ static void ft_up_2(size_t *pos, char *str)
|
||||||
(*pos) -= i;
|
(*pos) -= i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_up(void)
|
int ft_up(void)
|
||||||
{
|
{
|
||||||
if (!STR || !POS)
|
if (!STR || !POS)
|
||||||
return ;
|
return (0);
|
||||||
if (STR[POS - 1] == '\n')
|
if (STR[POS - 1] == '\n')
|
||||||
{
|
{
|
||||||
ft_puttermcaps("cd");
|
ft_puttermcaps("cd");
|
||||||
|
|
@ -54,6 +54,7 @@ void ft_up(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ft_up_2(&POS, STR);
|
ft_up_2(&POS, STR);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_down_2(size_t *pos, char *str)
|
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);
|
ft_get_beggin_with_curs(str, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_down(void)
|
int ft_down(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!STR)
|
if (!STR)
|
||||||
return ;
|
return (0);
|
||||||
if (STR[POS] == '\n')
|
if (STR[POS] == '\n')
|
||||||
ft_down_2(&POS, STR);
|
ft_down_2(&POS, STR);
|
||||||
else
|
else
|
||||||
|
|
@ -93,4 +94,5 @@ void ft_down(void)
|
||||||
}
|
}
|
||||||
POS += i;
|
POS += i;
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
|
/* Created: 2017/01/05 16:02:43 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/07 15:27:48 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:47:11 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,12 +23,13 @@ int ft_found_next_char(char *str, size_t i)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_print(int ret)
|
int ft_print(int ret)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
j = 0;
|
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')
|
while (*(STR + POS + j) && *(STR + POS + j) != '\n')
|
||||||
{
|
{
|
||||||
ft_putchar(*(STR + POS + j));
|
ft_putchar(*(STR + POS + j));
|
||||||
|
|
@ -37,9 +38,10 @@ void ft_print(int ret)
|
||||||
ft_check_end_of_line(STR, POS + j);
|
ft_check_end_of_line(STR, POS + j);
|
||||||
ft_putnc('\b', j - 1);
|
ft_putnc('\b', j - 1);
|
||||||
++POS;
|
++POS;
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
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_puttermcaps("cd");
|
||||||
ft_current_str(*str, *i);
|
ft_current_str(*str, *i);
|
||||||
|
|
@ -52,14 +54,14 @@ void ft_suppr_2(char **str, size_t *i, size_t tmp)
|
||||||
ft_strdel(str);
|
ft_strdel(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_suppr(void)
|
int ft_suppr(void)
|
||||||
{
|
{
|
||||||
size_t tmp;
|
size_t tmp;
|
||||||
char boolean;
|
char boolean;
|
||||||
|
|
||||||
boolean = 0;
|
boolean = 0;
|
||||||
if (POS <= 0)
|
if (POS <= 0)
|
||||||
return ;
|
return (0);
|
||||||
if (STR[POS - 1] != '\n')
|
if (STR[POS - 1] != '\n')
|
||||||
boolean = 1;
|
boolean = 1;
|
||||||
--POS;
|
--POS;
|
||||||
|
|
@ -67,24 +69,28 @@ void ft_suppr(void)
|
||||||
if (boolean)
|
if (boolean)
|
||||||
{
|
{
|
||||||
ft_get_beggin_with_curs(STR, &POS);
|
ft_get_beggin_with_curs(STR, &POS);
|
||||||
STR = ft_remove_imput(STR, tmp);
|
if (!(STR = ft_remove_imput(STR, tmp)))
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
STR = ft_remove_imput(STR, tmp);
|
if (!(STR = ft_remove_imput(STR, tmp)))
|
||||||
|
return (-1);
|
||||||
ft_get_beggin(STR, &POS);
|
ft_get_beggin(STR, &POS);
|
||||||
}
|
}
|
||||||
ft_suppr_2(&STR, &POS, tmp);
|
ft_suppr_2(&STR, &POS, tmp);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_del(void)
|
int ft_del(void)
|
||||||
{
|
{
|
||||||
size_t tmp;
|
size_t tmp;
|
||||||
|
|
||||||
tmp = POS;
|
tmp = POS;
|
||||||
STR = ft_remove_imput(STR, tmp);
|
if (!(STR = ft_remove_imput(STR, tmp)))
|
||||||
|
return (-1);
|
||||||
if (!(STR && POS < ft_strlen(STR) + 1))
|
if (!(STR && POS < ft_strlen(STR) + 1))
|
||||||
return ;
|
return (0);
|
||||||
if (POS)
|
if (POS)
|
||||||
{
|
{
|
||||||
--POS;
|
--POS;
|
||||||
|
|
@ -97,4 +103,5 @@ void ft_del(void)
|
||||||
++POS;
|
++POS;
|
||||||
ft_putnc('\b', POS - tmp);
|
ft_putnc('\b', POS - tmp);
|
||||||
POS = tmp;
|
POS = tmp;
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
|
/* Created: 2016/12/19 16:52:57 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/02/18 13:58:29 by gwojda ### ########.fr */
|
/* Updated: 2017/03/17 10:47:31 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#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;
|
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]))
|
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);
|
++(*pos);
|
||||||
++(*j);
|
++(*j);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ft_read_it_2(int input, char t[5])
|
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';
|
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;
|
int j;
|
||||||
char t[5];
|
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 == 126 || input == 993090331 || input == 925981467 ||
|
||||||
input == 21298 || input == 892427035 || input == 8270395 || input ==
|
input == 21298 || input == 892427035 || input == 8270395 || input ==
|
||||||
942758683 || input == 993090331 || input == 18489 || input == 17977)
|
942758683 || input == 993090331 || input == 18489 || input == 17977)
|
||||||
return ;
|
return (0);
|
||||||
ft_read_it_2(input, t);
|
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)
|
if (!*str)
|
||||||
return ;
|
return (0);
|
||||||
*pos = pos_tmp;
|
*pos = pos_tmp;
|
||||||
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_tmp + j));
|
ft_putnc('\b', *pos - (pos_tmp + j));
|
||||||
*pos = (pos_tmp + j);
|
*pos = (pos_tmp + j);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/16 18:40:39 by ariard ### ########.fr */
|
/* Updated: 2017/03/17 10:54:25 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,13 +19,15 @@ int readline(int has_prompt, char **input)
|
||||||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret);
|
return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret);
|
||||||
readline_init(has_prompt);
|
readline_init(has_prompt);
|
||||||
*input = ft_read_stdin();
|
ret = ft_read_stdin(input);
|
||||||
|
if (ret < 0)
|
||||||
|
return (ret);
|
||||||
if (STR)
|
if (STR)
|
||||||
ft_current_str(STR, POS);
|
ft_current_str(STR, POS);
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
if (has_prompt)
|
if (has_prompt)
|
||||||
*input = ft_history_parsing();
|
ret = ft_history_parsing(has_prompt, input);
|
||||||
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
|
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Updated: 2017/03/17 10:51:23 by gwojda ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue