Fix completion nested in the command
This commit is contained in:
parent
7a35430c5c
commit
46d7e7ce4e
9 changed files with 74 additions and 29 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
|
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 01:19:17 by alao ### ########.fr */
|
/* Updated: 2017/02/16 17:09:17 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -65,7 +65,10 @@ typedef struct s_comp
|
||||||
char *match;
|
char *match;
|
||||||
char *home;
|
char *home;
|
||||||
char *pwd;
|
char *pwd;
|
||||||
|
char *start;
|
||||||
|
char *between;
|
||||||
char *trail;
|
char *trail;
|
||||||
|
int cutpoint;
|
||||||
int prompt;
|
int prompt;
|
||||||
int c_sx;
|
int c_sx;
|
||||||
int c_sy;
|
int c_sy;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/10 11:37:43 by alao #+# #+# */
|
/* Created: 2017/01/10 11:37:43 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 11:37:43 by alao ### ########.fr */
|
/* Updated: 2017/02/16 17:43:57 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -53,6 +53,8 @@ int c_clear(t_data *s)
|
||||||
ptr->cpath ? ft_memdel((void *)&ptr->cpath) : (0);
|
ptr->cpath ? ft_memdel((void *)&ptr->cpath) : (0);
|
||||||
ptr->home ? ft_memdel((void *)&ptr->home) : (0);
|
ptr->home ? ft_memdel((void *)&ptr->home) : (0);
|
||||||
ptr->pwd ? ft_memdel((void *)&ptr->pwd) : (0);
|
ptr->pwd ? ft_memdel((void *)&ptr->pwd) : (0);
|
||||||
|
ptr->start ? ft_memdel((void *)&ptr->start) : (0);
|
||||||
|
ptr->between ? ft_memdel((void *)&ptr->between) : (0);
|
||||||
ptr->trail ? ft_memdel((void *)&ptr->trail) : (0);
|
ptr->trail ? ft_memdel((void *)&ptr->trail) : (0);
|
||||||
if (ptr->lst && ptr->lst->name)
|
if (ptr->lst && ptr->lst->name)
|
||||||
c_clear_lst(ptr);
|
c_clear_lst(ptr);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:31:21 by alao #+# #+# */
|
/* Created: 2017/01/09 13:31:21 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 16:31:34 by alao ### ########.fr */
|
/* Updated: 2017/02/16 18:00:04 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,22 +21,16 @@
|
||||||
|
|
||||||
static int c_exclusion_folder(t_comp *c)
|
static int c_exclusion_folder(t_comp *c)
|
||||||
{
|
{
|
||||||
DG("Exclusion");
|
|
||||||
DIR *rep;
|
DIR *rep;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
char *tmp2;
|
||||||
|
|
||||||
tmp = ft_strjoin(c->cpath, c->match);
|
tmp = ft_strjoin(c->cpath, c->match);
|
||||||
if ((rep = opendir(tmp)) && (!closedir(rep)))
|
if ((rep = opendir(tmp)) && (!closedir(rep)))
|
||||||
{
|
{
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp2 = ft_strjoin(c->match, "/");
|
||||||
tmp = ft_strjoin(c->rcmd, "/");
|
c_updater(c, tmp2);
|
||||||
if (c->trail)
|
tmp2 ? ft_memdel((void *)&tmp2) : (0);
|
||||||
data_singleton()->line.input = ft_strjoin(tmp, c->trail);
|
|
||||||
else
|
|
||||||
data_singleton()->line.input = ft_strdup(tmp);
|
|
||||||
data_singleton()->line.pos = data_singleton()->line.pos + 1;
|
|
||||||
c->isfolder = 1;
|
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 11:21:16 by alao #+# #+# */
|
/* Created: 2017/01/09 11:21:16 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/15 19:05:04 by alao ### ########.fr */
|
/* Updated: 2017/02/16 17:45:54 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,9 +19,11 @@
|
||||||
static char *c_trimmer(char *cmd, int st, int nd)
|
static char *c_trimmer(char *cmd, int st, int nd)
|
||||||
{
|
{
|
||||||
char *rt;
|
char *rt;
|
||||||
|
char *tmp;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
rt = NULL;
|
rt = NULL;
|
||||||
|
tmp = NULL;
|
||||||
len = ft_strlen(cmd);
|
len = ft_strlen(cmd);
|
||||||
if (st == len)
|
if (st == len)
|
||||||
st--;
|
st--;
|
||||||
|
|
@ -31,7 +33,15 @@ static char *c_trimmer(char *cmd, int st, int nd)
|
||||||
while (nd < len && cmd[nd] && cmd[nd] != ';' && cmd[nd] != ' ')
|
while (nd < len && cmd[nd] && cmd[nd] != ';' && cmd[nd] != ' ')
|
||||||
nd++;
|
nd++;
|
||||||
rt = ft_strsub(cmd, st, nd - st);
|
rt = ft_strsub(cmd, st, nd - st);
|
||||||
return (rt);
|
data_singleton()->comp->cutpoint = st;
|
||||||
|
st = 0;
|
||||||
|
while (rt[st] == ' ')
|
||||||
|
st++;
|
||||||
|
tmp = ft_strsub(rt, st, ft_strlen(rt));
|
||||||
|
if (st)
|
||||||
|
data_singleton()->comp->between = ft_strsub(rt, 0, st);
|
||||||
|
rt ? ft_memdel((void *)&rt) : (0);
|
||||||
|
return (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -46,12 +56,19 @@ void c_init(t_data *s, long int input)
|
||||||
|
|
||||||
if (!(s->comp = (t_comp *)malloc((sizeof(t_comp)))))
|
if (!(s->comp = (t_comp *)malloc((sizeof(t_comp)))))
|
||||||
return ;
|
return ;
|
||||||
|
s->comp->cutpoint = 0;
|
||||||
|
s->comp->between = NULL;
|
||||||
s->comp->rcmd = c_trimmer(s->line.input, s->line.pos, s->line.pos);
|
s->comp->rcmd = c_trimmer(s->line.input, s->line.pos, s->line.pos);
|
||||||
len_trail = ft_strlen(s->line.input) - s->line.pos;
|
len_trail = ft_strlen(s->line.input) - s->line.pos;
|
||||||
if (ft_strlen(s->line.input) > s->line.pos)
|
if (ft_strlen(s->line.input) > s->line.pos)
|
||||||
s->comp->trail = ft_strsub(s->line.input, s->line.pos, len_trail);
|
s->comp->trail = ft_strsub(s->line.input, s->line.pos, len_trail);
|
||||||
else
|
else
|
||||||
s->comp->trail = NULL;
|
s->comp->trail = NULL;
|
||||||
|
|
||||||
|
if (s->comp->cutpoint)
|
||||||
|
s->comp->start = ft_strsub(s->line.input, 0, s->comp->cutpoint);
|
||||||
|
else
|
||||||
|
s->comp->start = NULL;
|
||||||
s->comp->ircmd = s->line.pos;
|
s->comp->ircmd = s->line.pos;
|
||||||
s->comp->match = NULL;
|
s->comp->match = NULL;
|
||||||
s->comp->cpath = NULL;
|
s->comp->cpath = NULL;
|
||||||
|
|
@ -63,5 +80,10 @@ void c_init(t_data *s, long int input)
|
||||||
s->comp->key = input;
|
s->comp->key = input;
|
||||||
s->comp->isfolder = 0;
|
s->comp->isfolder = 0;
|
||||||
s->comp->prompt = s->line.prompt_size;
|
s->comp->prompt = s->line.prompt_size;
|
||||||
|
// DG("Init end as:");
|
||||||
|
// DG("Start [%s]", s->comp->start);
|
||||||
|
// DG("Between [%s]", s->comp->between);
|
||||||
|
// DG("RCMD [%s]", s->comp->rcmd);
|
||||||
|
// DG("Trail [%s]", s->comp->trail);
|
||||||
c_matching(s, s->comp);
|
c_matching(s, s->comp);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
|
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 15:16:05 by alao ### ########.fr */
|
/* Updated: 2017/02/16 17:57:51 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ int c_matching(t_data *s, t_comp *c)
|
||||||
c_seek_binary(s, c);
|
c_seek_binary(s, c);
|
||||||
else
|
else
|
||||||
c_seek_files(s, c);
|
c_seek_files(s, c);
|
||||||
if (c->lst)
|
if (s->comp && c->lst)
|
||||||
{
|
{
|
||||||
c_sizing(c);
|
c_sizing(c);
|
||||||
return (1);
|
return (1);
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,31 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/03 13:10:38 by alao #+# #+# */
|
/* Created: 2017/02/03 13:10:38 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 15:16:10 by alao ### ########.fr */
|
/* Updated: 2017/02/16 18:02:47 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
|
|
||||||
|
static int c_updater_rcmd(t_comp *c)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
char *tmp2;
|
||||||
|
int new_pos;
|
||||||
|
|
||||||
|
tmp = ft_strjoin(c->start, c->between);
|
||||||
|
tmp2 = ft_strjoin(tmp, c->rcmd);
|
||||||
|
c->rcmd ? ft_memdel((void *)&c->rcmd) : (0);
|
||||||
|
c->rcmd = ft_strjoin(tmp2, c->trail);
|
||||||
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
|
tmp2 ? ft_memdel((void *)&tmp2) : (0);
|
||||||
|
data_singleton()->line.input ? ft_memdel((void *)&data_singleton()->line.input) : (0);
|
||||||
|
data_singleton()->line.input = ft_strdup(c->rcmd);
|
||||||
|
new_pos = ft_strlen(c->start) + ft_strlen(c->between) + ft_strlen(c->rcmd);
|
||||||
|
data_singleton()->line.pos = new_pos;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Output function. Will update the data->line.input along with the
|
** Output function. Will update the data->line.input along with the
|
||||||
** position of the cursor in data->line.pos. If the autocompletion occur in
|
** position of the cursor in data->line.pos. If the autocompletion occur in
|
||||||
|
|
@ -34,14 +53,12 @@ int c_updater(t_comp *c, char *select)
|
||||||
tmp = ft_strdup(c->rcmd);
|
tmp = ft_strdup(c->rcmd);
|
||||||
rt = ft_strjoin(tmp, select);
|
rt = ft_strjoin(tmp, select);
|
||||||
tmp ? ft_memdel((void *)&tmp) : (0);
|
tmp ? ft_memdel((void *)&tmp) : (0);
|
||||||
data_singleton()->line.input ? ft_memdel((void *)&data_singleton()->line.input) : (0);
|
c->rcmd ? ft_memdel((void *)&c->rcmd) : (0);
|
||||||
if (c->trail)
|
c->rcmd = ft_strdup(rt);
|
||||||
data_singleton()->line.input = ft_strjoin(rt, c->trail);
|
c_updater_rcmd(c);
|
||||||
else
|
|
||||||
data_singleton()->line.input = ft_strdup(rt);
|
|
||||||
data_singleton()->line.pos = ft_strlen(c->rcmd) + ft_strlen(select);
|
|
||||||
rt ? ft_memdel((void *)&rt) : (0);
|
rt ? ft_memdel((void *)&rt) : (0);
|
||||||
c_clear(data_singleton());
|
c_clear(data_singleton());
|
||||||
|
// DG("Module complete commands [%s] with pos [%d]", data_singleton()->line.input, data_singleton()->line.pos);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
|
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 16:37:35 by alao ### ########.fr */
|
/* Updated: 2017/02/16 18:04:15 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -68,5 +68,10 @@ int c_rematch(t_comp *c, long int keypress)
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c_term_clear(c);
|
||||||
|
c_clear(data_singleton());
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/10/11 10:44:40 by alao #+# #+# */
|
/* Created: 2016/10/11 10:44:40 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 12:16:30 by alao ### ########.fr */
|
/* Updated: 2017/02/16 16:58:53 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ void c_term_clear(t_comp *c)
|
||||||
ft_putstr(tgetstr("up", NULL));
|
ft_putstr(tgetstr("up", NULL));
|
||||||
i = 0;
|
i = 0;
|
||||||
lcmd = 0;
|
lcmd = 0;
|
||||||
c->rcmd ? lcmd += (int)ft_strlen(c->rcmd) + c->prompt + 1 : 0;
|
c->rcmd ? lcmd += c->ircmd + c->prompt + 1 : 0;
|
||||||
while (i < lcmd)
|
while (i < lcmd)
|
||||||
{
|
{
|
||||||
ft_putstr(tgetstr("nd", NULL));
|
ft_putstr(tgetstr("nd", NULL));
|
||||||
|
|
@ -53,7 +53,7 @@ void c_term_mv_back(t_comp *c)
|
||||||
ft_putstr(tgetstr("cr", NULL));
|
ft_putstr(tgetstr("cr", NULL));
|
||||||
i = 0;
|
i = 0;
|
||||||
lcmd = 0;
|
lcmd = 0;
|
||||||
c->rcmd ? lcmd += (int)ft_strlen(c->rcmd) + c->prompt + 1 : 0;
|
c->rcmd ? lcmd += c->ircmd + c->prompt + 1 : 0;
|
||||||
while (i < lcmd)
|
while (i < lcmd)
|
||||||
{
|
{
|
||||||
ft_putstr(tgetstr("nd", NULL));
|
ft_putstr(tgetstr("nd", NULL));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/09/20 14:50:33 by alao #+# #+# */
|
/* Created: 2016/09/20 14:50:33 by alao #+# #+# */
|
||||||
/* Updated: 2017/02/16 11:47:59 by alao ### ########.fr */
|
/* Updated: 2017/02/16 17:59:23 by alao ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -91,6 +91,8 @@ int completion(long int keypress)
|
||||||
s->line.input[s->line.pos] != '\0')
|
s->line.input[s->line.pos] != '\0')
|
||||||
return (0);
|
return (0);
|
||||||
c_init(s, keypress);
|
c_init(s, keypress);
|
||||||
|
if (s->comp == NULL)
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue