"resolution des for"
This commit is contained in:
Antoine Riard 2017-03-22 15:54:16 +01:00
commit 78f764f151

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:49:09 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));
}
/*
@ -43,9 +69,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);
DG("current_word = \"%s\"", current_word);
current_word = c_current_words();
if (ft_strchr(c->rcmd, '/'))
c_seek_abs_path(c, current_word);
else if (ft_strchr(c->rcmd, '$'))
@ -54,6 +78,7 @@ int c_matching(t_data *s, t_comp *c)
c_seek_binary(s, c);
else
c_seek_files(s, c, current_word);
ft_strdel(&current_word);
if (s->comp && s->comp->lst)
{
c_sizing(c);