mise a la norme edition de ligne

This commit is contained in:
gwojda 2017-03-17 15:13:02 +01:00
parent 76584b9ff7
commit b4b8c1ddda
7 changed files with 55 additions and 51 deletions

View file

@ -6,14 +6,14 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/16 23:02:12 by jhalford ### ########.fr # # Updated: 2017/03/17 14:37:09 by gwojda ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
NAME = 42sh NAME = 42sh
CC = gcc CC = gcc
FLAGS = -Wall -Wextra -Werror -fvisibility=hidden FLAGS = -Wall -Wextra -Werror -g
D_FLAGS = -g D_FLAGS = -g
DELTA = $$(echo "$$(tput cols)-47"|bc) DELTA = $$(echo "$$(tput cols)-47"|bc)

View file

@ -6,7 +6,7 @@
/* 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/17 12:20:31 by gwojda ### ########.fr */ /* Updated: 2017/03/17 12:32:16 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,6 +41,7 @@ int ft_control_d(char **str, size_t *pos)
int ft_control_c(char **str, size_t *pos) int ft_control_c(char **str, size_t *pos)
{ {
set_exitstatus(1, 1);
if (*str) if (*str)
ft_current_str(*str, *pos); ft_current_str(*str, *pos);
ft_strdel(str); ft_strdel(str);

View file

@ -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/17 12:15:58 by gwojda ### ########.fr */ /* Updated: 2017/03/17 15:11:10 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,52 +38,60 @@ t_key g_key[] =
{0 , 0 }, {0 , 0 },
}; };
static void init_read_stdin(char **str, size_t *pos) static void init_read_stdin(char ***str, size_t **pos)
{ {
if (*str) *pos = &data_singleton()->line.pos;
*str = &data_singleton()->line.input;
if (**str)
{ {
ft_current_str(*str, *pos); ft_current_str(**str, **pos);
ft_get_next_str(*str, pos); ft_get_next_str(**str, *pos);
if ((*str)[*pos]) if ((**str)[**pos])
++(*pos); ++(**pos);
} }
if (data_singleton()->comp) if (data_singleton()->comp)
c_clear(data_singleton()); c_clear(data_singleton());
signal(SIGWINCH, sigwinch_resize); signal(SIGWINCH, sigwinch_resize);
} }
static int read_stdin(int *ret, int *j)
{
*j = 0;
*ret = 0;
if (read(0, ret, sizeof(int)) < 0)
return (-1);
return (1);
}
static int press_enter(char **input, char **str)
{
*input = *str;
return (0);
}
int ft_read_stdin(char **input) int ft_read_stdin(char **input)
{ {
int ret; int ret;
int j; int j;
char **str;
size_t *pos;
init_read_stdin(&data_singleton()->line.input, &data_singleton()->line.pos); init_read_stdin(&str, &pos);
while (42) while (42)
{ {
ret = 0; if (read_stdin(&ret, &j) < 0)
j = 0; return (-1);
read(0, &ret, sizeof(int)); if (ft_completion(ret, str, pos))
if (ft_completion(ret, &data_singleton()->line.input,
&data_singleton()->line.pos))
continue ; continue ;
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 && (ret = g_key[j].f(str, pos)))
{ return (ret);
if ((ret = g_key[j].f(&data_singleton()->line.input, else if (!g_key[j].value && ft_isprint(ret))
&data_singleton()->line.pos))) ft_print(ret, str, pos);
return (ret); else if (!g_key[j].value && ret == 10)
} return (press_enter(input, str));
else if (ft_isprint(ret)) else if (!g_key[j].value && ft_isascii(ret) == 0)
ft_print(ret, &data_singleton()->line.input, ft_read_it(ret, pos, str);
&data_singleton()->line.pos);
else if (ret == 10)
{
*input = data_singleton()->line.input;
return (0);
}
else if (ft_isascii(ret) == 0)
ft_read_it(ret, &data_singleton()->line.pos,
&data_singleton()->line.input);
} }
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */ /* Created: 2017/03/07 17:34:23 by gwojda #+# #+# */
/* Updated: 2017/03/17 13:52:05 by gwojda ### ########.fr */ /* Updated: 2017/03/17 14:35:12 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -39,21 +39,16 @@ void ft_init_history(void)
return ; return ;
path = ft_str3join(home, "/", ".42sh_history"); path = ft_str3join(home, "/", ".42sh_history");
if ((fd = open(path, O_RDONLY)) < 0) if ((fd = open(path, O_RDONLY)) < 0)
{ return (free(path));
free(path);
return ;
}
while (get_next_line(fd, &str) > 0) while (get_next_line(fd, &str) > 0)
{ {
if (ft_str_is_print(str) && *str) if (ft_str_is_print(str) && *str)
ft_push_back_history(&data_singleton()->line.list_beg, ft_push_back_history(&data_singleton()->line.list_beg,
ft_create_history_list(str)); ft_create_history_list(str));
else else if (!corrupt)
corrupt = CORRUPT; ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home);
free(str); free(str);
} }
if (corrupt)
ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home);
free(path); free(path);
free(str); free(str);
close(fd); close(fd);

View file

@ -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/03/17 11:49:18 by gwojda ### ########.fr */ /* Updated: 2017/03/17 12:33:43 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -74,8 +74,7 @@ int ft_found_prev_word(char **str, size_t *pos)
ft_puttermcaps("cd"); ft_puttermcaps("cd");
*pos -= 2; *pos -= 2;
ft_get_beggin(*str, pos); ft_get_beggin(*str, pos);
if (!*pos && (*str)[*pos] == '\n') (!*pos && (*str)[*pos] == '\n') ? ++(*pos) : 0;
++(*pos);
ft_current_str(*str, *pos); ft_current_str(*str, *pos);
ft_get_next_str(*str, pos); ft_get_next_str(*str, pos);
++(*pos); ++(*pos);

View file

@ -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/03/17 12:19:23 by gwojda ### ########.fr */ /* Updated: 2017/03/17 12:32:51 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -54,7 +54,7 @@ static void ft_suppr_2(char **str, size_t *i, size_t tmp)
ft_strdel(str); ft_strdel(str);
} }
int ft_suppr(char **str, size_t *pos) int ft_suppr(char **str, size_t *pos)
{ {
size_t tmp; size_t tmp;
char boolean; char boolean;
@ -82,7 +82,7 @@ int ft_suppr(char **str, size_t *pos)
return (0); return (0);
} }
int ft_del(char **str, size_t *pos) int ft_del(char **str, size_t *pos)
{ {
size_t tmp; size_t tmp;

View file

@ -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/17 12:20:12 by gwojda ### ########.fr */ /* Updated: 2017/03/17 14:56:35 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,6 +20,7 @@ int readline(int has_prompt, char **input)
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);
ret = ft_read_stdin(input); ret = ft_read_stdin(input);
DG("ret = %s", input);
if (ret < 0) if (ret < 0)
return (ret); return (ret);
if (data_singleton()->line.input) if (data_singleton()->line.input)