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.

125 lines
2.8 KiB

  1. //
  2. // Copyright (c) 1997-1999 Microsoft Corporation.
  3. //
  4. #include "stdafx.h"
  5. #include "eudcedit.h"
  6. #ifdef BUILD_ON_WINNT
  7. #include "extfunc.h"
  8. #endif // BUILD_ON_WINNT
  9. #pragma pack(2)
  10. #define SEGMAX 256
  11. #define EUDCCODEBASE ((unsigned short)0xe000)
  12. static int init = 0;
  13. static unsigned short segStart[SEGMAX];
  14. static unsigned short segEnd[SEGMAX];
  15. static unsigned short segUni[SEGMAX];
  16. static int segCnt = 0;
  17. static int recCnt = 0;
  18. static void
  19. setseg( unsigned short segH, unsigned short segLS, unsigned short segLE)
  20. {
  21. unsigned short cCnt;
  22. if ( segCnt >= SEGMAX)
  23. return;
  24. cCnt = segLE - segLS + 1;
  25. segStart[segCnt] = (segH<<8)+segLS;
  26. segEnd[segCnt] = (segH<<8)+segLE;
  27. segUni[segCnt] = EUDCCODEBASE +recCnt;
  28. recCnt += cCnt;
  29. segCnt++;
  30. }
  31. void
  32. makeUniCodeTbl ( )
  33. {
  34. int base;
  35. unsigned short slow, elow;
  36. int n;
  37. int nlow;
  38. unsigned short high;
  39. COUNTRYINFO *cInfo;
  40. //we don't need an unicode table if we only have unicode
  41. if (CountryInfo.bOnlyUnicode)
  42. return;
  43. if ( init) return ;
  44. cInfo = &CountryInfo;
  45. base = 0;
  46. segCnt = recCnt = 0;
  47. for ( n=0; n < cInfo->nRange - 1; n++) {
  48. #ifdef BUILD_ON_WINNT
  49. /* CHS needs to dynamically calculate trailbyte range for each
  50. * EUDC select range.
  51. */
  52. if (cInfo->LangID == EUDC_CHS)
  53. CorrectTrailByteRange(n);
  54. #endif // BUILD_ON_WINNT
  55. for ( high = cInfo->sLeadByte[n]; high <=cInfo->eLeadByte[n];
  56. high++){
  57. if ( high == cInfo->sLeadByte[n])
  58. slow = cInfo->sRange[n] & 0xff;
  59. else
  60. slow = cInfo->sTralByte[0];
  61. if ( high ==cInfo->eLeadByte[n])
  62. elow = cInfo->eRange[n] & 0xff;
  63. else
  64. elow = cInfo->eTralByte[cInfo->nTralByte-1];
  65. for ( nlow = 0; nlow < cInfo->nTralByte; nlow++) {
  66. if ( slow >= cInfo->sTralByte[nlow]
  67. && slow <= cInfo->eTralByte[nlow]) {
  68. if ( elow <= cInfo->eTralByte[nlow] )
  69. setseg( high, slow, elow);
  70. else
  71. setseg( high, slow, cInfo->eTralByte[nlow]);
  72. }
  73. else if ( slow < cInfo->sTralByte[nlow]
  74. && elow >= cInfo->sTralByte[nlow]) {
  75. if ( elow <= cInfo->eTralByte[nlow] )
  76. setseg( high, cInfo->sTralByte[nlow], elow);
  77. else
  78. setseg( high, cInfo->sTralByte[nlow],
  79. cInfo->sTralByte[nlow]);
  80. }
  81. }
  82. }
  83. }
  84. init = 1;
  85. }
  86. unsigned short
  87. sjisToUniEUDC( unsigned short code)
  88. {
  89. int seg;
  90. unsigned short ofs;
  91. for ( seg = 0; seg < segCnt; seg++) {
  92. if ( code <= segEnd[seg]) {
  93. if ( segStart[seg] <= code) {
  94. ofs = code - segStart[seg];
  95. return segUni[seg]+ofs;
  96. }
  97. }
  98. }
  99. return (unsigned short)0xffff;
  100. }
  101. unsigned short
  102. getMaxUniCode( )
  103. {
  104. USHORT ansiMax;
  105. if (CountryInfo.bOnlyUnicode)
  106. ansiMax = 0;
  107. else
  108. ansiMax = segUni[segCnt-1] + (segEnd[segCnt-1] - segStart[segCnt-1]);
  109. return max(ansiMax, CountryInfo.eRange[CountryInfo.nRange-1]);
  110. }
  111. /* EOF */