This commit is contained in:
gwojda 2017-03-08 16:07:12 +01:00
parent 301ec53259
commit 8cad57fc8e
3 changed files with 42 additions and 6 deletions

View file

@ -6,11 +6,12 @@
/* 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/03/08 13:46:46 by gwojda ### ########.fr */ /* Updated: 2017/03/08 16:06:04 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "completion.h" #include "completion.h"
int c_chevron(t_comp *c);
/* /*
** If the parsing for local file fail. The function is called to check if the ** If the parsing for local file fail. The function is called to check if the
@ -70,7 +71,9 @@ static char *c_slicer(t_comp *c)
i--; i--;
tmp[i] == '/' ? i++ : (0); tmp[i] == '/' ? i++ : (0);
rt = (i == (int)ft_strlen(tmp) - 1) ? NULL : ft_strsub(tmp, 0, i); rt = (i == (int)ft_strlen(tmp) - 1) ? NULL : ft_strsub(tmp, 0, i);
// if (i <= (int)ft_strlen(tmp) - i + 1) if (c_chevron(c))
c->match = ft_strdup("");
else
c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i); c->match = ft_strsub(tmp, i, ft_strlen(tmp) - i);
tmp ? ft_memdel((void *)&tmp) : (0); tmp ? ft_memdel((void *)&tmp) : (0);
return (rt); return (rt);
@ -85,6 +88,11 @@ int c_seek_files(t_data *s, t_comp *c)
char *path; char *path;
(void)s; (void)s;
if (c->rcmd[0] == '.')
{
c->cpath = ft_strdup("./");
c->match = ft_strdup(".");
}
if (c->cpath == NULL) if (c->cpath == NULL)
{ {
path = c_slicer(c); path = c_slicer(c);

View file

@ -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/03/08 13:47:34 by gwojda ### ########.fr */ /* Updated: 2017/03/08 16:06:13 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,6 +36,26 @@ static int c_exclusion_folder(t_comp *c)
tmp ? ft_memdel((void *)&tmp) : (0); tmp ? ft_memdel((void *)&tmp) : (0);
return (0); return (0);
} }
/*
** chevron y es-tu ???
*/
int c_chevron(t_comp *c)
{
size_t pos;
pos = c->ircmd;
while (pos)
{
if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>')
return (1);
--pos;
}
if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>')
return (1);
return (0);
}
/* /*
** Start the parsing for the autocompletion. ** Start the parsing for the autocompletion.
** Check the first char of the c->rcmd for a . or /. to see if it's a local ** Check the first char of the c->rcmd for a . or /. to see if it's a local
@ -51,14 +71,22 @@ static int c_exclusion_folder(t_comp *c)
int c_matching(t_data *s, t_comp *c) int c_matching(t_data *s, t_comp *c)
{ {
if (c->rcmd[0] == '.' || c->rcmd[0] == '/') char *tmp;
if (ft_strchr(c->rcmd, '/'))
{ {
c->cpath = ft_strndup(c->rcmd, ft_strrchr(c->rcmd, '/') - c->rcmd + 1); c->cpath = ft_strndup(c->rcmd, ft_strrchr(c->rcmd, '/') - c->rcmd + 1);
if (c->rcmd[0] == '~')
{
tmp = c->cpath;
c->cpath = ft_str3join(getenv("PWD"), "/", c->cpath + 2);
free(tmp);
}
!c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0; !c->match ? c->match = ft_strdupi_w(ft_strrchr(c->rcmd, '/') + 1) : 0;
c_parser(c, c->cpath, c->match); c_parser(c, c->cpath, c->match);
c_exclusion_folder(c); c_exclusion_folder(c);
} }
else if (!(ft_strchr(c->rcmd, ' '))) else if (c->rcmd[0] != '.' && !(ft_strchr(c->rcmd, ' ')) && !c_chevron(c))
c_seek_binary(s, c); c_seek_binary(s, c);
else else
c_seek_files(s, c); c_seek_files(s, c);

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:52:07 by alao #+# #+# */ /* Created: 2017/01/09 13:52:07 by alao #+# #+# */
/* Updated: 2017/03/08 12:56:35 by gwojda ### ########.fr */ /* Updated: 2017/03/08 15:47:58 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */