Exemplo n.º 1
0
void					print_hex(va_list *valist, t_spec_flags *opts, char c)
{
	uintmax_t	hex;
	char		*str;
	int			len;
	int			prefix;

	prefix = (c == 'p' || opts->sharp);
	if (c == 'p')
		hex = va_arg(*valist, size_t);
	else
		hex = printf_uintcast(valist, opts);
	str = ft_hextoa(hex, c == 'X');
	len = MAX(opts->precision, (int)ft_strlen(str));
	if (!opts->minus)
		ft_putnchar(opts->width - len - (prefix ? 2 : 0), \
				opts->zero ? '0' : ' ');
	if (prefix && (hex != 0 || c == 'p'))
		ft_putstr(c == 'X' ? "0X" : "0x");
	ft_putnchar(opts->precision - ft_strlen(str), '0');
	if (!opts->precision_set || (hex != 0 && opts->precision > 0))
		ft_putstr(str);
	if (opts->minus)
		ft_putnchar(opts->width - len - (prefix ? 2 : 0), ' ');
}
Exemplo n.º 2
0
void					print_int(va_list *valist, t_spec_flags *opts)
{
	char		*str;
	intmax_t	nbr;
	int			len;

	nbr = printf_intcast(valist, opts);
	str = ft_lltoa(nbr);
	len = MAX((int)ft_strlen(nbr < 0 ? str + 1 : str), \
			opts->precision) + (opts->space || opts->plus);
	if (!opts->minus)
		ft_putnchar(opts->width - len, opts->zero ? '0' : ' ');
	if (nbr < 0)
		ft_putchar('-');
	if (opts->plus && *str != '-')
		ft_putchar('+');
	else if (opts->space && *str != '-')
		ft_putchar(' ');
	ft_putnchar(opts->precision - ft_strlen(nbr < 0 ? str + 1 : str), '0');
	if (nbr != 0 || !opts->precision_set || opts->precision > 0)
		ft_putstr(nbr < 0 ? str + 1 : str);
	if (opts->minus)
		ft_putnchar(opts->width - len, ' ');
	free(str);
}
Exemplo n.º 3
0
int	ft_before_octal(int size, t_elem list, uintmax_t l, int i)
{
	int result;

	result = 0;
	if ((result = ft_width_before_octal(size, list, l, i)) > 0)
		i = result;
	else if (list.width && list.point == 0 && list.width > size && !list.minus)
	{
		if (list.zero && !list.minus)
			i += ft_putnchar('0', list.width - (list.sharp ? 0 : list.zero) -
				size - list.size + (list.zero && !l ? 1 : 0)
				- (list.sharp && l ? 1 : 0));
		else if (list.sharp && l && !list.zero)
			i += ft_putnchar(' ', list.width - size - list.size
				- (list.sharp && l ? 1 : 0) - 1);
		else
			i += ft_putnchar(' ', list.width - size - list.size
				- (list.sharp && l ? 1 : 0));
	}
	if (list.width && list.size == 1 && list.point > size)
		i += ft_putchar('-');
	if (list.zero > 0 && list.point == 0 && list.width > size
		&& list.plus == 0 && !list.minus && l)
		i += ft_putchar('0');
	return (i);
}
Exemplo n.º 4
0
static void		print_nlists_32(char *ptr, struct nlist **t_el,
								char *st, int nsyms)
{
	int		i;
	char	c;

	i = 0;
	while (i < nsyms)
	{
		c = get_symbol(ptr, t_el[i], FT_NM_CPU_32);
		if (c == 'A'
			|| (c != 'u' && c != 'c' && *(st + t_el[i]->n_un.n_strx)
				&& *(st + t_el[i]->n_un.n_strx) != '/'
				&& (!t_el[i]->n_value
					|| (i == nsyms - 1)
					|| ((t_el[i]->n_value != t_el[i + 1]->n_value)
					|| ft_strcmp(st + t_el[i]->n_un.n_strx,
								st + t_el[i + 1]->n_un.n_strx)))))
		{
			if (c != 'U' && c != 'I')
				ft_putnbr_base(t_el[i]->n_value, FT_NM_BASE, FT_NM_ADDR_LEN_32);
			else
				ft_putnchar(' ', FT_NM_ADDR_LEN_32);
			format_print(t_el[i], st, c);
		}
		++i;
	}
}
Exemplo n.º 5
0
int	ft_printf(char *str, ...)
{
	int			i;
	t_param		*param;
	t_str_conv	*sub;
	t_str_conv	*firstsub;
	va_list		ap;

	i = 0;
	va_start(ap, str);
	param = ft_param_builder();
	sub = ft_strsplit_to_conv(str, param, ap);
	firstsub = sub;
	while (sub)
	{
		if (sub->error)
			return (ft_param_cleaner(&param, &firstsub));
		if (sub->str_out)
			ft_putnchar(sub->str_out, sub->size);
		i = i + sub->size;
		sub = sub->next;
	}
	ft_param_cleaner(&param, &firstsub);
	va_end(ap);
	return (i);
}
Exemplo n.º 6
0
void					print_octal(va_list *valist, t_spec_flags *opts)
{
	uintmax_t	octal;
	int			octlen;

	octal = printf_uintcast(valist, opts);
	octlen = MAX((int)opts->precision, ft_octlen(octal) + opts->sharp);
	if (!opts->minus)
		ft_putnchar(opts->width - octlen, opts->zero ? '0' : ' ');
	ft_putnchar(opts->precision - ft_octlen(octal) - opts->sharp, '0');
	if (opts->sharp && octal != 0)
		ft_putchar('0');
	if (!opts->precision_set || octal != 0)
		ft_putoctal(octal);
	if (opts->minus)
		ft_putnchar(opts->width - octlen, ' ');
}
Exemplo n.º 7
0
// int	ft_aff_unsigned_long_next(char *finder, t_elem list, intmax_t i)
// {
// 	int k;
// 	int size;
//
// 	k = 0;
// 	size = ((finder[0] == 'o') || (finder[0] == 'O')) ? ft_lenbr_base_max(i, 8) : 0;
// 	if ((finder[0] == 'd') || (finder[0] == 'i'))
// 	{
// 		if ((list.width && list.minus == 0) || (list.point && list.minus == 0))
// 			k += ft_handlewidth_digit(list, (long long)i, finder);
// 		if (list.plus > 0 && i >= 0)
// 			k += ft_putchar('+');
// 		k += i == LLONG_MIN ? ft_putstr("-9223372036854775808")
// 		: ft_putnbr_base(i, 10, 0);
// 		if ((list.width > 0 && finder[0] == 'D' && list.width >
// 		ft_lenbr_max((unsigned long)i) && list.minus != 0) || (list.width > 0
// 			&& list.width > ft_lenbr((int)i) && list.minus != 0))
// 			k += ft_handlewidth_digit(list, (long long)i, finder);
// 		return (k);
// 	}
// 	else if ((finder[0] == 'o') || (finder[0] == 'O'))
// 		{
// 			if ((k = ft_before_octal(size, list, i, k)))
// 				(void)k;
// 			if (list.point && list.point > size)
// 				k += ft_putnchar('0', list.point - size -
// 				(list.pointzero && list.sharp ? 1 : 0));
// 		}
// 	return (k);
// }
//
// int	ft_aff_unsigned_long(char *finder, va_list op, t_elem list)
// {
// 	intmax_t	i;
// 	int			k;
// 	int size;
//
// 	size = ((finder[0] == 'o') || (finder[0] == 'O')) ? ft_lenbr_base_max(i, 8) : 0;
// 	k = 0;
// 	i = va_arg(op, intmax_t);
// 	if (finder[0] == 'z')
// 		finder++;
// 	if ((k = ft_aff_unsigned_long_next(finder, list, i)))
// 		(void)k;
// 	else if ((finder[0] == 'o') || (finder[0] == 'O'))
// 	{
// 		k += ft_putnbr_base_max((unsigned long)i, 8, 0);
// 		if ((k += ft_after_octal(size, list, i, k)))
// 			(void)k;
// 	}
// 	else if (finder[0] == 'x')
// 		return (ft_putnbr_base_max((unsigned long)i, 16, 0));
// 	else if (finder[0] == 'X')
// 		return (ft_putnbr_base_maj_max((unsigned long)i, 16, 0));
// 	else
// 		return (ft_putnbr_base_max((unsigned long)i, 10, 0));
// 	return (ft_lenbr_max((uintmax_t)i));
// }
//
int	ft_aff_percent(char *finder, va_list op, t_elem list)
{
	int i;

	(void)finder;
	(void)op;
	i = 0;
	if (list.width && !list.minus && !list.point && !list.zero)
		i += ft_putnchar(' ', list.width - 1);
	else if ((list.width && !list.minus && list.point) ||
	(list.zero && list.width))
		i += ft_putnchar('0', list.width - 1);
	i += ft_putchar('%');
	if (list.width && list.minus)
		i += ft_putnchar(' ', list.width - 1);
	return (i);
}
Exemplo n.º 8
0
void	ft_putspace(int s, char *str)
{
	int len;

	len = (s - ft_strlen(str)) + 1;
	ft_putnchar(' ', len);
	ft_putstr(str);
}
Exemplo n.º 9
0
void					print_uint(va_list *valist, t_spec_flags *opts)
{
	char		*str;
	uintmax_t	nbr;
	int			len;

	nbr = printf_uintcast(valist, opts);
	str = ft_ulltoa(nbr);
	len = MAX((int)ft_strlen(str), opts->precision);
	if (!opts->minus)
		ft_putnchar(opts->width - len, opts->zero ? '0' : ' ');
	ft_putnchar(opts->precision - ft_strlen(str), '0');
	if (nbr != 0 || !opts->precision_set || opts->precision > 0)
		ft_putstr(str);
	if (opts->minus)
		ft_putnchar(opts->width - len, ' ');
	free(str);
}
Exemplo n.º 10
0
int	ft_handlespace_int(t_elem list, char *finder, long long numb, int i)
{
	long long size;

	size = ft_getsize(finder, numb);
	if ((list.width && list.width > list.point && list.width >= size &&
		list.point) || (list.width && list.width > list.point && list.width
			> size && list.minus && ((list.pointzero) || (list.zero))))
	{
		if (list.point < size && !numb)
			i = ft_putnchar(' ', list.width - list.minus - list.plus);
		else if (list.point < size)
			i = ft_putnchar(' ', list.width - size - list.whitespace -
			list.size - ((list.plus && (((int)numb >= 0) ||
			(finder[-1] == 'z'))) ? list.plus : 0));
		else if ((i = ft_put_spaces(list, finder, numb, i)))
			return (i);
	}
	return (i);
}
Exemplo n.º 11
0
int		check_p(char c, t_args **arg, va_list ap)
{
	int				len;
	unsigned long	val;
	int				prec;

	len = 0;
	if (c == 'p')
	{
		val = (unsigned long)va_arg(ap, void*);
		prec = ((*arg)->precision >= 0) ? (*arg)->precision : (*arg)->field - \
			ft_nbrlen_base(val, 16, -1) - 2 + (val == 0);
		len += ft_putnchar(' ', (!(*arg)->justify && !(*arg)->zero) ? \
				(*arg)->field - ft_nbrlen_base(val, 16, -1) - 2 : 0);
		len += ft_putstr("0x");
		len += ft_putnbr_base(val, 16, ((*arg)->zero || \
					(*arg)->precision >= 0) ? prec : -1, 0);
		len += ft_putnchar(' ', ((*arg)->justify) ? (*arg)->field -\
				ft_nbrlen_base(val, 16, -1) - 2 : 0);
	}
Exemplo n.º 12
0
char	ft_print_w(unsigned char *f, unsigned int e, wchar_t c)
{
	if (e < 0x07FF)
	{
		init_wchar(f, c, 2);
		ft_putnchar(f, 2);
		return (2);
	}
	else if (e < 0xFFFF)
	{
		init_wchar(f, c, 3);
		ft_putnchar(f, 3);
		return (3);
	}
	else
	{
		init_wchar(f, c, 4);
		ft_putnchar(f, 4);
		return (4);
	}
}
Exemplo n.º 13
0
int		ft_putncharl(char c, size_t n)
{
	int		ret;
	int		sum;

	if ((ret = ft_putnchar(c, n)) < 0)
		return (ret);
	sum = ret;
	if ((ret = ft_putchar('\n')) < 0)
		return (ret);
	return (sum + ret);
}
Exemplo n.º 14
0
int	ft_after_octal(int size, t_elem list, uintmax_t l, int i)
{
	if (list.width && list.width > list.point &&
		list.width > size && list.point && list.minus)
	{
		if (list.point < size && !l)
			i += ft_putnchar(' ', list.width);
		else if (list.point < size)
			i += ft_putnchar(' ', list.width - size -
			(list.pointzero || list.zero || list.sharp ? 1 : 0));
		else if (list.point != size)
			i += ft_putnchar(' ', list.width - list.point - list.size);
		else
			i += ft_putnchar(' ', list.width - list.zero
				- list.point + size - list.size);
	}
	else if (list.width && list.point == 0 && list.width > size && list.minus)
	{
		if (list.zero && !list.minus)
			i += ft_putnchar('0', list.width - list.zero
				- size - list.size + list.minus);
		else
			i += ft_putnchar(' ', list.width - size - list.size
				- (list.sharp && l && list.point >= 0 ? 1 : 0));
	}
	return (i);
}
Exemplo n.º 15
0
int	ft_aff_pointer(char *finder, va_list op, t_elem list)
{
	void	*ptr;
	int		i;

	i = 0;
	(void)finder;
	ptr = va_arg(op, void *);
	if (list.width > 3 && list.minus == 0
	&& list.width > ft_lenbr_base((long long)ptr, 16) + 2)
		i = ft_putnchar(' ', list.width
			- ft_lenbr_base((long long)ptr, 16) - 2);
	i += ft_putstr("0x");
	if (ptr != 0)
		i += ft_putnbr_base((long long)ptr, 16, 0);
	else if (!list.point && !list.sharp)
		i += ft_putchar('0');
	if (list.width > 3 && list.minus != 0
	&& list.width > ft_lenbr_base((long long)ptr, 16) + 2)
		i += ft_putnchar(' ', list.width
			- ft_lenbr_base((long long)ptr, 16) - 2);
	return (i);
}
Exemplo n.º 16
0
int	ft_width_before_octal(int size, t_elem list, uintmax_t l, int i)
{
	if ((list.point && list.width > list.point && list.width >= size
		&& !list.minus && !list.sharp) || (!list.zero && list.width
		&& list.width > list.point && list.width > size && ((list.pointzero)
		|| (!list.pointzero && list.width > size + 1)) && ((!list.minus)
		|| (list.minus && list.width < size + 1)) && ((!list.sharp) ||
		(list.sharp && size + 1 < list.width))))
	{
		if (list.point < size && !l)
			i += ft_putnchar(' ', list.width);
		else if (list.point < size)
			i += ft_putnchar(' ', list.width - size -
			(list.pointzero || list.zero || list.sharp ? 1 : 0));
		else if (list.point != size)
			i += ft_putnchar(' ', list.width - list.point - list.size);
		else
			i += ft_putnchar(' ', list.width - list.zero
				- list.point - (list.point - size) - list.size - list.sharp);
	}
	i = ft_prefix_before_octal(size, list, l, i);
	return (i);
}
Exemplo n.º 17
0
int	ft_putunbr_base(unsigned long long n, int base, int prec, int maj)
{
	const char	basestr[17] = "0123456789abcdef";
	const char	basestrmaj[17] = "0123456789ABCDEF";
	int			wr;

	wr = 0;
	if (n == 0 && prec == 0)
		return (0);
	if (prec > 0)
	{
		wr += ft_putnchar('0', prec - ft_nbrlen_base(n, base, 0));
	}
	if ((n / base) > 0)
		wr += ft_putunbr_base(n / base, base, 0, maj);
	ft_putchar((maj) ? basestrmaj[(n % base)] : basestr[(n % base)]);
	return (++wr);
}
Exemplo n.º 18
0
int	ft_handlewidth_digit(t_elem list, long long numb, char *finder)
{
	int				i;
	long long		size;

	size = ft_getsize(finder, numb);
	i = 0;
	i = ft_handlezero_int(list, finder, numb, i);
	if (list.plus > 0 && list.zero == 0 && list.point != 0
		&& !list.minus && (int)numb >= 0)
		i += ft_putchar('+');
	if (list.width && list.size == 1 && list.point && !list.minus && finder[-1] != 'z')
		i += ft_putchar('-');
	if (list.zero > 0 && list.point == 0 && list.width > size && list.plus == 0
		&& !list.minus && !list.whitespace && !numb)
		i += ft_putchar('0');
	if (list.point && list.point > size && !list.minus)
		i += ft_putnchar('0', list.point - size);
	return (i);
}
Exemplo n.º 19
0
int	ft_aff_octal(char *finder, va_list op, t_elem list)
{
	uintmax_t	l;
	int			i;
	int			result;
	int			size;

	result = 0;
	i = 0;
	l = va_arg(op, uintmax_t);
	size = ft_lenbr_base_max(l, 8);
	if ((result = ft_before_octal(size, list, l, i)) > i)
		i = result;
	if (list.point && list.point > size)
		i += ft_putnchar('0', list.point - size -
		(list.pointzero && list.sharp ? 1 : 0));
	if ((result = ft_disp_octal(finder, list, l, i)) > i)
		i = result;
	if ((result = ft_after_octal(size, list, l, i)) > i)
		i = result;
	return (i);
}
Exemplo n.º 20
0
int	ft_handlezero_int(t_elem list, char *finder, long long numb, int i)
{
	long long size;

	size = ft_lenbr((unsigned long)numb);
	// size = ft_getsize(finder, numb);
	// printf("|%d|%d|\n", list.point, size);
	// if ((list.pointzero && list.point > size))
	// ft_greenstr("FEWREWREW");
	if ((i = ft_handlespace_int(list, finder, numb, i)) != 0)
		(void)i;
	else if (list.width && ((list.point == 0) || (list.pointzero)) && ((list.width > size) || (list.pointzero && list.point > size && (int)numb < 0)))
	{
		  // ft_greenstr("TWEt");
		if (((list.zero) || (list.pointzero)) && !list.minus && !list.plus && (int)numb < 0)
		{
			if (list.pointzero && (int)numb < 0)
				i = ft_putnchar('0', list.point - size + 1);
			else
			i = ft_putnchar('0', list.width - (!numb ? list.zero : 0) -
				list.whitespace - size - list.size);
			}
		else if (list.zero && list.plus && !list.size
			&& !list.minus)
			i = ft_putnchar('0', list.width - (!numb ? list.zero : 0) -
				list.zero - list.whitespace - size - list.size);
		else if (list.zero && list.plus && list.size && numb > 0)
			i = ft_putnchar('0', list.width -
				list.zero - list.whitespace - size + list.minus);
		else if (numb && finder[0] == 'D')
			i = ft_putnchar(' ', list.width - size - list.size
			- (list.size ? 0 : list.plus));
		else if (numb)
			i = ft_putnchar(' ', list.width - size - list.size
			- (list.size || (int)numb < 0 ? 0 : list.plus));
	}
	return (i);
}