Exemple #1
0
void		ft_create_builtin(t_term *term)
{
	char	*tmp;
	int		i;

	i = 0;
	tmp = NULL;
	if (ft_strcmp(term->cmds[0], "cd") == 0)
		ft_cd(term);
	else if (ft_strcmp(term->cmds[0], "env") == 0)
		(!term->cmds[1]) ? ft_display_env(term) : ft_env_options(term);
	else if (ft_strcmp(term->cmds[0], "setenv") == 0)
		ft_process_setenv(term, term->cmds[1], term->cmds[2]);
	else if (ft_strcmp(term->cmds[0], "unsetenv") == 0)
		ft_process_unsetenv(term, term->cmds[1]);
	else if (ft_strcmp(term->cmds[0], "exit") == 0)
	{
		reset_shell();
		ft_putendl("Exiting shell");
		if (term->cmds[1])
			i = ft_atoi(term->cmds[1]);
		ft_free_struct(term);
		exit(i);
	}
	term->i = 0;
	term->u = NULL;
}
Exemple #2
0
int		heredoc(t_group *grp, t_redir *curr)
{
	int		fd;

	TERM(other_read) = true;
	set_shell((~ICANON & ~ECHO));
	fd = open(TMP_FROM, O_WRONLY | O_APPEND | O_CREAT, 0644);
	while (grp->exit[1] == false)
	{
		TERM(cmd_line) = ft_strdup("");
		show_prompt(grp, "heredoc> ", 9, "\033[1;34m");
		read_cmd(grp, 0);
		if (ft_strcmp(TERM(cmd_line), curr->name) == 0)
			break ;
		ft_putendl_fd(TERM(cmd_line), fd);
		REMOVE(&TERM(cmd_line));
	}
	TERM(curs_pos) = 0;
	TERM(cmd_size) = 0;
	REMOVE(&TERM(cmd_line));
	TERM(other_read) = false;
	reset_shell();
	return (true);
}