Lines Matching +full:count +full:- +full:width
2 * Copyright (c) 1997-2010, 2012-2015 Wind River Systems, Inc.
5 * SPDX-License-Identifier: Apache-2.0
113 #define WCHAR_IS_SIGNED ((WCHAR_MIN - 0) != 0)
196 /** Left-justify value in width */
202 /** Space for non-negative sign */
211 /** Width field present */
214 /** Width value from int argument
226 * prec_value is set to the value of a non-negative argument.
254 /** Set for floating point values that have a non-zero
263 /** Width value from specification.
279 * For example for zero-padded hexadecimal integers
313 * unconsumed character. There must be at least one non-digit character in
324 val = 10U * val + *sp++ - '0'; in extract_decimal()
346 case '-': in extract_flags()
347 conv->flag_dash = true; in extract_flags()
350 conv->flag_plus = true; in extract_flags()
353 conv->flag_space = true; in extract_flags()
356 conv->flag_hash = true; in extract_flags()
359 conv->flag_zero = true; in extract_flags()
370 if (conv->flag_zero && conv->flag_dash) { in extract_flags()
371 conv->flag_zero = false; in extract_flags()
379 /** Extract a C99 conversion specification width.
386 * @return a pointer the first character that follows the width.
391 conv->width_present = true; in extract_width()
394 conv->width_star = true; in extract_width()
399 size_t width = extract_decimal(&sp); in extract_width() local
402 conv->width_present = true; in extract_width()
403 conv->width_value = width; in extract_width()
404 conv->unsupported |= ((conv->width_value < 0) in extract_width()
405 || (width != (size_t)conv->width_value)); in extract_width()
415 * @param sp pointer to the first character after the width element of a
423 conv->prec_present = (*sp == '.'); in extract_prec()
425 if (!conv->prec_present) { in extract_prec()
431 conv->prec_star = true; in extract_prec()
437 conv->prec_value = prec; in extract_prec()
438 conv->unsupported |= ((conv->prec_value < 0) in extract_prec()
439 || (prec != (size_t)conv->prec_value)); in extract_prec()
459 conv->length_mod = LENGTH_HH; in extract_length()
462 conv->length_mod = LENGTH_H; in extract_length()
467 conv->length_mod = LENGTH_LL; in extract_length()
470 conv->length_mod = LENGTH_L; in extract_length()
474 conv->length_mod = LENGTH_J; in extract_length()
478 conv->length_mod = LENGTH_Z; in extract_length()
482 conv->length_mod = LENGTH_T; in extract_length()
486 conv->length_mod = LENGTH_UPPER_L; in extract_length()
492 conv->unsupported = true; in extract_length()
495 conv->length_mod = LENGTH_NONE; in extract_length()
518 conv->specifier = *sp; in extract_specifier()
521 switch (conv->specifier) { in extract_specifier()
523 conv->specifier_cat = SPECIFIER_SINT; in extract_specifier()
526 conv->specifier_cat = SPECIFIER_UINT; in extract_specifier()
529 if (conv->length_mod == LENGTH_UPPER_L) { in extract_specifier()
530 conv->invalid = true; in extract_specifier()
536 if (conv->specifier == 'c') { in extract_specifier()
537 unsupported = (conv->length_mod != LENGTH_NONE); in extract_specifier()
542 switch (conv->length_mod) { in extract_specifier()
571 conv->specifier_cat = SPECIFIER_FP; in extract_specifier()
580 conv->specifier_a = (conv->specifier == 'a') in extract_specifier()
581 || (conv->specifier == 'A'); in extract_specifier()
582 if (conv->specifier_a in extract_specifier()
591 if (conv->length_mod == LENGTH_L) { in extract_specifier()
592 conv->length_mod = LENGTH_NONE; in extract_specifier()
593 } else if ((conv->length_mod != LENGTH_NONE) in extract_specifier()
594 && (conv->length_mod != LENGTH_UPPER_L)) { in extract_specifier()
595 conv->invalid = true; in extract_specifier()
604 conv->specifier_cat = SPECIFIER_PTR; in extract_specifier()
606 if (conv->length_mod == LENGTH_UPPER_L) { in extract_specifier()
613 conv->specifier_cat = SPECIFIER_PTR; in extract_specifier()
620 if (conv->length_mod != LENGTH_NONE) { in extract_specifier()
626 conv->invalid = true; in extract_specifier()
630 conv->unsupported |= unsupported; in extract_specifier()
652 * fast-exit. in extract_conversion()
656 conv->specifier = *sp; in extract_conversion()
674 /* The compiler can optimize this on its own on 64-bit architectures */ in _ldiv5()
681 * Tiny integer divide-by-five routine. The full 64 bit division
691 * This produces a 128-bit result, but we drop the bottom 64 bits which
694 * most 32-bit architectures means only a register drop.
699 * the multiplier in a single 32-bit register given its pattern.
752 --*digit_count; in _get_digit()
755 *fr &= (BIT64(60) - 1U); in _get_digit()
795 bool upcase = isupper((int)conv->specifier) != 0; in encode_uint()
796 const unsigned int radix = conversion_radix(conv->specifier); in encode_uint()
797 char *bp = bps + (bpe - bps); in encode_uint()
802 --bp; in encode_uint()
804 : upcase ? ('A' + lsv - 10) : ('a' + lsv - 10); in encode_uint()
809 * from the radix without re-checking specifier. in encode_uint()
811 if (conv->flag_hash) { in encode_uint()
813 conv->altform_0 = true; in encode_uint()
815 conv->altform_0c = true; in encode_uint()
824 /* Number of bits in the fractional part of an IEEE 754-2008 double
829 /* Number of hex "digits" in the fractional part of an IEEE 754-2008
834 /* Number of bits in the exponent of an IEEE 754-2008 double precision
839 /* Mask for the sign (negative) bit of an IEEE 754-2008 double precision
844 /* Mask for the high-bit of a uint64_t representation of a fractional
849 /* Convert the IEEE 754-2008 double to text format.
851 * @param value the 64-bit floating point value.
885 /* Prepend the sign: '-' if negative, flags control in encode_float()
886 * non-negative behavior. in encode_float()
889 *sign = '-'; in encode_float()
890 } else if (conv->flag_plus) { in encode_float()
892 } else if (conv->flag_space) { in encode_float()
898 /* Extract the non-negative offset exponent and fraction. Record in encode_float()
901 char c = conv->specifier; in encode_float()
906 /* Exponent of all-ones signals infinity or NaN, which are in encode_float()
936 /* No zero-padding with text values */ in encode_float()
937 conv->flag_zero = false; in encode_float()
951 || conv->specifier_a)) { in encode_float()
957 * non-fractional value. Subnormals require increasing the in encode_float()
960 expo -= 1023; in encode_float()
972 * range, zero-pruning enabled. in encode_float()
977 if (!(conv->specifier_a && conv->prec_present)) { in encode_float()
981 conv->pad0_pre_exp = precision - FRACTION_HEX; in encode_float()
982 conv->pad_fp = true; in encode_float()
986 size_t pos = 4 * (FRACTION_HEX - precision) - 1; in encode_float()
1000 bool require_dp = ((fract != 0) || conv->flag_hash); in encode_float()
1014 char *sp = bps + (spe - bps); in encode_float()
1023 while ((spe - sp) < FRACTION_HEX) { in encode_float()
1024 --sp; in encode_float()
1033 --precision; in encode_float()
1037 while (*--buf == '0') { in encode_float()
1051 *buf = '-'; in encode_float()
1053 expo = -expo; in encode_float()
1069 /* Remainder of code operates on a 64-bit fraction, so shift up (and in encode_float()
1076 /* Non-zero values need normalization. */ in encode_float()
1083 expo--; in encode_float()
1087 * and set the implicit 1 bit in the (shifted) 53-bit in encode_float()
1090 expo -= (1023 - 1); /* +1 since .1 vs 1. */ in encode_float()
1100 * 0 and -2 as the magnitude of a fractional decimal digit is 3 bits. in encode_float()
1104 while (expo < -2) { in encode_float()
1117 decexp--; in encode_float()
1128 expo--; in encode_float()
1134 expo--; in encode_float()
1143 fract >>= (4 - expo); in encode_float()
1147 * representation and correct the precision and zero-pruning in encode_float()
1150 if ((decexp < (-4 + 1)) || (decexp > precision)) { in encode_float()
1151 c += 'e' - 'g'; /* e or E */ in encode_float()
1153 precision--; in encode_float()
1157 precision -= decexp; in encode_float()
1159 if (!conv->flag_hash && (precision > 0)) { in encode_float()
1182 while (decimals-- != 0) { in encode_float()
1198 decexp--; in encode_float()
1201 conv->pad0_value = decexp; in encode_float()
1212 if (conv->flag_hash || (precision > 0)) { in encode_float()
1218 conv->pad0_value = -decexp; in encode_float()
1219 if (conv->pad0_value > precision) { in encode_float()
1220 conv->pad0_value = precision; in encode_float()
1223 precision -= conv->pad0_value; in encode_float()
1224 conv->pad_postdp = (conv->pad0_value > 0); in encode_float()
1228 * this is significant so reduce the base-10 exponent. in encode_float()
1232 decexp--; in encode_float()
1238 if (conv->flag_hash || (precision > 0)) { in encode_float()
1247 precision--; in encode_float()
1250 conv->pad0_pre_exp = precision; in encode_float()
1253 conv->pad0_pre_exp = 0; in encode_float()
1255 --buf; in encode_float()
1267 decexp = -decexp; in encode_float()
1268 *buf = '-'; in encode_float()
1288 conv->pad_fp = (conv->pad0_value > 0) in encode_float()
1289 || (conv->pad0_pre_exp > 0); in encode_float()
1292 * store EOS as a non-digit/non-decimal value so we don't have to in encode_float()
1300 /* Store a count into the pointer provided in a %n specifier.
1303 * the count will be stored.
1305 * @param dp where the count should be stored.
1307 * @param count the count to be stored.
1311 int count) in store_count() argument
1313 switch ((enum length_mod_enum)conv->length_mod) { in store_count()
1315 *(int *)dp = count; in store_count()
1318 *(signed char *)dp = (signed char)count; in store_count()
1321 *(short *)dp = (short)count; in store_count()
1324 *(long *)dp = (long)count; in store_count()
1327 *(long long *)dp = (long long)count; in store_count()
1330 *(intmax_t *)dp = (intmax_t)count; in store_count()
1333 *(size_t *)dp = (size_t)count; in store_count()
1336 *(ptrdiff_t *)dp = (ptrdiff_t)count; in store_count()
1353 size_t count = 0; in outs() local
1363 ++count; in outs()
1366 return (int)count; in outs()
1373 size_t count = 0; in z_cbvprintf_impl() local
1381 * updating count. in z_cbvprintf_impl()
1383 * NB: c is evaluated exactly once: side-effects are OK in z_cbvprintf_impl()
1391 ++count; \ in z_cbvprintf_impl()
1404 count += rc; \ in z_cbvprintf_impl()
1428 int width = -1; in z_cbvprintf_impl() local
1429 int precision = -1; in z_cbvprintf_impl()
1436 if (conv->specifier_cat != SPECIFIER_INVALID) { in z_cbvprintf_impl()
1446 /* If dynamic width is specified, process it, in z_cbvprintf_impl()
1447 * otherwise set width if present. in z_cbvprintf_impl()
1449 if (conv->width_star) { in z_cbvprintf_impl()
1450 width = va_arg(ap, int); in z_cbvprintf_impl()
1452 if (width < 0) { in z_cbvprintf_impl()
1453 conv->flag_dash = true; in z_cbvprintf_impl()
1454 width = -width; in z_cbvprintf_impl()
1456 } else if (conv->width_present) { in z_cbvprintf_impl()
1457 width = conv->width_value; in z_cbvprintf_impl()
1466 if (conv->prec_star) { in z_cbvprintf_impl()
1470 conv->prec_present = false; in z_cbvprintf_impl()
1474 } else if (conv->prec_present) { in z_cbvprintf_impl()
1475 precision = conv->prec_value; in z_cbvprintf_impl()
1480 /* Reuse width and precision memory in conv for value in z_cbvprintf_impl()
1483 conv->pad0_value = 0; in z_cbvprintf_impl()
1484 conv->pad0_pre_exp = 0; in z_cbvprintf_impl()
1488 && (conv->specifier_cat == SPECIFIER_FP) in z_cbvprintf_impl()
1489 && !conv->prec_present) { in z_cbvprintf_impl()
1490 if (conv->specifier_a) { in z_cbvprintf_impl()
1504 = (enum specifier_cat_enum)conv->specifier_cat; in z_cbvprintf_impl()
1506 = (enum length_mod_enum)conv->length_mod; in z_cbvprintf_impl()
1519 value->sint = va_arg(ap, int); in z_cbvprintf_impl()
1523 && (conv->specifier == 'c')) { in z_cbvprintf_impl()
1524 value->sint = (wchar_t)va_arg(ap, in z_cbvprintf_impl()
1527 value->sint = va_arg(ap, long); in z_cbvprintf_impl()
1531 value->sint = in z_cbvprintf_impl()
1535 value->sint = in z_cbvprintf_impl()
1547 value->sint = in z_cbvprintf_impl()
1552 value->sint = (signed char)value->sint; in z_cbvprintf_impl()
1554 value->sint = (short)value->sint; in z_cbvprintf_impl()
1562 value->uint = va_arg(ap, unsigned int); in z_cbvprintf_impl()
1566 && (conv->specifier == 'c')) { in z_cbvprintf_impl()
1567 value->uint = (wchar_t)va_arg(ap, in z_cbvprintf_impl()
1570 value->uint = va_arg(ap, unsigned long); in z_cbvprintf_impl()
1574 value->uint = in z_cbvprintf_impl()
1579 value->uint = in z_cbvprintf_impl()
1585 value->uint = in z_cbvprintf_impl()
1590 value->uint = (unsigned char)value->uint; in z_cbvprintf_impl()
1592 value->uint = (unsigned short)value->uint; in z_cbvprintf_impl()
1596 value->ldbl = va_arg(ap, long double); in z_cbvprintf_impl()
1598 value->dbl = va_arg(ap, double); in z_cbvprintf_impl()
1601 value->ptr = va_arg(ap, void *); in z_cbvprintf_impl()
1609 if (conv->invalid || conv->unsupported) { in z_cbvprintf_impl()
1617 switch (conv->specifier) { in z_cbvprintf_impl()
1622 bps = (const char *)value->ptr; in z_cbvprintf_impl()
1633 precision = -1; in z_cbvprintf_impl()
1638 /* Implementation-defined: null is "(nil)", non-null in z_cbvprintf_impl()
1642 if (value->ptr != NULL) { in z_cbvprintf_impl()
1643 bps = encode_uint((uintptr_t)value->ptr, conv, in z_cbvprintf_impl()
1647 conv->altform_0c = true; in z_cbvprintf_impl()
1648 conv->specifier = 'x'; in z_cbvprintf_impl()
1659 buf[0] = CHAR_IS_SIGNED ? value->sint : value->uint; in z_cbvprintf_impl()
1664 if (conv->flag_plus) { in z_cbvprintf_impl()
1666 } else if (conv->flag_space) { in z_cbvprintf_impl()
1674 sint = value->sint; in z_cbvprintf_impl()
1676 sign = '-'; in z_cbvprintf_impl()
1677 value->uint = (uint_value_type)-sint; in z_cbvprintf_impl()
1679 value->uint = (uint_value_type)sint; in z_cbvprintf_impl()
1687 bps = encode_uint(value->uint, conv, buf, bpe); in z_cbvprintf_impl()
1691 * length. Note that a non-empty sign is not in the in z_cbvprintf_impl()
1696 size_t len = bpe - bps; in z_cbvprintf_impl()
1698 /* Zero-padding flag is ignored for integer in z_cbvprintf_impl()
1701 conv->flag_zero = false; in z_cbvprintf_impl()
1705 conv->pad0_value = precision - (int)len; in z_cbvprintf_impl()
1712 store_count(conv, value->ptr, count); in z_cbvprintf_impl()
1719 bps = encode_float(value->dbl, conv, precision, in z_cbvprintf_impl()
1743 * * any sign character (sint-only) in z_cbvprintf_impl()
1746 * * any pre-decimal content from the converted value in z_cbvprintf_impl()
1750 * * any pre-exponent content from the converted value in z_cbvprintf_impl()
1753 * * for non-FP: in z_cbvprintf_impl()
1757 size_t nj_len = (bpe - bps); in z_cbvprintf_impl()
1764 if (conv->altform_0c) { in z_cbvprintf_impl()
1766 } else if (conv->altform_0) { in z_cbvprintf_impl()
1770 nj_len += conv->pad0_value; in z_cbvprintf_impl()
1771 if (conv->pad_fp) { in z_cbvprintf_impl()
1772 nj_len += conv->pad0_pre_exp; in z_cbvprintf_impl()
1775 /* If we have a width update width to hold the padding we need in z_cbvprintf_impl()
1779 * If a non-negative padding width is present and we're doing in z_cbvprintf_impl()
1780 * right-justification, emit the padding now. in z_cbvprintf_impl()
1782 if (width > 0) { in z_cbvprintf_impl()
1783 width -= (int)nj_len; in z_cbvprintf_impl()
1785 if (!conv->flag_dash) { in z_cbvprintf_impl()
1788 /* If we're zero-padding we have to emit the in z_cbvprintf_impl()
1791 if (conv->flag_zero) { in z_cbvprintf_impl()
1799 while (width-- > 0) { in z_cbvprintf_impl()
1812 if (IS_ENABLED(CONFIG_CBPRINTF_FP_SUPPORT) && conv->pad_fp) { in z_cbvprintf_impl()
1815 if (conv->specifier_a) { in z_cbvprintf_impl()
1827 pad_len = conv->pad0_value; in z_cbvprintf_impl()
1828 if (!conv->pad_postdp) { in z_cbvprintf_impl()
1829 while (pad_len-- > 0) { in z_cbvprintf_impl()
1838 * post-dp. in z_cbvprintf_impl()
1840 while (pad_len-- > 0) { in z_cbvprintf_impl()
1850 pad_len = conv->pad0_pre_exp; in z_cbvprintf_impl()
1851 while (pad_len-- > 0) { in z_cbvprintf_impl()
1857 if ((conv->altform_0c | conv->altform_0) != 0) { in z_cbvprintf_impl()
1861 if (conv->altform_0c) { in z_cbvprintf_impl()
1862 OUTC(conv->specifier); in z_cbvprintf_impl()
1865 pad_len = conv->pad0_value; in z_cbvprintf_impl()
1866 while (pad_len-- > 0) { in z_cbvprintf_impl()
1874 while (width > 0) { in z_cbvprintf_impl()
1876 --width; in z_cbvprintf_impl()
1880 return count; in z_cbvprintf_impl()