Exemplo n.º 1
0
static void
putc_debug (void *p, char c)
{
	(void) p;

	if (c == '\n')
		default_putchar ('\r');

	default_putchar (c);
}
Exemplo n.º 2
0
static void print_guid(const uint8_t* data)
{
	print_hex(data +  0, 4);
	default_putchar('-');
	print_hex(data +  4, 2);
	default_putchar('-');
	print_hex(data +  6, 2);
	default_putchar('-');
	print_hex(data +  8, 2);
	default_putchar('-');
	print_hex(data + 10, 6);
}
Exemplo n.º 3
0
static void
putc_debug (void *p, char c)
{
	(void) p;

	default_putchar (c);
}
Exemplo n.º 4
0
static void print_hex(const uint8_t* data, uint16_t len)
{
	uint8_t d;

	while(len>0)
	{
		d = *data++;
		default_putchar(hex_char(d>>4));
		default_putchar(hex_char(d&0xF));
		len--;
	}
}
Exemplo n.º 5
0
static void
number (long num, unsigned int base, int size, int precision,
	int type)
{
  char c, sign;
  static char tmp[66];

  const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
  int i;

  if (type & LARGE)
    digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if (type & LEFT)
    type &= ~ZEROPAD;
  if (base < 2 || base > 36)
    return;
  c = (type & ZEROPAD) ? '0' : ' ';
  sign = 0;
  if (type & SIGN)
    {
      if (num < 0)
	{
	  sign = '-';
	  num = -num;
	  size--;
	}
      else if (type & PLUS)
	{
	  sign = '+';
	  size--;
	}
      else if (type & SPACE)
	{
	  sign = ' ';
	  size--;
	}
    }
  i = 0;
  if (num == 0)
    tmp[i++] = '0';
  else
    while (num != 0)
      tmp[i++] = digits[do_div (num, base)];
  if (i > precision)
    precision = i;
  size -= precision;
  if (!(type & (ZEROPAD + LEFT)))
    while (size-- > 0)
      default_putchar(' ');
  if (sign)
    default_putchar(sign);
  if (!(type & LEFT))
    while (size-- > 0)
      default_putchar(c);
  while (i < precision--)
    default_putchar('0');
  while (i-- > 0)
    default_putchar(tmp[i]);
  while (size-- > 0)
    default_putchar(' ');
}
Exemplo n.º 6
0
static void
tiny_vsprintf (const char *fmt, va_list args)
{
  int len;
  unsigned long num;
  int i, base;
  const char *s;

  int flags;			/* flags to number() */

  int field_width;		/* width of output field */
  int precision;		/* min. # of digits for integers; max
				   number of chars for from string */
  int qualifier;		/* 'h', 'l', or 'q' for integer fields */

  for (; *fmt; ++fmt)
    {
      if (*fmt != '%')
	{
	  if(*fmt=='\n')
	    default_putchar('\r');
	  default_putchar(*fmt);
	  continue;
	}

      /* process flags */
      flags = 0;
    repeat:
      ++fmt;			/* this also skips first '%' */
      switch (*fmt)
	{
	case '-':
	  flags |= LEFT;
	  goto repeat;
	case '+':
	  flags |= PLUS;
	  goto repeat;
	case ' ':
	  flags |= SPACE;
	  goto repeat;
	case '0':
	  flags |= ZEROPAD;
	  goto repeat;
	}

      /* get field width */
      field_width = -1;
      if (is_digit (*fmt))
	field_width = skip_atoi (&fmt);
      else if (*fmt == '*')
	{
	  ++fmt;
	  /* it's the next argument */
	  field_width = va_arg (args, int);
	  if (field_width < 0)
	    {
	      field_width = -field_width;
	      flags |= LEFT;
	    }
	}

      /* get the precision */
      precision = -1;
      if (*fmt == '.')
	{
	  ++fmt;
	  if (is_digit (*fmt))
	    precision = skip_atoi (&fmt);
	  else if (*fmt == '*')
	    {
	      ++fmt;
	      /* it's the next argument */
	      precision = va_arg (args, int);
	    }