diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index c40d11e4..25f39efa 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* builtin_read.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -30,17 +30,18 @@ typedef struct s_readopt t_readopt; struct s_read { - t_flag opts; - char **names; - char delim; - int nchars; - char *prompt; - int timeout; - int fd; - char *input; + t_flag opts; + char **names; + char delim; + int nchars; + char *prompt; + int timeout; + int fd; + 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); diff --git a/42sh/includes/ft_curs.h b/42sh/includes/ft_curs.h index 94b1a6bd..d411b2c5 100644 --- a/42sh/includes/ft_curs.h +++ b/42sh/includes/ft_curs.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ typedef struct s_curs t_curs; ** Cursor data : cursor's coordonate and windows size */ -struct s_curs +struct s_curs { int co; int li; @@ -79,6 +79,6 @@ void curs_write(t_curs *curs, char *str, size_t len); void curs_write_static(t_curs *curs, char *str, size_t len); void curs_video_write(t_curs *curs, char *str, size_t len); void curs_video_write_static( - t_curs *curs, char *str, size_t len); + t_curs *curs, char *str, size_t len); #endif diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 4282c854..9d78c82b 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index f64c4a15..2e56a7d5 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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(); diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 69c3a8a0..6c16b270 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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,9 +80,8 @@ 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) - return (-1); + if (ft_isprint(ret) && search(str, &str_srch, ret, &srch_pos) < 0) + return (-1); else if (!ft_isprint(ret) && ret == 127 && srch_pos) { --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)); } diff --git a/42sh/src/line_editing/readline.c b/42sh/src/line_editing/readline.c index 068889a0..6205bbc9 100644 --- a/42sh/src/line_editing/readline.c +++ b/42sh/src/line_editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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)