mise a la norme edition de ligne
This commit is contained in:
parent
76584b9ff7
commit
b4b8c1ddda
7 changed files with 55 additions and 51 deletions
|
|
@ -6,14 +6,14 @@
|
|||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
|
||||
CC = gcc
|
||||
FLAGS = -Wall -Wextra -Werror -fvisibility=hidden
|
||||
FLAGS = -Wall -Wextra -Werror -g
|
||||
D_FLAGS = -g
|
||||
|
||||
DELTA = $$(echo "$$(tput cols)-47"|bc)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
set_exitstatus(1, 1);
|
||||
if (*str)
|
||||
ft_current_str(*str, *pos);
|
||||
ft_strdel(str);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 },
|
||||
};
|
||||
|
||||
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_get_next_str(*str, pos);
|
||||
if ((*str)[*pos])
|
||||
++(*pos);
|
||||
ft_current_str(**str, **pos);
|
||||
ft_get_next_str(**str, *pos);
|
||||
if ((**str)[**pos])
|
||||
++(**pos);
|
||||
}
|
||||
if (data_singleton()->comp)
|
||||
c_clear(data_singleton());
|
||||
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 ret;
|
||||
int j;
|
||||
int ret;
|
||||
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)
|
||||
{
|
||||
ret = 0;
|
||||
j = 0;
|
||||
read(0, &ret, sizeof(int));
|
||||
if (ft_completion(ret, &data_singleton()->line.input,
|
||||
&data_singleton()->line.pos))
|
||||
if (read_stdin(&ret, &j) < 0)
|
||||
return (-1);
|
||||
if (ft_completion(ret, str, pos))
|
||||
continue ;
|
||||
while (g_key[j].value && g_key[j].value != ret)
|
||||
++j;
|
||||
if (g_key[j].value)
|
||||
{
|
||||
if ((ret = g_key[j].f(&data_singleton()->line.input,
|
||||
&data_singleton()->line.pos)))
|
||||
return (ret);
|
||||
}
|
||||
else if (ft_isprint(ret))
|
||||
ft_print(ret, &data_singleton()->line.input,
|
||||
&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);
|
||||
if (g_key[j].value && (ret = g_key[j].f(str, pos)))
|
||||
return (ret);
|
||||
else if (!g_key[j].value && ft_isprint(ret))
|
||||
ft_print(ret, str, pos);
|
||||
else if (!g_key[j].value && ret == 10)
|
||||
return (press_enter(input, str));
|
||||
else if (!g_key[j].value && ft_isascii(ret) == 0)
|
||||
ft_read_it(ret, pos, str);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 ;
|
||||
path = ft_str3join(home, "/", ".42sh_history");
|
||||
if ((fd = open(path, O_RDONLY)) < 0)
|
||||
{
|
||||
free(path);
|
||||
return ;
|
||||
}
|
||||
return (free(path));
|
||||
while (get_next_line(fd, &str) > 0)
|
||||
{
|
||||
if (ft_str_is_print(str) && *str)
|
||||
ft_push_back_history(&data_singleton()->line.list_beg,
|
||||
ft_create_history_list(str));
|
||||
else
|
||||
corrupt = CORRUPT;
|
||||
else if (!corrupt)
|
||||
ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home);
|
||||
free(str);
|
||||
}
|
||||
if (corrupt)
|
||||
ft_dprintf(2, "42sh: corrupt history file %s/.zsh_history", home);
|
||||
free(path);
|
||||
free(str);
|
||||
close(fd);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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");
|
||||
*pos -= 2;
|
||||
ft_get_beggin(*str, pos);
|
||||
if (!*pos && (*str)[*pos] == '\n')
|
||||
++(*pos);
|
||||
(!*pos && (*str)[*pos] == '\n') ? ++(*pos) : 0;
|
||||
ft_current_str(*str, *pos);
|
||||
ft_get_next_str(*str, pos);
|
||||
++(*pos);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
int ft_suppr(char **str, size_t *pos)
|
||||
int ft_suppr(char **str, size_t *pos)
|
||||
{
|
||||
size_t tmp;
|
||||
char boolean;
|
||||
|
|
@ -82,7 +82,7 @@ int ft_suppr(char **str, size_t *pos)
|
|||
return (0);
|
||||
}
|
||||
|
||||
int ft_del(char **str, size_t *pos)
|
||||
int ft_del(char **str, size_t *pos)
|
||||
{
|
||||
size_t tmp;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
readline_init(has_prompt);
|
||||
ret = ft_read_stdin(input);
|
||||
DG("ret = %s", input);
|
||||
if (ret < 0)
|
||||
return (ret);
|
||||
if (data_singleton()->line.input)
|
||||
|
|
|
|||
Loading…
Reference in a new issue