Esempio n. 1
0
std::basic_ostream<C, T>& print_max_width(std::basic_ostream<C, T>& o, double d, int width = 6) {
#if 1
  return print_width(o, d, width);
#else
  typedef std::basic_ostream<C, T> stream_t;
  local_stream_format<stream_t> save(o);
  if (width > 0) {
    double p = std::fabs(d);
    if (d < 0) --width;
    int wholes = (int)std::log10(p);  // 1: log=0, digits=1
    int need = 1 + (wholes < 0 ? -wholes : wholes);
    if (need > width) {
      int unit_e_exp = 1 + 1 + 2;
      if (width >= unit_e_exp) o << std::scientific << std::setprecision(width - unit_e_exp);
    } else {
      o << std::fixed;
      int need_dot = need + 1;
      if (need_dot < width)
        o << std::setprecision(width - need_dot);
      else
        o << std::setprecision(0);
    }
  }
  return o << d;
#endif
}
Esempio n. 2
0
static int	zero_handling(t_env *env, int size, int s_tmp, int tmp)
{
	if (env->zero == 1)
		size += print_width(env->width->value - size - 1, env);
	else
	{
		if (env->sharp == 1 && env->precision->value <= s_tmp && tmp != 0)
		{
			size++;
			size += print_width(env->width->value - size - 1, env);
			ft_putchar('0');
		}
		else
		{
			if (env->precision->value > s_tmp)
				size += print_width(env->width->value - size + s_tmp - 1, env);
			else
				size += print_width(env->width->value - size - 1, env);
		}
	}
	return (size);
}
Esempio n. 3
0
int		ft_printf_pe(va_list args, t_env *env)
{
	int		size;

	size = 0;
	(void)args;
	if (env->minus == 1)
		size += ft_putchar('%');
	size += print_width(env->width->value - 1, env);
	if (env->minus == 0)
		size += ft_putchar('%');
	return (size);
}
Esempio n. 4
0
int			ft_printf_o(va_list args, t_env *env)
{
	int				size;
	unsigned int	tmp;
	int				size_tmp;

	size = 0;
	tmp = va_arg(args, int);
	get_size_octal(tmp, &size);
	size_tmp = size + 1;
	if (env->minus == 1)
	{
		if (env->sharp == 1 && env->precision->value <= size_tmp && tmp != 0)
			size += ft_putchar('0');
		size += print_precision_o(tmp, size_tmp, env);
		size += print_width(env->width->value - size - 1, env);
	}
	else
	{
		size = zero_handling(env, size, size_tmp, tmp);
		size += print_precision_o(tmp, size_tmp, env);
	}
	return (size + 1);
}
int						print_hexadecimal_up_int(t_flags *flags, va_list ap)
{
	unsigned int		c_copy;
	unsigned int		c;
	char				*str;
	int					len;

	len = 0;
	c = va_arg(ap, unsigned int);
	hex_up_arg_to_str_unsigned(&str, c);
	c_copy = c;
	print_precision(flags, &str);
	flag_hash_hexadecimal_up(flags, &str, c);
	print_width(flags, &str);
	flag_minus(flags, &str);
	if (c_copy > 0)
		flag_space(flags, &str);
	flag_null(flags, &str);
	check_null_end(flags, &str, c_copy);
	len = ft_strlen(str);
	ft_putstr(str);
	ft_strdel(&str);
	return (len);
}
Esempio n. 6
0
static int
pre_it(DECL_ARGS)
{
	const struct roff_node *bln;

	switch (n->type) {
	case ROFFT_HEAD:
		outflags |= MMAN_PP | MMAN_nl;
		bln = n->parent->parent;
		if (0 == bln->norm->Bl.comp ||
		    (NULL == n->parent->prev &&
		     NULL == bln->parent->prev))
			outflags |= MMAN_sp;
		outflags &= ~MMAN_br;
		switch (bln->norm->Bl.type) {
		case LIST_item:
			return 0;
		case LIST_inset:
		case LIST_diag:
		case LIST_ohang:
			if (bln->norm->Bl.type == LIST_diag)
				print_line(".B \"", 0);
			else
				print_line(".BR \\& \"", 0);
			outflags &= ~MMAN_spc;
			return 1;
		case LIST_bullet:
		case LIST_dash:
		case LIST_hyphen:
			print_width(&bln->norm->Bl, NULL);
			TPremain = 0;
			outflags |= MMAN_nl;
			font_push('B');
			if (LIST_bullet == bln->norm->Bl.type)
				print_word("\\(bu");
			else
				print_word("-");
			font_pop();
			outflags |= MMAN_nl;
			return 0;
		case LIST_enum:
			print_width(&bln->norm->Bl, NULL);
			TPremain = 0;
			outflags |= MMAN_nl;
			print_count(&bln->norm->Bl.count);
			outflags |= MMAN_nl;
			return 0;
		case LIST_hang:
			print_width(&bln->norm->Bl, n->child);
			TPremain = 0;
			outflags |= MMAN_nl;
			return 1;
		case LIST_tag:
			print_width(&bln->norm->Bl, n->child);
			putchar('\n');
			outflags &= ~MMAN_spc;
			return 1;
		default:
			return 1;
		}
	default:
		break;
	}
	return 1;
}
Esempio n. 7
0
void print(O& o, double d, width const& w) {
  print_width(o, d, w.chars);
}
Esempio n. 8
0
std::basic_ostream<C, T>& print(std::basic_ostream<C, T>& o, double d, int width) {
  print_width(o, d, width);
  return o;
}
Esempio n. 9
0
static int
pre_it(DECL_ARGS)
{
	const struct mdoc_node *bln;

	switch (n->type) {
	case MDOC_HEAD:
		outflags |= MMAN_PP | MMAN_nl;
		bln = n->parent->parent;
		if (0 == bln->norm->Bl.comp ||
		    (NULL == n->parent->prev &&
		     NULL == bln->parent->prev))
			outflags |= MMAN_sp;
		outflags &= ~MMAN_br;
		switch (bln->norm->Bl.type) {
		case LIST_item:
			return(0);
		case LIST_inset:
			/* FALLTHROUGH */
		case LIST_diag:
			/* FALLTHROUGH */
		case LIST_ohang:
			if (bln->norm->Bl.type == LIST_diag)
				print_line(".B \"", 0);
			else
				print_line(".R \"", 0);
			outflags &= ~MMAN_spc;
			return(1);
		case LIST_bullet:
			/* FALLTHROUGH */
		case LIST_dash:
			/* FALLTHROUGH */
		case LIST_hyphen:
			print_width(bln->norm->Bl.width, NULL, 0);
			TPremain = 0;
			outflags |= MMAN_nl;
			font_push('B');
			if (LIST_bullet == bln->norm->Bl.type)
				print_word("o");
			else
				print_word("-");
			font_pop();
			outflags |= MMAN_nl;
			return(0);
		case LIST_enum:
			print_width(bln->norm->Bl.width, NULL, 0);
			TPremain = 0;
			outflags |= MMAN_nl;
			print_count(&bln->norm->Bl.count);
			outflags |= MMAN_nl;
			return(0);
		case LIST_hang:
			print_width(bln->norm->Bl.width, n->child, 6);
			TPremain = 0;
			outflags |= MMAN_nl;
			return(1);
		case LIST_tag:
			print_width(bln->norm->Bl.width, n->child, 0);
			putchar('\n');
			outflags &= ~MMAN_spc;
			return(1);
		default:
			return(1);
		}
	default:
		break;
	}
	return(1);
}