ReactOS 0.4.15-dev-7842-g558ab78
printf_stubs.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>
Include dependency graph for printf_stubs.c:

Go to the source code of this file.

Functions

int __cdecl KmtWcToMb (char *mbchar, wchar_t wchar)
 
int __cdecl streamout (FILE *stream, const char *format, va_list argptr)
 
int __cdecl KmtVSNPrintF (char *buffer, size_t count, const char *format, va_list argptr)
 

Function Documentation

◆ KmtVSNPrintF()

int __cdecl KmtVSNPrintF ( char buffer,
size_t  count,
const char format,
va_list  argptr 
)

Definition at line 21 of file printf_stubs.c.

22{
23 int result;
25
26 stream._base = (char *)buffer;
27 stream._ptr = stream._base;
28 stream._charbuf = 0;
29 stream._cnt = (int)count;
30 stream._bufsiz = 0;
31 stream._flag = _IOSTRG | _IOWRT;
32 stream._tmpfname = 0;
33
34 result = streamout(&stream, format, argptr);
35
36 /* Only zero terminate if there is enough space left */
37 if (stream._cnt) *(char *)stream._ptr = '\0';
38
39 return result;
40}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLuint buffer
Definition: glext.h:5915
GLuint64EXT * result
Definition: glext.h:11304
#define _IOWRT
Definition: stdio.h:125
#define _IOSTRG
Definition: stdio.h:134
int __cdecl streamout(FILE *stream, const char *format, va_list argptr)
Definition: streamout.c:326
Definition: parse.h:23

◆ KmtWcToMb()

int __cdecl KmtWcToMb ( char mbchar,
wchar_t  wchar 
)

Definition at line 13 of file printf_stubs.c.

14{
15 *mbchar = (char)wchar;
16 return 1;
17}
unsigned char
Definition: typeof.h:29

◆ streamout()

int __cdecl streamout ( FILE stream,
const char format,
va_list  argptr 
)

Definition at line 326 of file streamout.c.

