/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_f_fail.c                                        :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#include "ft_d_define.h"
#include "ft_s_struct.h"

static void
	ft_write_fail(const char concern[],
				const char msg[],
				t_msh *msh)
{
	ft_dprintf(STDERR_FILENO, "%s: %s: %s\n", msh->shname, concern, msg);
}

void
	ft_fail_no_options(const char concern[],
					t_msh *msh)
{
	ft_write_fail(concern, FT_FAIL_NO_OPTIONS, msh);
}

void
	ft_fail_identifier(const char concern[],
					const char identifier[],
					t_msh *msh)
{
	ft_dprintf(STDERR_FILENO, "%s: %s: `%s': not a valid identifier\n",
		msh->shname, concern, identifier);
}

void
	ft_fail_too_many_args(const char concern[],
						t_msh *msh)
{
	ft_write_fail(concern, FT_FAIL_TOO_MANY_ARGS, msh);
}

void
	ft_fail_alloc(t_msh *msh)
{
	ft_dprintf(STDERR_FILENO, "%s: %s\n", msh->shname, strerror(errno));
	exit(FT_RET_ALLOC);
}