55 #ifdef CLIB_STANDALONE 56 #include <vppinfra/standalone_stdio.h> 109 l0 = i0 + fi->
width[0];
121 uword n_left = 0, n_right = 0;
134 n_right = n_left = n / 2;
191 uword is_first_digit = 1;
194 for (i = 0; i < 2; i++)
196 if (c ==
'0' && i == 0 && is_first_digit)
201 fi.
width[
i] = va_arg (*va,
int);
206 while (c >=
'0' && c <=
'9')
231 if (c ==
'l' && *f ==
'l')
247 .uppercase_digits = 0,
258 s =
format (s,
"**** CLIB unknown format `%%%c' ****", c);
286 if (c ==
'x' || c ==
'X')
294 number = va_arg (*va,
unsigned long long);
299 number = va_arg (*va,
long);
304 number = va_arg (*va,
word);
309 number = va_arg (*va,
int);
321 char *cstring = va_arg (*va,
char *);
329 else if (fi.
width[1] != 0)
332 len = strlen (cstring);
337 for (i = 0; i <
len; i++)
338 vec_add1 (s, cstring[i] ==
'_' ?
' ' : cstring[i]);
347 u8 *v = va_arg (*va,
u8 *);
350 if (fi.
width[1] != 0)
370 typedef u8 *(user_func_t) (
u8 * s, va_list * args);
371 user_func_t *u = va_arg (*va, user_func_t *);
378 s =
justify (s, &fi, s_initial_len);
389 const u8 *f = (
u8 *) fmt, *g;
417 return (
u8 *)
"liar liar pants on fire s can't be zero!";
432 return (
u8 *)
"liar liar pants on fire s can't be zero!";
448 ret = fwrite (s,
vec_len (s), 1, f);
497 ret = write (fd, s,
vec_len (s));
509 u8 digit_buffer[128];
510 u8 *d = digit_buffer +
sizeof (digit_buffer);
520 number &= ((
u64) 1 << options->
n_bits) - 1;
522 base = options->
base;
529 if (r < 10 + 26 + 26)
533 else if (r < 10 + 26)
536 c =
'A' + (r - 10 - 26);
539 && base <= 10 + 26 && c >=
'a' && c <=
'z')
555 vec_add (s, d, digit_buffer +
sizeof (digit_buffer) - d);
561 #define f64_down(f,sign,expon,fraction) \ 563 union { u64 u; f64 f; } _f64_down_tmp; \ 564 _f64_down_tmp.f = (f); \ 565 (sign) = (_f64_down_tmp.u >> 63); \ 566 (expon) = ((_f64_down_tmp.u >> 52) & 0x7ff) - 1023; \ 567 (fraction) = ((_f64_down_tmp.u << 12) >> 12) | ((u64) 1 << 52); \ 580 tmp.u = (
u64) ((sign) != 0) << 63;
587 tmp.u |= (
u64) expon << 52;
589 tmp.u |= fraction & (((
u64) 1 << 52) - 1);
598 static int n_bits = 0;
614 return f64_up (0, base2_expon - n_bits, 0);
623 static f64 t[8] = { 1e+0, 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, };
633 static f64 t[8] = { 1e-0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7, };
648 word expon2, expon10;
653 f64_down (x, sign, expon2, fraction);
657 expon2 * .301029995663981195213738894724493 ;
683 *expon_return = expon10;
706 word sign, expon, n_fraction_done, added_decimal_point;
711 if (n_fraction_digits == ~0)
712 n_fraction_digits = 7;
715 added_decimal_point = 0;
734 return format (s,
"%cNaN", sign ?
'-' :
'+');
738 return format (s,
"%cinfinity", sign ?
'-' :
'+');
743 if ((
word) - expon > (
word) n_fraction_digits
744 && (output_style ==
'f' || (output_style ==
'g')))
750 if (output_style ==
'f' 751 || (output_style ==
'g' && expon > -10 && expon < 10))
757 n_fraction_done =
clib_min (-(expon + 1), n_fraction_digits);
759 decimal_point = -n_fraction_done;
760 added_decimal_point = 1;
763 decimal_point = expon + 1;
789 if (decimal_point <= 0
790 && n_fraction_done + 1 == n_fraction_digits && digit < 9)
798 n_fraction_done += decimal_point < 0;
799 if (decimal_point <= 0 && n_fraction_done >= n_fraction_digits)
802 if (decimal_point == 0 && x != 0)
805 added_decimal_point = 1;
813 if (decimal_point > 0)
819 if (n_fraction_done < n_fraction_digits)
821 if (!added_decimal_point)
826 if (output_style ==
'e')
827 s =
format (s,
"e%wd", expon);
void os_puts(u8 *string, uword length, uword is_error)
Optimized string handling code, including c11-compliant "safe C library" variants.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
#define vec_insert(V, N, M)
Insert N vector elements starting at element M, initialize new elements to zero (no header...
#define vec_free(V)
Free vector's memory (no header).
static uword pointer_to_uword(const void *p)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".