This commit is contained in:
gwojda 2017-03-20 14:18:26 +01:00
parent 4ea510774d
commit 5b5a4442e2
6 changed files with 32 additions and 33 deletions

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* builtin_read.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
/* Updated: 2017/03/15 19:13:26 by jhalford ### ########.fr */
/* Updated: 2017/03/20 12:36:08 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,7 +40,8 @@ struct s_read
char *input;
};
int builtin_read(const char *path, char *const av[], char *const envp[]);
int builtin_read(const char *path, char *const av[],
char *const envp[]);
int bt_read_init(t_read *data, char **av);

View file

@ -6,7 +6,7 @@
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 16:34:51 by sbenning #+# #+# */
/* Updated: 2017/03/15 18:47:56 by jhalford ### ########.fr */
/* Updated: 2017/03/20 12:33:06 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/03/17 17:24:03 by gwojda ### ########.fr */
/* Updated: 2017/03/20 12:32:15 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -57,9 +57,6 @@
# define CORRUPT 1
//# define STR data_singleton()->line.input
//# define POS data_singleton()->line.pos
# define ERROR_CNTL_R 1
typedef struct s_list_history

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:37:51 by jhalford ### ########.fr */
/* Updated: 2017/03/20 14:17:40 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,10 +30,8 @@ int builtin_exit(const char *path, char *const av[], char *const envp[])
data_singleton()->argv[0]);
return (0);
}
if (av && av[1])
status = ft_atoi(av[1]);
else
status = ft_atoi(ft_getenv(data_singleton()->env, "?"));
status = (av && av[1]) ?
ft_atoi(av[1]) : ft_atoi(ft_getenv(data_singleton()->env, "?"));
if (SH_IS_INTERACTIVE(data_singleton()->opts))
tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes);
job_hup_all();

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */
/* Updated: 2017/03/18 14:29:15 by gwojda ### ########.fr */
/* Updated: 2017/03/20 14:09:01 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +23,7 @@ static void ft_clear_prompt(size_t *pos, size_t srch_pos)
ft_puttermcaps("cd");
}
static int ft_surch_and_realloc(char **str, char **str_srch,
static int search(char **str, char **str_srch,
int ret, size_t *srch_pos)
{
if (!(*str_srch = ft_realloc_imput(*str_srch, ret, *srch_pos)))
@ -51,7 +51,7 @@ static void ft_give_new_prompt(char *str_srch, size_t srch_pos)
}
}
static void ft_modify_str(char *str_srch, size_t srch_pos, char **str,
static int ft_modify_str(char *str_srch, size_t srch_pos, char **str,
size_t *pos)
{
ft_clear_prompt(pos, srch_pos);
@ -63,6 +63,7 @@ static void ft_modify_str(char *str_srch, size_t srch_pos, char **str,
ft_get_next_str(*str, pos);
}
free(str_srch);
return (0);
}
int ft_surch_in_history(char **str, size_t *pos)
@ -79,8 +80,7 @@ int ft_surch_in_history(char **str, size_t *pos)
ft_give_new_prompt(str_srch, srch_pos);
ret = 0;
read(0, &ret, sizeof(int));
if (ft_isprint(ret) &&
ft_surch_and_realloc(str, &str_srch, ret, &srch_pos) < 0)
if (ft_isprint(ret) && search(str, &str_srch, ret, &srch_pos) < 0)
return (-1);
else if (!ft_isprint(ret) && ret == 127 && srch_pos)
{
@ -92,6 +92,5 @@ int ft_surch_in_history(char **str, size_t *pos)
else if (ret != 127 && !ft_isprint(ret))
break ;
}
ft_modify_str(str_srch, srch_pos, str, pos);
return (0);
return (ft_modify_str(str_srch, srch_pos, str, pos));
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/20 12:56:36 by gwojda ### ########.fr */
/* Updated: 2017/03/20 14:16:03 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,11 @@ int readline(int has_prompt, char **input)
if (!has_prompt)
data_singleton()->line.prompt_size = 1;
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
return ((ret = get_next_line(data_singleton()->fd, input)) >= 0 ? !ret : ret);
{
if ((ret = get_next_line(data_singleton()->fd, input)) >= 0)
return (!ret);
return (ret);
}
readline_init(has_prompt);
ret = ft_read_stdin(input);
if (ret < 0)