ReactOS 0.4.16-dev-2104-gb84fa49
printf.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 Piotr Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include "bnum.h"
20
21#ifdef PRINTF_WIDE
22#define APICHAR wchar_t
23#define CONVCHAR char
24#define FUNC_NAME(func) func ## _w
25#else
26#define APICHAR char
27#define CONVCHAR wchar_t
28#define FUNC_NAME(func) func ## _a
29#endif
30
31struct FUNC_NAME(_str_ctx) {
32 size_t len;
33 APICHAR *buf;
34};
35
36static int FUNC_NAME(puts_clbk_str)(void *ctx, int len, const APICHAR *str)
37{
38 struct FUNC_NAME(_str_ctx) *out = ctx;
39
40 if(!out->buf)
41 return len;
42
43 if(out->len < len) {
44 memmove(out->buf, str, out->len*sizeof(APICHAR));
45 out->buf += out->len;
46 out->len = 0;
47 return -1;
48 }
49
50 memmove(out->buf, str, len*sizeof(APICHAR));
51 out->buf += len;
52 out->len -= len;
53 return len;
54}
55
56static inline const APICHAR* FUNC_NAME(pf_parse_int)(const APICHAR *fmt, int *val)
57{
58 *val = 0;
59
60 while (*fmt >= '0' && *fmt <= '9') {
61 *val *= 10;
62 *val += *fmt++ - '0';
63 }
64
65 return fmt;
66}
67
68/* pf_fill: takes care of signs, alignment, zero and field padding */
69static inline int FUNC_NAME(pf_fill)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
70 int len, pf_flags *flags, BOOL left)
71{
72 int i, r = 0, written;
73
74 if(flags->Sign && !strchr("diaAeEfFgG", flags->Format))
75 flags->Sign = 0;
76
77 if(left && flags->Sign) {
78 APICHAR ch = flags->Sign;
79 flags->FieldLength--;
80 if(flags->PadZero)
81 r = pf_puts(puts_ctx, 1, &ch);
82 }
83 written = r;
84
85 if((!left && flags->LeftAlign) || (left && !flags->LeftAlign)) {
86 APICHAR ch;
87
88 if(left && flags->PadZero)
89 ch = '0';
90 else
91 ch = ' ';
92
93 for(i=0; i<flags->FieldLength-len && r>=0; i++) {
94 r = pf_puts(puts_ctx, 1, &ch);
95 written += r;
96 }
97 }
98
99
100 if(r>=0 && left && flags->Sign && !flags->PadZero) {
101 APICHAR ch = flags->Sign;
102 r = pf_puts(puts_ctx, 1, &ch);
103 written += r;
104 }
105
106 return r>=0 ? written : r;
107}
108
109#ifndef PRINTF_HELPERS
110#define PRINTF_HELPERS
111static inline int wcstombs_len(char *mbstr, const wchar_t *wcstr,
112 int len, _locale_t locale)
113{
114 char buf[MB_LEN_MAX];
115 int i, r, mblen = 0;
116
117 for(i=0; i<len; i++) {
118 r = _wctomb_l(mbstr ? mbstr+mblen : buf, wcstr[i], locale);
119 if(r < 0) return r;
120 mblen += r;
121 }
122 return mblen;
123}
124
125static inline int mbstowcs_len(wchar_t *wcstr, const char *mbstr,
126 int len, _locale_t locale)
127{
128 int i, r, wlen = 0;
129 WCHAR buf;
130
131 for(i=0; i<len; wlen++) {
132 r = _mbtowc_l(wcstr ? wcstr+wlen : &buf, mbstr+i, len-i, locale);
133 if(r < 0) return r;
134 i += r ? r : 1;
135 }
136 return wlen;
137}
138
139static inline unsigned int log2i(unsigned int x)
140{
143 return result;
144}
145
146static inline unsigned int log10i(unsigned int x)
147{
148 unsigned int t = ((log2i(x) + 1) * 1233) / 4096;
149 return t - (x < p10s[t]);
150}
151
152#endif
153
154static inline int FUNC_NAME(pf_output_wstr)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
155 const wchar_t *str, int len, _locale_t locale)
156{
157#ifdef PRINTF_WIDE
158 return pf_puts(puts_ctx, len, str);
159#else
160 LPSTR out;
161 int len_a = wcstombs_len(NULL, str, len, locale);
162 if(len_a < 0)
163 return -1;
164
165 out = HeapAlloc(GetProcessHeap(), 0, len_a);
166 if(!out)
167 return -1;
168
170 len = pf_puts(puts_ctx, len_a, out);
172 return len;
173#endif
174}
175
176static inline int FUNC_NAME(pf_output_str)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
177 const char *str, int len, _locale_t locale)
178{
179#ifdef PRINTF_WIDE
180 LPWSTR out;
181 int len_w = mbstowcs_len(NULL, str, len, locale);
182 if(len_w < 0)
183 return -1;
184
185 out = HeapAlloc(GetProcessHeap(), 0, len_w*sizeof(WCHAR));
186 if(!out)
187 return -1;
188
190 len = pf_puts(puts_ctx, len_w, out);
192 return len;
193#else
194 return pf_puts(puts_ctx, len, str);
195#endif
196}
197
198static inline int FUNC_NAME(pf_output_format_wstr)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
199 const wchar_t *str, int len, pf_flags *flags, _locale_t locale)
200{
201 int r, ret;
202
203 if(len < 0) {
204 /* Do not search past the length specified by the precision. */
205 if(flags->Precision>=0)
206 len = wcsnlen(str, flags->Precision);
207 else
208 len = wcslen(str);
209 }
210
211 if(flags->Precision>=0 && flags->Precision<len)
212 len = flags->Precision;
213
214 r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, TRUE);
215 ret = r;
216 if(r >= 0) {
217 r = FUNC_NAME(pf_output_wstr)(pf_puts, puts_ctx, str, len, locale);
218 ret += r;
219 }
220 if(r >= 0) {
221 r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, FALSE);
222 ret += r;
223 }
224
225 return r>=0 ? ret : r;
226}
227
228static inline int FUNC_NAME(pf_output_format_str)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
229 const char *str, int len, pf_flags *flags, _locale_t locale)
230{
231 int r, ret;
232
233 if(len < 0) {
234 /* Do not search past the length specified by the precision. */
235 if(flags->Precision>=0)
236 len = strnlen(str, flags->Precision);
237 else
238 len = strlen(str);
239 }
240
241 if(flags->Precision>=0 && flags->Precision<len)
242 len = flags->Precision;
243
244 r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, TRUE);
245 ret = r;
246 if(r >= 0) {
247 r = FUNC_NAME(pf_output_str)(pf_puts, puts_ctx, str, len, locale);
248 ret += r;
249 }
250 if(r >= 0) {
251 r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, FALSE);
252 ret += r;
253 }
254
255 return r>=0 ? ret : r;
256}
257
258static inline int FUNC_NAME(pf_handle_string)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
259 const void *str, int len, pf_flags *flags, _locale_t locale, BOOL legacy_wide)
260{
261 BOOL api_is_wide = sizeof(APICHAR) == sizeof(wchar_t);
262 BOOL complement_is_narrow = legacy_wide ? api_is_wide : FALSE;
263#ifdef PRINTF_WIDE
264
265 if(!str)
266 return FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, L"(null)", 6, flags, locale);
267#else
268 if(!str)
269 return FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, "(null)", 6, flags, locale);
270#endif
271
272 if((flags->NaturalString && api_is_wide) || flags->WideString || flags->IntegerLength == LEN_LONG)
273 return FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, str, len, flags, locale);
274 if((flags->NaturalString && !api_is_wide) || flags->IntegerLength == LEN_SHORT)
275 return FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, str, len, flags, locale);
276
277 if((flags->Format=='S' || flags->Format=='C') == complement_is_narrow)
278 return FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, str, len, flags, locale);
279 else
280 return FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, str, len, flags, locale);
281}
282
283static inline int FUNC_NAME(pf_output_special_fp)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
284 double v, pf_flags *flags, _locale_t locale,
285 BOOL legacy_msvcrt_compat, BOOL three_digit_exp)
286{
287 APICHAR pfx[16], sfx[8], *p;
288 int len = 0, r, frac_len, pfx_len, sfx_len;
289
290 if(!legacy_msvcrt_compat) {
291 const char *str;
292
293 if(isinf(v)) {
294 if(strchr("AEFG", flags->Format)) str = "INF";
295 else str = "inf";
296 }else {
297 if(strchr("AEFG", flags->Format)) str = (flags->Sign == '-' ? "NAN(IND)" : "NAN");
298 else str = (flags->Sign == '-' ? "nan(ind)" : "nan");
299 }
300
301 flags->Precision = -1;
302 flags->PadZero = FALSE;
303 return FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, str, -1, flags, locale);
304 }
305
306 /* workaround a bug in native implementation */
307 if(flags->Format=='g' || flags->Format=='G')
308 flags->Precision--;
309
310 p = pfx;
311 if(flags->PadZero && (flags->Format=='a' || flags->Format=='A')) {
312 if (flags->Sign) *p++ = flags->Sign;
313 *p++ = '0';
314 *p++ = (flags->Format=='a' ? 'x' : 'X');
315 r = pf_puts(puts_ctx, p-pfx, pfx);
316 if(r < 0) return r;
317 len += r;
318
319 flags->FieldLength -= p-pfx;
320 }
321
322 p = pfx;
323 if(!flags->PadZero && (flags->Format=='a' || flags->Format=='A')) {
324 *p++ = '0';
325 *p++ = (flags->Format=='a' ? 'x' : 'X');
326 }
327
328 *p++ = '1';
329 *p++ = *(locale ? locale->locinfo : get_locinfo())->lconv->decimal_point;
330 *p++ = '#';
331 frac_len = 1;
332
333 if(isinf(v)) {
334 *p++ = 'I';
335 *p++ = 'N';
336 *p++ = 'F';
337 frac_len += 3;
338 }else if(flags->Sign == '-') {
339 *p++ = 'I';
340 *p++ = 'N';
341 *p++ = 'D';
342 frac_len += 3;
343 }else {
344 *p++ = 'Q';
345 *p++ = 'N';
346 *p++ = 'A';
347 *p++ = 'N';
348 frac_len += 4;
349 }
350 *p = 0;
351 pfx_len = p - pfx;
352
353 if(len) flags->Sign = 0;
354
355 if(flags->Precision>=0 && flags->Precision<frac_len)
356 p[flags->Precision - frac_len - 1]++;
357
358 p = sfx;
359 if(strchr("aAeE", flags->Format)) {
360 if(flags->Format == 'a') *p++ = 'p';
361 else if(flags->Format == 'A') *p++ = 'P';
362 else if(flags->Format == 'e') *p++ = 'e';
363 else *p++ = 'E';
364
365 *p++ = '+';
366 *p++ = '0';
367
368 if(flags->Format == 'e' || flags->Format == 'E') {
369 *p++ = '0';
370 if(three_digit_exp) *p++ = '0';
371 }
372 }
373 *p = 0;
374
375 if(!flags->Alternate && (flags->Format == 'g' || flags->Format == 'G')) sfx_len = frac_len;
376 else sfx_len = flags->Precision;
377
378 if(sfx_len == -1) {
379 if(strchr("fFeE", flags->Format)) sfx_len = 6;
380 else if(flags->Format == 'a' || flags->Format == 'A') sfx_len = 13;
381 }
382 sfx_len += p - sfx - frac_len;
383
384 if(sfx_len > 0) flags->FieldLength -= sfx_len;
385 if(flags->Precision >= 0) {
386 if(!flags->Precision) flags->Precision--;
387 flags->Precision += pfx_len - frac_len;
388 }
389#ifdef PRINTF_WIDE
390 r = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, pfx, -1, flags, locale);
391#else
392 r = FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, pfx, -1, flags, locale);
393#endif
394 if(r < 0) return r;
395 len += r;
396
397 flags->FieldLength = sfx_len;
398 flags->PadZero = TRUE;
399 flags->Precision = -1;
400 flags->Sign = 0;
401#ifdef PRINTF_WIDE
402 r = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, sfx, -1, flags, locale);
403#else
404 r = FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, sfx, -1, flags, locale);
405#endif
406 if(r < 0) return r;
407 len += r;
408
409 return len;
410}
411
412static inline int FUNC_NAME(pf_output_hex_fp)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
413 double v, pf_flags *flags, _locale_t locale, BOOL standard_rounding)
414{
415 const APICHAR digits[2][16] = {
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' }
418 };
419
420 APICHAR pfx[4+MANT_BITS/4+1], sfx[8], *p;
421 ULONGLONG mant;
422 int len = 0, sfx_len = 0, r, exp;
423
424 mant = (*(ULONGLONG*)&v) << 1;
425 exp = (mant >> MANT_BITS);
426 exp -= (1 << (EXP_BITS - 1)) - 1;
427 mant = (mant << EXP_BITS) >> (EXP_BITS+1);
428
429 p = pfx;
430 if(flags->PadZero) {
431 if(flags->Sign) *p++ = flags->Sign;
432 *p++ = '0';
433 *p++ = (flags->Format=='a' ? 'x' : 'X');
434 r = pf_puts(puts_ctx, p-pfx, pfx);
435 if(r < 0) return r;
436 len += r;
437
438 flags->FieldLength -= p-pfx;
439 flags->Sign = 0;
440 p = pfx;
441 }else {
442 *p++ = '0';
443 *p++ = (flags->Format=='a' ? 'x' : 'X');
444 }
445 if(exp == -(1 << (EXP_BITS-1))+1) {
446 if(!mant) exp = 0;
447 else exp++;
448 *p++ = '0';
449 }else {
450 *p++ = '1';
451 }
452 *p++ = *(locale ? locale->locinfo : get_locinfo())->lconv->decimal_point;
453 for(r=MANT_BITS/4-1; r>=0; r--) {
454 p[r] = digits[flags->Format == 'A'][mant & 15];
455 mant >>= 4;
456 }
457 if(!flags->Precision) {
458 if(p[0] >= '8') p[-2]++;
459 if(!flags->Alternate) p--;
460 }else if(flags->Precision>0 && flags->Precision<MANT_BITS/4) {
461 BOOL round_up = FALSE;
462
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') {
466 for(r = flags->Precision+1; r<MANT_BITS/4; r++) {
467 if(p[r] != '0') {
468 round_up = TRUE;
469 break;
470 }
471 }
472
473 if(!round_up) {
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;
477 }
478 }
479
480 for(r=flags->Precision-1; r>=0 && round_up; r--) {
481 round_up = FALSE;
482 if(p[r]=='f' || p[r]=='F') {
483 p[r] = '0';
484 round_up = TRUE;
485 }else if(p[r] == '9') {
486 p[r] = (flags->Format == 'a' ? 'a' : 'A');
487 }else {
488 p[r]++;
489 }
490 }
491 if(round_up) p[-2]++;
492 p += flags->Precision;
493 }else {
494 p += MANT_BITS/4;
495 if(flags->Precision > MANT_BITS/4) sfx_len += flags->Precision - MANT_BITS/4;
496 }
497 *p = 0;
498
499 p = sfx;
500 *p++ = (flags->Format == 'a' ? 'p' : 'P');
501 if(exp < 0) {
502 *p++ = '-';
503 exp = -exp;
504 }else {
505 *p++ = '+';
506 }
507 for(r=3; r>=0; r--) {
508 p[r] = exp%10 + '0';
509 exp /= 10;
510 if(!exp) break;
511 }
512 for(exp=0; exp<4-r; exp++)
513 p[exp] = p[exp+r];
514 p += exp;
515 *p = 0;
516 sfx_len += p - sfx;
517
518 flags->FieldLength -= sfx_len;
519 flags->Precision = -1;
520#ifdef PRINTF_WIDE
521 r = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, pfx, -1, flags, locale);
522#else
523 r = FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, pfx, -1, flags, locale);
524#endif
525 if(r < 0) return r;
526 len += r;
527
528 flags->FieldLength = sfx_len;
529 flags->PadZero = TRUE;
530 flags->Sign = 0;
531#ifdef PRINTF_WIDE
532 r = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, sfx, -1, flags, locale);
533#else
534 r = FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, sfx, -1, flags, locale);
535#endif
536 if(r < 0) return r;
537 len += r;
538
539 return len;
540}
541
542/* pf_integer_conv: prints x to buf, including alternate formats and
543 additional precision digits, but not field characters or the sign */
545{
546 unsigned int base;
547 const char *digits;
548 int i, j, k;
549
550 if(flags->Format == 'o')
551 base = 8;
552 else if(flags->Format=='x' || flags->Format=='X')
553 base = 16;
554 else
555 base = 10;
556
557 if(flags->Format == 'X')
558 digits = "0123456789ABCDEFX";
559 else
560 digits = "0123456789abcdefx";
561
562 if(x<0 && (flags->Format=='d' || flags->Format=='i')) {
563 x = -x;
564 flags->Sign = '-';
565 }
566
567 i = 0;
568 if(x == 0) {
569 flags->Alternate = FALSE;
570 if(flags->Precision)
571 buf[i++] = '0';
572 } else {
573 while(x != 0) {
574 j = (ULONGLONG)x%base;
575 x = (ULONGLONG)x/base;
576 buf[i++] = digits[j];
577 }
578 }
579 k = flags->Precision-i;
580 while(k-- > 0)
581 buf[i++] = '0';
582 if(flags->Alternate) {
583 if(base == 16) {
584 buf[i++] = digits[16];
585 buf[i++] = '0';
586 } else if(base==8 && buf[i-1]!='0')
587 buf[i++] = '0';
588 }
589
590 /* Adjust precision so pf_fill won't truncate the number later */
591 flags->Precision = i;
592
593 buf[i] = '\0';
594 j = 0;
595 while(--i > j) {
596 APICHAR tmp = buf[j];
597 buf[j] = buf[i];
598 buf[i] = tmp;
599 j++;
600 }
601}
602
603static inline int FUNC_NAME(pf_output_fp)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
604 double v, pf_flags *flags, _locale_t locale, BOOL three_digit_exp,
605 BOOL standard_rounding)
606{
607 int e2, e10 = 0, round_pos, round_limb, radix_pos, first_limb_len, i, len, r, ret;
608#ifdef _MSC_VER
609 BYTE bnum_data[FIELD_OFFSET(struct bnum, data) + BNUM_PREC64 * sizeof(DWORD)];
610#else
611 BYTE bnum_data[FIELD_OFFSET(struct bnum, data[BNUM_PREC64])];
612#endif
613 struct bnum *b = (struct bnum*)bnum_data;
615 BOOL trim_tail = FALSE, round_up = FALSE;
616 pf_flags f;
617 int limb_len, prec;
618 ULONGLONG m;
619 DWORD l;
620
621 if(flags->Precision == -1)
622 flags->Precision = 6;
623
624 v = frexp(v, &e2);
625 if(v) {
626 m = (ULONGLONG)1 << (MANT_BITS - 1);
627 m |= (*(ULONGLONG*)&v & (((ULONGLONG)1 << (MANT_BITS - 1)) - 1));
628 b->b = 0;
629 b->e = 2;
630 b->size = BNUM_PREC64;
631 b->data[0] = m % LIMB_MAX;
632 b->data[1] = m / LIMB_MAX;
633 e2 -= MANT_BITS;
634
635 while(e2 > 0) {
636 int shift = e2 > 29 ? 29 : e2;
637 if(bnum_lshift(b, shift)) e10 += LIMB_DIGITS;
638 e2 -= shift;
639 }
640 while(e2 < 0) {
641 int shift = -e2 > 9 ? 9 : -e2;
642 if(bnum_rshift(b, shift)) e10 -= LIMB_DIGITS;
643 e2 += shift;
644 }
645 } else {
646 b->b = 0;
647 b->e = 1;
648 b->size = BNUM_PREC64;
649 b->data[0] = 0;
650 e10 = -LIMB_DIGITS;
651 }
652
653 if(!b->data[bnum_idx(b, b->e-1)])
654 first_limb_len = 1;
655 else
656 first_limb_len = log10i(b->data[bnum_idx(b, b->e - 1)]) + 1;
657 radix_pos = first_limb_len + LIMB_DIGITS + e10;
658
659 round_pos = flags->Precision;
660 if(flags->Format=='f' || flags->Format=='F')
661 round_pos += radix_pos;
662 else if(!flags->Precision || flags->Format=='e' || flags->Format=='E')
663 round_pos++;
664 if (round_pos <= first_limb_len)
665 round_limb = b->e + (first_limb_len - round_pos) / LIMB_DIGITS - 1;
666 else
667 round_limb = b->e - (round_pos - first_limb_len - 1) / LIMB_DIGITS - 2;
668
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;
672 } else {
673 round_pos = LIMB_DIGITS - (round_pos - first_limb_len) % LIMB_DIGITS;
674 if (round_pos == LIMB_DIGITS) round_pos = 0;
675 }
676
677 if (round_pos) {
678 l = b->data[bnum_idx(b, round_limb)] % p10s[round_pos];
679 b->data[bnum_idx(b, round_limb)] -= l;
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--) {
684 if(b->data[bnum_idx(b, r)]) {
685 round_up = TRUE;
686 break;
687 }
688 }
689
690 if(!round_up) round_up = b->data[bnum_idx(b, round_limb)] / p10s[round_pos] & 1;
691 }
692 } else if(round_limb - 1 >= b->b) {
693 if(!standard_rounding) round_up = (2*b->data[bnum_idx(b, round_limb-1)] >= LIMB_MAX);
694 else if(2*b->data[bnum_idx(b, round_limb-1)] > LIMB_MAX) round_up = TRUE;
695 else if(2*b->data[bnum_idx(b, round_limb-1)] == LIMB_MAX) {
696 for(r = round_limb-2; r >= b->b; r--) {
697 if(b->data[bnum_idx(b, r)]) {
698 round_up = TRUE;
699 break;
700 }
701 }
702
703 if(!round_up) round_up = b->data[bnum_idx(b, round_limb)] & 1;
704 }
705 }
706 b->b = round_limb;
707
708 if(round_up) {
709 b->data[bnum_idx(b, b->b)] += p10s[round_pos];
710 for(i = b->b; i < b->e; i++) {
711 if(b->data[bnum_idx(b, i)] < LIMB_MAX) break;
712
713 b->data[bnum_idx(b, i)] -= LIMB_MAX;
714 if(i+1 < b->e) b->data[bnum_idx(b, i+1)]++;
715 else b->data[bnum_idx(b, i+1)] = 1;
716 }
717 if(i == b->e-1) {
718 if(!b->data[bnum_idx(b, b->e-1)])
719 i = 1;
720 else
721 i = log10i(b->data[bnum_idx(b, b->e-1)]) + 1;
722 if(i != first_limb_len) {
723 first_limb_len = i;
724 radix_pos++;
725
726 round_pos++;
727 if (round_pos == LIMB_DIGITS)
728 {
729 round_pos = 0;
730 round_limb++;
731 }
732 }
733 } else if(i == b->e) {
734 first_limb_len = 1;
735 radix_pos++;
736 b->e++;
737
738 round_pos++;
739 if (round_pos == LIMB_DIGITS)
740 {
741 round_pos = 0;
742 round_limb++;
743 }
744 }
745 }
746 }
747 else if(b->e <= round_limb) { /* got 0 or 1 after rounding */
748 if(b->e == round_limb) {
749 if(!standard_rounding) round_up = b->data[bnum_idx(b, b->e-1)] >= LIMB_MAX/2;
750 else if(b->data[bnum_idx(b, b->e-1)] > LIMB_MAX/2) round_up = TRUE;
751 else if(b->data[bnum_idx(b, b->e-1)] == LIMB_MAX/2) {
752 for(r = b->e-2; r >= b->b; r--) {
753 if(b->data[bnum_idx(b, r)]) {
754 round_up = TRUE;
755 break;
756 }
757 }
758 }
759 }
760
761 b->data[bnum_idx(b, round_limb)] = round_up;
762 b->b = round_limb;
763 b->e = b->b + 1;
764 first_limb_len = 1;
765 radix_pos++;
766 }
767
768 if(flags->Format=='g' || flags->Format=='G') {
769 trim_tail = TRUE;
770
771 if(radix_pos>=-3 && radix_pos<=flags->Precision) {
772 flags->Format -= 1;
773 if(!flags->Precision) flags->Precision++;
774 flags->Precision -= radix_pos;
775 } else {
776 flags->Format -= 2;
777 if(flags->Precision > 0) flags->Precision--;
778 }
779 }
780
781 if(trim_tail && !flags->Alternate) {
782 for(i=round_limb; flags->Precision>0 && i<b->e; i++) {
783 if(i>=b->b)
784 l = b->data[bnum_idx(b, i)];
785 else
786 l = 0;
787
788 if(i == round_limb) {
789 if(flags->Format=='f' || flags->Format=='F')
790 r = radix_pos + flags->Precision;
791 else
792 r = flags->Precision + 1;
793 r = first_limb_len + LIMB_DIGITS * (b->e-1 - b->b) - r;
794 r %= LIMB_DIGITS;
795 if(r < 0) r += LIMB_DIGITS;
796 l /= p10s[r];
797 limb_len = LIMB_DIGITS - r;
798 } else {
799 limb_len = LIMB_DIGITS;
800 }
801
802 if(!l) {
803 flags->Precision -= limb_len;
804 } else {
805 while(l % 10 == 0) {
806 flags->Precision--;
807 l /= 10;
808 }
809 }
810
811 if(flags->Precision <= 0) {
812 flags->Precision = 0;
813 break;
814 }
815 if(l)
816 break;
817 }
818 }
819
820 len = flags->Precision;
821 if(flags->Precision || flags->Alternate) len++;
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') {
825 radix_pos--;
826 if(!trim_tail || radix_pos) {
827 len += 3; /* strlen("1e+") */
828 if(three_digit_exp || radix_pos<-99 || radix_pos>99) len += 3;
829 else len += 2;
830 } else {
831 len++;
832 }
833 }
834
835 r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, TRUE);
836 if(r < 0) return r;
837 ret = r;
838
839 f.Format = 'd';
840 f.PadZero = TRUE;
841 if(flags->Format=='f' || flags->Format=='F') {
842 if(radix_pos <= 0) {
843 buf[0] = '0';
844 r = pf_puts(puts_ctx, 1, buf);
845 if(r < 0) return r;
846 ret += r;
847 }
848
849 limb_len = LIMB_DIGITS;
850 for(i=b->e-1; radix_pos>0 && i>=b->b; i--) {
851 limb_len = (i == b->e-1 ? first_limb_len : LIMB_DIGITS);
852 l = b->data[bnum_idx(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;
857 } else {
858 f.Precision = limb_len;
859 limb_len = LIMB_DIGITS;
860 }
861 radix_pos -= f.Precision;
863
864 r = pf_puts(puts_ctx, f.Precision, buf);
865 if(r < 0) return r;
866 ret += r;
867 }
868
869 buf[0] = '0';
870 for(; radix_pos>0; radix_pos--) {
871 r = pf_puts(puts_ctx, 1, buf);
872 if(r < 0) return r;
873 ret += r;
874 }
875
876 if(flags->Precision || flags->Alternate) {
877 buf[0] = *(locale ? locale->locinfo : get_locinfo())->lconv->decimal_point;
878 r = pf_puts(puts_ctx, 1, buf);
879 if(r < 0) return r;
880 ret += r;
881 }
882
883 prec = flags->Precision;
884 buf[0] = '0';
885 for(; prec>0 && radix_pos+LIMB_DIGITS-first_limb_len<0; radix_pos++, prec--) {
886 r = pf_puts(puts_ctx, 1, buf);
887 if(r < 0) return r;
888 ret += r;
889 }
890
891 for(; prec>0 && i>=b->b; i--) {
892 l = b->data[bnum_idx(b, i)];
893 if(limb_len != LIMB_DIGITS)
894 l %= p10s[limb_len];
895 if(limb_len > prec) {
896 f.Precision = prec;
897 l /= p10s[limb_len - prec];
898 } else {
899 f.Precision = limb_len;
900 limb_len = LIMB_DIGITS;
901 }
902 prec -= f.Precision;
904
905 r = pf_puts(puts_ctx, f.Precision, buf);
906 if(r < 0) return r;
907 ret += r;
908 }
909
910 buf[0] = '0';
911 for(; prec>0; prec--) {
912 r = pf_puts(puts_ctx, 1, buf);
913 if(r < 0) return r;
914 ret += r;
915 }
916 } else {
917 l = b->data[bnum_idx(b, b->e - 1)];
918 l /= p10s[first_limb_len - 1];
919
920 buf[0] = '0' + l;
921 r = pf_puts(puts_ctx, 1, buf);
922 if(r < 0) return r;
923 ret += r;
924
925 if(flags->Precision || flags->Alternate) {
926 buf[0] = *(locale ? locale->locinfo : get_locinfo())->lconv->decimal_point;
927 r = pf_puts(puts_ctx, 1, buf);
928 if(r < 0) return r;
929 ret += r;
930 }
931
932 prec = flags->Precision;
933 limb_len = LIMB_DIGITS;
934 for(i=b->e-1; prec>0 && i>=b->b; i--) {
935 l = b->data[bnum_idx(b, i)];
936 if(i == b->e-1) {
937 limb_len = first_limb_len - 1;
938 l %= p10s[limb_len];
939 }
940
941 if(limb_len > prec) {
942 f.Precision = prec;
943 l /= p10s[limb_len - prec];
944 } else {
945 f.Precision = limb_len;
946 limb_len = LIMB_DIGITS;
947 }
948 prec -= f.Precision;
950
951 r = pf_puts(puts_ctx, f.Precision, buf);
952 if(r < 0) return r;
953 ret += r;
954 }
955
956 buf[0] = '0';
957 for(; prec>0; prec--) {
958 r = pf_puts(puts_ctx, 1, buf);
959 if(r < 0) return r;
960 ret += r;
961 }
962
963 if(!trim_tail || radix_pos) {
964 buf[0] = flags->Format;
965 buf[1] = radix_pos < 0 ? '-' : '+';
966 r = pf_puts(puts_ctx, 2, buf);
967 if(r < 0) return r;
968 ret += r;
969
970 f.Precision = three_digit_exp ? 3 : 2;
971 FUNC_NAME(pf_integer_conv)(buf, &f, radix_pos);
972 r = pf_puts(puts_ctx, f.Precision, buf);
973 if(r < 0) return r;
974 ret += r;
975 }
976 }
977
978 r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, FALSE);
979 if(r < 0) return r;
980 ret += r;
981 return ret;
982}
983
984int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const APICHAR *fmt,
986 args_clbk pf_args, void *args_ctx, va_list *valist)
987{
988 const APICHAR *q, *p = fmt;
989 APICHAR buf[32];
990 int written = 0, pos, i;
992 BOOL positional_params = options & MSVCRT_PRINTF_POSITIONAL_PARAMS;
993 BOOL invoke_invalid_param_handler = options & MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER;
994#if _MSVCR_VER >= 140
999#else
1000 BOOL legacy_wide = TRUE, legacy_msvcrt_compat = TRUE;
1001 BOOL three_digit_exp = _get_output_format() != _TWO_DIGIT_EXPONENT;
1002 BOOL standard_rounding = FALSE;
1003#endif
1004
1005 if (!MSVCRT_CHECK_PMT(fmt != NULL))
1006 return -1;
1007
1008 while(*p) {
1009 /* output characters before '%' */
1010 for(q=p; *q && *q!='%'; q++);
1011 if(p != q) {
1012 i = pf_puts(puts_ctx, q-p, p);
1013 if(i < 0)
1014 return i;
1015
1016 written += i;
1017 p = q;
1018 continue;
1019 }
1020
1021 /* *p == '%' here */
1022 p++;
1023
1024 /* output a single '%' character */
1025 if(*p == '%') {
1026 i = pf_puts(puts_ctx, 1, p++);
1027 if(i < 0)
1028 return i;
1029
1030 written += i;
1031 continue;
1032 }
1033
1034 /* check parameter position */
1035 if(positional_params && (q = FUNC_NAME(pf_parse_int)(p, &pos)) && *q=='$')
1036 p = q+1;
1037 else
1038 pos = -1;
1039
1040 /* parse the flags */
1041 memset(&flags, 0, sizeof(flags));
1042 while(*p) {
1043 if(*p=='+' || *p==' ') {
1044 if(flags.Sign != '+')
1045 flags.Sign = *p;
1046 } else if(*p == '-')
1047 flags.LeftAlign = TRUE;
1048 else if(*p == '0')
1049 flags.PadZero = TRUE;
1050 else if(*p == '#')
1051 flags.Alternate = TRUE;
1052 else
1053 break;
1054
1055 p++;
1056 }
1057
1058 /* parse the width */
1059 if(*p == '*') {
1060 p++;
1061 if(positional_params && (q = FUNC_NAME(pf_parse_int)(p, &i)) && *q=='$')
1062 p = q+1;
1063 else
1064 i = -1;
1065
1066 flags.FieldLength = pf_args(args_ctx, i, VT_INT, valist).get_int;
1067 if(flags.FieldLength < 0) {
1068 flags.LeftAlign = TRUE;
1069 flags.FieldLength = -flags.FieldLength;
1070 }
1071 }
1072
1073#if _MSVCR_VER >= 140
1074 if (*p >= '0' && *p <= '9')
1075 flags.FieldLength = 0;
1076#endif
1077
1078 while (*p >= '0' && *p <= '9') {
1079 flags.FieldLength *= 10;
1080 flags.FieldLength += *p++ - '0';
1081 }
1082
1083 /* parse the precision */
1084 flags.Precision = -1;
1085 if(*p == '.') {
1086 flags.Precision = 0;
1087 p++;
1088 if(*p == '*') {
1089 p++;
1090 if(positional_params && (q = FUNC_NAME(pf_parse_int)(p, &i)) && *q=='$')
1091 p = q+1;
1092 else
1093 i = -1;
1094
1095 flags.Precision = pf_args(args_ctx, i, VT_INT, valist).get_int;
1096 } else while (*p >= '0' && *p <= '9') {
1097 flags.Precision *= 10;
1098 flags.Precision += *p++ - '0';
1099 }
1100 }
1101
1102 /* parse argument size modifier */
1103 while(*p) {
1104 if(*p=='l' && *(p+1)=='l') {
1105 flags.IntegerDouble = TRUE;
1106 p++;
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') {
1113 flags.IntegerDouble = TRUE;
1114 p += 2;
1115 } else if(*(p+1)=='3' && *(p+2)=='2')
1116 p += 2;
1117 else if(p[1] && strchr("diouxX", p[1]))
1118 flags.IntegerNative = TRUE;
1119 else
1120 break;
1121 } else if(*p == 'w')
1122 flags.WideString = TRUE;
1123#if _MSVCR_VER == 0 || _MSVCR_VER >= 140
1124 else if((*p == 'z' || *p == 't') && p[1] && strchr("diouxX", p[1]))
1125 flags.IntegerNative = TRUE;
1126 else if(*p == 'j')
1127 flags.IntegerDouble = TRUE;
1128#endif
1129#if _MSVCR_VER >= 140
1130 else if(*p == 'T')
1131 flags.NaturalString = TRUE;
1132#endif
1133 else if(*p != 'L' && ((*p != 'F' && *p != 'N') || !legacy_msvcrt_compat))
1134 break;
1135 p++;
1136 }
1137
1138 flags.Format = *p;
1139
1140 if(flags.Format == 's' || flags.Format == 'S') {
1141 i = FUNC_NAME(pf_handle_string)(pf_puts, puts_ctx,
1142 pf_args(args_ctx, pos, VT_PTR, valist).get_ptr,
1143 -1, &flags, locale, legacy_wide);
1144 } else if(flags.Format == 'c' || flags.Format == 'C') {
1145 int ch = pf_args(args_ctx, pos, VT_INT, valist).get_int;
1146
1147 i = FUNC_NAME(pf_handle_string)(pf_puts, puts_ctx, &ch, 1, &flags, locale, legacy_wide);
1148 if(i < 0) i = 0; /* ignore conversion error */
1149 } else if(flags.Format == 'p') {
1150 flags.Format = 'X';
1151 flags.PadZero = TRUE;
1152 i = flags.Precision;
1153 flags.Precision = 2*sizeof(void*);
1155 (ULONG_PTR)pf_args(args_ctx, pos, VT_PTR, valist).get_ptr);
1156 flags.PadZero = FALSE;
1157 flags.Precision = i;
1158
1159#ifdef PRINTF_WIDE
1160 i = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, buf, -1, &flags, locale);
1161#else
1162 i = FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, buf, -1, &flags, locale);
1163#endif
1164 } else if(flags.Format == 'n') {
1165 int *used;
1166
1167 if(!n_format_enabled) {
1168 MSVCRT_INVALID_PMT("\'n\' format specifier disabled", EINVAL);
1169 return -1;
1170 }
1171
1172 used = pf_args(args_ctx, pos, VT_PTR, valist).get_ptr;
1173 *used = written;
1174 i = 0;
1175 } else if(flags.Format && strchr("diouxX", flags.Format)) {
1176 APICHAR *tmp = buf;
1177 int max_len;
1178
1179 /* 0 padding is added after '0x' if Alternate flag is in use */
1180 if((flags.Format=='x' || flags.Format=='X') && flags.PadZero && flags.Alternate
1181 && !flags.LeftAlign && flags.Precision<flags.FieldLength-2)
1182 flags.Precision = flags.FieldLength - 2;
1183
1184 max_len = (flags.FieldLength>flags.Precision ? flags.FieldLength : flags.Precision) + 10;
1185 if(max_len > ARRAY_SIZE(buf))
1186 tmp = HeapAlloc(GetProcessHeap(), 0, max_len);
1187 if(!tmp)
1188 return -1;
1189
1190 if(flags.IntegerDouble || (flags.IntegerNative && sizeof(void*) == 8))
1191 FUNC_NAME(pf_integer_conv)(tmp, &flags, pf_args(args_ctx, pos,
1192 VT_I8, valist).get_longlong);
1193 else if(flags.Format=='d' || flags.Format=='i')
1195 flags.IntegerLength != LEN_SHORT ?
1196 pf_args(args_ctx, pos, VT_INT, valist).get_int :
1197 (short)pf_args(args_ctx, pos, VT_INT, valist).get_int);
1198 else
1200 flags.IntegerLength != LEN_SHORT ?
1201 (unsigned)pf_args(args_ctx, pos, VT_INT, valist).get_int :
1202 (unsigned short)pf_args(args_ctx, pos, VT_INT, valist).get_int);
1203
1204#ifdef PRINTF_WIDE
1205 i = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, tmp, -1, &flags, locale);
1206#else
1207 i = FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, tmp, -1, &flags, locale);
1208#endif
1209 if(tmp != buf)
1210 HeapFree(GetProcessHeap(), 0, tmp);
1211 } else if(flags.Format && strchr("aAeEfFgG", flags.Format)) {
1212 double val = pf_args(args_ctx, pos, VT_R8, valist).get_double;
1213
1214 if(signbit(val)) {
1215 flags.Sign = '-';
1216 val = -val;
1217 }
1218
1219 if(isinf(val) || isnan(val))
1220 i = FUNC_NAME(pf_output_special_fp)(pf_puts, puts_ctx, val, &flags,
1221 locale, legacy_msvcrt_compat, three_digit_exp);
1222 else if(flags.Format=='a' || flags.Format=='A')
1223 i = FUNC_NAME(pf_output_hex_fp)(pf_puts, puts_ctx, val, &flags,
1224 locale, standard_rounding);
1225 else
1226 i = FUNC_NAME(pf_output_fp)(pf_puts, puts_ctx, val, &flags,
1227 locale, three_digit_exp, standard_rounding);
1228 } else {
1229 if(invoke_invalid_param_handler) {
1231 *_errno() = EINVAL;
1232 return -1;
1233 }
1234
1235 continue;
1236 }
1237
1238 if(i < 0)
1239 return i;
1240 written += i;
1241 p++;
1242 }
1243
1244 return written;
1245}
1246
1247#ifndef PRINTF_WIDE
1254
1255/* This functions stores types of arguments. It uses args[0] internally */
1257{
1258 static const printf_arg ret;
1259 printf_arg *args = ctx;
1260
1261 if(pos == -1) {
1262 args[0].get_int |= TYPE_CLBK_VA_LIST;
1263 return ret;
1264 } else
1265 args[0].get_int |= TYPE_CLBK_POSITIONAL;
1266
1267 if(pos<1 || pos>_ARGMAX)
1268 args[0].get_int |= TYPE_CLBK_ERROR_POS;
1269 else if(args[pos].get_int && args[pos].get_int!=type)
1270 args[0].get_int |= TYPE_CLBK_ERROR_TYPE;
1271 else
1272 args[pos].get_int = type;
1273
1274 return ret;
1275}
1276#endif
1277
1279{
1280 struct FUNC_NAME(_str_ctx) puts_ctx = {INT_MAX, NULL};
1281 printf_arg *args = args_ctx;
1282 int i, j;
1283
1286 if(i < 0)
1287 return i;
1288
1289 if(args[0].get_int==0 || args[0].get_int==TYPE_CLBK_VA_LIST)
1290 return 0;
1292 return -1;
1293
1294 for(i=_ARGMAX; i>0; i--)
1295 if(args[i].get_int)
1296 break;
1297
1298 for(j=1; j<=i; j++) {
1299 switch(args[j].get_int) {
1300 case VT_I8:
1301 args[j].get_longlong = va_arg(valist, LONGLONG);
1302 break;
1303 case VT_INT:
1304 args[j].get_int = va_arg(valist, int);
1305 break;
1306 case VT_R8:
1307 args[j].get_double = va_arg(valist, double);
1308 break;
1309 case VT_PTR:
1310 args[j].get_ptr = va_arg(valist, void*);
1311 break;
1312 default:
1313 return -1;
1314 }
1315 }
1316
1317 return j;
1318}
1319
1320#undef APICHAR
1321#undef CONVCHAR
1322#undef FUNC_NAME
static int used
Definition: adh-main.c:39
#define ARRAY_SIZE(A)
Definition: main.h:20
static const int p10s[]
Definition: bnum.h:25
#define EXP_BITS
Definition: bnum.h:22
#define MANT_BITS
Definition: bnum.h:23
static BOOL bnum_lshift(struct bnum *b, int shift)
Definition: bnum.h:47
#define BNUM_PREC64
Definition: bnum.h:30
#define LIMB_DIGITS
Definition: bnum.h:27
#define LIMB_MAX
Definition: bnum.h:28
static int bnum_idx(struct bnum *b, int idx)
Definition: bnum.h:41
static BOOL bnum_rshift(struct bnum *b, int shift)
Definition: bnum.h:79
r l[0]
Definition: byte_order.h:168
Definition: _locale.h:75
static int get_int(D3DXPARAMETER_TYPE type, const void *data)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
@ VT_INT
Definition: compat.h:2316
@ VT_PTR
Definition: compat.h:2320
@ VT_R8
Definition: compat.h:2300
@ VT_I8
Definition: compat.h:2314
unsigned char ch[4][2]
Definition: console.c:118
void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t arg)
Definition: errno.c:461
int *CDECL _errno(void)
Definition: errno.c:215
#define _ARGMAX
Definition: corecrt.h:157
#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)
Definition: mbcs.c:3161
_ACRTIMP int __cdecl _wctomb_l(char *, wchar_t, _locale_t)
Definition: wcs.c:2147
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
_ACRTIMP size_t __cdecl wcsnlen(const wchar_t *, size_t)
Definition: wcs.c:2920
#define EINVAL
Definition: errno.h:44
#define MB_LEN_MAX
Definition: limits.h:7
#define INT_MAX
Definition: limits.h:26
#define isinf(x)
Definition: math.h:359
#define isnan(x)
Definition: math.h:360
#define signbit(x)
Definition: math.h:362
_ACRTIMP double __cdecl frexp(double, int *)
Definition: frexp.c:14
#define va_arg(v, l)
Definition: stdarg.h:27
#define _TWO_DIGIT_EXPONENT
Definition: stdio.h:68
_ACRTIMP unsigned int __cdecl _get_output_format(void)
Definition: misc.c:401
_ACRTIMP int __cdecl mblen(const char *, size_t)
Definition: mbcs.c:3087
_ACRTIMP char *__cdecl strchr(const char *, int)
Definition: string.c:3286
_ACRTIMP size_t __cdecl strnlen(const char *, size_t)
Definition: string.c:1602
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
char * va_list
Definition: vadefs.h:50
#define MSVCRT_PRINTF_POSITIONAL_PARAMS
Definition: msvcrt.h:409
#define MSVCRT_INVALID_PMT(x, err)
Definition: msvcrt.h:376
#define MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER
Definition: msvcrt.h:410
printf_arg(* args_clbk)(void *, int, int, va_list *)
Definition: msvcrt.h:389
#define MSVCRT_CHECK_PMT(x)
Definition: msvcrt.h:378
static BOOL n_format_enabled
Definition: wcs.c:49
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLdouble * v
Definition: gl.h:2040
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat f
Definition: glext.h:7540
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLint left
Definition: glext.h:7726
GLbitfield flags
Definition: glext.h:7161
GLuint GLfloat * val
Definition: glext.h:7180
GLuint64EXT * result
Definition: glext.h:11304
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
const GLfloat * m
Definition: glext.h:10848
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
Definition: glfuncs.h:248
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
Definition: glfuncs.h:250
static const int digits[]
Definition: decode.c:71
#define e
Definition: ke_i.h:82
#define f
Definition: ke_i.h:83
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static va_list valist
Definition: printf.c:46
static unsigned(__cdecl *hash_bstr)(bstr_t s)
#define shift
Definition: input.c:1755
DWORD exp
Definition: msg.c:16058
int k
Definition: mpi.c:3369
#define DWORD
Definition: nt_native.h:44
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)
Definition: printf.h:228
static unsigned int log10i(unsigned int x)
Definition: printf.h:146
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)
Definition: printf.h:283
static int wcstombs_len(char *mbstr, const wchar_t *wcstr, int len, _locale_t locale)
Definition: printf.h:111
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)
Definition: printf.h:154
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)
Definition: printf.h:258
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)
Definition: printf.h:984
types_clbk_flags
Definition: printf.h:1248
@ TYPE_CLBK_VA_LIST
Definition: printf.h:1249
@ TYPE_CLBK_ERROR_TYPE
Definition: printf.h:1252
@ TYPE_CLBK_POSITIONAL
Definition: printf.h:1250
@ TYPE_CLBK_ERROR_POS
Definition: printf.h:1251
static int FUNC_NAME() puts_clbk_str(void *ctx, int len, const APICHAR *str)
Definition: printf.h:36
static int mbstowcs_len(wchar_t *wcstr, const char *mbstr, int len, _locale_t locale)
Definition: printf.h:125
#define APICHAR
Definition: printf.h:26
int FUNC_NAME() create_positional_ctx(void *args_ctx, const APICHAR *format, va_list valist)
Definition: printf.h:1278
static unsigned int log2i(unsigned int x)
Definition: printf.h:139
static int FUNC_NAME() pf_output_str(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const char *str, int len, _locale_t locale)
Definition: printf.h:176
static printf_arg arg_clbk_type(void *ctx, int pos, int type, va_list *valist)
Definition: printf.h:1256
static const APICHAR *FUNC_NAME() pf_parse_int(const APICHAR *fmt, int *val)
Definition: printf.h:56
#define FUNC_NAME(func)
Definition: printf.h:28
static int FUNC_NAME() pf_fill(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, int len, pf_flags *flags, BOOL left)
Definition: printf.h:69
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)
Definition: printf.h:198
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)
Definition: printf.h:603
static void FUNC_NAME() pf_integer_conv(APICHAR *buf, pf_flags *flags, LONGLONG x)
Definition: printf.h:544
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)
Definition: printf.h:412
const WCHAR * str
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask)
Definition: intrin_arm.h:180
#define memset(x, y, z)
Definition: compat.h:39
Definition: match.c:390
Definition: bnum.h:34
Definition: dsound.c:943
Definition: format.c:58
Definition: locale.h:37
char * decimal_point
Definition: locale.h:38
Definition: wcs.c:41
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
int64_t LONGLONG
Definition: typedefs.h:68
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#define get_locinfo()
Definition: winesup.h:25
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char * LPSTR
Definition: xmlstorage.h:182
unsigned char BYTE
Definition: xxhash.c:193