fix bugs completion...

This commit is contained in:
gwojda 2017-03-22 15:46:42 +01:00
parent 1cc5de10e5
commit dea3e1c7a8

View file

@ -6,33 +6,59 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
/* Updated: 2017/03/22 15:13:12 by gwojda ### ########.fr */
/* Updated: 2017/03/22 15:46:22 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static int c_is_delim(char c)
{
if (c == ' ' || c == '<' || c == '>' || c == '\n' || c == ';')
return (1);
return (0);
}
static char *c_strdupi(char *s, int (*f)(char))
{
int i;
char *str;
i = 0;
while (s[i] && !(*f)(s[i]))
i++;
str = (char *)ft_malloc(sizeof(char) * (i + 1));
if (str)
{
str[i--] = '\0';
while (i >= 0)
{
str[i] = s[i];
i--;
}
}
return (str);
}
/*
** Seek the current word.
*/
static char *c_current_words(t_comp *c)
static char *c_current_words(void)
{
size_t pos;
char *str;
(void)c;
pos = data_singleton()->line.pos;
str = data_singleton()->line.input;
DG("pos = \"%zu\"", pos);
while (pos && str[pos] != ' ' && str[pos] != '<'
&& str[pos] != '>' && str[pos] != '\n' && str[pos] != ';')
if (pos && c_is_delim(str[pos]))
--pos;
if (str[pos] == ' ' || str[pos] == '<'
|| str[pos] == '>' || str[pos] == '\n' || str[pos] == ';')
while (pos && !c_is_delim(str[pos]))
--pos;
if (c_is_delim(str[pos]))
++pos;
DG("pos = \"%zu\"", pos);
return (str + pos);
return (c_strdupi(str + pos, &c_is_delim));
}
/*
@ -44,7 +70,7 @@ int c_matching(t_data *s, t_comp *c)
char *current_word;
DG("c->rcmd = \"%s\"", c->rcmd);
current_word = c_current_words(c);
current_word = c_current_words();
DG("current_word = \"%s\"", current_word);
if (ft_strchr(c->rcmd, '/'))
c_seek_abs_path(c, current_word);