Leaked source code of windows server 2003
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.

155 lines
4.2 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1995-1999 Microsoft Corporation
  3. Module Name:
  4. mbcs.cxx
  5. Abstract:
  6. MBCS support related code used by the lexer.
  7. Notes:
  8. History:
  9. RyszardK Sep-1996 Created.
  10. ----------------------------------------------------------------------------*/
  11. #pragma warning ( disable : 4514 )
  12. #include <windows.h>
  13. #include <stdlib.h>
  14. #include "mbcs.hxx"
  15. CharacterSet CurrentCharSet;
  16. int
  17. CharacterSet::DBCSDefaultToCaseSensitive()
  18. {
  19. // these languages do not distinguish cases
  20. return (
  21. PRIMARYLANGID(LANGIDFROMLCID(CurrentLCID)) == LANG_JAPANESE ||
  22. PRIMARYLANGID(LANGIDFROMLCID(CurrentLCID)) == LANG_CHINESE ||
  23. PRIMARYLANGID(LANGIDFROMLCID(CurrentLCID)) == LANG_KOREAN
  24. );
  25. }
  26. CharacterSet::CharacterSet()
  27. {
  28. memset( DbcsLeadByteTable, 0, 128 );
  29. SetDbcsLeadByteTable( GetSystemDefaultLCID() );
  30. }
  31. CharacterSet::DBCS_ERRORS
  32. CharacterSet::SetDbcsLeadByteTable(
  33. unsigned long ulLocale )
  34. {
  35. DBCS_ERRORS dbcsRet = dbcs_Failure;
  36. if (CurrentLCID != ulLocale)
  37. {
  38. dbcsRet = dbcs_Success;
  39. char szCodePage[6];
  40. if ( GetLocaleInfo( ulLocale,
  41. LOCALE_NOUSEROVERRIDE | LOCALE_IDEFAULTANSICODEPAGE,
  42. szCodePage,
  43. sizeof(szCodePage) ) )
  44. {
  45. unsigned int CodePage = atoi( szCodePage );
  46. for (int i = 128; i < 256; i++ )
  47. {
  48. DbcsLeadByteTable[i] = (char) IsDBCSLeadByteEx( CodePage,
  49. (char) i );
  50. }
  51. }
  52. else
  53. {
  54. unsigned char i = 0;
  55. switch (PRIMARYLANGID(ulLocale))
  56. {
  57. case LANG_CHINESE:
  58. if (SUBLANGID(ulLocale) == SUBLANG_CHINESE_SIMPLIFIED)
  59. {
  60. for (i=0xA1; i <= 0xFE; i++)
  61. {
  62. DbcsLeadByteTable[i] = 1;
  63. }
  64. }
  65. break;
  66. case LANG_KOREAN:
  67. for (i = 0x81; i <= 0xFE; i++)
  68. {
  69. DbcsLeadByteTable[i] = 1;
  70. }
  71. break;
  72. case LANG_JAPANESE:
  73. for (i = 0x81; i <= 0x9F; i++)
  74. {
  75. DbcsLeadByteTable[i] = 1;
  76. }
  77. for (i = 0xE0; i <= 0xFC; i++)
  78. {
  79. DbcsLeadByteTable[i] = 1;
  80. }
  81. break;
  82. default:
  83. dbcsRet = dbcs_BadLCID;
  84. break;
  85. }
  86. }
  87. }
  88. else
  89. {
  90. dbcsRet = dbcs_Success;
  91. }
  92. if (CurrentLCID != (unsigned long)-1 &&
  93. CurrentLCID != ulLocale &&
  94. ulLocale != 0)
  95. {
  96. dbcsRet = dbcs_LCIDConflict;
  97. }
  98. CurrentLCID = ulLocale;
  99. return dbcsRet;
  100. }
  101. int
  102. CharacterSet::CompareDBCSString(
  103. char* szLHStr,
  104. char* szRHStr,
  105. unsigned long ulFlags
  106. )
  107. {
  108. int nRet = CompareStringA( CurrentLCID,
  109. NORM_IGNOREWIDTH | NORM_IGNOREKANATYPE | ulFlags,
  110. szLHStr,
  111. -1,
  112. szRHStr,
  113. -1) - 2;
  114. if (nRet == -2)
  115. {
  116. nRet = strcmp(szLHStr, szRHStr);
  117. }
  118. return nRet;
  119. }
  120. unsigned int
  121. GetConsoleMaxLineCount()
  122. {
  123. CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
  124. HANDLE hOutput = GetStdHandle( STD_OUTPUT_HANDLE );
  125. ZeroMemory( &ConsoleInfo, sizeof( ConsoleInfo ) );
  126. BOOL fResult = GetConsoleScreenBufferInfo( hOutput, &ConsoleInfo );
  127. if ( fResult )
  128. {
  129. return ConsoleInfo.srWindow.Bottom - 1;
  130. }
  131. else
  132. {
  133. return 23;
  134. }
  135. }