Esempio n. 1
0
int		print_xp(char c, int len, unsigned long long arg, t_flags *fl)
{
	int		nb;

	nb = 0;
	if (fl->prec < len && (fl->minus || arg != 0))
		fl->prec = len;
	if (c == 'p' && fl->larg && arg == 0)
		fl->prec = len;
	if (fl->prec == -1)
		nb += print_char(fl->larg + fl->prec, ' ');
	else if (fl->larg > fl->prec && !fl->minus && !fl->zero)
		nb += print_char(fl->larg - fl->prec, ' ');
	if (fl->dieze && c == 'X' && arg != 0)
		nb += write(1, "0X", 2);
	else if ((arg != 0 && fl->dieze && c == 'x') || c == 'p')
		nb += write(1, "0x", 2);
	if (fl->zero)
		nb += print_char(fl->larg - fl->prec, '0');
	nb += print_char(fl->prec - len, '0');
	if ((c == 'x' || c == 'p') && (arg != 0 || fl->prec))
		nb += ft_putstri(ft_itoa_base(arg, "0123456789abcdef"));
	else if (c == 'X' && (arg != 0 || fl->dieze || fl->prec))
		nb += ft_putstri(ft_itoa_base(arg, "0123456789ABCDEF"));
	if (fl->minus)
		nb += print_char(fl->larg - fl->prec, ' ');
	return (nb);
}
Esempio n. 2
0
static char	*ft_add_di(t_flags *flags, long long arg, char *str, int lg)
{
	if (flags->modifier == 'z')
		str = ft_itoa_base(arg, 10);
	else if (lg == 0)
		str = ft_itoa(arg);
	else
		str = ft_itoa_base(arg, 10);
	if (str && *str && *str == '-')
		flags->plus = '-';
	return (str);
}
Esempio n. 3
0
int		ft_unload_hex3(t_print *gl, char *str, unsigned long long int x, char t)
{
	if (x == 0)
	{
		ft_putstr(gl->s);
		while (gl->p-- != 0)
		{
			ft_putchar('0');
			gl->larg--;
			gl->i++;
			if (gl->p < 0)
				break ;
		}
		while (gl->larg-- > 0 && gl->i++ < 2147483647)
			ft_putchar(' ');
		return (gl->i + ft_strlen(gl->s));
	}
	if (!ft_isupper(t))
		str = ft_itoa_base(x, 16);
	else
		str = ft_itoa_base_maj(x, 16);
	gl->space = ft_strlen(str);
	ft_putstr(gl->s);
	return (unload_hex(gl, str, x, t));
}
Esempio n. 4
0
char		*render_opts_numeric_signed(t_opts *opts, va_list *pa)
{
	intmax_t		n;
	char			*s;

	if (!ft_strcmp(opts->modify, "l") || opts->type == 'D')
		n = (long)va_arg(*pa, intmax_t);
	else if (!ft_strcmp(opts->modify, "hh"))
		n = (char)(va_arg(*pa, intmax_t));
	else if (!ft_strcmp(opts->modify, "h"))
		n = (short)va_arg(*pa, intmax_t);
	else if (!ft_strcmp(opts->modify, "ll"))
		n = (long long)va_arg(*pa, intmax_t);
	else if (!ft_strcmp(opts->modify, "z"))
		n = (size_t)(va_arg(*pa, intmax_t));
	else if (!ft_strcmp(opts->modify, "j"))
		n = (intmax_t)(va_arg(*pa, intmax_t));
	else
		n = (int)(va_arg(*pa, intmax_t));
	s = ft_itoa_base(n, 10);
	s = applyprecision(opts, s);
	s = applyflag(opts, s);
	s = applywidth(opts, s);
	return (s);
}
Esempio n. 5
0
void		pf_o(t_dt *data)
{
	t_av	av;
	int		len;

	av.ui = get_modifier(data);
	av.s = ft_itoa_base(av.ui, 8);
	av.len = ft_strlen(av.s) + data->flag.hash;
	len = (data->flag.precision > av.len) ? data->flag.precision : av.len;
	print_zero_space(data, &av);
	if (*data->tail == 'o')
	{
		if (data->flag.hash || !data->flag.point || av.ui)
			write_str(data, av.s, av.len - data->flag.hash);
	}
	else if (!data->flag.point || *(data->flag.point + 1) != '0')
		write_str(data, av.s, av.len - data->flag.hash);
	if (data->flag.minus)
	{
		while (data->flag.min_width > len && data->flag.min_width--)
			write_char(data, ' ');
	}
	if (av.s)
		free(av.s);
}
Esempio n. 6
0
char		*ft_itoa_base(int value, int base)
{
	char	*s;
	char	*c;
	int		l;
	int		v;

	if (base == 0)
		return (NULL);
	if (value < 0)
		return (s = ft_strjoin("-\0", ft_itoa_base(-value, base)));
	while ((v = value) != 0)
	{
		v /= base;
		l == (int)NULL ? l = 1 : ++l;
	}
	if (!(s = (char*)malloc(sizeof(char) * l + 1)))
		return (NULL);
	s[l--] = '\0';
	c = "0123456789ABCDEF\0";
	while (value != 0)
	{
		s[l] = c[value % base];
		value /= base;
		--l;
	}
	return (s);
}
Esempio n. 7
0
int		ft_unload_oct(t_print *gl, char *str, unsigned long long int o)
{
	str = ft_itoa_base(o, 8);
	gl->space = ft_strlen(str);
	ft_putstr(gl->s);
	if (gl->p < 0)
	{
		while (gl->larg > (gl->space + gl->hash) && gl->i < 2147483647)
		{
			ft_putchar(gl->c);
			gl->larg--;
			gl->i++;
		}
		if (gl->hash == 1 && o != 0)
		{
			ft_putchar('0');
			gl->space++;
		}
		ft_putstr(str);
		free(str);
	}
	if (gl->p >= 0)
		ft_unload_oct2(gl, str, o);
	return (gl->space + gl->i + ft_strlen(gl->s));
}
Esempio n. 8
0
int		ft_unload_oct3(t_print *gl, char *str, unsigned long long int o)
{
	str = ft_itoa_base(o, 8);
	gl->space = ft_strlen(str);
	ft_putstr(gl->s);
	if (gl->hash == 1 && o != 0)
	{
		gl->hash = 0;
		ft_putchar('0');
		gl->space++;
	}
	while (gl->p > gl->space)
	{
		ft_putchar('0');
		gl->space++;
	}
	ft_putstr(str);
	free(str);
	while (gl->larg-- > gl->space && gl->i < 2147483647)
	{
		ft_putchar(' ');
		gl->i++;
	}
	return (gl->space + gl->i + ft_strlen(gl->s));
}
Esempio n. 9
0
size_t				ptr_conv(va_list *ap, int *i, t_opt *data)
{
	uint64_t		*address;
	char			*str;
	size_t			nbr;

	str = NULL;
	address = va_arg(*ap, void *);
	if (address == 0 && data->flags[1] == 0)
	{
		str = ft_strnew(1);
		str[0] = '0';
	}
	else
		str = ft_itoa_base((uint64_t)address, 16);
	str = apply_prec(data, str);
	str = ft_strjoin2("0x", str);
	str = apply_uoptions(data, str);
	str = apply_minsize(data, str);
	ft_putstr(str);
	*i = *i + 1;
	nbr = ft_strlen(str);
	ft_strdel(&str);
	return (nbr);
}
Esempio n. 10
0
int				ft_printf_o2(unsigned long nb, t_flags f)
{
	int					len;
	char				*print;
	int					tmp_len;

	len = 0;
	tmp_len = 0;
	print = ft_itoa_base(nb, 8);
	if (f.hashtag == 1 && nb > 0 && f.precision < (int)ft_strlen(print))
		tmp_len += 1;
	if ((int)ft_strlen(print) < f.precision && f.precision >= 0)
		tmp_len += f.precision;
	else
		tmp_len += ft_strlen(print);
	if (tmp_len >= (int)f.len_field)
		len += print_number(print, f, nb);
	else if (f.minus == 1)
		len = minus(len, print, f, nb);
	else
	{
		while (len < (int)f.len_field - tmp_len)
			len += ft_putchar(' ');
		len += print_number(print, f, nb);
	}
	free(print);
	return (len);
}
Esempio n. 11
0
int		ft_unload_hex(t_print *gl, char *str, unsigned long long int x, char t)
{
	if (!ft_isupper(t))
		str = ft_itoa_base(x, 16);
	else
		str = ft_itoa_base_maj(x, 16);
	gl->space = ft_strlen(str);
	ft_putstr(gl->s);
	if (gl->p < 0)
	{
		if (gl->hash == 2 && gl->c == '0')
		{
			gl->hash = 0;
			ft_putchar('0');
			gl->space++;
			if (!ft_isupper(t))
				ft_putchar('x');
			else
				ft_putchar('X');
			gl->space++;
		}
		unload_hex3(gl, str, x, t);
	}
	if (gl->p >= 0)
		ft_unload_hex2(gl, str, x, t);
	return (gl->space + gl->i + ft_strlen(gl->s));
}
Esempio n. 12
0
char	*get_unicode(int c)
{
	char	*bin;
	char	*code;
	int		i;
	int		j;

	bin = ft_itoa_base(c, "01");
	if (c < 128)
		code = ft_strdup("0xxxxxx");
	else if (c < 2048)
		code = ft_strdup("110xxxxx10xxxxxx");
	else if (c < 131072)
		code = ft_strdup("1110xxxx10xxxxxx10xxxxxx");
	else
		code = ft_strdup("11110xxx10xxxxxx10xxxxxx10xxxxxx");
	i = ft_strlen(code);
	j = ft_strlen(bin) - 1;
	while (--i > 0)
		if (code[i] == 'x')
		{
			if (j >= 0)
				code[i] = bin[j--];
			else
				code[i] = '0';
		}
	return (code);
}
Esempio n. 13
0
int					convert_unsigned(va_list *ap, t_data *data, int *i, char c)
{
	uintmax_t	arg;
	char		*str;
	int			ret;

	(*i)++;
	arg = get_unsigned_arg(ap, data->length);
	if (data->precision == -42 && !arg)
		return (convert_unsigned_0(data, c));
	str = ft_itoa_base(arg, c);
	if (data->sharp && data->zero && data->width - 2 >
		(int)ft_strlen(str) && !data->precision)
		str = apply_precision(str, data->width - 2 - ft_strlen(str));
	if (data->precision > (int)ft_strlen(str))
		str = apply_precision(str, data->precision - ft_strlen(str));
	if (data->sharp && arg)
		str = convert_unsigned_helper(str, c);
	if (data->width > (int)ft_strlen(str))
		str = apply_width(str, data, data->width - ft_strlen(str));
	if (c == 'X')
		ft_strmaj(str);
	ft_putstr(str);
	ret = ft_strlen(str);
	ft_strdel(&str);
	return (ret);
}
Esempio n. 14
0
int				ft_printf_x(va_list ap, t_flags f)
{
	t_len				lenf;
	unsigned long long	nb;
	char				*print;

	lenf.len = 0;
	lenf.tmp_len = 0;
	nb = unsigned_check(ap, f);
	print = ft_itoa_base(nb, 16);
	if (f.hashtag == 1)
		lenf.tmp_len += 2;
	if ((int)ft_strlen(print) < f.precision)
		lenf.tmp_len += f.precision;
	else
		lenf.tmp_len += ft_strlen(print);
	if (lenf.tmp_len >= (int)f.len_field)
		lenf.len += print_number(print, f, nb, f.precision);
	else if (f.minus == 1)
		lenf.len = minus(f, lenf.len, nb, print);
	else
	{
		while (lenf.len < (int)f.len_field - lenf.tmp_len && f.zero != 1)
			lenf.len += ft_putchar(' ');
		lenf.len += print_number(print, f, nb, (int)f.len_field - lenf.tmp_len);
	}
	return (free_ret(print, lenf.len));
}
Esempio n. 15
0
void				treat_ushort(t_prf *env, char **result)
{
	unsigned short	to_format;

	to_format = va_arg(env->args, unsigned int);
	*result = ft_itoa_base(to_format, env->cur_specs->base);
}
Esempio n. 16
0
void	history_exit(t_data *data)
{
	char		*path;
	int			fd;
	t_history	*history;

	if (get_history_path(data, &path) == 1)
		return ;
	fd = open(path, O_RDWR | O_CREAT | O_APPEND, 0600);
	free(path);
	if (fd == -1 || (history = data->history) == NULL)
		return ;
	while (history->prec && history->prec->get_from_file == 0)
		history = history->prec;
	if (history->get_from_file == 1)
		return ;
	while (history)
	{
		path = ft_itoa_base(history->time, 10);
		path = ft_strjoinaf1(path, ";");
		path = ft_strjoinaf1(path, history->line);
		path = ft_strjoinaf1(path, "\n");
		write(fd, path, ft_strlen(path));
		free(path);
		history = history->next;
	}
	close(fd);
}
Esempio n. 17
0
void				treat_ptr(t_prf *env, char **result)
{
	unsigned long int	to_format;

	to_format = va_arg(env->args, unsigned long int);
	*result = ft_itoa_base(to_format, env->cur_specs->base);
	*result = ft_strjoinf("0x", *result, 2);
}
Esempio n. 18
0
void	ft_putaddr(const void *addr)
{
	char	*str;

	ft_putstr("0x");
	str = ft_itoa_base((uintptr_t)addr, 16);
	ft_putstr(str);
	ft_strdel(&str);
}
Esempio n. 19
0
char	*ft_itoa_base(unsigned long long n, char *base)
{
	char				*s;
	unsigned long long	i;

	i = ft_strlen(base);
	s = (char *)malloc(sizeof(char) * 2);
	if (!s)
		return (NULL);
	if (n >= i)
		s = ft_strjoin(ft_itoa_base(n / i, base), ft_itoa_base(n % i, base));
	else if (n < i)
	{
		s[0] = base[n];
		s[1] = '\0';
	}
	return (s);
}
Esempio n. 20
0
int			conversion_u_up(int *i, va_list params, int nb_char)
{
	unsigned long	nb;
	char			*unb;

	nb = va_arg(params, unsigned long);
	unb = ft_itoa_base(nb, 10);
	ft_putstr(unb);
	nb_char += ft_strlen(unb);
	(*i)++;
	return (nb_char);
}
Esempio n. 21
0
char	*ft_convert_base(char *nbr, char *base_from, char *base_to)
{
	int	nbr_dec;
	int	bf;
	int	bt;

	if (valid_base(base_from, &bf) == 0 || valid_base(base_to, &bt) == 0)
		return (0);
	if (ft_atodec(nbr, base_from, bf, &nbr_dec) == 0)
		return (0);
	return(ft_itoa_base(nbr_dec, bt, base_to));
}
Esempio n. 22
0
int				ft_putwchar(wchar_t c, int count)
{
    char	**final;

    FT_INIT(char *, bin_value, ft_strnew(33));
    FT_INIT(int, i, 0);
    FT_INIT(int, octet, 0);
    bin_value = ft_itoa_base((int)c, 2);
    if (ft_strlen(bin_value) <= 7)
        return (ftp_putchar((char)c));
    else if (ft_strlen(bin_value) <= 11)
        final = set_mask(bin_value, MASK_2);
    else if (ft_strlen(bin_value) > 11 && ft_strlen(bin_value) <= 16)
Esempio n. 23
0
static char	*ft_set_arg_o(t_printf **ges)
{
	unsigned int	arg;
	unsigned short	arg2;
	unsigned char	arg3;

	arg = 0;
	arg2 = 0;
	arg3 = 0;
	if ((*ges)->modif == 1)
	{
		arg3 = va_arg((*ges)->ap, unsigned int);
		return (ft_itoa_base(arg3, 8));
	}
Esempio n. 24
0
static void					ft_putstr_left(t_var *e, unsigned long value)
{
	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_itoa_base(value, 2, 1);
	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);
}
Esempio n. 25
0
int		couting(wchar_t n)
{
	int i;

	i = ft_strlen(ft_itoa_base(n, 2));
	if (i <= 7)
		return (1);
	if (i > 7 && i <= 11)
		return (2);
	if (i > 11 && i <= 16)
		return (3);
	if (i > 16 && i <= 21)
		return (4);
	return (0);
}
Esempio n. 26
0
int		main(int ac, char **av)
{
	int		n;
	int		b;

	if (ac > 1)
		n = atoi(av[1]);
	else
		n = -2147483648;
	if (ac > 2)
		b = atoi(av[2]);
	else
		b = 10;
	printf("Le nombre %i en base %i : %s\n", n, b, ft_itoa_base(n, b));
	return (0);
}
Esempio n. 27
0
static void					ft_putstr_right(t_var *e, unsigned long value)
{
	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->t_size - 2, 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_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)
		ft_put_zero(e->f_precis - e->t_size, e);
	ft_itoa_base(value, 2, 1);
}
Esempio n. 28
0
char		*ft_mask(wint_t c)
{
	char	*mask;
	char	*bin;

	mask = NULL;
	if (c <= 127)
		mask = ft_strdup("0xxxxxxx");
	else if (c <= 2047)
		mask = ft_strdup("110xxxxx10xxxxxx");
	else
		mask = ft_strdup("1110xxxx10xxxxxx10xxxxxx");
	bin = ft_itoa_base(c, 2);
	if (!mask || !bin)
		return (NULL);
	ft_set_mask(mask, bin);
	free(bin);
	return (mask);
}
Esempio n. 29
0
int		print_u(int len, unsigned long long arg, t_flags *fl)
{
	int		nb;

	nb = 0;
	if (fl->prec < len && (arg != 0 || fl->minus))
		fl->prec = len;
	if (fl->prec == -1)
		nb += print_char(fl->larg + fl->prec, ' ');
	else if (fl->larg > fl->prec && !fl->minus && !fl->zero)
		nb += print_char(fl->larg - fl->prec, ' ');
	if (fl->zero)
		nb += print_char(fl->larg - len, '0');
	nb += print_char(fl->prec - len, '0');
	if (arg != 0 || fl->prec || fl->minus)
		nb += ft_putstri(ft_itoa_base(arg, "0123456789"));
	if (fl->minus)
		nb += print_char(fl->larg - fl->prec, ' ');
	return (nb);
}
Esempio n. 30
0
int		handle_coding_byte(int cursor, t_vm *vm, int op)
{
	int		i;
	char	*coding_byte;

	cursor += 1;
	coding_byte = ft_itoa_base(vm->memory[ft_loop_memory(cursor)], 2, 0);
	if (ft_strlen(coding_byte) < 8)
		coding_byte = ft_strjoin("0", coding_byte);
	i = 0;
	while (i < 6)
	{
		if (get_argument_type(coding_byte + i) == T_REG)
			cursor += 1;
		if (get_argument_type(coding_byte + i) == T_IND)
			cursor += 2;
		if (get_argument_type(coding_byte + i) == T_DIR)
			cursor += get_label_size(op);
		i = i + 2;
	}
	return (cursor);
}