Пример #1
0
static void		free_everything(char **cmds, t_state *state)
{
	ft_strtabdel(&cmds);
	ft_strtabdel(&state->redirection_to_free_in_fork);
	ft_strtabdel(&state->cmds_shell_entry_to_free_in_fork);
	ft_strdel(&state->new_line_shell_entry_to_free_in_fork);
	free_minishell(state);
}
Пример #2
0
int			ft_check_unlocated_cmd(t_sh *sh, char **args)
{
	int		i;
	char	*path;
	char	**pathlst;

	i = -1;
	path = ft_search_inallenv(sh, "PATH");
	pathlst = ft_strsplit(path, ':');
	while (path && pathlst[++i])
	{
		ft_strdel(&path);
		path = ft_strjoin_key(pathlst[i], args[0], "/");
		if (access(path, F_OK) != -1)
			break ;
	}
	if (!path || !pathlst[i])
		LAST_RET_VAL = ft_error2("command not found", args[0]);
	else if (access(path, X_OK) == -1)
		LAST_RET_VAL = ft_error2("permission denied", args[0]);
	else
		ft_fork_and_exec(sh, path, args);
	ft_strdel(&path);
	ft_strtabdel(&pathlst);
	return (LAST_RET_VAL);
}
Пример #3
0
int		ft_strtabrealloc(char ***strtab, int addsize)
{
	char	**newtab;

	newtab = ft_strtabcpy(*strtab, addsize);
	if (!newtab)
		return (-1);
	ft_strtabdel(strtab);
	*strtab = newtab;
	return (0);
}
Пример #4
0
void			handle_line(t_state *state, char *line)
{
	char	**cmds;
	int		redirection_count;

	redirection_count = ft_wordcountwith_redirection(line, "<|>&");
	if (redirection_count > 1)
	{
		if (!is_valid_cmd(state->pwd))
			print_no_such_file_or_dir(state, state->shell_name, state->pwd);
		else if (check_if_valid_entry(state, line))
			run_redirection(state, line);
	}
	else if (redirection_count == 1)
	{
		cmds = ft_strsplitwith_quote(line, " \t", 1);
		if (cmds && cmds[0])
			handle_cmds(state, line, cmds);
		ft_strtabdel(&cmds);
	}
}