327{
328 static const TCHAR digits_l[] = _T("0123456789abcdef0x");
329 static const TCHAR digits_u[] = _T("0123456789ABCDEF0X");
330 static const char *_nullstring = "(null)";
332 TCHAR chr, *string;
333 STRING *nt_string;
334 const TCHAR *digits, *prefix;
335 int base, fieldwidth, precision, padding;
336 size_t prefixlen, len;
337 int written = 1, written_all = 0;
338 unsigned int flags;
339 unsigned __int64 val64;
340
341 buffer[BUFFER_SIZE] = '\0';
342
343 while (written >= 0)
344 {
345 chr = *format++;
346
347 /* Check for end of format string */
348 if (chr == _T('\0')) break;
349
350 /* Check for 'normal' character or double % */
351 if ((chr != _T('%')) ||
352 (chr = *format++) == _T('%'))
353 {
354 /* Write the character to the stream */
355 if ((written = streamout_char(stream, chr)) == 0) return -1;
356 written_all += written;
357 continue;
358 }
359
360 /* Handle flags */
361 flags = 0;
362 while (1)
363 {
364 if (chr == _T('-')) flags |= FLAG_ALIGN_LEFT;
365 else if (chr == _T('+')) flags |= FLAG_FORCE_SIGN;
366 else if (chr == _T(' ')) flags |= FLAG_FORCE_SIGNSP;
367 else if (chr == _T('0')) flags |= FLAG_PAD_ZERO;
368 else if (chr == _T('#')) flags |= FLAG_SPECIAL;
369 else break;
370 chr = *format++;
371 }
372
373 /* Handle field width modifier */
374 if (chr == _T('*'))
375 {
376#ifdef _USER32_WSPRINTF
377 if ((written = streamout_char(stream, chr)) == 0) return -1;
378 written_all += written;
379 continue;
380#else
381 fieldwidth = va_arg(argptr, int);
382 if (fieldwidth < 0)
383 {
385 fieldwidth = -fieldwidth;
386 }
387 chr = *format++;
388#endif
389 }
390 else
391 {
392 fieldwidth = 0;
393 while (chr >= _T('0') && chr <= _T('9'))
394 {
395 fieldwidth = fieldwidth * 10 + (chr - _T('0'));
396 chr = *format++;
397 }
398 }
399
400 /* Handle precision modifier */
401 if (chr == '.')
402 {
403 chr = *format++;
404
405 if (chr == _T('*'))
406 {
407#ifdef _USER32_WSPRINTF
408 if ((written = streamout_char(stream, chr)) == 0) return -1;
409 written_all += written;
410 continue;
411#else
412 precision = va_arg(argptr, int);
413 chr = *format++;
414#endif
415 }
416 else
417 {
418 precision = 0;
419 while (chr >= _T('0') && chr <= _T('9'))
420 {
421 precision = precision * 10 + (chr - _T('0'));
422 chr = *format++;
423 }
424 }
425 }
426 else precision = -1;
427
428 /* Handle argument size prefix */
429 do
430 {
431 if (chr == _T('h')) flags |= FLAG_SHORT;
432 else if (chr == _T('w')) flags |= FLAG_WIDECHAR;
433 else if (chr == _T('L')) flags |= 0; // FIXME: long double
434 else if (chr == _T('F')) flags |= 0; // FIXME: what is that?
435 else if (chr == _T('z') && *format && strchr("udxXion", *format))
436 {
438 }
439 else if (chr == _T('l'))
440 {
441 /* Check if this is the 2nd 'l' in a row */
442 if (format[-2] == 'l') flags |= FLAG_INT64;
443 else flags |= FLAG_LONG;
444 }
445 else if (chr == _T('I'))
446 {
447 if (format[0] == _T('3') && format[1] == _T('2'))
448 {
449 format += 2;
450 }
451 else if (format[0] == _T('6') && format[1] == _T('4'))
452 {
453 format += 2;
454 flags |= FLAG_INT64;
455 }
456 else if (format[0] == _T('x') || format[0] == _T('X') ||
457 format[0] == _T('d') || format[0] == _T('i') ||
458 format[0] == _T('u') || format[0] == _T('o'))
459 {
461 }
462 else break;
463 }
464 else break;
465 chr = *format++;
466 }
467 while (USE_MULTISIZE);
468
469 /* Handle the format specifier */
470 digits = digits_l;
471 string = &buffer[BUFFER_SIZE];
472 base = 10;
473 prefix = 0;
474 switch (chr)
475 {
476 case _T('n'):
478 *va_arg(argptr, __int64*) = written_all;
479 else if (flags & FLAG_SHORT)
480 *va_arg(argptr, short*) = written_all;
481 else
482 *va_arg(argptr, int*) = written_all;
483 continue;
484
485 case _T('C'):
486#ifndef _UNICODE
488#endif
489 goto case_char;
490
491 case _T('c'):
492#ifdef _UNICODE
494#endif
495 case_char:
496 string = buffer;
497 len = 1;
498 if (flags & FLAG_WIDECHAR)
499 {
500 ((wchar_t*)string)[0] = va_arg(argptr, int);
501 ((wchar_t*)string)[1] = _T('\0');
502 }
503 else
504 {
505 ((char*)string)[0] = va_arg(argptr, int);
506 ((char*)string)[1] = _T('\0');
507 }
508 break;
509
510 case _T('Z'):
511 nt_string = va_arg(argptr, void*);
512 if (nt_string && (string = nt_string->Buffer))
513 {
514 len = nt_string->Length;
515 if (flags & FLAG_WIDECHAR) len /= sizeof(wchar_t);
516 break;
517 }
518 string = 0;
519 goto case_string;
520
521 case _T('S'):
522 string = va_arg(argptr, void*);
523#ifndef _UNICODE
524 if (!(flags & FLAG_SHORT)) flags |= FLAG_WIDECHAR;
525#endif
526 goto case_string;
527
528 case _T('s'):
529 string = va_arg(argptr, void*);
530#ifdef _UNICODE
531 if (!(flags & FLAG_SHORT)) flags |= FLAG_WIDECHAR;
532#endif
533
534 case_string:
535 if (!string)
536 {
537 string = (TCHAR*)_nullstring;
538 flags &= ~FLAG_WIDECHAR;
539 }
540
541 if (flags & FLAG_WIDECHAR)
542 len = wcsnlen((wchar_t*)string, (unsigned)precision);
543 else
544 len = strnlen((char*)string, (unsigned)precision);
545 precision = 0;
546 break;
547
548#ifndef _USER32_WSPRINTF
549 case _T('G'):
550 case _T('E'):
551 case _T('A'):
552 case _T('g'):
553 case _T('e'):
554 case _T('a'):
555 case _T('f'):
556#ifdef _UNICODE
558#else
559 flags &= ~FLAG_WIDECHAR;
560#endif
561 /* Use external function, one for kernel one for user mode */
562 format_float(chr, flags, precision, &string, &prefix, &argptr);
563 len = _tcslen(string);
564 precision = 0;
565 break;
566#endif
567
568 case _T('d'):
569 case _T('i'):
570 val64 = (__int64)va_arg_f(argptr, flags);
571
572 if ((__int64)val64 < 0)
573 {
574 val64 = -(__int64)val64;
575 prefix = _T("-");
576 }
577 else if (flags & FLAG_FORCE_SIGN)
578 prefix = _T("+");
579 else if (flags & FLAG_FORCE_SIGNSP)
580 prefix = _T(" ");
581
582 goto case_number;
583
584 case _T('o'):
585 base = 8;
586 if (flags & FLAG_SPECIAL)
587 {
588 prefix = _T("0");
589 if (precision > 0) precision--;
590 }
591 goto case_unsigned;
592
593 case _T('p'):
594 precision = 2 * sizeof(void*);
595 flags &= ~FLAG_PAD_ZERO;
597 /* Fall through */
598
599 case _T('X'):
600 digits = digits_u;
601 /* Fall through */
602
603 case _T('x'):
604 base = 16;
605 if (flags & FLAG_SPECIAL)
606 {
607 prefix = &digits[16];
608#ifdef _USER32_WSPRINTF
609 fieldwidth += 2;
610#endif
611 }
612
613 case _T('u'):
614 case_unsigned:
615 val64 = va_arg_fu(argptr, flags);
616
617 case_number:
618#ifdef _UNICODE
620#else
621 flags &= ~FLAG_WIDECHAR;
622#endif
623 if (precision < 0) precision = 1;
624
625 /* Gather digits in reverse order */
626 while (val64)
627 {
628 *--string = digits[val64 % base];
629 val64 /= base;
630 precision--;
631 }
632
633 len = _tcslen(string);
634 break;
635
636 default:
637 /* Treat anything else as a new character */
638 format--;
639 continue;
640 }
641
642 /* Calculate padding */
643 prefixlen = prefix ? _tcslen(prefix) : 0;
644 if (precision < 0) precision = 0;
645 padding = (int)(fieldwidth - len - prefixlen - precision);
646 if (padding < 0) padding = 0;
647
648 /* Optional left space padding */
649 if ((flags & (FLAG_ALIGN_LEFT | FLAG_PAD_ZERO)) == 0)
650 {
651 for (; padding > 0; padding--)
652 {
653 if ((written = streamout_char(stream, _T(' '))) == 0) return -1;
654 written_all += written;
655 }
656 }
657
658 /* Optional prefix */
659 if (prefix)
660 {
661 written = streamout_string(stream, prefix, prefixlen);
662 if (written == -1) return -1;
663 written_all += written;
664 }
665
666 /* Optional left '0' padding */
667 if ((flags & FLAG_ALIGN_LEFT) == 0) precision += padding;
668 while (precision-- > 0)
669 {
670 if ((written = streamout_char(stream, _T('0'))) == 0) return -1;
671 written_all += written;
672 }
673
674 /* Output the string */
675 if (flags & FLAG_WIDECHAR)
676 written = streamout_wstring(stream, (wchar_t*)string, len);
677 else
678 written = streamout_astring(stream, (char*)string, len);
679 if (written == -1) return -1;
680 written_all += written;
681
682#if 0 && SUPPORT_FLOAT
683 /* Optional right '0' padding */
684 while (precision-- > 0)
685 {
686 if ((written = streamout_char(stream, _T('0'))) == 0) return -1;
687 written_all += written;
688 len++;
689 }
690#endif
691
692 /* Optional right padding */
694 {
695 while (padding-- > 0)
696 {
697 if ((written = streamout_char(stream, _T(' '))) == 0) return -1;
698 written_all += written;
699 }
700 }
701
702 }
703
704 if (written == -1) return -1;
705
706 return written_all;
707}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define __int64
Definition: basetyps.h:16
std::wstring STRING
Definition: fontsub.cpp:33
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
GLenum GLint GLint * precision
Definition: glext.h:7539
static const int digits[]
Definition: decode.c:71
if(dx< 0)
Definition: linetemp.h:194
char string[160]
Definition: util.h:11
static const DWORD padding[]
Definition: mciwnd.c:89
#define BUFFER_SIZE
Definition: streamout.c:23
#define USE_MULTISIZE
Definition: streamout.c:321
static int streamout_char(FILE *stream, int chr)
Definition: streamout.c:229
static int streamout_astring(FILE *stream, const char *string, size_t count)
Definition: streamout.c:252
#define va_arg_f(argptr, flags)
Definition: streamout.c:57
#define streamout_string
Definition: streamout.c:315
void format_float(TCHAR chr, unsigned int flags, int precision, TCHAR **string, const TCHAR **prefix, va_list *argptr)
Definition: streamout.c:82
@ FLAG_FORCE_SIGNSP
Definition: streamout.c:40
@ FLAG_INT64
Definition: streamout.c:48
@ FLAG_PAD_ZERO
Definition: streamout.c:41
@ FLAG_SHORT
Definition: streamout.c:45
@ FLAG_ALIGN_LEFT
Definition: streamout.c:38
@ FLAG_LONG
Definition: streamout.c:46
@ FLAG_INTPTR
Definition: streamout.c:52
@ FLAG_FORCE_SIGN
Definition: streamout.c:39
@ FLAG_SPECIAL
Definition: streamout.c:42
@ FLAG_WIDECHAR
Definition: streamout.c:47
static int streamout_wstring(FILE *stream, const wchar_t *string, size_t count)
Definition: streamout.c:280
#define va_arg_fu(argptr, flags)
Definition: streamout.c:62
#define _UNICODE
Definition: textw.c:5
#define wchar_t
Definition: wchar.h:102
#define _T(x)
Definition: vfdio.h:22
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
char TCHAR
Definition: xmlstorage.h:189
#define _tcslen
Definition: xmlstorage.h:198

Referenced by KmtVSNPrintF().