diff --git a/42sh/includes/completion.h b/42sh/includes/completion.h index c2ac1d27..d37a9653 100644 --- a/42sh/includes/completion.h +++ b/42sh/includes/completion.h @@ -6,7 +6,7 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/18 11:13:04 by alao #+# #+# */ -/* Updated: 2017/03/27 17:42:17 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 08:13:56 by alao ### ########.fr */ /* */ /* ************************************************************************** */ @@ -179,6 +179,10 @@ void c_printer(t_comp *c); ** c_exclusion_foldr : Check for match folder. ** ft_sstrlen : Return size of char **. ** ft_sstrtostr : Create char * from char ** with char *sep between. +** ft_add_escape : Add escape char to str. +** c_lst_id : Repair ID list. +** c_is_delim : Check char for specific one. +** c_strdupi : Dupe */ int c_clear(t_data *s); @@ -189,6 +193,7 @@ int ft_sstrlen(char **s); char *ft_sstrtostr(char **s, char *sep); char *ft_add_escape(char *str, char to_escape); void c_lst_id(t_comp *c); +int c_is_delim(char c); char *c_strdupi(char *s, int (*f)(char)); #endif diff --git a/42sh/src/completion/c_match.c b/42sh/src/completion/c_match.c index 6c5ef2a4..12438105 100644 --- a/42sh/src/completion/c_match.c +++ b/42sh/src/completion/c_match.c @@ -6,19 +6,27 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */ -/* Updated: 2017/03/27 22:32:20 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 09:09:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int c_is_delim(char c) +/* +** Check char +*/ + +int c_is_delim(char c) { if (c == ' ' || c == '<' || c == '>' || c == '\n' || c == ';') return (1); return (0); } +/* +** strdupi +*/ + char *c_strdupi(char *s, int (*f)(char)) { int i; diff --git a/42sh/src/completion/c_match_update.c b/42sh/src/completion/c_match_update.c index bda1b63b..11ef0788 100644 --- a/42sh/src/completion/c_match_update.c +++ b/42sh/src/completion/c_match_update.c @@ -6,12 +6,28 @@ /* By: alao +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 12:03:30 by alao #+# #+# */ -/* Updated: 2017/03/27 18:50:28 by gwojda ### ########.fr */ +/* Updated: 2017/03/28 09:10:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "completion.h" +static char *c_current_words(void) +{ + size_t pos; + char *str; + + pos = data_singleton()->line.pos; + str = data_singleton()->line.input; + if (pos && c_is_delim(str[pos])) + --pos; + while (pos && !c_is_delim(str[pos])) + --pos; + if (c_is_delim(str[pos])) + ++pos; + return (c_strdupi(str + pos, &c_is_delim)); +} + /* ** Recreate a c->match value by adding the new key pressed to it. */ @@ -20,17 +36,22 @@ static int c_refresh_match(t_comp *c, long int keypress) { char *tmp; char kpconv[2]; + char *dump; kpconv[0] = (char)keypress; kpconv[1] = '\0'; tmp = c->match ? ft_strjoin(c->match, kpconv) : ft_strdup(kpconv); c->match ? ft_memdel((void *)&c->match) : (0); + dump = c_current_words(); + if (!(ft_strchr(dump, '$'))) + c->match = ft_strdup(tmp); tmp ? ft_memdel((void *)&tmp) : (0); tmp = ft_strjoin(c->rcmd, kpconv); c->rcmd ? ft_memdel((void *)&c->rcmd) : (0); c->rcmd = ft_strdup(tmp); c->ircmd++; tmp ? ft_memdel((void *)&tmp) : (0); + dump ? ft_memdel((void *)&dump) : (0); return (0); }