sbenning: remove OLD folder

This commit is contained in:
Samuel BENNING 2016-12-14 13:16:43 +01:00
parent 0a3b0cc03e
commit 7ebd3d4ada
52 changed files with 0 additions and 1452 deletions

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_copy_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 14:01:31 by sbenning #+# #+# */
/* Updated: 2016/12/09 18:22:38 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;
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_cut_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 14:19:20 by sbenning #+# #+# */
/* Updated: 2016/12/09 16:24:12 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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;
}

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_dquote_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 00:46:36 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:05:12 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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));
}

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_end_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:29:15 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:04:48 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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;
}

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_esc_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 00:40:22 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:05:51 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));
}

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_home_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:28:10 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:04:47 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;
}

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_insert_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 18:28:01 by sbenning #+# #+# */
/* Updated: 2016/12/09 18:29:33 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;
}

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_left_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:17:13 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:37:48 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;
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_nl_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:03:22 by sbenning #+# #+# */
/* Updated: 2016/12/12 12:09:12 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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;
}

View file

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_pagedown_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:32:26 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:04:19 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;
}

View file

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_pageup_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:32:16 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:04:07 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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;
}

View file

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_paste_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 14:40:45 by sbenning #+# #+# */
/* Updated: 2016/12/09 18:22:38 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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;
}

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_quote_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 00:45:34 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:05:26 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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));
}

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_retarr_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 20:06:50 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:04:31 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;
}

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_right_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:20:15 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:03:24 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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;
}

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_select_end_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 13:19:35 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:07:40 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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);
}

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_select_home_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 13:18:43 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:07:55 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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);
}

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_select_left_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 03:06:59 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:08:10 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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);
}

View file

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_select_right_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 03:16:57 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:08:30 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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);
}

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_select_left_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 03:06:59 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:08:47 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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);
}

View file

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_select_right_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 03:16:57 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:37:31 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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);
}

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_select_left_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 03:06:59 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:09:03 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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);
}

View file

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_select_right_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 03:16:57 by sbenning #+# #+# */
/* Updated: 2016/12/10 12:09:16 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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);
}

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_suppr_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/09 02:23:56 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:04:43 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
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;
}

View file

@ -1,45 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_left_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:17:13 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:03:42 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
static 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_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;
}

View file

@ -1,44 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rl_right_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 19:20:15 by sbenning #+# #+# */
/* Updated: 2016/12/09 12:03:54 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_readline.h"
static 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);
}
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;
}

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_clear_line.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:42:45 by jhalford #+# #+# */
/* Updated: 2016/11/10 13:42:59 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_clear_line(t_data *data, char *buf)
{
ft_line_end(data, buf);
while (ft_key_del(data, buf))
;
return (1);
}

View file

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cursor_left.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:43:10 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:26:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_cursor_left(t_data *data, char *buf)
{
char *res;
res = NULL;
(void)buf;
if (!data->line.input_pos)
return (0);
if (data->line.input[data->line.input_pos - 1] == '\n')
return (0);
data->line.input_pos--;
if (!(res = tgetstr("le", NULL)))
return (-1);
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
return (1);
}

View file

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cursor_right.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:43:31 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:26:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_cursor_right(t_data *data, char *buf)
{
char *res;
res = NULL;
(void)buf;
if (!data->line.input[data->line.input_pos])
return (0);
if (data->line.input[data->line.input_pos] == '\n')
return (0);
data->line.input_pos++;
if ((res = tgetstr("nd", NULL)) == NULL)
return (-1);
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
return (1);
}

View file

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_history_add.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:43:40 by jhalford #+# #+# */
/* Updated: 2016/12/07 16:52:48 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_history_add(t_data *data)
{
t_dlist *new;
char *str;
str = data->line.input;
if (data->line.history)
while (data->line.history->next)
data->line.history = data->line.history->next;
if (!data->line.history->prev
|| ft_strcmp(str, (char *)data->line.history->prev->content))
{
new = ft_dlstnew(str, sizeof(char) * (ft_strlen(str) + 1));
ft_dlstadd_before(&data->line.history, new);
data->line.history = data->line.history->next;
ft_strdel((char **)&data->line.history->content);
}
return (0);
}

View file

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_history_down.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:06 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:27:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_history_down(t_data *data, char *buf)
{
int i;
char *str;
(void)buf;
if (!data->line.history)
return (0);
if (!data->line.history->next)
return (0);
data->line.history = data->line.history->next;
str = data->line.history->content;
i = 0;
if (!data->line.history->next)
ft_strdel(&str);
return (0);
}

View file

@ -1,29 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_history_up.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:15 by jhalford #+# #+# */
/* Updated: 2016/12/07 16:52:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_history_up(t_data *data, char *buf)
{
int i;
char *str;
(void)buf;
if (!data->line.history)
return (0);
if (!data->line.history->prev)
return (0);
data->line.history = data->line.history->prev;
str = data->line.history->content;
i = 0;
return (0);
}

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_input_is_escaped.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:17 by jhalford #+# #+# */
/* Updated: 2016/11/10 13:44:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_input_is_escaped(t_dlist *input_chain)
{
if (*(char *)input_chain->content == '\\')
return (1);
else
return (0);
}

View file

@ -1,68 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_interactive_sh.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:12 by jhalford #+# #+# */
/* Updated: 2016/12/07 17:27:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
t_stof g_keys[] = {
{FT_KEY_C_K, NULL},
{FT_KEY_TAB, &ft_key_default},
{FT_KEY_C_H, &ft_line_start},
{FT_KEY_C_L, &ft_line_end},
{FT_KEY_C_U, &ft_clear_line},
{FT_KEY_ESC, NULL},
/* {FT_KEY_UP, &ft_history_up}, */
/* {FT_KEY_DOWN, &ft_history_down}, */
{FT_KEY_UP, NULL},
{FT_KEY_DOWN, NULL},
/* {FT_KEY_C_UP, &ft_line_up}, */
/* {FT_KEY_C_DOWN, &ft_line_down}, */
{FT_KEY_C_UP, NULL},
{FT_KEY_C_DOWN, NULL},
{FT_KEY_RIGHT, &ft_cursor_right},
{FT_KEY_LEFT, &ft_cursor_left},
{FT_KEY_C_RIGHT, &ft_word_right},
{FT_KEY_C_LEFT, &ft_word_left},
{FT_KEY_ENTER, &ft_key_enter},
{FT_KEY_DEL, &ft_key_del},
{FT_KEY_C_D, &ft_key_ctrl_d},
{FT_KEY_C_C, &ft_key_ctrl_c},
{FT_KEY_C_Z, NULL},
{NULL, &ft_key_default},
};
int ft_interactive_sh(t_data *data)
{
char buf[4];
int ret;
int i;
if ((input_init(data)))
return (-1);
while (1)
{
ft_bzero(buf, 4);
ret = read(0, buf, 4);
i = 0;
while (g_keys[i].name && ft_strcmp(buf, g_keys[i].name))
i++;
if (!g_keys[i].f)
continue ;
if ((ret = (*g_keys[i].f)(data, buf)) < 0)
return (-1);
else if (ret == 2)
{
ft_lstdel(&data->line.qstack, &ft_lst_cfree);
ft_set_termios(data, 0);
return (0);
}
}
}

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_key_ctrl_c.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:24 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:29:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_key_ctrl_c(t_data *data, char *buf)
{
(void)buf;
ft_strdel(&data->line.input);
data->line.input = ft_memalloc(10);
ft_putendl("");
ft_prompt();
return (0);
}

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_key_ctrl_d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:24 by jhalford #+# #+# */
/* Updated: 2016/12/07 18:12:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_key_ctrl_d(t_data *data, char *buf)
{
(void)data;
(void)buf;
data_exit(data);
ft_putendl("exit");
exit(0);
}

View file

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_key_default.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:45:23 by jhalford #+# #+# */
/* Updated: 2016/12/09 14:48:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_key_default(t_data *data, char *buf)
{
char *res;
char *tmp;
tmp = data->line.input;
data->line.input = ft_strinsert(data->line.input, *buf, data->line.input_pos);
data->line.input_pos++;
ft_strdel(&tmp);
qstate_update(data, *buf);
if ((res = tgetstr("IC", NULL)))
{
tputs(tgoto(res, 0, 0), 1, &ft_putchar);
ft_putchar(buf[0]);
return (0);
}
else
return (-1);
}

View file

@ -1,42 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_key_del.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 15:57:43 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:30:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_key_del(t_data *data, char *buf)
{
char *res;
(void)data;
(void)buf;
if (!data->line.input_pos)
return (0);
if (data->line.input[data->line.input_pos - 1] == '\n')
return (0);
qstate_update(data, -1);
ft_strcpy(data->line.input + data->line.input_pos - 1,
data->line.input + data->line.input_pos);
data->line.input_pos--;
if ((res = tgetstr("le", NULL)) == NULL)
{
ft_printf("le error\n");
return (-1);
}
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
if ((res = tgetstr("DC", NULL)) == NULL)
{
ft_printf("DC error\n");
return (-1);
}
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
return (1);
}

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_key_enter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 15:56:36 by jhalford #+# #+# */
/* Updated: 2016/12/07 17:35:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_key_enter(t_data *data, char *buf)
{
(void)buf;
if (*(t_qstate*)data->line.qstack->content == Q_NONE)
{
ft_putchar('\n');
return (2);
}
ft_key_default(data, buf);
ft_printf("> ");
return (0);
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_line_down.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:31 by jhalford #+# #+# */
/* Updated: 2016/11/10 13:44:31 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_line_go_down(t_dlist **input_chain)
{
char *res;
(void)input_chain;
if ((res = tgetstr("up", NULL)) == NULL)
return (-1);
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
return (0);
}

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_line_end.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:33 by jhalford #+# #+# */
/* Updated: 2016/11/10 13:44:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_line_end(t_data *data, char *buf)
{
while (ft_cursor_right(data, buf))
;
return (0);
}

View file

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_line_start.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:34 by jhalford #+# #+# */
/* Updated: 2016/11/10 13:44:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_line_start(t_data *data, char *buf)
{
while (ft_cursor_left(data, buf))
;
return (0);
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_line_up.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:35 by jhalford #+# #+# */
/* Updated: 2016/11/10 13:44:35 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_line_go_up(t_dlist **input_chain)
{
char *res;
(void)input_chain;
if ((res = tgetstr("up", NULL)) == NULL)
return (-1);
tputs(tgoto(res, 0, 0), 0, &ft_putchar);
return (0);
}

View file

@ -1,19 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_prompt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */
/* Updated: 2016/11/28 15:16:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_prompt(void)
{
ft_putstr(SHELL_PROMPT);
return (0);
}

View file

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_set_termios.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */
/* Updated: 2016/12/07 14:20:59 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_set_termios(t_data *data, int input_mode)
{
struct termios term;
(void)data;
if (tcgetattr(0, &term) == -1)
return (-1);
if (input_mode)
term.c_lflag &= ~(ICANON) & ~(ISIG) & ~(ECHO);
else
term.c_lflag |= ICANON | ISIG | ECHO;
term.c_cc[VMIN] = 1;
term.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSADRAIN, &term) == -1)
return (-1);
return (0);
}

View file

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_word_left.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:36 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:31:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_word_left(t_data *data, char *buf)
{
ft_cursor_left(data, buf);
while (FT_WS(data->line.input[data->line.input_pos - 1]))
if (!ft_cursor_left(data, buf))
return (0);
while (!FT_WS(data->line.input[data->line.input_pos - 1]))
if (!ft_cursor_left(data, buf))
return (0);
return (0);
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_word_right.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:44:37 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:31:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
int ft_word_right(t_data *data, char *buf)
{
while (!FT_WS(data->line.input[data->line.input_pos]))
if (!ft_cursor_right(data, buf))
return (0);
while (FT_WS(data->line.input[data->line.input_pos]))
if (!ft_cursor_right(data, buf))
return (0);
return (0);
}

View file

@ -1,29 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 13:35:03 by jhalford #+# #+# */
/* Updated: 2016/12/07 16:30:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int input_init(t_data *data)
{
char null;
null = '\0';
ft_strdel(&data->line.input);
data->line.input = ft_memalloc(10);
data->line.input_pos = 0;
data->line.qstack = ft_lstnew(NULL, sizeof(t_qstate));
*((t_qstate*)data->line.qstack->content) = Q_NONE;
if (ft_set_termios(data, 1))
return (-1);
ft_prompt();
return (0);
}

View file

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* qstate_update.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 15:56:40 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:36:24 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void qstate_update(t_data *data, char c)
{
t_qstate *state;
t_qstate *new;
t_list **list;
t_list *tmp;
list = &data->line.qstack;
state = (*list)->content;
if (c == -1)
{
tmp = ft_lstpop(list);
ft_lstdelone(&tmp, &ft_lst_cfree);
return ;
}
ft_lstadd(list, ft_lstnew(NULL, sizeof(t_qstate)));
new = (*list)->content;
*new = *state;
if (*state == Q_NONE)
qstate_none(new, c);
else if (*state == Q_QUOTE)
qstate_quote(new, c);
else if (*state == Q_DQUOTE)
qstate_dquote(new, c);
else if (*state == Q_BACKSLASH)
*new = *(t_qstate*)(*list)->next->next->content;
}

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* qstate_dquote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:10:09 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:26:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
void qstate_dquote(t_qstate *new, char c)
{
if (c == '\\')
*new = Q_BACKSLASH;
else if (c == '\"')
*new = Q_NONE;
}

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* qstate_none.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:08:48 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:51:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
void qstate_none(t_qstate *new, char c)
{
if (c == '\\')
*new = Q_BACKSLASH;
else if (c == '\"')
*new = Q_DQUOTE;
else if (c == '\'')
*new = Q_QUOTE;
}

View file

@ -1,19 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* qstate_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:10:09 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:26:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
void qstate_quote(t_qstate *new, char c)
{
if (c == '\'')
*new = Q_NONE;
}