22#define APICHAR wchar_t
24#define FUNC_NAME(func) func ## _w
27#define CONVCHAR wchar_t
28#define FUNC_NAME(func) func ## _a
31struct FUNC_NAME(_str_ctx) {
38 struct FUNC_NAME(_str_ctx) *
out =
ctx;
60 while (*
fmt >=
'0' && *
fmt <=
'9') {
72 int i,
r = 0, written;
81 r = pf_puts(puts_ctx, 1, &
ch);
94 r = pf_puts(puts_ctx, 1, &
ch);
102 r = pf_puts(puts_ctx, 1, &
ch);
106 return r>=0 ? written :
r;
109#ifndef PRINTF_HELPERS
110#define PRINTF_HELPERS
131 for(
i=0;
i<
len; wlen++) {
139static inline unsigned int log2i(
unsigned int x)
146static inline unsigned int log10i(
unsigned int x)
148 unsigned int t = ((
log2i(
x) + 1) * 1233) / 4096;
158 return pf_puts(puts_ctx,
len,
str);
170 len = pf_puts(puts_ctx, len_a,
out);
190 len = pf_puts(puts_ctx, len_w,
out);
194 return pf_puts(puts_ctx,
len,
str);
205 if(
flags->Precision>=0)
225 return r>=0 ?
ret :
r;
235 if(
flags->Precision>=0)
255 return r>=0 ?
ret :
r;
261 BOOL api_is_wide =
sizeof(
APICHAR) ==
sizeof(
wchar_t);
262 BOOL complement_is_narrow = legacy_wide ? api_is_wide :
FALSE;
272 if((
flags->NaturalString && api_is_wide) ||
flags->WideString ||
flags->IntegerLength == LEN_LONG)
274 if((
flags->NaturalString && !api_is_wide) ||
flags->IntegerLength == LEN_SHORT)
277 if((
flags->Format==
'S' ||
flags->Format==
'C') == complement_is_narrow)
285 BOOL legacy_msvcrt_compat,
BOOL three_digit_exp)
288 int len = 0,
r, frac_len, pfx_len, sfx_len;
290 if(!legacy_msvcrt_compat) {
298 else str = (
flags->Sign ==
'-' ?
"nan(ind)" :
"nan");
301 flags->Precision = -1;
314 *
p++ = (
flags->Format==
'a' ?
'x' :
'X');
315 r = pf_puts(puts_ctx,
p-pfx, pfx);
319 flags->FieldLength -=
p-pfx;
325 *
p++ = (
flags->Format==
'a' ?
'x' :
'X');
338 }
else if(
flags->Sign ==
'-') {
355 if(
flags->Precision>=0 &&
flags->Precision<frac_len)
356 p[
flags->Precision - frac_len - 1]++;
360 if(
flags->Format ==
'a') *
p++ =
'p';
361 else if(
flags->Format ==
'A') *
p++ =
'P';
362 else if(
flags->Format ==
'e') *
p++ =
'e';
368 if(
flags->Format ==
'e' ||
flags->Format ==
'E') {
370 if(three_digit_exp) *
p++ =
'0';
375 if(!
flags->Alternate && (
flags->Format ==
'g' ||
flags->Format ==
'G')) sfx_len = frac_len;
376 else sfx_len =
flags->Precision;
380 else if(
flags->Format ==
'a' ||
flags->Format ==
'A') sfx_len = 13;
382 sfx_len +=
p - sfx - frac_len;
384 if(sfx_len > 0)
flags->FieldLength -= sfx_len;
385 if(
flags->Precision >= 0) {
387 flags->Precision += pfx_len - frac_len;
397 flags->FieldLength = sfx_len;
399 flags->Precision = -1;
416 {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'a',
'b',
'c',
'd',
'e',
'f' },
417 {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' }
422 int len = 0, sfx_len = 0,
r,
exp;
427 mant = (mant << EXP_BITS) >> (
EXP_BITS+1);
433 *
p++ = (
flags->Format==
'a' ?
'x' :
'X');
434 r = pf_puts(puts_ctx,
p-pfx, pfx);
438 flags->FieldLength -=
p-pfx;
443 *
p++ = (
flags->Format==
'a' ?
'x' :
'X');
457 if(!
flags->Precision) {
458 if(
p[0] >=
'8')
p[-2]++;
459 if(!
flags->Alternate)
p--;
463 if(!standard_rounding) round_up = (
p[
flags->Precision] >=
'8');
464 else if(
p[
flags->Precision] >
'8') round_up =
TRUE;
465 else if(
p[
flags->Precision] ==
'8') {
474 if(
p[
flags->Precision-1] <=
'9') round_up = (
p[
flags->Precision-1] -
'0') & 1;
475 else if(
p[
flags->Precision-1] <=
'F') round_up = (
p[
flags->Precision-1] -
'A') & 1;
476 else round_up = (
p[
flags->Precision-1] -
'a') & 1;
480 for(
r=
flags->Precision-1;
r>=0 && round_up;
r--) {
482 if(
p[
r]==
'f' ||
p[
r]==
'F') {
485 }
else if(
p[
r] ==
'9') {
486 p[
r] = (
flags->Format ==
'a' ?
'a' :
'A');
491 if(round_up)
p[-2]++;
500 *
p++ = (
flags->Format ==
'a' ?
'p' :
'P');
507 for(
r=3;
r>=0;
r--) {
518 flags->FieldLength -= sfx_len;
519 flags->Precision = -1;
528 flags->FieldLength = sfx_len;
550 if(
flags->Format ==
'o')
552 else if(
flags->Format==
'x' ||
flags->Format==
'X')
557 if(
flags->Format ==
'X')
558 digits =
"0123456789ABCDEFX";
560 digits =
"0123456789abcdefx";
562 if(
x<0 && (
flags->Format==
'd' ||
flags->Format==
'i')) {
582 if(
flags->Alternate) {
605 BOOL standard_rounding)
607 int e2, e10 = 0, round_pos, round_limb, radix_pos, first_limb_len,
i,
len,
r,
ret;
613 struct bnum *
b = (
struct bnum*)bnum_data;
621 if(
flags->Precision == -1)
622 flags->Precision = 6;
636 int shift = e2 > 29 ? 29 : e2;
641 int shift = -e2 > 9 ? 9 : -e2;
659 round_pos =
flags->Precision;
661 round_pos += radix_pos;
664 if (round_pos <= first_limb_len)
665 round_limb =
b->e + (first_limb_len - round_pos) /
LIMB_DIGITS - 1;
667 round_limb =
b->e - (round_pos - first_limb_len - 1) /
LIMB_DIGITS - 2;
669 if (
b->b<=round_limb && round_limb<b->
e) {
670 if (round_pos <= first_limb_len) {
671 round_pos = first_limb_len - round_pos;
680 if(!standard_rounding) round_up = (2*
l >=
p10s[round_pos]);
681 else if(2*
l >
p10s[round_pos]) round_up =
TRUE;
682 else if(2*
l ==
p10s[round_pos]) {
683 for(
r = round_limb-1;
r >=
b->b;
r--) {
690 if(!round_up) round_up =
b->data[
bnum_idx(
b, round_limb)] /
p10s[round_pos] & 1;
692 }
else if(round_limb - 1 >=
b->b) {
696 for(
r = round_limb-2;
r >=
b->b;
r--) {
703 if(!round_up) round_up =
b->data[
bnum_idx(
b, round_limb)] & 1;
710 for(
i =
b->b; i < b->
e;
i++) {
722 if(
i != first_limb_len) {
733 }
else if(
i ==
b->e) {
747 else if(
b->e <= round_limb) {
748 if(
b->e == round_limb) {
752 for(
r =
b->e-2;
r >=
b->b;
r--) {
768 if(
flags->Format==
'g' ||
flags->Format==
'G') {
771 if(radix_pos>=-3 && radix_pos<=flags->Precision) {
774 flags->Precision -= radix_pos;
781 if(trim_tail && !
flags->Alternate) {
782 for(
i=round_limb;
flags->Precision>0 &&
i<
b->e;
i++) {
788 if(
i == round_limb) {
790 r = radix_pos +
flags->Precision;
803 flags->Precision -= limb_len;
811 if(
flags->Precision <= 0) {
812 flags->Precision = 0;
822 if(
flags->Format==
'f' ||
flags->Format==
'F') {
823 len += (radix_pos > 0 ? radix_pos : 1);
824 }
else if(
flags->Format==
'e' ||
flags->Format==
'E') {
826 if(!trim_tail || radix_pos) {
828 if(three_digit_exp || radix_pos<-99 || radix_pos>99)
len += 3;
841 if(
flags->Format==
'f' ||
flags->Format==
'F') {
844 r = pf_puts(puts_ctx, 1,
buf);
850 for(
i=
b->e-1; radix_pos>0 &&
i>=
b->b;
i--) {
853 if(limb_len > radix_pos) {
854 f.Precision = radix_pos;
855 l /=
p10s[limb_len - radix_pos];
856 limb_len = limb_len - radix_pos;
858 f.Precision = limb_len;
861 radix_pos -=
f.Precision;
864 r = pf_puts(puts_ctx,
f.Precision,
buf);
870 for(; radix_pos>0; radix_pos--) {
871 r = pf_puts(puts_ctx, 1,
buf);
878 r = pf_puts(puts_ctx, 1,
buf);
883 prec =
flags->Precision;
885 for(; prec>0 && radix_pos+
LIMB_DIGITS-first_limb_len<0; radix_pos++, prec--) {
886 r = pf_puts(puts_ctx, 1,
buf);
891 for(; prec>0 &&
i>=
b->b;
i--) {
895 if(limb_len > prec) {
897 l /=
p10s[limb_len - prec];
899 f.Precision = limb_len;
905 r = pf_puts(puts_ctx,
f.Precision,
buf);
911 for(; prec>0; prec--) {
912 r = pf_puts(puts_ctx, 1,
buf);
918 l /=
p10s[first_limb_len - 1];
921 r = pf_puts(puts_ctx, 1,
buf);
927 r = pf_puts(puts_ctx, 1,
buf);
932 prec =
flags->Precision;
934 for(
i=
b->e-1; prec>0 &&
i>=
b->b;
i--) {
937 limb_len = first_limb_len - 1;
941 if(limb_len > prec) {
943 l /=
p10s[limb_len - prec];
945 f.Precision = limb_len;
951 r = pf_puts(puts_ctx,
f.Precision,
buf);
957 for(; prec>0; prec--) {
958 r = pf_puts(puts_ctx, 1,
buf);
963 if(!trim_tail || radix_pos) {
965 buf[1] = radix_pos < 0 ?
'-' :
'+';
966 r = pf_puts(puts_ctx, 2,
buf);
970 f.Precision = three_digit_exp ? 3 : 2;
972 r = pf_puts(puts_ctx,
f.Precision,
buf);
990 int written = 0,
pos,
i;
1010 for(
q=
p; *
q && *
q!=
'%';
q++);
1012 i = pf_puts(puts_ctx,
q-
p,
p);
1026 i = pf_puts(puts_ctx, 1,
p++);
1043 if(*
p==
'+' || *
p==
' ') {
1044 if(
flags.Sign !=
'+')
1046 }
else if(*
p ==
'-')
1067 if(
flags.FieldLength < 0) {
1073#if _MSVCR_VER >= 140
1074 if (*
p >=
'0' && *
p <=
'9')
1075 flags.FieldLength = 0;
1078 while (*
p >=
'0' && *
p <=
'9') {
1079 flags.FieldLength *= 10;
1080 flags.FieldLength += *
p++ -
'0';
1084 flags.Precision = -1;
1086 flags.Precision = 0;
1096 }
else while (*
p >=
'0' && *
p <=
'9') {
1097 flags.Precision *= 10;
1098 flags.Precision += *
p++ -
'0';
1104 if(*
p==
'l' && *(
p+1)==
'l') {
1107 }
else if(*
p==
'l') {
1108 flags.IntegerLength = LEN_LONG;
1109 }
else if(*
p ==
'h') {
1110 flags.IntegerLength = LEN_SHORT;
1111 }
else if(*
p ==
'I') {
1112 if(*(
p+1)==
'6' && *(
p+2)==
'4') {
1115 }
else if(*(
p+1)==
'3' && *(
p+2)==
'2')
1117 else if(
p[1] &&
strchr(
"diouxX",
p[1]))
1121 }
else if(*
p ==
'w')
1123#if _MSVCR_VER == 0 || _MSVCR_VER >= 140
1124 else if((*
p ==
'z' || *
p ==
't') &&
p[1] &&
strchr(
"diouxX",
p[1]))
1129#if _MSVCR_VER >= 140
1133 else if(*
p !=
'L' && ((*
p !=
'F' && *
p !=
'N') || !legacy_msvcrt_compat))
1140 if(
flags.Format ==
's' ||
flags.Format ==
'S') {
1144 }
else if(
flags.Format ==
'c' ||
flags.Format ==
'C') {
1149 }
else if(
flags.Format ==
'p') {
1153 flags.Precision = 2*
sizeof(
void*);
1164 }
else if(
flags.Format ==
'n') {
1190 if(
flags.IntegerDouble || (
flags.IntegerNative &&
sizeof(
void*) == 8))
1193 else if(
flags.Format==
'd' ||
flags.Format==
'i')
1195 flags.IntegerLength != LEN_SHORT ?
1200 flags.IntegerLength != LEN_SHORT ?
1221 locale, legacy_msvcrt_compat, three_digit_exp);
1222 else if(
flags.Format==
'a' ||
flags.Format==
'A')
1224 locale, standard_rounding);
1227 locale, three_digit_exp, standard_rounding);
1229 if(invoke_invalid_param_handler) {
1280 struct FUNC_NAME(_str_ctx) puts_ctx = {
INT_MAX,
NULL};
1298 for(
j=1;
j<=
i;
j++) {
static BOOL bnum_lshift(struct bnum *b, int shift)
static int bnum_idx(struct bnum *b, int idx)
static BOOL bnum_rshift(struct bnum *b, int shift)
static int get_int(D3DXPARAMETER_TYPE type, const void *data)
#define HeapFree(x, y, z)
void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t arg)
#define _CRT_INTERNAL_PRINTF_STANDARD_ROUNDING
#define _CRT_INTERNAL_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS
#define _CRT_INTERNAL_PRINTF_LEGACY_WIDE_SPECIFIERS
#define _CRT_INTERNAL_PRINTF_LEGACY_MSVCRT_COMPATIBILITY
_ACRTIMP int __cdecl _mbtowc_l(wchar_t *, const char *, size_t, _locale_t)
_ACRTIMP int __cdecl _wctomb_l(char *, wchar_t, _locale_t)
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
_ACRTIMP size_t __cdecl wcsnlen(const wchar_t *, size_t)
_ACRTIMP double __cdecl frexp(double, int *)
#define _TWO_DIGIT_EXPONENT
_ACRTIMP unsigned int __cdecl _get_output_format(void)
_ACRTIMP int __cdecl mblen(const char *, size_t)
_ACRTIMP char *__cdecl strchr(const char *, int)
_ACRTIMP size_t __cdecl strnlen(const char *, size_t)
_ACRTIMP size_t __cdecl strlen(const char *)
#define MSVCRT_PRINTF_POSITIONAL_PARAMS
#define MSVCRT_INVALID_PMT(x, err)
#define MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
printf_arg(* args_clbk)(void *, int, int, va_list *)
#define MSVCRT_CHECK_PMT(x)
static BOOL n_format_enabled
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
GLint GLint GLint GLint GLint x
GLuint GLuint GLsizei GLenum type
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble r
GLdouble GLdouble GLdouble GLdouble q
GLboolean GLboolean GLboolean b
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
static const int digits[]
#define memmove(s1, s2, n)
static unsigned(__cdecl *hash_bstr)(bstr_t s)
static int FUNC_NAME() pf_output_format_str(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const char *str, int len, pf_flags *flags, _locale_t locale)
static unsigned int log10i(unsigned int x)
static int FUNC_NAME() pf_output_special_fp(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, double v, pf_flags *flags, _locale_t locale, BOOL legacy_msvcrt_compat, BOOL three_digit_exp)
static int wcstombs_len(char *mbstr, const wchar_t *wcstr, int len, _locale_t locale)
static int FUNC_NAME() pf_output_wstr(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const wchar_t *str, int len, _locale_t locale)
static int FUNC_NAME() pf_handle_string(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const void *str, int len, pf_flags *flags, _locale_t locale, BOOL legacy_wide)
int FUNC_NAME() pf_printf(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const APICHAR *fmt, _locale_t locale, DWORD options, args_clbk pf_args, void *args_ctx, va_list *valist)
static int FUNC_NAME() puts_clbk_str(void *ctx, int len, const APICHAR *str)
static int mbstowcs_len(wchar_t *wcstr, const char *mbstr, int len, _locale_t locale)
int FUNC_NAME() create_positional_ctx(void *args_ctx, const APICHAR *format, va_list valist)
static unsigned int log2i(unsigned int x)
static int FUNC_NAME() pf_output_str(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const char *str, int len, _locale_t locale)
static printf_arg arg_clbk_type(void *ctx, int pos, int type, va_list *valist)
static const APICHAR *FUNC_NAME() pf_parse_int(const APICHAR *fmt, int *val)
static int FUNC_NAME() pf_fill(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, int len, pf_flags *flags, BOOL left)
static int FUNC_NAME() pf_output_format_wstr(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const wchar_t *str, int len, pf_flags *flags, _locale_t locale)
static int FUNC_NAME() pf_output_fp(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, double v, pf_flags *flags, _locale_t locale, BOOL three_digit_exp, BOOL standard_rounding)
static void FUNC_NAME() pf_integer_conv(APICHAR *buf, pf_flags *flags, LONGLONG x)
static int FUNC_NAME() pf_output_hex_fp(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, double v, pf_flags *flags, _locale_t locale, BOOL standard_rounding)
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask)
#define FIELD_OFFSET(t, f)
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out