Reactos

[CONUTILS] Diverse improvements: start doxygenating and add some resource messsage helper functions.

- Start to doxygenate the library, focusing in great details on the
functions of the "outstream" module.
- Add a K32LoadStringEx function that expands (K32)LoadString by
allowing a LanguageId parameter to be able to load strings from other
languages than the current one.
- Add "ConResMsg*" helper functions to be able to (format and) print
message strings with inserts that come *NOT* from a message table (as
usual) *BUT* from resource string tables.
Will be helpful for CORE-14265 in particular.

[CMD] Fix the call to ConMsgPrintfV().

+981 -79
+1 -1
base/shell/cmd/console.c
··· 141 141 NULL, 142 142 MessageId, 143 143 LANG_USER_DEFAULT, 144 - arg_ptr); 144 + &arg_ptr); 145 145 va_end(arg_ptr); 146 146 147 147 if (Len <= 0)
+15
sdk/lib/conutils/conutils.h
··· 8 8 * Copyright 2017-2018 Hermes Belusca-Maito 9 9 */ 10 10 11 + /** 12 + * @file conutils.h 13 + * @ingroup ConUtils 14 + * 15 + * @defgroup ConUtils ReactOS Console Utilities Library 16 + * 17 + * @brief This library contains common functions used in many places inside 18 + * the ReactOS console utilities and the ReactOS Command-Line Interpreter. 19 + * Most of these functions are related with internationalisation and 20 + * the problem of correctly displaying Unicode text on the console. 21 + * Besides those, helpful functions for retrieving strings and messages 22 + * from application resources are provided, together with printf-like 23 + * functionality. 24 + **/ 25 + 11 26 #ifndef __CONUTILS_H__ 12 27 #define __CONUTILS_H__ 13 28
+7 -4
sdk/lib/conutils/instream.c
··· 8 8 * Copyright 2017-2018 Hermes Belusca-Maito 9 9 */ 10 10 11 + /** 12 + * @file instream.c 13 + * @ingroup ConUtils 14 + * 15 + * @brief Console I/O utility API -- Input 16 + **/ 17 + 11 18 /* 12 19 * Enable this define if you want to only use CRT functions to output 13 20 * UNICODE stream to the console, as in the way explained by ··· 41 48 #include "stream.h" 42 49 #include "stream_private.h" 43 50 44 - 45 - /* 46 - * Console I/O utility API -- Input 47 - */ 48 51 49 52 /* EOF */
+7 -4
sdk/lib/conutils/instream.h
··· 8 8 * Copyright 2017-2018 Hermes Belusca-Maito 9 9 */ 10 10 11 + /** 12 + * @file instream.h 13 + * @ingroup ConUtils 14 + * 15 + * @brief Console I/O utility API -- Input 16 + **/ 17 + 11 18 #ifndef __INSTREAM_H__ 12 19 #define __INSTREAM_H__ 13 20 ··· 31 38 32 39 // Shadow type, implementation-specific 33 40 typedef struct _CON_STREAM CON_STREAM, *PCON_STREAM; 34 - 35 - /* 36 - * Console I/O utility API -- Input 37 - */ 38 41 39 42 40 43 #ifdef __cplusplus
+777 -31
sdk/lib/conutils/outstream.c
··· 8 8 * Copyright 2017-2018 Hermes Belusca-Maito 9 9 */ 10 10 11 + /** 12 + * @file outstream.c 13 + * @ingroup ConUtils 14 + * 15 + * @brief Console I/O utility API -- Output 16 + **/ 17 + 11 18 /* 12 19 * Enable this define if you want to only use CRT functions to output 13 20 * UNICODE stream to the console, as in the way explained by ··· 51 58 // #define MAX_MESSAGE_SIZE 512 // See shutdown... 52 59 53 60 54 - /* 55 - * Console I/O utility API -- Output 56 - */ 57 - 58 - // NOTE: Should be called with the stream locked. 61 + /** 62 + * @name ConWrite 63 + * Writes a counted string to a stream. 64 + * 65 + * @param[in] Stream 66 + * Stream to which the write operation is issued. 67 + * 68 + * @param[in] szStr 69 + * Pointer to the counted string to write. 70 + * 71 + * @param[in] len 72 + * Length of the string pointed by @p szStr, specified 73 + * in number of characters. 74 + * 75 + * @return 76 + * Numbers of characters successfully written to @p Stream. 77 + * 78 + * @note 79 + * This function is used as an internal function. 80 + * Use the ConStreamWrite() function instead. 81 + * 82 + * @remark 83 + * Should be called with the stream locked. 84 + **/ 59 85 INT 60 86 __stdcall 61 87 ConWrite( 62 88 IN PCON_STREAM Stream, 63 89 IN PTCHAR szStr, 64 - IN DWORD len) 90 + IN DWORD len) 65 91 { 66 92 #ifndef USE_CRT 67 93 DWORD TotalLen = len, dwNumBytes = 0; ··· 339 365 #endif 340 366 341 367 368 + /** 369 + * @name ConStreamWrite 370 + * Writes a counted string to a stream. 371 + * 372 + * @param[in] Stream 373 + * Stream to which the write operation is issued. 374 + * 375 + * @param[in] szStr 376 + * Pointer to the counted string to write. 377 + * 378 + * @param[in] len 379 + * Length of the string pointed by @p szStr, specified 380 + * in number of characters. 381 + * 382 + * @return 383 + * Numbers of characters successfully written to @p Stream. 384 + **/ 342 385 INT 343 386 ConStreamWrite( 344 387 IN PCON_STREAM Stream, 345 388 IN PTCHAR szStr, 346 - IN DWORD len) 389 + IN DWORD len) 347 390 { 348 391 INT Len; 349 392 CON_STREAM_WRITE2(Stream, szStr, len, Len); 350 393 return Len; 351 394 } 352 395 396 + /** 397 + * @name ConPuts 398 + * Writes a NULL-terminated string to a stream. 399 + * 400 + * @param[in] Stream 401 + * Stream to which the write operation is issued. 402 + * 403 + * @param[in] szStr 404 + * Pointer to the NULL-terminated string to write. 405 + * 406 + * @return 407 + * Numbers of characters successfully written to @p Stream. 408 + * 409 + * @remark 410 + * Contrary to the CRT puts() function, ConPuts() does not append 411 + * a terminating new-line character. In this way it behaves more like 412 + * the CRT fputs() function. 413 + **/ 353 414 INT 354 415 ConPuts( 355 416 IN PCON_STREAM Stream, ··· 367 428 return Len; 368 429 } 369 430 431 + /** 432 + * @name ConPrintfV 433 + * Formats and writes a NULL-terminated string to a stream. 434 + * 435 + * @param[in] Stream 436 + * Stream to which the write operation is issued. 437 + * 438 + * @param[in] szStr 439 + * Pointer to the NULL-terminated format string, that follows the same 440 + * specifications as the @a szStr format string in ConPrintf(). 441 + * 442 + * @param[in] args 443 + * Parameter describing a variable number of arguments, 444 + * initialized with va_start(), that can be expected by the function, 445 + * depending on the @p szStr format string. Each argument is used to 446 + * replace a <em>format specifier</em> in the format string. 447 + * 448 + * @return 449 + * Numbers of characters successfully written to @p Stream. 450 + * 451 + * @see ConPrintf(), printf(), vprintf() 452 + **/ 370 453 INT 371 454 ConPrintfV( 372 455 IN PCON_STREAM Stream, 373 456 IN LPWSTR szStr, 374 - IN va_list args) // arg_ptr 457 + IN va_list args) 375 458 { 376 459 INT Len; 377 460 WCHAR bufSrc[CON_RC_STRING_MAX_SIZE]; ··· 396 479 return Len; 397 480 } 398 481 482 + /** 483 + * @name ConPrintf 484 + * Formats and writes a NULL-terminated string to a stream. 485 + * 486 + * @param[in] Stream 487 + * Stream to which the write operation is issued. 488 + * 489 + * @param[in] szStr 490 + * Pointer to the NULL-terminated format string, that follows the same 491 + * specifications as the @a format string in printf(). This string can 492 + * optionally contain embedded <em>format specifiers</em> that are 493 + * replaced by the values specified in subsequent additional arguments 494 + * and formatted as requested. 495 + * 496 + * @param[in] ... 497 + * Additional arguments that can be expected by the function, depending 498 + * on the @p szStr format string. Each argument is used to replace a 499 + * <em>format specifier</em> in the format string. 500 + * 501 + * @return 502 + * Numbers of characters successfully written to @p Stream. 503 + * 504 + * @see ConPrintfV(), printf(), vprintf() 505 + **/ 399 506 INT 400 507 __cdecl 401 508 ConPrintf( ··· 416 523 return Len; 417 524 } 418 525 526 + /** 527 + * @name ConResPutsEx 528 + * Writes a string resource to a stream. 529 + * 530 + * @param[in] Stream 531 + * Stream to which the write operation is issued. 532 + * 533 + * @param[in] hInstance 534 + * Optional handle to an instance of the module whose executable file 535 + * contains the string resource. Can be set to NULL to get the handle 536 + * to the application itself. 537 + * 538 + * @param[in] uID 539 + * The identifier of the string to be written. 540 + * 541 + * @param[in] LanguageId 542 + * The language identifier of the resource. If this parameter is 543 + * <tt>MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)</tt>, the current language 544 + * associated with the calling thread is used. To specify a language other 545 + * than the current language, use the @c MAKELANGID macro to create this 546 + * parameter. 547 + * 548 + * @return 549 + * Numbers of characters successfully written to @p Stream. 550 + * 551 + * @remark 552 + * Similarly to ConPuts(), no terminating new-line character is appended. 553 + * 554 + * @see ConPuts(), ConResPuts() 555 + **/ 419 556 INT 420 557 ConResPutsEx( 421 558 IN PCON_STREAM Stream, 422 559 IN HINSTANCE hInstance OPTIONAL, 423 - IN UINT uID) 560 + IN UINT uID, 561 + IN LANGID LanguageId) 424 562 { 425 563 INT Len; 426 564 PWCHAR szStr = NULL; 427 565 428 - Len = K32LoadStringW(hInstance, uID, (PWSTR)&szStr, 0); 566 + Len = K32LoadStringExW(hInstance, uID, LanguageId, (PWSTR)&szStr, 0); 429 567 if (szStr && Len) 430 568 // Len = ConPuts(Stream, szStr); 431 569 CON_STREAM_WRITE2(Stream, szStr, Len, Len); ··· 437 575 return Len; 438 576 } 439 577 578 + /** 579 + * @name ConResPuts 580 + * Writes a string resource contained in the current application 581 + * to a stream. 582 + * 583 + * @param[in] Stream 584 + * Stream to which the write operation is issued. 585 + * 586 + * @param[in] uID 587 + * The identifier of the string to be written. 588 + * 589 + * @return 590 + * Numbers of characters successfully written to @p Stream. 591 + * 592 + * @remark 593 + * Similarly to ConPuts(), no terminating new-line character is appended. 594 + * 595 + * @see ConPuts(), ConResPutsEx() 596 + **/ 440 597 INT 441 598 ConResPuts( 442 599 IN PCON_STREAM Stream, 443 600 IN UINT uID) 444 601 { 445 - return ConResPutsEx(Stream, NULL /*GetModuleHandleW(NULL)*/, uID); 602 + return ConResPutsEx(Stream, NULL /*GetModuleHandleW(NULL)*/, 603 + uID, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 446 604 } 447 605 606 + /** 607 + * @name ConResPrintfExV 608 + * Formats and writes a string resource to a stream. 609 + * 610 + * @param[in] Stream 611 + * Stream to which the write operation is issued. 612 + * 613 + * @param[in] hInstance 614 + * Optional handle to an instance of the module whose executable file 615 + * contains the string resource. Can be set to NULL to get the handle 616 + * to the application itself. 617 + * 618 + * @param[in] uID 619 + * The identifier of the format string. The format string follows the 620 + * same specifications as the @a szStr format string in ConPrintf(). 621 + * 622 + * @param[in] LanguageId 623 + * The language identifier of the resource. If this parameter is 624 + * <tt>MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)</tt>, the current language 625 + * associated with the calling thread is used. To specify a language other 626 + * than the current language, use the @c MAKELANGID macro to create this 627 + * parameter. 628 + * 629 + * @param[in] args 630 + * Parameter describing a variable number of arguments, 631 + * initialized with va_start(), that can be expected by the function, 632 + * depending on the @p szStr format string. Each argument is used to 633 + * replace a <em>format specifier</em> in the format string. 634 + * 635 + * @return 636 + * Numbers of characters successfully written to @p Stream. 637 + * 638 + * @see ConPrintf(), ConResPrintfEx(), ConResPrintfV(), ConResPrintf() 639 + **/ 448 640 INT 449 641 ConResPrintfExV( 450 642 IN PCON_STREAM Stream, 451 643 IN HINSTANCE hInstance OPTIONAL, 452 644 IN UINT uID, 453 - IN va_list args) // arg_ptr 645 + IN LANGID LanguageId, 646 + IN va_list args) 454 647 { 455 648 INT Len; 456 649 WCHAR bufSrc[CON_RC_STRING_MAX_SIZE]; 457 650 458 651 // NOTE: We may use the special behaviour where nBufMaxSize == 0 459 - Len = K32LoadStringW(hInstance, uID, bufSrc, ARRAYSIZE(bufSrc)); 652 + Len = K32LoadStringExW(hInstance, uID, LanguageId, bufSrc, ARRAYSIZE(bufSrc)); 460 653 if (Len) 461 654 Len = ConPrintfV(Stream, bufSrc, args); 462 655 463 656 return Len; 464 657 } 465 658 659 + /** 660 + * @name ConResPrintfV 661 + * Formats and writes a string resource contained in the 662 + * current application to a stream. 663 + * 664 + * @param[in] Stream 665 + * Stream to which the write operation is issued. 666 + * 667 + * @param[in] uID 668 + * The identifier of the format string. The format string follows the 669 + * same specifications as the @a szStr format string in ConPrintf(). 670 + * 671 + * @param[in] args 672 + * Parameter describing a variable number of arguments, 673 + * initialized with va_start(), that can be expected by the function, 674 + * depending on the @p szStr format string. Each argument is used to 675 + * replace a <em>format specifier</em> in the format string. 676 + * 677 + * @return 678 + * Numbers of characters successfully written to @p Stream. 679 + * 680 + * @see ConPrintf(), ConResPrintfExV(), ConResPrintfEx(), ConResPrintf() 681 + **/ 466 682 INT 467 683 ConResPrintfV( 468 684 IN PCON_STREAM Stream, 469 685 IN UINT uID, 470 - IN va_list args) // arg_ptr 686 + IN va_list args) 471 687 { 472 - return ConResPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/, uID, args); 688 + return ConResPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/, 689 + uID, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), 690 + args); 473 691 } 474 692 693 + /** 694 + * @name ConResPrintfEx 695 + * Formats and writes a string resource to a stream. 696 + * 697 + * @param[in] Stream 698 + * Stream to which the write operation is issued. 699 + * 700 + * @param[in] hInstance 701 + * Optional handle to an instance of the module whose executable file 702 + * contains the string resource. Can be set to NULL to get the handle 703 + * to the application itself. 704 + * 705 + * @param[in] uID 706 + * The identifier of the format string. The format string follows the 707 + * same specifications as the @a szStr format string in ConPrintf(). 708 + * 709 + * @param[in] LanguageId 710 + * The language identifier of the resource. If this parameter is 711 + * <tt>MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)</tt>, the current language 712 + * associated with the calling thread is used. To specify a language other 713 + * than the current language, use the @c MAKELANGID macro to create this 714 + * parameter. 715 + * 716 + * @param[in] ... 717 + * Additional arguments that can be expected by the function, depending 718 + * on the @p szStr format string. Each argument is used to replace a 719 + * <em>format specifier</em> in the format string. 720 + * 721 + * @return 722 + * Numbers of characters successfully written to @p Stream. 723 + * 724 + * @see ConPrintf(), ConResPrintfExV(), ConResPrintfV(), ConResPrintf() 725 + **/ 475 726 INT 476 727 __cdecl 477 728 ConResPrintfEx( 478 729 IN PCON_STREAM Stream, 479 730 IN HINSTANCE hInstance OPTIONAL, 480 - IN UINT uID, 731 + IN UINT uID, 732 + IN LANGID LanguageId, 481 733 ...) 482 734 { 483 735 INT Len; 484 736 va_list args; 485 737 486 - va_start(args, uID); 487 - Len = ConResPrintfExV(Stream, hInstance, uID, args); 738 + va_start(args, LanguageId); 739 + Len = ConResPrintfExV(Stream, hInstance, uID, LanguageId, args); 488 740 va_end(args); 489 741 490 742 return Len; 491 743 } 492 744 745 + /** 746 + * @name ConResPrintf 747 + * Formats and writes a string resource contained in the 748 + * current application to a stream. 749 + * 750 + * @param[in] Stream 751 + * Stream to which the write operation is issued. 752 + * 753 + * @param[in] uID 754 + * The identifier of the format string. The format string follows the 755 + * same specifications as the @a szStr format string in ConPrintf(). 756 + * 757 + * @param[in] ... 758 + * Additional arguments that can be expected by the function, depending 759 + * on the @p szStr format string. Each argument is used to replace a 760 + * <em>format specifier</em> in the format string. 761 + * 762 + * @return 763 + * Numbers of characters successfully written to @p Stream. 764 + * 765 + * @see ConPrintf(), ConResPrintfExV(), ConResPrintfEx(), ConResPrintfV() 766 + **/ 493 767 INT 494 768 __cdecl 495 769 ConResPrintf( ··· 507 781 return Len; 508 782 } 509 783 784 + /** 785 + * @name ConMsgPuts 786 + * Writes a message string to a stream without formatting. The function 787 + * requires a message definition as input. The message definition can come 788 + * from a buffer passed to the function. It can come from a message table 789 + * resource in an already-loaded module, or the caller can ask the function 790 + * to search the system's message table resource(s) for the message definition. 791 + * Please refer to the Win32 FormatMessage() function for more details. 792 + * 793 + * @param[in] Stream 794 + * Stream to which the write operation is issued. 795 + * 796 + * @param[in] dwFlags 797 + * The formatting options, and how to interpret the @p lpSource parameter. 798 + * See FormatMessage() for more details. The @b@c FORMAT_MESSAGE_ALLOCATE_BUFFER 799 + * and @b@c FORMAT_MESSAGE_ARGUMENT_ARRAY flags are always ignored. 800 + * The function implicitly uses the @b@c FORMAT_MESSAGE_IGNORE_INSERTS and 801 + * @b@c FORMAT_MESSAGE_MAX_WIDTH_MASK flags to implement its behaviour. 802 + * 803 + * @param[in] lpSource 804 + * The location of the message definition. The type of this parameter 805 + * depends upon the settings in the @p dwFlags parameter. 806 + * 807 + * @param[in] dwMessageId 808 + * The message identifier for the requested message. This parameter 809 + * is ignored if @p dwFlags includes @b@c FORMAT_MESSAGE_FROM_STRING. 810 + * 811 + * @param[in] dwLanguageId 812 + * The language identifier for the requested message. This parameter 813 + * is ignored if @p dwFlags includes @b@c FORMAT_MESSAGE_FROM_STRING. 814 + * 815 + * @return 816 + * Numbers of characters successfully written to @p Stream. 817 + * 818 + * @remark 819 + * Similarly to ConPuts(), no terminating new-line character is appended. 820 + * 821 + * @see ConPuts(), ConResPuts() and associated functions, 822 + * <a href="FormatMessage() (on MSDN)">https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx</a> 823 + **/ 510 824 INT 511 825 ConMsgPuts( 512 826 IN PCON_STREAM Stream, ··· 521 835 522 836 /* 523 837 * Sanitize dwFlags. This version always ignore explicitely the inserts 524 - * as we emulate the behaviour of the *puts function. 838 + * as we emulate the behaviour of the (f)puts function. 525 839 */ 526 840 dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer. 527 841 dwFlags |= FORMAT_MESSAGE_IGNORE_INSERTS; // Ignore inserts for FormatMessage. ··· 540 854 dwMessageId, 541 855 dwLanguageId, 542 856 (LPWSTR)&lpMsgBuf, 543 - 0, NULL); 857 + 0, 858 + NULL); 544 859 } 545 860 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 546 861 { ··· 572 887 return Len; 573 888 } 574 889 890 + /** 891 + * @name ConMsgPrintf2V 892 + * Formats and writes a message string to a stream. 893 + * 894 + * @remark For internal use only. 895 + * 896 + * @see ConMsgPrintfV() 897 + **/ 575 898 INT 576 899 ConMsgPrintf2V( 577 900 IN PCON_STREAM Stream, ··· 579 902 IN LPCVOID lpSource OPTIONAL, 580 903 IN DWORD dwMessageId, 581 904 IN DWORD dwLanguageId, 582 - IN va_list args) // arg_ptr 905 + IN va_list args) 583 906 { 584 907 INT Len; 585 908 DWORD dwLength = 0; ··· 606 929 dwMessageId, 607 930 dwLanguageId, 608 931 (LPWSTR)&lpMsgBuf, 609 - 0, NULL); 932 + 0, 933 + NULL); 610 934 } 611 935 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 612 936 { ··· 638 962 return Len; 639 963 } 640 964 965 + /** 966 + * @name ConMsgPrintfV 967 + * Formats and writes a message string to a stream. The function requires 968 + * a message definition as input. The message definition can come from a 969 + * buffer passed to the function. It can come from a message table resource 970 + * in an already-loaded module, or the caller can ask the function to search 971 + * the system's message table resource(s) for the message definition. 972 + * Please refer to the Win32 FormatMessage() function for more details. 973 + * 974 + * @param[in] Stream 975 + * Stream to which the write operation is issued. 976 + * 977 + * @param[in] dwFlags 978 + * The formatting options, and how to interpret the @p lpSource parameter. 979 + * See FormatMessage() for more details. The @b@c FORMAT_MESSAGE_ALLOCATE_BUFFER 980 + * flags is always ignored. The function implicitly uses the 981 + * @b@c FORMAT_MESSAGE_MAX_WIDTH_MASK flag to implement its behaviour. 982 + * 983 + * @param[in] lpSource 984 + * The location of the message definition. The type of this parameter 985 + * depends upon the settings in the @p dwFlags parameter. 986 + * 987 + * @param[in] dwMessageId 988 + * The message identifier for the requested message. This parameter 989 + * is ignored if @p dwFlags includes @b@c FORMAT_MESSAGE_FROM_STRING. 990 + * 991 + * @param[in] dwLanguageId 992 + * The language identifier for the requested message. This parameter 993 + * is ignored if @p dwFlags includes @b@c FORMAT_MESSAGE_FROM_STRING. 994 + * 995 + * @param[in] Arguments 996 + * Optional pointer to an array of values describing a variable number of 997 + * arguments, depending on the message string. Each argument is used to 998 + * replace an <em>insert sequence</em> in the message string. 999 + * By default, the @p Arguments parameter is of type @c va_list*, initialized 1000 + * with va_start(). The state of the @c va_list argument is undefined upon 1001 + * return from the function. To use the @c va_list again, destroy the variable 1002 + * argument list pointer using va_end() and reinitialize it with va_start(). 1003 + * If you do not have a pointer of type @c va_list*, then specify the 1004 + * @b@c FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array 1005 + * of @c DWORD_PTR values; those values are input to the message formatted 1006 + * as the insert values. Each insert must have a corresponding element in 1007 + * the array. 1008 + * 1009 + * @remark 1010 + * Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, 1011 + * the ConMsg* functions work on format strings that contain <em>insert sequences</em>. 1012 + * These sequences extend the standard <em>format specifiers</em> as they 1013 + * allow to specify an <em>insert number</em> referring which precise value 1014 + * given in arguments to use. 1015 + * 1016 + * @return 1017 + * Numbers of characters successfully written to @p Stream. 1018 + * 1019 + * @see ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), 1020 + * <a href="FormatMessage() (on MSDN)">https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx</a> 1021 + **/ 641 1022 INT 642 1023 ConMsgPrintfV( 643 1024 IN PCON_STREAM Stream, ··· 645 1026 IN LPCVOID lpSource OPTIONAL, 646 1027 IN DWORD dwMessageId, 647 1028 IN DWORD dwLanguageId, 648 - IN va_list args) // arg_ptr 1029 + IN va_list *Arguments OPTIONAL) 649 1030 { 650 1031 INT Len; 651 1032 DWORD dwLength = 0; ··· 653 1034 654 1035 /* Sanitize dwFlags */ 655 1036 dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer. 656 - // dwFlags &= ~FORMAT_MESSAGE_IGNORE_INSERTS; // We always use arguments. 657 - dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY; // We always use arguments of type 'va_list'. 658 - 659 1037 // 660 1038 // NOTE: Technique taken from eventvwr.c!GetMessageStringFromDll() 661 1039 // 662 - 663 1040 dwFlags |= FORMAT_MESSAGE_MAX_WIDTH_MASK; 664 1041 665 1042 /* ··· 672 1049 dwMessageId, 673 1050 dwLanguageId, 674 1051 (LPWSTR)&lpMsgBuf, 675 - 0, &args); 1052 + 0, 1053 + Arguments); 676 1054 677 1055 Len = (INT)dwLength; 678 1056 ··· 684 1062 { 685 1063 // ASSERT(dwLength != 0); 686 1064 687 - // Len = ConPrintfV(Stream, lpMsgBuf, args); 688 1065 CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len); 689 1066 690 1067 /* Fixup returned length in case of errors */ ··· 698 1075 return Len; 699 1076 } 700 1077 1078 + /** 1079 + * @name ConMsgPrintf 1080 + * Formats and writes a message string to a stream. The function requires 1081 + * a message definition as input. The message definition can come from a 1082 + * buffer passed to the function. It can come from a message table resource 1083 + * in an already-loaded module, or the caller can ask the function to search 1084 + * the system's message table resource(s) for the message definition. 1085 + * Please refer to the Win32 FormatMessage() function for more details. 1086 + * 1087 + * @param[in] Stream 1088 + * Stream to which the write operation is issued. 1089 + * 1090 + * @param[in] dwFlags 1091 + * The formatting options, and how to interpret the @p lpSource parameter. 1092 + * See FormatMessage() for more details. The @b@c FORMAT_MESSAGE_ALLOCATE_BUFFER 1093 + * and @b@c FORMAT_MESSAGE_ARGUMENT_ARRAY flags are always ignored. 1094 + * The function implicitly uses the @b@c FORMAT_MESSAGE_MAX_WIDTH_MASK flag 1095 + * to implement its behaviour. 1096 + * 1097 + * @param[in] lpSource 1098 + * The location of the message definition. The type of this parameter 1099 + * depends upon the settings in the @p dwFlags parameter. 1100 + * 1101 + * @param[in] dwMessageId 1102 + * The message identifier for the requested message. This parameter 1103 + * is ignored if @p dwFlags includes @b@c FORMAT_MESSAGE_FROM_STRING. 1104 + * 1105 + * @param[in] dwLanguageId 1106 + * The language identifier for the requested message. This parameter 1107 + * is ignored if @p dwFlags includes @b@c FORMAT_MESSAGE_FROM_STRING. 1108 + * 1109 + * @param[in] ... 1110 + * Additional arguments that can be expected by the function, depending 1111 + * on the message string. Each argument is used to replace an 1112 + * <em>insert sequence</em> in the message string. 1113 + * 1114 + * @remark 1115 + * Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, 1116 + * the ConMsg* functions work on format strings that contain <em>insert sequences</em>. 1117 + * These sequences extend the standard <em>format specifiers</em> as they 1118 + * allow to specify an <em>insert number</em> referring which precise value 1119 + * given in arguments to use. 1120 + * 1121 + * @return 1122 + * Numbers of characters successfully written to @p Stream. 1123 + * 1124 + * @see ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintfV(), 1125 + * <a href="FormatMessage() (on MSDN)">https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx</a> 1126 + **/ 701 1127 INT 702 1128 __cdecl 703 1129 ConMsgPrintf( ··· 710 1136 { 711 1137 INT Len; 712 1138 va_list args; 1139 + 1140 + /* Sanitize dwFlags */ 1141 + dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY; 713 1142 714 1143 va_start(args, dwLanguageId); 715 - // ConMsgPrintf2V 716 1144 Len = ConMsgPrintfV(Stream, 717 1145 dwFlags, 718 1146 lpSource, 719 1147 dwMessageId, 720 1148 dwLanguageId, 721 - args); 1149 + &args); 1150 + va_end(args); 1151 + 1152 + return Len; 1153 + } 1154 + 1155 + /** 1156 + * @name ConResMsgPrintfExV 1157 + * Formats and writes a message string to a stream. The function requires 1158 + * a message definition as input. Contrary to the ConMsg* or the Win32 1159 + * FormatMessage() functions, the message definition comes from a resource 1160 + * string table, much like the strings for ConResPrintf(), but is formatted 1161 + * according to the rules of ConMsgPrintf(). 1162 + * 1163 + * @param[in] Stream 1164 + * Stream to which the write operation is issued. 1165 + * 1166 + * @param[in] hInstance 1167 + * Optional handle to an instance of the module whose executable file 1168 + * contains the string resource. Can be set to NULL to get the handle 1169 + * to the application itself. 1170 + * 1171 + * @param[in] dwFlags 1172 + * The formatting options, see FormatMessage() for more details. 1173 + * The only valid flags are @b@c FORMAT_MESSAGE_ARGUMENT_ARRAY and 1174 + * @b@c FORMAT_MESSAGE_IGNORE_INSERTS. All the other flags are internally 1175 + * overridden by the function to implement its behaviour. 1176 + * 1177 + * @param[in] uID 1178 + * The identifier of the message string. The format string follows the 1179 + * same specifications as the @a lpSource format string in ConMsgPrintf(). 1180 + * 1181 + * @param[in] LanguageId 1182 + * The language identifier of the resource. If this parameter is 1183 + * <tt>MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)</tt>, the current language 1184 + * associated with the calling thread is used. To specify a language other 1185 + * than the current language, use the @c MAKELANGID macro to create this 1186 + * parameter. 1187 + * 1188 + * @param[in] args 1189 + * Parameter describing a variable number of arguments, initialized 1190 + * with va_start(), that can be expected by the function, depending 1191 + * on the message string. Each argument is used to replace an 1192 + * <em>insert sequence</em> in the message string. 1193 + * 1194 + * @remark 1195 + * Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, 1196 + * the ConMsg* functions work on format strings that contain <em>insert sequences</em>. 1197 + * These sequences extend the standard <em>format specifiers</em> as they 1198 + * allow to specify an <em>insert number</em> referring which precise value 1199 + * given in arguments to use. 1200 + * 1201 + * @return 1202 + * Numbers of characters successfully written to @p Stream. 1203 + * 1204 + * @see ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), 1205 + * <a href="FormatMessage() (on MSDN)">https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx</a> 1206 + **/ 1207 + INT 1208 + ConResMsgPrintfExV( 1209 + IN PCON_STREAM Stream, 1210 + IN HINSTANCE hInstance OPTIONAL, 1211 + IN DWORD dwFlags, 1212 + IN UINT uID, 1213 + IN LANGID LanguageId, 1214 + IN va_list *Arguments OPTIONAL) 1215 + { 1216 + INT Len; 1217 + DWORD dwLength = 0; 1218 + LPWSTR lpMsgBuf = NULL; 1219 + WCHAR bufSrc[CON_RC_STRING_MAX_SIZE]; 1220 + 1221 + /* Retrieve the string from the resource string table */ 1222 + // NOTE: We may use the special behaviour where nBufMaxSize == 0 1223 + Len = K32LoadStringExW(hInstance, uID, LanguageId, bufSrc, ARRAYSIZE(bufSrc)); 1224 + if (Len == 0) 1225 + return Len; 1226 + 1227 + /* Sanitize dwFlags */ 1228 + dwFlags |= FORMAT_MESSAGE_ALLOCATE_BUFFER; // Always allocate an internal buffer. 1229 + // 1230 + // NOTE: Technique taken from eventvwr.c!GetMessageStringFromDll() 1231 + // 1232 + dwFlags |= FORMAT_MESSAGE_MAX_WIDTH_MASK; 1233 + 1234 + /* The string has already been manually loaded */ 1235 + dwFlags &= ~(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM); 1236 + dwFlags |= FORMAT_MESSAGE_FROM_STRING; 1237 + 1238 + /* 1239 + * Retrieve the message string without appending extra newlines. 1240 + * Use the "safe" FormatMessage version (SEH-protected) to protect 1241 + * from invalid string parameters. 1242 + */ 1243 + dwLength = FormatMessageSafeW(dwFlags, 1244 + bufSrc, 1245 + 0, 0, 1246 + (LPWSTR)&lpMsgBuf, 1247 + 0, 1248 + Arguments); 1249 + 1250 + Len = (INT)dwLength; 1251 + 1252 + if (!lpMsgBuf) 1253 + { 1254 + // ASSERT(dwLength == 0); 1255 + } 1256 + else 1257 + { 1258 + // ASSERT(dwLength != 0); 1259 + 1260 + CON_STREAM_WRITE2(Stream, lpMsgBuf, dwLength, Len); 1261 + 1262 + /* Fixup returned length in case of errors */ 1263 + if (Len < 0) 1264 + Len = 0; 1265 + 1266 + /* Free the buffer allocated by FormatMessage */ 1267 + LocalFree(lpMsgBuf); 1268 + } 1269 + 1270 + return Len; 1271 + } 1272 + 1273 + /** 1274 + * @name ConResMsgPrintfV 1275 + * Formats and writes a message string to a stream. The function requires 1276 + * a message definition as input. Contrary to the ConMsg* or the Win32 1277 + * FormatMessage() functions, the message definition comes from a resource 1278 + * string table, much like the strings for ConResPrintf(), but is formatted 1279 + * according to the rules of ConMsgPrintf(). 1280 + * 1281 + * @param[in] Stream 1282 + * Stream to which the write operation is issued. 1283 + * 1284 + * @param[in] dwFlags 1285 + * The formatting options, see FormatMessage() for more details. 1286 + * The only valid flags are @b@c FORMAT_MESSAGE_ARGUMENT_ARRAY and 1287 + * @b@c FORMAT_MESSAGE_IGNORE_INSERTS. All the other flags are internally 1288 + * overridden by the function to implement its behaviour. 1289 + * 1290 + * @param[in] uID 1291 + * The identifier of the message string. The format string follows the 1292 + * same specifications as the @a lpSource format string in ConMsgPrintf(). 1293 + * 1294 + * @param[in] Arguments 1295 + * Optional pointer to an array of values describing a variable number of 1296 + * arguments, depending on the message string. Each argument is used to 1297 + * replace an <em>insert sequence</em> in the message string. 1298 + * By default, the @p Arguments parameter is of type @c va_list*, initialized 1299 + * with va_start(). The state of the @c va_list argument is undefined upon 1300 + * return from the function. To use the @c va_list again, destroy the variable 1301 + * argument list pointer using va_end() and reinitialize it with va_start(). 1302 + * If you do not have a pointer of type @c va_list*, then specify the 1303 + * @b@c FORMAT_MESSAGE_ARGUMENT_ARRAY flag and pass a pointer to an array 1304 + * of @c DWORD_PTR values; those values are input to the message formatted 1305 + * as the insert values. Each insert must have a corresponding element in 1306 + * the array. 1307 + * 1308 + * @remark 1309 + * Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, 1310 + * the ConMsg* functions work on format strings that contain <em>insert sequences</em>. 1311 + * These sequences extend the standard <em>format specifiers</em> as they 1312 + * allow to specify an <em>insert number</em> referring which precise value 1313 + * given in arguments to use. 1314 + * 1315 + * @return 1316 + * Numbers of characters successfully written to @p Stream. 1317 + * 1318 + * @see ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), 1319 + * <a href="FormatMessage() (on MSDN)">https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx</a> 1320 + **/ 1321 + INT 1322 + ConResMsgPrintfV( 1323 + IN PCON_STREAM Stream, 1324 + IN DWORD dwFlags, 1325 + IN UINT uID, 1326 + IN va_list *Arguments OPTIONAL) 1327 + { 1328 + return ConResMsgPrintfExV(Stream, NULL /*GetModuleHandleW(NULL)*/, 1329 + dwFlags, uID, 1330 + MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), 1331 + Arguments); 1332 + } 1333 + 1334 + /** 1335 + * @name ConResMsgPrintfEx 1336 + * Formats and writes a message string to a stream. The function requires 1337 + * a message definition as input. Contrary to the ConMsg* or the Win32 1338 + * FormatMessage() functions, the message definition comes from a resource 1339 + * string table, much like the strings for ConResPrintf(), but is formatted 1340 + * according to the rules of ConMsgPrintf(). 1341 + * 1342 + * @param[in] Stream 1343 + * Stream to which the write operation is issued. 1344 + * 1345 + * @param[in] hInstance 1346 + * Optional handle to an instance of the module whose executable file 1347 + * contains the string resource. Can be set to NULL to get the handle 1348 + * to the application itself. 1349 + * 1350 + * @param[in] dwFlags 1351 + * The formatting options, see FormatMessage() for more details. 1352 + * The only valid flag is @b@c FORMAT_MESSAGE_IGNORE_INSERTS. 1353 + * All the other flags are internally overridden by the function 1354 + * to implement its behaviour. 1355 + * 1356 + * @param[in] uID 1357 + * The identifier of the message string. The format string follows the 1358 + * same specifications as the @a lpSource format string in ConMsgPrintf(). 1359 + * 1360 + * @param[in] LanguageId 1361 + * The language identifier of the resource. If this parameter is 1362 + * <tt>MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)</tt>, the current language 1363 + * associated with the calling thread is used. To specify a language other 1364 + * than the current language, use the @c MAKELANGID macro to create this 1365 + * parameter. 1366 + * 1367 + * @param[in] ... 1368 + * Additional arguments that can be expected by the function, depending 1369 + * on the message string. Each argument is used to replace an 1370 + * <em>insert sequence</em> in the message string. 1371 + * 1372 + * @remark 1373 + * Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, 1374 + * the ConMsg* functions work on format strings that contain <em>insert sequences</em>. 1375 + * These sequences extend the standard <em>format specifiers</em> as they 1376 + * allow to specify an <em>insert number</em> referring which precise value 1377 + * given in arguments to use. 1378 + * 1379 + * @return 1380 + * Numbers of characters successfully written to @p Stream. 1381 + * 1382 + * @see ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), 1383 + * <a href="FormatMessage() (on MSDN)">https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx</a> 1384 + **/ 1385 + INT 1386 + __cdecl 1387 + ConResMsgPrintfEx( 1388 + IN PCON_STREAM Stream, 1389 + IN HINSTANCE hInstance OPTIONAL, 1390 + IN DWORD dwFlags, 1391 + IN UINT uID, 1392 + IN LANGID LanguageId, 1393 + ...) 1394 + { 1395 + INT Len; 1396 + va_list args; 1397 + 1398 + /* Sanitize dwFlags */ 1399 + dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY; 1400 + 1401 + va_start(args, LanguageId); 1402 + Len = ConResMsgPrintfExV(Stream, 1403 + hInstance, 1404 + dwFlags, 1405 + uID, 1406 + LanguageId, 1407 + &args); 1408 + va_end(args); 1409 + 1410 + return Len; 1411 + } 1412 + 1413 + /** 1414 + * @name ConResMsgPrintf 1415 + * Formats and writes a message string to a stream. The function requires 1416 + * a message definition as input. Contrary to the ConMsg* or the Win32 1417 + * FormatMessage() functions, the message definition comes from a resource 1418 + * string table, much like the strings for ConResPrintf(), but is formatted 1419 + * according to the rules of ConMsgPrintf(). 1420 + * 1421 + * @param[in] Stream 1422 + * Stream to which the write operation is issued. 1423 + * 1424 + * @param[in] dwFlags 1425 + * The formatting options, see FormatMessage() for more details. 1426 + * The only valid flag is @b@c FORMAT_MESSAGE_IGNORE_INSERTS. 1427 + * All the other flags are internally overridden by the function 1428 + * to implement its behaviour. 1429 + * 1430 + * @param[in] uID 1431 + * The identifier of the message string. The format string follows the 1432 + * same specifications as the @a lpSource format string in ConMsgPrintf(). 1433 + * 1434 + * @param[in] ... 1435 + * Additional arguments that can be expected by the function, depending 1436 + * on the message string. Each argument is used to replace an 1437 + * <em>insert sequence</em> in the message string. 1438 + * 1439 + * @remark 1440 + * Contrary to printf(), ConPrintf(), ConResPrintf() and associated functions, 1441 + * the ConMsg* functions work on format strings that contain <em>insert sequences</em>. 1442 + * These sequences extend the standard <em>format specifiers</em> as they 1443 + * allow to specify an <em>insert number</em> referring which precise value 1444 + * given in arguments to use. 1445 + * 1446 + * @return 1447 + * Numbers of characters successfully written to @p Stream. 1448 + * 1449 + * @see ConPrintf(), ConResPrintf() and associated functions, ConMsgPrintf(), 1450 + * <a href="FormatMessage() (on MSDN)">https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx</a> 1451 + **/ 1452 + INT 1453 + __cdecl 1454 + ConResMsgPrintf( 1455 + IN PCON_STREAM Stream, 1456 + IN DWORD dwFlags, 1457 + IN UINT uID, 1458 + ...) 1459 + { 1460 + INT Len; 1461 + va_list args; 1462 + 1463 + /* Sanitize dwFlags */ 1464 + dwFlags &= ~FORMAT_MESSAGE_ARGUMENT_ARRAY; 1465 + 1466 + va_start(args, uID); 1467 + Len = ConResMsgPrintfV(Stream, dwFlags, uID, &args); 722 1468 va_end(args); 723 1469 724 1470 return Len;
+53 -13
sdk/lib/conutils/outstream.h
··· 8 8 * Copyright 2017-2018 Hermes Belusca-Maito 9 9 */ 10 10 11 + /** 12 + * @file outstream.h 13 + * @ingroup ConUtils 14 + * 15 + * @brief Console I/O utility API -- Output 16 + **/ 17 + 11 18 #ifndef __OUTSTREAM_H__ 12 19 #define __OUTSTREAM_H__ 13 20 ··· 37 44 typedef INT (__stdcall *CON_WRITE_FUNC)(IN PCON_STREAM, IN PTCHAR, IN DWORD); 38 45 39 46 40 - /* 41 - * Console I/O utility API -- Output 42 - */ 43 - 44 47 INT 45 48 __stdcall 46 49 ConWrite( 47 50 IN PCON_STREAM Stream, 48 51 IN PTCHAR szStr, 49 - IN DWORD len); 52 + IN DWORD len); 50 53 51 54 INT 52 55 ConStreamWrite( 53 56 IN PCON_STREAM Stream, 54 57 IN PTCHAR szStr, 55 - IN DWORD len); 58 + IN DWORD len); 56 59 57 60 INT 58 61 ConPuts( ··· 63 66 ConPrintfV( 64 67 IN PCON_STREAM Stream, 65 68 IN LPWSTR szStr, 66 - IN va_list args); // arg_ptr 69 + IN va_list args); 67 70 68 71 INT 69 72 __cdecl ··· 76 79 ConResPutsEx( 77 80 IN PCON_STREAM Stream, 78 81 IN HINSTANCE hInstance OPTIONAL, 79 - IN UINT uID); 82 + IN UINT uID, 83 + IN LANGID LanguageId); 80 84 81 85 INT 82 86 ConResPuts( ··· 88 92 IN PCON_STREAM Stream, 89 93 IN HINSTANCE hInstance OPTIONAL, 90 94 IN UINT uID, 91 - IN va_list args); // arg_ptr 95 + IN LANGID LanguageId, 96 + IN va_list args); 92 97 93 98 INT 94 99 ConResPrintfV( 95 100 IN PCON_STREAM Stream, 96 101 IN UINT uID, 97 - IN va_list args); // arg_ptr 102 + IN va_list args); 98 103 99 104 INT 100 105 __cdecl 101 106 ConResPrintfEx( 102 107 IN PCON_STREAM Stream, 103 108 IN HINSTANCE hInstance OPTIONAL, 104 - IN UINT uID, 109 + IN UINT uID, 110 + IN LANGID LanguageId, 105 111 ...); 106 112 107 113 INT ··· 126 132 IN LPCVOID lpSource OPTIONAL, 127 133 IN DWORD dwMessageId, 128 134 IN DWORD dwLanguageId, 129 - IN va_list args); // arg_ptr 135 + IN va_list args); 130 136 131 137 INT 132 138 ConMsgPrintfV( ··· 135 141 IN LPCVOID lpSource OPTIONAL, 136 142 IN DWORD dwMessageId, 137 143 IN DWORD dwLanguageId, 138 - IN va_list args); // arg_ptr 144 + IN va_list *Arguments OPTIONAL); 139 145 140 146 INT 141 147 __cdecl ··· 145 151 IN LPCVOID lpSource OPTIONAL, 146 152 IN DWORD dwMessageId, 147 153 IN DWORD dwLanguageId, 154 + ...); 155 + 156 + INT 157 + ConResMsgPrintfExV( 158 + IN PCON_STREAM Stream, 159 + IN HINSTANCE hInstance OPTIONAL, 160 + IN DWORD dwFlags, 161 + IN UINT uID, 162 + IN LANGID LanguageId, 163 + IN va_list *Arguments OPTIONAL); 164 + 165 + INT 166 + ConResMsgPrintfV( 167 + IN PCON_STREAM Stream, 168 + IN DWORD dwFlags, 169 + IN UINT uID, 170 + IN va_list *Arguments OPTIONAL); 171 + 172 + INT 173 + __cdecl 174 + ConResMsgPrintfEx( 175 + IN PCON_STREAM Stream, 176 + IN HINSTANCE hInstance OPTIONAL, 177 + IN DWORD dwFlags, 178 + IN UINT uID, 179 + IN LANGID LanguageId, 180 + ...); 181 + 182 + INT 183 + __cdecl 184 + ConResMsgPrintf( 185 + IN PCON_STREAM Stream, 186 + IN DWORD dwFlags, 187 + IN UINT uID, 148 188 ...); 149 189 150 190
+7
sdk/lib/conutils/pager.c
··· 6 6 * Copyright 2017-2018 Hermes Belusca-Maito 7 7 */ 8 8 9 + /** 10 + * @file pager.c 11 + * @ingroup ConUtils 12 + * 13 + * @brief Console/terminal paging functionality. 14 + **/ 15 + 9 16 /* FIXME: Temporary HACK before we cleanly support UNICODE functions */ 10 17 #define UNICODE 11 18 #define _UNICODE
+7
sdk/lib/conutils/pager.h
··· 6 6 * Copyright 2017-2018 Hermes Belusca-Maito 7 7 */ 8 8 9 + /** 10 + * @file pager.h 11 + * @ingroup ConUtils 12 + * 13 + * @brief Console/terminal paging functionality. 14 + **/ 15 + 9 16 #ifndef __PAGER_H__ 10 17 #define __PAGER_H__ 11 18
+7
sdk/lib/conutils/screen.c
··· 6 6 * Copyright 2017-2018 Hermes Belusca-Maito 7 7 */ 8 8 9 + /** 10 + * @file screen.c 11 + * @ingroup ConUtils 12 + * 13 + * @brief Console/terminal screen management. 14 + **/ 15 + 9 16 /* FIXME: Temporary HACK before we cleanly support UNICODE functions */ 10 17 #define UNICODE 11 18 #define _UNICODE
+7
sdk/lib/conutils/screen.h
··· 6 6 * Copyright 2017-2018 Hermes Belusca-Maito 7 7 */ 8 8 9 + /** 10 + * @file screen.h 11 + * @ingroup ConUtils 12 + * 13 + * @brief Console/terminal screen management. 14 + **/ 15 + 9 16 #ifndef __SCREEN_H__ 10 17 #define __SCREEN_H__ 11 18
+7 -4
sdk/lib/conutils/stream.c
··· 8 8 * Copyright 2017-2018 Hermes Belusca-Maito 9 9 */ 10 10 11 + /** 12 + * @file stream.c 13 + * @ingroup ConUtils 14 + * 15 + * @brief Console I/O streams 16 + **/ 17 + 11 18 /* 12 19 * Enable this define if you want to only use CRT functions to output 13 20 * UNICODE stream to the console, as in the way explained by ··· 36 43 #include "stream.h" 37 44 #include "stream_private.h" 38 45 39 - 40 - /* 41 - * Console I/O streams 42 - */ 43 46 44 47 /* 45 48 * Standard console streams, initialized by
+7 -4
sdk/lib/conutils/stream.h
··· 8 8 * Copyright 2017-2018 Hermes Belusca-Maito 9 9 */ 10 10 11 + /** 12 + * @file stream.h 13 + * @ingroup ConUtils 14 + * 15 + * @brief Console I/O streams 16 + **/ 17 + 11 18 #ifndef __STREAM_H__ 12 19 #define __STREAM_H__ 13 20 ··· 28 35 #ifdef __cplusplus 29 36 extern "C" { 30 37 #endif 31 - 32 - /* 33 - * Console I/O streams 34 - */ 35 38 36 39 /* 37 40 * See http://archives.miloush.net/michkap/archive/2009/08/14/9869928.html
+63 -14
sdk/lib/conutils/utils.c
··· 7 7 * Copyright 2017-2018 Hermes Belusca-Maito 8 8 */ 9 9 10 + /** 11 + * @file utils.c 12 + * @ingroup ConUtils 13 + * 14 + * @brief General-purpose utility functions (wrappers around 15 + * or reimplementations of Win32 APIs). 16 + **/ 17 + 10 18 /* FIXME: Temporary HACK before we cleanly support UNICODE functions */ 11 19 #define UNICODE 12 20 #define _UNICODE ··· 24 32 // #include "conutils.h" 25 33 #include "utils.h" 26 34 27 - /* 28 - * General-purpose utility functions (wrappers around, 29 - * or reimplementations of, Win32 APIs). 30 - */ 31 - 32 35 #if 0 // The following function may be useful in the future... 33 36 34 37 // Performs MultiByteToWideChar then WideCharToMultiByte . ··· 55 58 */ 56 59 INT 57 60 WINAPI 58 - K32LoadStringW( 61 + K32LoadStringExW( 59 62 IN HINSTANCE hInstance OPTIONAL, 60 63 IN UINT uID, 64 + IN LANGID LanguageId, 61 65 OUT LPWSTR lpBuffer, 62 66 IN INT nBufferMax) 63 67 { ··· 71 75 72 76 /* Use LOWORD (incremented by 1) as ResourceID */ 73 77 /* There are always blocks of 16 strings */ 74 - // FindResourceExW(hInstance, RT_STRING, name, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); 75 - // NOTE: Instead of using LANG_NEUTRAL, one might use LANG_USER_DEFAULT... 76 - hrsrc = FindResourceW(hInstance, 77 - MAKEINTRESOURCEW((LOWORD(uID) >> 4) + 1), 78 - (LPWSTR)RT_STRING); 78 + hrsrc = FindResourceExW(hInstance, 79 + (LPCWSTR)RT_STRING, 80 + MAKEINTRESOURCEW((LOWORD(uID) >> 4) + 1), 81 + LanguageId); 79 82 if (!hrsrc) return 0; 80 83 81 84 hmem = LoadResource(hInstance, hrsrc); ··· 116 119 } 117 120 118 121 return i; 122 + } 123 + 124 + INT 125 + WINAPI 126 + K32LoadStringW( 127 + IN HINSTANCE hInstance OPTIONAL, 128 + IN UINT uID, 129 + OUT LPWSTR lpBuffer, 130 + IN INT nBufferMax) 131 + { 132 + // NOTE: Instead of using LANG_NEUTRAL, one might use LANG_USER_DEFAULT... 133 + return K32LoadStringExW(hInstance, uID, 134 + MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), 135 + lpBuffer, nBufferMax); 119 136 } 120 137 121 138 /* ··· 194 211 return dwLength; 195 212 } 196 213 214 + /** 215 + * @name IsTTYHandle 216 + * Checks whether a handle refers to a valid TTY object. 217 + * A TTY object may be a console or a "communications" (e.g. serial) port. 218 + * 219 + * @param[in] hHandle 220 + * Handle to the TTY object to check for. 221 + * 222 + * @return 223 + * @b@c TRUE when the handle refers to a valid TTY object, 224 + * @b@c FALSE if it does not. 225 + * 226 + * @remark 227 + * This test is more general than IsConsoleHandle() as it is not limited 228 + * to Win32 console objects only. 229 + * 230 + * @see IsConsoleHandle() 231 + **/ 197 232 BOOL 198 233 IsTTYHandle(IN HANDLE hHandle) 199 234 { 200 235 /* 201 - * More general test than IsConsoleHandle. Consoles, as well as 202 - * serial ports, etc... verify this test, but only consoles verify 203 - * the IsConsoleHandle test: indeed the latter checks whether 236 + * More general test than IsConsoleHandle(). Consoles, as well as serial 237 + * (communications) ports, etc... verify this test, but only consoles 238 + * verify the IsConsoleHandle() test: indeed the latter checks whether 204 239 * the handle is really handled by the console subsystem. 205 240 */ 206 241 return ((GetFileType(hHandle) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR); 207 242 } 208 243 244 + /** 245 + * @name IsConsoleHandle 246 + * Checks whether a handle refers to a valid Win32 console object. 247 + * 248 + * @param[in] hHandle 249 + * Handle to the Win32 console object to check for: 250 + * console input buffer, console output buffer. 251 + * 252 + * @return 253 + * @b@c TRUE when the handle refers to a valid Win32 console object, 254 + * @b@c FALSE if it does not. 255 + * 256 + * @see IsTTYHandle() 257 + **/ 209 258 BOOL 210 259 IsConsoleHandle(IN HANDLE hHandle) 211 260 {
+16 -4
sdk/lib/conutils/utils.h
··· 7 7 * Copyright 2017-2018 Hermes Belusca-Maito 8 8 */ 9 9 10 + /** 11 + * @file utils.h 12 + * @ingroup ConUtils 13 + * 14 + * @brief General-purpose utility functions (wrappers around 15 + * or reimplementations of Win32 APIs). 16 + **/ 17 + 10 18 #ifndef __UTILS_H__ 11 19 #define __UTILS_H__ 12 20 ··· 20 28 extern "C" { 21 29 #endif 22 30 23 - /* 24 - * General-purpose utility functions (wrappers around, 25 - * or reimplementations of, Win32 APIs). 26 - */ 31 + INT 32 + WINAPI 33 + K32LoadStringExW( 34 + IN HINSTANCE hInstance OPTIONAL, 35 + IN UINT uID, 36 + IN LANGID LanguageId, 37 + OUT LPWSTR lpBuffer, 38 + IN INT nBufferMax); 27 39 28 40 INT 29 41 WINAPI