Completion: Fix rematch files

This commit is contained in:
M600 2017-03-28 08:15:50 +02:00
parent 20f8fa1b26
commit 02ae438650
3 changed files with 38 additions and 4 deletions

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,19 +6,27 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
/* Updated: 2017/03/27 18:51:59 by gwojda ### ########.fr */
/* Updated: 2017/03/28 08:15:31 by alao ### ########.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;

View file

@ -6,12 +6,28 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
/* Updated: 2017/03/27 18:50:28 by gwojda ### ########.fr */
/* Updated: 2017/03/28 08:14:15 by alao ### ########.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);
}