Esempio n. 1
0
t_env	get_dir(t_env *env, char **line)
{
	struct dirent	*pdirent;
	DIR				*pdir;
	char			*linel;
	char			**line2;
	int				i;

	linel = get_path(env);
	ft_strcpy(linel, ft_strfcut(linel, 5));
	line2 = ft_strsplit(linel, ':');
	i = -1;
	while (line2[++i] != NULL && ft_strcpy(line2[i], ft_strcat(line2[i], "/")))
	{
		pdir = opendir(line2[i]);
		while (pdir != NULL && (pdirent = readdir(pdir)) != NULL)
			if (ft_strcmp(pdirent->d_name, line[0]) == 0)
			{
				env->path = (char *)malloc(sizeof(char *) \
						* ft_strlen(line2[i]) + 1);
				ft_strcpy(env->path, line2[i]);
				return (*env);
			}
	}
	ft_putstr(line[0]);
	ft_putstr(": command not found.\n");
	return (*env);
}
Esempio n. 2
0
int		ft_isbuiltin(t_env *env, char *line)
{
	char	**line2;
	int		i;
	t_main w;

	i = 0;
	line2 = ft_strsplit(line, ' ');
	if (ft_strcmp(line2[0], "echo") == 0 && (i = 1))
	{
		line = ft_strfcut(line, 5);
		ft_echo(line);
	}
	else if (ft_strncmp(line, "cd", 2) == 0 && (i = 1))
		ft_cd(line);
	else if (ft_strncmp(line, "unsetenv", 7) == 0 && (i = 1))
		env = ft_unsetenv(env);
	else if (ft_strncmp(line, "env", 2) == 0 && (i = 1))
		print_env(env);
	else if (ft_strncmp(line, "setenv", 5) == 0 && (i = 1))
	{
		line = ft_strrw(line);
		line2 = ft_strsplit(line, ' ');
		env = set_env(line2, env);
	}
	if (i == 1)
		ft_doublecoms(env, &w, 0);
	return (1);
}
Esempio n. 3
0
int		ft_builtin(t_env *env, char *line)
{
	int		i;
	char	**line2;

	i = 0;
	line2 = NULL;
	line2 = ft_strsplit(line, ' ');
	line2[0] = ft_strtrim(line2[0]);
	if (ft_strcmp(line2[0], "echo") == 0 && (i = 1))
	{
		line = ft_strfcut(line, 5);
		ft_echo(env, line);
	}
	else if (ft_strncmp(line, "cd", 2) == 0 && (i = 1))
		ft_cd(line, env);
	else if (ft_strcmp(line, "clear") == 0 && (i = 1))
		tputs(tgetstr("cl", NULL), 1, ft_ft_putchar);
	else if (ft_strncmp(line, "unsetenv", 7) == 0 && (i = 1))
	{
		line2 = ft_strsplit(line, ' ');
		env = ft_unsetenv(env, line2[1]);
	}
	else if (i == 0)
		i = ft_builtin2(env, line);
	return (i);
}