Lines Matching refs:spec
261 static void set_field_width(struct printf_spec *spec, int width) in set_field_width() argument
263 spec->field_width = width; in set_field_width()
264 if (WARN_ONCE(spec->field_width != width, "field width %d too large", in set_field_width()
266 spec->field_width = in set_field_width()
271 static void set_precision(struct printf_spec *spec, int prec) in set_precision() argument
273 spec->precision = prec; in set_precision()
274 if (WARN_ONCE(spec->precision != prec, "precision %d too large", in set_precision()
276 spec->precision = clamp(prec, 0, PRECISION_MAX); in set_precision()
281 number(char *buf, char *end, unsigned long long num, struct printf_spec spec) in number() argument
287 int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10); in number()
290 int field_width = spec.field_width; in number()
291 int precision = spec.precision; in number()
295 locase = (spec.flags & SMALL); in number()
296 if (spec.flags & LEFT) in number()
297 spec.flags &= ~ZEROPAD; in number()
299 if (spec.flags & SIGN) { in number()
304 } else if (spec.flags & PLUS) { in number()
307 } else if (spec.flags & SPACE) { in number()
313 if (spec.base == 16) in number()
321 if (num < spec.base) in number()
323 else if (spec.base != 10) { /* 8 or 16 */ in number()
324 int mask = spec.base - 1; in number()
327 if (spec.base == 16) in number()
343 if (!(spec.flags & (ZEROPAD | LEFT))) { in number()
358 if (spec.base == 16 || !is_zero) { in number()
363 if (spec.base == 16) { in number()
370 if (!(spec.flags & LEFT)) { in number()
371 char c = ' ' + (spec.flags & ZEROPAD); in number()
404 struct printf_spec spec; in special_hex_number() local
406 spec.type = FORMAT_TYPE_PTR; in special_hex_number()
407 spec.field_width = 2 + 2 * size; /* 0x + hex */ in special_hex_number()
408 spec.flags = SPECIAL | SMALL | ZEROPAD; in special_hex_number()
409 spec.base = 16; in special_hex_number()
410 spec.precision = -1; in special_hex_number()
412 return number(buf, end, num, spec); in special_hex_number()
442 struct printf_spec spec) in widen_string() argument
446 if (likely(n >= spec.field_width)) in widen_string()
449 spaces = spec.field_width - n; in widen_string()
450 if (!(spec.flags & LEFT)) { in widen_string()
464 struct printf_spec spec) in string_nocheck() argument
467 int lim = spec.precision; in string_nocheck()
478 return widen_string(buf, len, end, spec); in string_nocheck()
483 struct printf_spec spec) in error_string() argument
490 if (spec.precision == -1) in error_string()
491 spec.precision = 2 * sizeof(void *); in error_string()
493 return string_nocheck(buf, end, s, spec); in error_string()
513 struct printf_spec spec) in check_pointer() argument
519 *buf = error_string(*buf, end, err_msg, spec); in check_pointer()
527 struct printf_spec spec) in string() argument
529 if (check_pointer(&buf, end, s, spec)) in string()
532 return string_nocheck(buf, end, s, spec); in string()
536 struct printf_spec spec) in pointer_string() argument
538 spec.base = 16; in pointer_string()
539 spec.flags |= SMALL; in pointer_string()
540 if (spec.field_width == -1) { in pointer_string()
541 spec.field_width = 2 * sizeof(ptr); in pointer_string()
542 spec.flags |= ZEROPAD; in pointer_string()
545 return number(buf, end, (unsigned long int)ptr, spec); in pointer_string()
549 struct printf_spec spec, in hex_string() argument
556 if (spec.field_width == 0) in hex_string()
560 if (check_pointer(&buf, end, addr, spec)) in hex_string()
578 if (spec.field_width > 0) in hex_string()
579 len = min_t(int, spec.field_width, 64); in hex_string()
601 struct printf_spec spec, in mac_address_string() argument
610 if (check_pointer(&buf, end, addr, spec)) in mac_address_string()
638 return string_nocheck(buf, end, mac_addr, spec); in mac_address_string()
642 struct printf_spec spec) in default_pointer() argument
644 return pointer_string(buf, end, ptr, spec); in default_pointer()
647 static char *err_ptr(char *buf, char *end, void *ptr, struct printf_spec spec) in err_ptr() argument
660 spec.flags |= SIGN; in err_ptr()
661 spec.base = 10; in err_ptr()
662 return number(buf, end, err, spec); in err_ptr()
797 void *ptr, struct printf_spec spec) in pointer() argument
810 return hex_string(buf, end, ptr, spec, fmt); in pointer()
822 return mac_address_string(buf, end, ptr, spec, fmt); in pointer()
857 return bdev_name(buf, end, ptr, spec, fmt); in pointer()
873 return pointer_string(buf, end, ptr, spec); in pointer()
877 return default_pointer(buf, end, ptr, spec); in pointer()
878 return err_ptr(buf, end, ptr, spec); in pointer()
883 return string(buf, end, ptr, spec); in pointer()
885 return error_string(buf, end, "(einval)", spec); in pointer()
888 return default_pointer(buf, end, ptr, spec); in pointer()
914 struct printf_spec *spec) in format_decode() argument
920 if (spec->type == FORMAT_TYPE_WIDTH) { in format_decode()
921 if (spec->field_width < 0) { in format_decode()
922 spec->field_width = -spec->field_width; in format_decode()
923 spec->flags |= LEFT; in format_decode()
925 spec->type = FORMAT_TYPE_NONE; in format_decode()
930 if (spec->type == FORMAT_TYPE_PRECISION) { in format_decode()
931 if (spec->precision < 0) in format_decode()
932 spec->precision = 0; in format_decode()
934 spec->type = FORMAT_TYPE_NONE; in format_decode()
939 spec->type = FORMAT_TYPE_NONE; in format_decode()
951 spec->flags = 0; in format_decode()
960 spec->flags |= LEFT; in format_decode()
963 spec->flags |= PLUS; in format_decode()
966 spec->flags |= SPACE; in format_decode()
969 spec->flags |= SPECIAL; in format_decode()
972 spec->flags |= ZEROPAD; in format_decode()
983 spec->field_width = -1; in format_decode()
986 spec->field_width = skip_atoi(&fmt); in format_decode()
989 spec->type = FORMAT_TYPE_WIDTH; in format_decode()
995 spec->precision = -1; in format_decode()
999 spec->precision = skip_atoi(&fmt); in format_decode()
1000 if (spec->precision < 0) in format_decode()
1001 spec->precision = 0; in format_decode()
1004 spec->type = FORMAT_TYPE_PRECISION; in format_decode()
1027 spec->base = 10; in format_decode()
1030 spec->type = FORMAT_TYPE_CHAR; in format_decode()
1034 spec->type = FORMAT_TYPE_STR; in format_decode()
1038 spec->type = FORMAT_TYPE_PTR; in format_decode()
1042 spec->type = FORMAT_TYPE_PERCENT_CHAR; in format_decode()
1047 spec->base = 8; in format_decode()
1051 spec->flags |= SMALL; in format_decode()
1055 spec->base = 16; in format_decode()
1060 spec->flags |= SIGN; in format_decode()
1077 spec->type = FORMAT_TYPE_INVALID; in format_decode()
1082 spec->type = FORMAT_TYPE_LONG_LONG; in format_decode()
1085 spec->type = FORMAT_TYPE_ULONG + (spec->flags & SIGN); in format_decode()
1087 spec->type = FORMAT_TYPE_SIZE_T; in format_decode()
1089 spec->type = FORMAT_TYPE_PTRDIFF; in format_decode()
1092 spec->type = FORMAT_TYPE_UBYTE + (spec->flags & SIGN); in format_decode()
1095 spec->type = FORMAT_TYPE_USHORT + (spec->flags & SIGN); in format_decode()
1098 spec->type = FORMAT_TYPE_UINT + (spec->flags & SIGN); in format_decode()
1136 struct printf_spec spec = { 0 }; in vsnprintf() local
1154 int read = format_decode(fmt, &spec); in vsnprintf()
1158 switch (spec.type) { in vsnprintf()
1171 set_field_width(&spec, va_arg(args, int)); in vsnprintf()
1175 set_precision(&spec, va_arg(args, int)); in vsnprintf()
1181 if (!(spec.flags & LEFT)) { in vsnprintf()
1182 while (--spec.field_width > 0) { in vsnprintf()
1192 while (--spec.field_width > 0) { in vsnprintf()
1201 str = string(str, end, va_arg(args, char *), spec); in vsnprintf()
1206 spec); in vsnprintf()
1229 switch (spec.type) { in vsnprintf()
1240 if (spec.flags & SIGN) in vsnprintf()
1267 str = number(str, end, num, spec); in vsnprintf()