Exemplo n.º 1
0
static void		ft_putstr_right_next(t_var *e, long value)
{
	if ((e->f_zero == 1 || e->f_precis != 1) && value < 0)
	{
		ft_putchar_ret('-', e);
		if (e->f_precis != 1 && e->f_precis >= e->t_size && value < 0)
		{
			ft_put_zero(e->f_precis - e->t_size + 1, e);
			e->u_exep = 1;
		}
		value *= -1;
	}
	if (e->f_zero == 1 && e->f_precis == 1 && e->f_space == 1)
		ft_put_zero(e->f_width - e->t_size - 1, e);
	else if (e->f_zero == 1 && e->f_precis == 1)
		ft_put_zero(e->f_width - e->t_size, e);
	else if (e->f_precis != 1 && e->f_precis > e->t_size && value >= 0 && \
			e->u_exep != 1)
		ft_put_zero(e->f_precis - e->t_size, e);
	if (e->f_positive == 0 && e->f_space == 1 && e->f_precis == 0)
		ft_putchar_ret(' ', e);
	if (value < 0)
		e->ret++;
	ft_putnbr(value);
}
Exemplo n.º 2
0
static void		ft_putstr_left(t_var *e, long value)
{
	if (value < 0)
		e->ret++;
	else if (e->f_positive == 1)
		ft_putchar_ret('+', e);
	else if (e->f_positive == 0 && e->f_space == 1)
		ft_putchar_ret(' ', e);
	if ((e->f_positive == 1 || e->f_space == 1) && e->f_precis != 1)
		e->f_precis++;
	if (value < 0 && e->f_precis != 1)
	{
		value *= -1;
		ft_putchar('-');
		e->f_precis++;
	}
	if (e->f_precis != 1 && e->f_width < e->f_precis)
		ft_put_zero(e->f_precis - e->t_size, e);
	else if (e->f_precis != 1 && e->f_width > e->f_precis)
		ft_put_zero(e->f_precis - e->t_size, e);
	ft_putnbr(value);
	if (e->f_left == 1 && e->f_width != 0 && e->f_width > e->t_size && \
			e->f_precis == 1)
		ft_put_space(e->f_width - e->t_size, e);
	else if (e->f_left == 1 && e->f_width != 0 && e->f_width > e->t_size\
			&& e->f_precis != 1)
		ft_put_space(e->f_width - e->f_precis, e);
}
Exemplo n.º 3
0
void	ft_putnbr_hexa(t_env *e, unsigned long long number, char spe)
{
	char				*base;
	char				*hex;
	int					i;

	if (number == 0)
	{
		ft_putchar_ret(e, '0');
		return ;
	}
	if (spe == 'x')
		base = HEXA;
	if (spe == 'X')
		base = HEXA_MAJ;
	i = ft_int_hex_len(number);
	hex = ft_strnew_ptf(i);
	while (number)
	{
		hex[--i] = base[number % 16];
		number = number / 16;
	}
	ft_putstr_ret(e, hex);
	free(hex);
}
Exemplo n.º 4
0
void	ft_putllunbr(t_env *e, unsigned long long int n)
{
	if (n < 10)
		ft_putchar_ret(e, n + '0');
	else if (n >= 10)
	{
		ft_putllunbr(e, n / 10);
		ft_putllunbr(e, n % 10);
	}
}
Exemplo n.º 5
0
void	type_other_char(char *fmt, t_var *e)
{
    if (fmt[e->i] == 'b')
        type_b(e);
    else
    {
        if (e->f_left == 0 && e->f_width != 0 && e->f_zero == 0)
            ft_put_space(e->f_width - 1, e);
        else if (e->f_left == 0 && e->f_width != 0 && e->f_zero == 1)
            ft_put_zero(e->f_width - 1, e);
        ft_putchar_ret(fmt[e->i], e);
        if (e->f_left == 1 && e->f_width != 0)
            ft_put_space(e->f_width - 1, e);
    }
}
Exemplo n.º 6
0
static void		ft_putstr_right(t_var *e, long value)
{
	if (e->f_zero == 1 && e->f_space == 1 && e->f_positive == 0 && value == 0)
		ft_put_space(1, e);
	else if ((e->f_zero == 0 && e->f_precis == 1) || (e->f_precis != 1 &&
					e->f_width > e->f_precis && e->f_precis < e->t_size))
		ft_put_space(e->f_width - e->t_size, e);
	else if (e->f_precis != 1 && e->f_width > e->f_precis && e->f_precis >\
			e->t_size)
		ft_put_space(e->f_width - e->f_precis - (value < 0 ? 1 : 0), e);
	else if (e->f_precis != 1 && e->f_width > e->f_precis && e->f_precis ==\
			e->t_size)
		ft_put_space(e->f_width - e->f_precis - 1, e);
	if (e->f_positive == 1)
		ft_putchar_ret('+', e);
	if (e->f_positive == 1 && e->f_precis != 1)
		e->f_precis++;
	ft_putstr_right_next(e, value);
}
Exemplo n.º 7
0
void	ft_putnbr_octal(t_env *e, unsigned long long number)
{
	char				*octal;
	int					i;

	if (number == 0)
	{
		ft_putchar_ret(e, '0');
		return ;
	}
	i = ft_int_octal_len(number);
	octal = ft_strnew_ptf(i);
	while (number)
	{
		octal[--i] = number % 8 + '0';
		number = number / 8;
	}
	ft_putstr_ret(e, octal);
	free(octal);
}