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.

162 lines
3.3 KiB

  1. // =================================================================================
  2. // Internet Character Set Conversion: Input from IS-2022-KR
  3. // =================================================================================
  4. #include "pch.hxx"
  5. #include "KscIn.h"
  6. #include "FEChrCnv.h"
  7. int KSC_to_Hangeul (CONV_CONTEXT *pcontext, UCHAR *pKSC, int KSC_len, UCHAR *pHangeul, int Hangeul_len)
  8. {
  9. long lConvertedSize;
  10. if (!Hangeul_len) {
  11. // Wanted the converted size
  12. if (!pcontext->pIncc0)
  13. pcontext->pIncc0 = new CInccKscIn;
  14. if (FAILED(((CInccKscIn*)pcontext->pIncc0)->GetStringSizeA(pKSC, KSC_len, &lConvertedSize)))
  15. return -1;
  16. } else {
  17. if (!pcontext->pIncc)
  18. pcontext->pIncc = new CInccKscIn;
  19. if (FAILED(((CInccKscIn*)pcontext->pIncc)->ConvertStringA(pKSC, KSC_len, pHangeul, Hangeul_len, &lConvertedSize)))
  20. return -1;
  21. }
  22. if (!pKSC) {
  23. // Let's clean up our context here.
  24. if (pcontext->pIncc0) {
  25. delete pcontext->pIncc0;
  26. pcontext->pIncc0 = NULL;
  27. }
  28. if (pcontext->pIncc) {
  29. delete pcontext->pIncc;
  30. pcontext->pIncc = NULL;
  31. }
  32. return 0;
  33. }
  34. return (int)lConvertedSize;
  35. }
  36. CInccKscIn::CInccKscIn()
  37. {
  38. pfnNextProc = ConvMain;
  39. fIsoMode = FALSE;
  40. fKscMode = FALSE;
  41. }
  42. HRESULT CInccKscIn::ConvertByte(BYTE by)
  43. {
  44. return (this->*pfnNextProc)(FALSE, by, lNextParam);
  45. }
  46. HRESULT CInccKscIn::CleanUp()
  47. {
  48. return (this->*pfnNextProc)(TRUE, 0, lNextParam);
  49. }
  50. HRESULT CInccKscIn::ConvMain(BOOL fCleanUp, BYTE by, long lParam)
  51. {
  52. HRESULT hr = S_OK;
  53. if (!fCleanUp) {
  54. if (by == ESC) {
  55. pfnNextProc = ConvEsc;
  56. } else {
  57. if (fIsoMode) {
  58. switch (by) {
  59. case SO:
  60. fKscMode = TRUE;
  61. break;
  62. case SI:
  63. fKscMode = FALSE;
  64. break;
  65. default:
  66. if (fKscMode) {
  67. switch (by) {
  68. case ' ':
  69. case '\t':
  70. case '\n':
  71. hr = Output(by);
  72. break;
  73. default:
  74. hr = Output(by | 0x80);
  75. break;
  76. }
  77. } else {
  78. hr = Output(by);
  79. }
  80. break;
  81. }
  82. } else {
  83. hr = Output(by);
  84. }
  85. }
  86. }
  87. return hr;
  88. }
  89. HRESULT CInccKscIn::ConvEsc(BOOL fCleanUp, BYTE by, long lParam)
  90. {
  91. pfnNextProc = ConvMain;
  92. if (!fCleanUp) {
  93. if (by == IS2022_IN_CHAR) {
  94. pfnNextProc = ConvIsoIn;
  95. return ResultFromScode(S_OK);
  96. } else {
  97. (void)Output(ESC);
  98. return ConvertByte(by);
  99. }
  100. } else {
  101. return Output(ESC);
  102. }
  103. }
  104. HRESULT CInccKscIn::ConvIsoIn(BOOL fCleanUp, BYTE by, long lParam)
  105. {
  106. pfnNextProc = ConvMain;
  107. if (!fCleanUp) {
  108. if (by == IS2022_IN_KSC_CHAR1) {
  109. pfnNextProc = ConvKsc1st;
  110. return ResultFromScode(S_OK);
  111. } else {
  112. (void)Output(ESC);
  113. (void)ConvertByte(IS2022_IN_CHAR);
  114. return ConvertByte(by);
  115. }
  116. } else {
  117. (void)Output(ESC);
  118. (void)ConvertByte(IS2022_IN_CHAR);
  119. return CleanUp();
  120. }
  121. }
  122. HRESULT CInccKscIn::ConvKsc1st(BOOL fCleanUp, BYTE by, long lParam)
  123. {
  124. pfnNextProc = ConvMain;
  125. if (!fCleanUp) {
  126. if (by == IS2022_IN_KSC_CHAR2) {
  127. fIsoMode = TRUE;
  128. return ResultFromScode(S_OK);
  129. } else {
  130. (void)Output(ESC);
  131. (void)ConvertByte(IS2022_IN_CHAR);
  132. (void)ConvertByte(IS2022_IN_KSC_CHAR1);
  133. return ConvertByte(by);
  134. }
  135. } else {
  136. (void)Output(ESC);
  137. (void)ConvertByte(IS2022_IN_CHAR);
  138. (void)ConvertByte(IS2022_IN_KSC_CHAR1);
  139. return CleanUp();
  140. }
  141. }