sbenning: refactoring rl_<files>
This commit is contained in:
parent
e578f0ef08
commit
323293a41d
48 changed files with 698 additions and 66 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 19:03:22 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/10 12:06:41 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 12:09:12 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,9 +16,9 @@ int rl_nl_function(t_line *line, long int input)
|
|||
{
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
RL_SET(line->bitset, RL_STACK);
|
||||
if (RL_NOT(line->bitset, RL_QUOTING))
|
||||
RL_SET(line->bitset, RL_FINISH);
|
||||
RL_SET(line->bitset, RL_STACK);
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/09 02:05:22 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/10 10:42:43 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 10:48:33 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
# define RL_INSERT_CODE 0x7e325b1b
|
||||
# define RL_CLEAR_CODE 0xc
|
||||
# define RL_NL_CODE 0xa
|
||||
# define RL_COMP_CODE 0x9
|
||||
# define RL_LEFT_CODE 0x445b1b
|
||||
# define RL_RIGHT_CODE 0x435b1b
|
||||
# define RL_WLEFT_CODE 0x44323b315b1b
|
||||
|
|
@ -52,6 +53,7 @@
|
|||
# define RL_INSERT_CODE 0x53323b315b1b
|
||||
# define RL_CLEAR_CODE 0xc
|
||||
# define RL_NL_CODE 0xa
|
||||
# define RL_COMP_CODE 0x9
|
||||
# define RL_LEFT_CODE 0x445b1b
|
||||
# define RL_RIGHT_CODE 0x435b1b
|
||||
# define RL_WLEFT_CODE 0x44323b315b1b
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 18:02:25 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/10 12:20:20 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 12:50:39 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,6 +30,15 @@
|
|||
|
||||
# define RL_OFFSET 1024
|
||||
|
||||
/*
|
||||
* Readline possible prompt
|
||||
*/
|
||||
|
||||
# define RL_PROMPT_DEFAULT "$> "
|
||||
# define RL_PROMPT_ESC "> "
|
||||
# define RL_PROMPT_QUOTE "quote> "
|
||||
# define RL_PROMPT_DQUOTE "double quote> "
|
||||
|
||||
/*
|
||||
* Bitset manipulation : X is the bitset and Y is the bit to manipulate
|
||||
* IS : Is Y set in X
|
||||
|
|
@ -65,6 +74,7 @@
|
|||
# define RL_DQUOTE 0x40
|
||||
# define RL_QUOTING (RL_ESC|RL_QUOTE|RL_DQUOTE)
|
||||
|
||||
typedef struct s_data t_data;
|
||||
typedef struct s_line t_line;
|
||||
typedef struct s_input t_input;
|
||||
typedef int (*t_input_function)(t_line *, long int);
|
||||
|
|
@ -112,6 +122,8 @@ struct s_input
|
|||
t_input_function function;
|
||||
};
|
||||
|
||||
# include "minishell.h"
|
||||
|
||||
/*
|
||||
* Readline setup/cleanup/teardown
|
||||
*/
|
||||
|
|
@ -132,9 +144,14 @@ void input_remove(t_line *line, int size);
|
|||
* Readline internal function
|
||||
*/
|
||||
|
||||
void rl_set_prompt(t_line *line);
|
||||
void rl_put_prompt(t_line *line);
|
||||
int rl_previous_word(t_line *line);
|
||||
int rl_next_word(t_line *line);
|
||||
int rl_clipboard_new(t_line *line);
|
||||
int rl_clipboard_new_cut(t_line *line);
|
||||
void rl_toogle_bitset(t_line *line, int set);
|
||||
int rl_finish(t_line *line);
|
||||
int rl_stack_line(t_line *line);
|
||||
int rl_merge_line(t_line *line);
|
||||
|
||||
|
|
@ -168,6 +185,7 @@ int rl_esc_function(t_line *line, long int input); /* Backslash */
|
|||
int rl_quote_function(t_line *line, long int input); /* Simple quote */
|
||||
int rl_dquote_function(t_line *line, long int input); /* Double quote */
|
||||
int rl_nl_function(t_line *line, long int input); /* New line */
|
||||
int rl_comp_function(t_line *line, long int input); /* New line */
|
||||
int rl_left_function(t_line *line, long int input); /* Left move */
|
||||
int rl_right_function(t_line *line, long int input); /* Right move */
|
||||
int rl_wleft_function(t_line *line, long int input); /* Word left move */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 18:03:48 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/10 11:50:51 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 10:48:50 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
static t_input g_input[] = {\
|
||||
{RL_NL_CODE, rl_nl_function},\
|
||||
{RL_COMP_CODE, rl_comp_function},\
|
||||
{RL_INSERT_CODE, rl_insert_function},\
|
||||
{RL_CLEAR_CODE, rl_clear_function},\
|
||||
{RL_RETARR_CODE, rl_retarr_function},\
|
||||
|
|
@ -43,50 +44,6 @@ static t_input g_input[] = {\
|
|||
{0x0, rl_default_function}\
|
||||
};
|
||||
|
||||
static void rl_toogle_bitset(t_line *line, int set)
|
||||
{
|
||||
static int esc;
|
||||
static int select;
|
||||
|
||||
if (!set)
|
||||
{
|
||||
esc = RL_IS(line->bitset, RL_ESC);
|
||||
select = RL_IS(line->bitset, RL_SELECT);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (esc)
|
||||
{
|
||||
RL_UNSET(line->bitset, RL_ESC);
|
||||
esc = 0;
|
||||
}
|
||||
if ((select && RL_NOT(line->bitset, RL_SELECT)) || (!select && RL_IS(line->bitset, RL_SELECT)))
|
||||
{
|
||||
rl_reset_display(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int rl_finish(t_line *line)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_STACK))
|
||||
{
|
||||
rl_end_function(line, 0);
|
||||
write(1, "\n", 1);
|
||||
if (rl_stack_line(line) < 0)
|
||||
return (-1);
|
||||
if (RL_NOT(line->bitset, RL_FINISH))
|
||||
{
|
||||
if (curs_coo_setup(&line->curs) < 0)
|
||||
return (-1);
|
||||
line->prompt = (RL_IS(line->bitset, RL_ESC) ? "> " : "quote> ");
|
||||
rl_put_prompt(line);
|
||||
}
|
||||
RL_UNSET(line->bitset, RL_STACK);
|
||||
}
|
||||
return (RL_IS(line->bitset, RL_FINISH));
|
||||
}
|
||||
|
||||
static t_input_function rl_get_function(long int input)
|
||||
{
|
||||
int i;
|
||||
|
|
|
|||
72
42sh/src/line-editing/rl_bitset.c
Normal file
72
42sh/src/line-editing/rl_bitset.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_bitset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 10:31:34 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:24:16 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
static void rl_toogle_esc(t_line *line, int set)
|
||||
{
|
||||
static int esc;
|
||||
|
||||
if (!set)
|
||||
esc = RL_IS(line->bitset, RL_ESC);
|
||||
else if (set && esc)
|
||||
{
|
||||
RL_UNSET(line->bitset, RL_ESC);
|
||||
esc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void rl_toogle_select(t_line *line, int set)
|
||||
{
|
||||
static int select;
|
||||
|
||||
if (!set)
|
||||
select = RL_IS(line->bitset, RL_SELECT);
|
||||
else if (set &&\
|
||||
((select && RL_NOT(line->bitset, RL_SELECT)) ||\
|
||||
(!select && RL_IS(line->bitset, RL_SELECT))))
|
||||
rl_reset_display(line);
|
||||
}
|
||||
|
||||
void rl_toogle_bitset(t_line *line, int set)
|
||||
{
|
||||
rl_toogle_esc(line, set);
|
||||
rl_toogle_select(line, set);
|
||||
}
|
||||
|
||||
int rl_finish(t_line *line)
|
||||
{
|
||||
int finish;
|
||||
int stack;
|
||||
|
||||
stack = RL_IS(line->bitset, RL_STACK);
|
||||
finish = RL_IS(line->bitset, RL_FINISH);
|
||||
if (!stack && !finish)
|
||||
return (0);
|
||||
rl_end_function(line, 0);
|
||||
write(1, "\n", 1);
|
||||
if (stack)
|
||||
{
|
||||
RL_UNSET(line->bitset, RL_STACK);
|
||||
if (rl_stack_line(line) < 0)
|
||||
return (-1);
|
||||
}
|
||||
if (finish)
|
||||
return (1);
|
||||
if (curs_coo_setup(&line->curs) < 0)
|
||||
return (-1);
|
||||
line->prompt = (RL_IS(line->bitset, RL_ESC) ? "> " : "quote> ");
|
||||
rl_set_prompt(line);
|
||||
rl_put_prompt(line);
|
||||
return (0);
|
||||
}
|
||||
|
||||
62
42sh/src/line-editing/rl_clipboard_function.c
Normal file
62
42sh/src/line-editing/rl_clipboard_function.c
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_clipboard_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:32:11 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:34:12 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_copy_function(t_line *line, long int input)
|
||||
{
|
||||
if (line->clipboard)
|
||||
ft_memdel((void **)&line->clipboard);
|
||||
if (rl_clipboard_new(line) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_cut_function(t_line *line, long int input)
|
||||
{
|
||||
if (line->clipboard)
|
||||
ft_memdel((void **)&line->clipboard);
|
||||
if (rl_clipboard_new_cut(line) < 0)
|
||||
return (-1);
|
||||
rl_reset_display_post(line);
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_paste_function(t_line *line, long int input)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (!line->clipboard)
|
||||
return (0);
|
||||
len = ft_strlen(line->clipboard);
|
||||
if (!len)
|
||||
return (0);
|
||||
if (RL_IS(line->bitset, RL_INSERT))
|
||||
{
|
||||
if (input_move(line, line->clipboard, len) < 0)
|
||||
return (-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input_maj(line, line->clipboard, len) < 0)
|
||||
return (-1);
|
||||
}
|
||||
rl_reset_display_post(line);
|
||||
curs_forward(&line->curs, len);
|
||||
line->pos += len;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
40
42sh/src/line-editing/rl_comp_function.c
Normal file
40
42sh/src/line-editing/rl_comp_function.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_comp_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 10:49:03 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 11:01:45 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
static int ft_autocomp(t_data *data)
|
||||
{
|
||||
return (0);
|
||||
int li;
|
||||
int co;
|
||||
|
||||
li = data->line.curs.li;
|
||||
co = data->line.curs.co;
|
||||
ft_putstr("\nTeeeeeeest");
|
||||
data->line.input = ft_strjoin(data->line.input, " JOIN ");
|
||||
curs_goto(&data->line.curs, li, co + 6);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int rl_comp_function(t_line *line, long int input)
|
||||
{
|
||||
t_data *data;
|
||||
|
||||
data = *data_singleton();
|
||||
if (ft_autocomp(data) < 0)
|
||||
return (-1);
|
||||
line->size = ft_strlen(line->input);
|
||||
line->used = line->size;
|
||||
curs_reset(0);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 18:30:38 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/09 12:04:50 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 11:50:26 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,8 +28,11 @@ int rl_default_function(t_line *line, long int input)
|
|||
if (input_maj(line, (char *)&input, sizeof(char)) < 0)
|
||||
return (-1);
|
||||
}
|
||||
curs_write(&line->curs, (char *)&input, sizeof(char));
|
||||
rl_reset_display_post(line);
|
||||
curs_forward(&line->curs, sizeof(char));
|
||||
line->pos += 1;
|
||||
/* curs_write(&line->curs, (char *)&input, sizeof(char));
|
||||
line->pos += 1;
|
||||
rl_reset_display_post(line);
|
||||
return (0);
|
||||
*/ return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,18 +6,19 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 18:42:31 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/09 16:30:35 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 10:28:59 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
|
||||
int input_extend(t_line *line, int size)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
size = (RL_OFFSET > size ? RL_OFFSET : size);
|
||||
if ((tmp = ft_strnew(line->size + size)) == NULL)
|
||||
size = (RL_OFFSET > size ? RL_OFFSET : size) + line->size;
|
||||
if ((tmp = ft_strnew(size)) == NULL)
|
||||
return (-1);
|
||||
if (line->input)
|
||||
{
|
||||
|
|
@ -25,15 +26,20 @@ int input_extend(t_line *line, int size)
|
|||
free(line->input);
|
||||
}
|
||||
line->input = tmp;
|
||||
line->size += size;
|
||||
line->size = size;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int rl_dynamic_buffer_extend(t_line *line, int size)
|
||||
{
|
||||
return (input_extend(line, size));
|
||||
}
|
||||
|
||||
int input_maj(t_line *line, char *str, int size)
|
||||
{
|
||||
if (line->used + size >= line->size)
|
||||
{
|
||||
if (input_extend(line, size) < 0)
|
||||
if (rl_dynamic_buffer_extend(line, size) < 0)
|
||||
return (-1);
|
||||
}
|
||||
ft_memcpy(line->input + line->pos, str, size);
|
||||
|
|
@ -48,7 +54,7 @@ int input_move(t_line *line, char *str, int size)
|
|||
|
||||
if (line->used + size >= line->size)
|
||||
{
|
||||
if (input_extend(line, size) < 0)
|
||||
if (rl_dynamic_buffer_extend(line, size) < 0)
|
||||
return (-1);
|
||||
}
|
||||
if ((dup = ft_strdup(line->input + line->pos)) == NULL)
|
||||
|
|
@ -75,3 +81,19 @@ void input_remove(t_line *line, int size)
|
|||
line->used -= size;
|
||||
ft_bzero(line->input + line->used, line->size - line->used);
|
||||
}
|
||||
|
||||
|
||||
int rl_dynamic_buffer_replace(t_line *line, char *str, int size)
|
||||
{
|
||||
return (input_maj(line, str, size));
|
||||
}
|
||||
|
||||
int rl_dynamic_buffer_insert(t_line *line, char *str, int size)
|
||||
{
|
||||
return (input_move(line, str, size));
|
||||
}
|
||||
|
||||
void rl_dynamic_buffer_remove(t_line *line, int size)
|
||||
{
|
||||
input_remove(line, size);
|
||||
}
|
||||
65
42sh/src/line-editing/rl_long_move_function.c
Normal file
65
42sh/src/line-editing/rl_long_move_function.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_long_move_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:55:48 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:57:16 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_home_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
curs_backward(&line->curs, line->pos);
|
||||
line->pos = 0;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_end_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
curs_forward(&line->curs, line->used - line->pos);
|
||||
line->pos = line->used;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_select_home_function(t_line *line, long int input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
if (RL_NOT(line->bitset, RL_SELECT))
|
||||
line->select = line->pos;
|
||||
ret = rl_home_function(line, input);
|
||||
RL_SET(line->bitset, RL_SELECT);
|
||||
rl_reset_display_post(line);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int rl_select_end_function(t_line *line, long int input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
if (RL_NOT(line->bitset, RL_SELECT))
|
||||
line->select = line->pos;
|
||||
ret = rl_end_function(line, input);
|
||||
RL_SET(line->bitset, RL_SELECT);
|
||||
rl_reset_display_ante(line);
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/09 01:25:03 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/09 01:58:15 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 11:34:02 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -22,17 +22,17 @@ int rl_merge_line(t_line *line)
|
|||
{
|
||||
next = line->stack->next;
|
||||
chunk = (char *)line->stack->content;
|
||||
size = line->stack->content_size;
|
||||
size = line->stack->content_size - 1;
|
||||
if (input_maj(line, chunk, size) < 0)
|
||||
return (-1);
|
||||
line->pos += size;
|
||||
if (next)
|
||||
/* if (next)
|
||||
{
|
||||
if (input_maj(line, "\n", 1) < 0)
|
||||
return (-1);
|
||||
line->pos += 1;
|
||||
}
|
||||
free(chunk);
|
||||
*/ free(chunk);
|
||||
free(line->stack);
|
||||
line->stack = next;
|
||||
}
|
||||
|
|
|
|||
72
42sh/src/line-editing/rl_page_move_function.c
Normal file
72
42sh/src/line-editing/rl_page_move_function.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_page_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:39:57 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:42:37 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_pagedown_function(t_line *line, long int input)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
len = line->used - line->pos;
|
||||
len = (line->curs.win_co > len ? len : line->curs.win_co);
|
||||
curs_forward(&line->curs, len);
|
||||
line->pos += len;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_pageup_function(t_line *line, long int input)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
len = (line->curs.win_co > line->pos ? line->pos : line->curs.win_co);
|
||||
curs_backward(&line->curs, len);
|
||||
line->pos -= len;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_select_pagedown_function(t_line *line, long int input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
if (RL_NOT(line->bitset, RL_SELECT))
|
||||
line->select = line->pos;
|
||||
ret = rl_pagedown_function(line, input);
|
||||
RL_SET(line->bitset, RL_SELECT);
|
||||
rl_reset_display_ante(line);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int rl_select_pageup_function(t_line *line, long int input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
if (RL_NOT(line->bitset, RL_SELECT))
|
||||
line->select = line->pos;
|
||||
ret = rl_pageup_function(line, input);
|
||||
RL_SET(line->bitset, RL_SELECT);
|
||||
rl_reset_display_post(line);
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -6,12 +6,24 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/09 01:45:09 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/09 13:38:07 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 12:20:55 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
void rl_set_prompt(t_line *line)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_ESC))
|
||||
line->prompt = RL_PROMPT_ESC;
|
||||
else if (RL_IS(line->bitset, RL_QUOTE))
|
||||
line->prompt = RL_PROMPT_QUOTE;
|
||||
else if (RL_IS(line->bitset, RL_DQUOTE))
|
||||
line->prompt = RL_PROMPT_DQUOTE;
|
||||
else
|
||||
line->prompt = RL_PROMPT_DEFAULT;
|
||||
}
|
||||
|
||||
void rl_put_prompt(t_line *line)
|
||||
{
|
||||
curs_write(&line->curs, line->prompt, ft_strlen(line->prompt));
|
||||
|
|
|
|||
44
42sh/src/line-editing/rl_quoting_function.c
Normal file
44
42sh/src/line-editing/rl_quoting_function.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_quoting_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:35:25 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:36:41 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_esc_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_NOT(line->bitset, RL_ESC))
|
||||
RL_SET(line->bitset, RL_ESC);
|
||||
return (rl_default_function(line, input));
|
||||
}
|
||||
|
||||
int rl_quote_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_NOT(line->bitset, RL_ESC))
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_QUOTE))
|
||||
RL_UNSET(line->bitset, RL_QUOTE);
|
||||
else
|
||||
RL_SET(line->bitset, RL_QUOTE);
|
||||
}
|
||||
return (rl_default_function(line, input));
|
||||
}
|
||||
|
||||
int rl_dquote_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_NOT(line->bitset, RL_ESC))
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_DQUOTE))
|
||||
RL_UNSET(line->bitset, RL_DQUOTE);
|
||||
else
|
||||
RL_SET(line->bitset, RL_DQUOTE);
|
||||
}
|
||||
return (rl_default_function(line, input));
|
||||
}
|
||||
39
42sh/src/line-editing/rl_remove_function.c
Normal file
39
42sh/src/line-editing/rl_remove_function.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_remove_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:45:08 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:46:39 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_retarr_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
input_remove(line, 1);
|
||||
curs_backward(&line->curs, 1);
|
||||
line->pos -= 1;
|
||||
rl_reset_display_post(line);
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_suppr_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
input_remove(line, -1);
|
||||
rl_reset_display_post(line);
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/08 18:07:47 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/09 13:39:22 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 12:20:55 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,6 +19,7 @@ int rl_setup(t_line *line)
|
|||
return (-1);
|
||||
RL_SET(line->bitset, RL_INSERT);
|
||||
line->prompt = "$> ";
|
||||
rl_set_prompt(line);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
65
42sh/src/line-editing/rl_short_move_function.c
Normal file
65
42sh/src/line-editing/rl_short_move_function.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_move_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:53:18 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:54:52 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_left_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
curs_backward(&line->curs, 1);
|
||||
line->pos -= 1;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_right_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
curs_forward(&line->curs, 1);
|
||||
line->pos += 1;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_select_left_function(t_line *line, long int input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
if (RL_NOT(line->bitset, RL_SELECT))
|
||||
line->select = line->pos;
|
||||
ret = rl_left_function(line, input);
|
||||
RL_SET(line->bitset, RL_SELECT);
|
||||
rl_reset_display_post(line);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int rl_select_right_function(t_line *line, long int input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
if (!RL_IS(line->bitset, RL_SELECT))
|
||||
line->select = line->pos;
|
||||
ret = rl_right_function(line, input);
|
||||
RL_SET(line->bitset, RL_SELECT);
|
||||
rl_reset_display_ante(line);
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/09 01:06:54 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/10 09:54:10 by sbenning ### ########.fr */
|
||||
/* Updated: 2016/12/12 11:33:28 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ int rl_stack_line(t_line *line)
|
|||
{
|
||||
t_list *elem;
|
||||
|
||||
elem = ft_lstnew(line->input, line->used);
|
||||
elem = ft_lstnew(line->input, line->used + 1);
|
||||
if (elem == NULL)
|
||||
return (-1);
|
||||
ft_lsteadd(&line->stack, elem);
|
||||
|
|
@ -24,5 +24,11 @@ int rl_stack_line(t_line *line)
|
|||
line->pos = 0;
|
||||
line->size = 0;
|
||||
line->used = 0;
|
||||
if (RL_NOT(line->bitset, RL_ESC))
|
||||
return (0);
|
||||
elem = ft_lstnew("\n", 2);
|
||||
if (elem == NULL)
|
||||
return (-1);
|
||||
ft_lsteadd(&line->stack, elem);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
34
42sh/src/line-editing/rl_state_function.c
Normal file
34
42sh/src/line-editing/rl_state_function.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_state_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 13:00:59 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 13:01:51 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_insert_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_INSERT))
|
||||
RL_UNSET(line->bitset, RL_INSERT);
|
||||
else
|
||||
RL_SET(line->bitset, RL_INSERT);
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_nl_function(t_line *line, long int input)
|
||||
{
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
RL_SET(line->bitset, RL_STACK);
|
||||
if (RL_NOT(line->bitset, RL_QUOTING))
|
||||
RL_SET(line->bitset, RL_FINISH);
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
67
42sh/src/line-editing/rl_word_move_function.c
Normal file
67
42sh/src/line-editing/rl_word_move_function.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_word_function.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:47:31 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:51:53 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_wleft_function(t_line *line, long int input)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
len = rl_previous_word(line);
|
||||
curs_backward(&line->curs, len);
|
||||
line->pos -= len;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_wright_function(t_line *line, long int input)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
len = rl_next_word(line);
|
||||
curs_forward(&line->curs, len);
|
||||
line->pos += len;
|
||||
return (0);
|
||||
(void)input;
|
||||
}
|
||||
|
||||
int rl_select_wleft_function(t_line *line, long int input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!line->pos)
|
||||
return (0);
|
||||
if (RL_NOT(line->bitset, RL_SELECT))
|
||||
line->select = line->pos;
|
||||
ret = rl_wleft_function(line, input);
|
||||
RL_SET(line->bitset, RL_SELECT);
|
||||
rl_reset_display_post(line);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int rl_select_wright_function(t_line *line, long int input)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (line->pos == line->used)
|
||||
return (0);
|
||||
if (RL_NOT(line->bitset, RL_SELECT))
|
||||
line->select = line->pos;
|
||||
ret = rl_wright_function(line, input);
|
||||
RL_SET(line->bitset, RL_SELECT);
|
||||
rl_reset_display_ante(line);
|
||||
return (ret);
|
||||
}
|
||||
51
42sh/src/line-editing/rl_word_utility.c
Normal file
51
42sh/src/line-editing/rl_word_utility.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rl_word_utility.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/12 12:48:07 by sbenning #+# #+# */
|
||||
/* Updated: 2016/12/12 12:50:44 by sbenning ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_readline.h"
|
||||
|
||||
int rl_previous_word(t_line *line)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
i = 0;
|
||||
while (line->input[i] && i < line->pos)
|
||||
{
|
||||
if (!i && line->input[i] != ' ')
|
||||
len = i;
|
||||
if (i && line->input[i - 1] == ' ' && line->input[i] != ' ')
|
||||
len = i;
|
||||
i++;
|
||||
}
|
||||
return (line->pos - len);
|
||||
}
|
||||
|
||||
int rl_next_word(t_line *line)
|
||||
{
|
||||
int i;
|
||||
int flag;
|
||||
|
||||
if (RL_IS(line->bitset, RL_SELECT))
|
||||
RL_UNSET(line->bitset, RL_SELECT);
|
||||
i = line->pos;
|
||||
flag = 0;
|
||||
while (line->input[i] && (line->input[i] == ' ' || !flag))
|
||||
{
|
||||
if (line->input[i] == ' ')
|
||||
flag = 1;
|
||||
i++;
|
||||
}
|
||||
return (i - line->pos);
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue