/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   utils.c                                            :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: mea <marvin@42.fr>                         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/05/03 08:57:53 by narnaud           #+#    #+#             */
/*   Updated: 2022/05/06 13:15:33 by narnaud          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "minishell.h"

int	is_empty(char *line)
{
	while (*line)
	{
		if (*line < 9 || (*line > 13 && *line != 32))
			return (0);
		line++;
	}
	return (1);
}

void	handle_status(t_datas *datas, int status)
{
	if (WIFSIGNALED(status))
	{
		datas->exit_code = 128 + WTERMSIG(status);
		if (datas->exit_code == 131)
			printf("Quit: 3\n");
	}
	else
		datas->exit_code = WEXITSTATUS(status);
}

void	nothing(int sig_num)
{
	(void)sig_num;
}

void	sigs_handler(int sig_num)
{
	if (sig_num == SIGINT)
		printf("\n");
	rl_on_new_line();
	rl_replace_line("", 0);
	rl_redisplay();
	return ;
}

void	halt(int ret_code)
{
	printf("exit\n");
	exit(ret_code);
}