111 char format_char = *(uint8_t *)format;
112 const char *format_cursor = &format[1];
113 int32_t text_length = 0;
114 int32_t written_count = 0;
116 format = format_cursor;
119 return written_count;
121 int32_t precision = -1;
122 int32_t uppercase_exponent = 0;
123 int32_t suppress_output = 0;
124 int32_t wide_text = 0;
125 int32_t field_width = 0;
126 int32_t prefix_length = 0;
127 uint32_t format_flags = 0;
129 const char *text = scratch;
131 while (written_count >= 0)
133 int32_t character_class;
135 if (format_char <
' ' || format_char >
'x')
139 int32_t class_lookup_bits = (int32_t)format_char;
147 switch (next_state_code)
155 CRT_write_char((int32_t)format_char, output_context, &written_count);
156 format_char = *(uint8_t *)format_cursor;
157 format = &format_cursor[1];
160 CRT_write_char((int32_t)format_char, output_context, &written_count);
167 precision = 0xffffffff;
168 uppercase_exponent = 0;
180 int32_t flag_character = (int32_t)format_char;
182 if (flag_character ==
' ')
184 else if (flag_character ==
'#')
186 else if (flag_character ==
'+')
188 else if (flag_character ==
'-')
190 else if (flag_character ==
'0')
198 if (format_char !=
'*')
199 field_width = (int32_t)format_char + field_width * 0xa -
'0';
202 int32_t argument_width =
CRT_VaArgInt(&argument_cursor);
204 field_width = argument_width;
206 if (argument_width < 0)
209 field_width = -(argument_width);
225 if (format_char !=
'*')
226 precision = (int32_t)format_char + precision * 0xa -
'0';
229 int32_t argument_precision =
CRT_VaArgInt(&argument_cursor);
231 precision = argument_precision;
233 if (argument_precision < 0)
234 precision = 0xffffffff;
242 if (format_char ==
'I')
244 if (*(uint8_t *)format_cursor !=
'6' || format_cursor[1] !=
'4')
252 CRT_write_char((int32_t)format_char, output_context, &written_count);
253 format_char = *(uint8_t *)format_cursor;
254 format = &format_cursor[1];
257 CRT_write_char((int32_t)format_char, output_context, &written_count);
262 format = &format_cursor[2];
265 else if (format_char ==
'h')
267 else if (format_char ==
'l')
269 else if (format_char ==
'w')
277 int32_t conversion_character = (int32_t)format_char;
280 switch (conversion_character)
290 int32_t hex_digit_offset = 0;
293 if (conversion_character ==
'd' || conversion_character ==
'i')
298 else if (conversion_character ==
'u')
300 else if (conversion_character ==
'o')
309 if (conversion_character ==
'p')
312 hex_digit_offset = conversion_character ==
'x' ? (
'a' -
'0' - 10) : (
'A' -
'0' - 10);
319 prefix[1] = (uint8_t)hex_digit_offset + (
'X' - (
'A' -
'0' - 10));
332 argument = (format_flags &
CRT_FORMAT_SIGNED) ? (int16_t)argument : (uint16_t)argument;
334 magnitude = (format_flags &
CRT_FORMAT_SIGNED) ? (uint64_t)(int64_t)argument : (uint32_t)argument;
339 magnitude = UINT64_C(0) - magnitude;
344 magnitude = (uint32_t)magnitude;
354 char *digit_cursor = scratch +
sizeof(scratch);
358 int32_t remaining_digit_precision = precision;
362 if (remaining_digit_precision <= 0 && !magnitude)
365 int32_t digit_character =
__aullrem(magnitude, (uint64_t)radix) +
'0';
367 magnitude =
__aulldiv(magnitude, (uint64_t)radix);
369 if (digit_character >
'9')
370 digit_character += hex_digit_offset;
372 *--digit_cursor = (char)digit_character;
375 text_length = (scratch +
sizeof(scratch)) - digit_cursor;
378 *--digit_cursor =
'0';
392 int32_t limit = precision == -1 ? INT32_MAX : precision;
398 text = (
const char *)str;
400 while (text_length != limit && str[text_length])
406 while (text_length != limit && text[text_length])
419 if (conversion_character ==
'E' || conversion_character ==
'G')
421 uppercase_exponent = 1;
422 format_char +=
'a' -
'A';
429 char *unsigned_float_text = scratch;
435 else if (!precision && format_char ==
'g')
438 uint8_t *after_double_argument = &argument_cursor[8];
440 argument_cursor = after_double_argument;
442 double floating_value;
444 *(uint32_t *)&floating_value = *(uint32_t *)(after_double_argument - 8);
445 *(uint32_t *)((
char *)&floating_value + 4) =
446 *(uint32_t *)(after_double_argument - 4);
448 precision, uppercase_exponent);
452 if (alternate_format && !precision)
455 if (format_char ==
'g' && !alternate_format)
458 if (scratch[0] ==
'-')
461 unsigned_float_text = &scratch[1];
465 str = unsigned_float_text;
477 uint8_t **character_arguments = &argument_cursor;
489 text_length = converted_character_bytes;
491 if (converted_character_bytes < 0)
503 if (!counted_string || !counted_string->
buffer)
510 text = counted_string->
buffer;
512 text_length = counted_string->
length;
514 text_length = (uint32_t)text_length >> 1;
524 *(uint32_t *)count_output_address = written_count;
526 *(uint16_t *)count_output_address = (uint16_t)written_count;
539 if (!suppress_output)
560 int32_t padding_count = field_width - prefix_length - text_length;
570 if (!wide_text || text_length <= 0)
574 uint16_t
const *wide_text_cursor = (uint16_t
const *)text;
575 int32_t wide_characters_remaining = text_length;
579 uint16_t wide_character = *wide_text_cursor++;
580 char multibyte_character[0x4];
582 multibyte_character, wide_character);
589 }
while (--wide_characters_remaining);
600 format_char = *(uint8_t *)format;
601 format_cursor = &format[1];
602 format = format_cursor;
607 parser_state = next_state;
610 return written_count;