Example #1
0
int			read_tube(t_app *app, char *line)
{
	char			**tube;
	unsigned int	count;
	int				rt;

	if (ft_strcount(line, ' ') != 1)
	{
		app->read_mode = 5;
		return (-1);
	}
	count = ft_strcount(line, '-');
	if (count != 2 || line[0] == '#' || line[0] == 'L')
	{
		if (line[0] != '#' && line[0] != 'L')
			app->read_mode = 5;
		return (-1);
	}
	tube = ft_strsplit(line, '-');
	clean_spaces(tube[0]);
	clean_spaces(tube[1]);
	rt = (read_tube2(app, what_nbr(app, tube[0]), what_nbr(app, tube[1])));
	while (count--)
		free(tube[count]);
	free(tube);
	return (rt);
}
Example #2
0
void		read_case(t_app *app, char *line)
{
	static int		n = 0;
	unsigned int	rt;
	unsigned int	i;
	unsigned int	count;
	char			**array;

	i = 0;
	rt = 0;
	count = ft_strcount(line, ' ');
	if (read_other(app, line))
		;
	else if (count == 3)
	{
		array = ft_strsplit(line, ' ');
		rt = read_block(app, array, n);
		while (i < count)
			free(array[i++]);
		free(array);
		n += rt;
	}
	else
		app->read_mode = 3;
}
Example #3
0
char	*search_cmd(t_app *app)
{
	int				i;
	int				size;
	t_elem_env		*cmd;
	char			**tab;
	char			*rt;

	i = -1;
	cmd = get_env(app, "PATH");
	if (!cmd )
	{
		ft_putendl("Pas de PATH");
		return (0);
	}
	size = ft_strcount(cmd->content, ':');
	tab = ft_strsplit(cmd->content, ':');
	while (++i < size)
	{
		if ((rt = search_cmd2(app, tab[i])))
		{
			clean_tab(tab, size);
			return (rt);
		}
	}
	clean_tab(tab, size);
	ft_printf("minishell: command not found: %s\n",
			app->cur_cmd->first->command);
	return (0);
}
Example #4
0
static void	check_empty_arguments(int *argc, char **argv)
{
	int i;

	i = 0;
	while (argv[i])
	{
		if (ft_strcount(argv[i], ft_isprint) <= 0)
			*argc -= 1;
		++i;
	}
}
Example #5
0
char			*ft_strdupif(const char *s, int (*f)(int c))
{
	size_t		i;
	size_t		e;
	size_t		len;
	char		*scop;

	i = 0;
	e = 0;
	len = (ft_strcount(s, f) + 1);
	if ((scop = (char*)malloc(sizeof(char) * len)))
	{
		while (s[i] && i <= len)
		{
			if (f(s[i]))
				scop[e++] = s[i];
			++i;
		}
		scop[e] = '\0';
		return (scop);
	}
	return (NULL);
}