Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.0 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. #include "graftabl.h"
  7. /************************************************************************\
  8. *
  9. * FUNCTION: 32-bit version of GRAFTABL
  10. *
  11. * Syntax: GRAFTABL [XXX]
  12. * GRAFTABL /STATUS
  13. *
  14. * COMMENTS: This program changes only Console Output CP and
  15. * cannot change console (input) CP as normal GRAFTABL
  16. * in MS-DOS 5.0
  17. *
  18. * HISTORY: Jan. 4, 1993
  19. * YSt
  20. *
  21. * Copyright Microsoft Corp. 1993
  22. *
  23. \************************************************************************/
  24. void _cdecl main( int argc, char* argv[] )
  25. {
  26. int iCP, iPrevCP, iRet;
  27. char szArgv[128];
  28. TCHAR szSour[256];
  29. char szDest[256];
  30. #ifdef DBCS
  31. //bug fix #14165
  32. //fix kksuzuka: #988
  33. //Support billingual messages.
  34. iPrevCP = GetConsoleOutputCP();
  35. switch (iPrevCP)
  36. {
  37. case 932:
  38. case 936:
  39. case 949:
  40. case 950:
  41. SetThreadLocale(
  42. MAKELCID( MAKELANGID( PRIMARYLANGID(GetSystemDefaultLangID()),
  43. SUBLANG_ENGLISH_US ),
  44. SORT_DEFAULT ) );
  45. break;
  46. default:
  47. SetThreadLocale(
  48. MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ),
  49. SORT_DEFAULT ) );
  50. break;
  51. }
  52. #else // !DBCS
  53. iPrevCP = 0;
  54. #endif // DBCS
  55. if(argc > 1) {
  56. strncpy(szArgv, argv[1],127);
  57. szArgv[127]='\0';
  58. _strupr(szArgv);
  59. // Help option
  60. if(!strcmp(szArgv, "/?") || !strcmp(szArgv, "-?")) {
  61. iRet = LoadString(NULL, HELP_TEXT, szSour, sizeof(szSour)/sizeof(TCHAR));
  62. CharToOem(szSour, szDest);
  63. printf(szDest);
  64. exit(0);
  65. }
  66. // Status option
  67. else if(!strcmp(szArgv, "/STATUS") ||
  68. !strcmp(szArgv, "-STATUS") ||
  69. !strcmp(szArgv, "-STA") ||
  70. !strcmp(szArgv, "/STA")) {
  71. iRet = LoadString(NULL, ACTIVE_CP, szSour, sizeof(szSour)/sizeof(TCHAR));
  72. CharToOem(szSour, szDest);
  73. #ifdef DBCS
  74. if(iPrevCP == 932) {
  75. iRet = LoadString(NULL,NONE_CP, szSour, sizeof(szSour)/sizeof(TCHAR));
  76. printf("%ws", szDest);
  77. }
  78. else
  79. #endif // DBCS
  80. printf(szDest, GetConsoleOutputCP());
  81. exit(0);
  82. }
  83. // Change output CP
  84. else {
  85. #ifdef DBCS // v-junm - 08/11/93
  86. // Since Japanese DOS runs in graphics mode, this function is not supported.
  87. if(((iCP = atoi(szArgv)) < 1) || (iCP > 10000) || (iCP == 932)) {
  88. #else // !DBCS
  89. iPrevCP = GetConsoleOutputCP();
  90. if(((iCP = atoi(szArgv)) < 1) || (iCP > 10000)) {
  91. #endif // !DBCS
  92. iRet = LoadString(NULL, INVALID_SWITCH, szSour, sizeof(szSour)/sizeof(TCHAR));
  93. CharToOem(szSour, szDest);
  94. fprintf(stderr, szDest, argv[1]);
  95. exit(1);
  96. }
  97. if(!SetConsoleOutputCP(iCP)) {
  98. iRet = LoadString(NULL, NOT_ALLOWED, szSour, sizeof(szSour)/sizeof(TCHAR));
  99. CharToOem(szSour, szDest);
  100. fprintf(stderr, szDest, iCP);
  101. exit(2);
  102. }
  103. }
  104. #ifdef DBCS
  105. //bug fix #14165
  106. //fix kksuzuka: #988
  107. //Support billingual messages.
  108. switch (iCP)
  109. {
  110. case 932:
  111. case 936:
  112. case 949:
  113. case 950:
  114. SetThreadLocale(
  115. MAKELCID( MAKELANGID( PRIMARYLANGID(GetSystemDefaultLangID()),
  116. SUBLANG_ENGLISH_US ),
  117. SORT_DEFAULT ) );
  118. break;
  119. default:
  120. SetThreadLocale(
  121. MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ),
  122. SORT_DEFAULT ) );
  123. break;
  124. }
  125. #endif // DBCS
  126. }
  127. #ifdef DBCS
  128. if(iPrevCP && iPrevCP != 932) {
  129. #else // !DBCS
  130. if(iPrevCP) {
  131. #endif // !DBCS
  132. iRet = LoadString(NULL,PREVIOUS_CP, szSour, sizeof(szSour)/sizeof(TCHAR));
  133. CharToOem(szSour, szDest);
  134. printf(szDest, iPrevCP);
  135. }
  136. else {
  137. iRet = LoadString(NULL,NONE_CP, szSour, sizeof(szSour)/sizeof(TCHAR));
  138. CharToOem(szSour, szDest);
  139. printf(szDest);
  140. }
  141. iRet = LoadString(NULL,ACTIVE_CP, szSour, sizeof(szSour)/sizeof(TCHAR));
  142. CharToOem(szSour, szDest);
  143. #ifdef DBCS
  144. if ( GetConsoleOutputCP() != 932 )
  145. #endif // DBCS
  146. printf(szDest, GetConsoleOutputCP());
  147. }