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.

105 lines
2.3 KiB

  1. // =================================================================================
  2. // Internet Character Set Conversion: Output to IS-2022-KSC
  3. // =================================================================================
  4. #include "pch.hxx"
  5. #include "KscOut.h"
  6. #include "FEChrCnv.h"
  7. int Hangeul_to_KSC (CONV_CONTEXT *pcontext, UCHAR *pHangeul, int Hangeul_len, UCHAR *pKSC, int KSC_len)
  8. {
  9. long lConvertedSize;
  10. if (!KSC_len) {
  11. // Wanted the converted size
  12. if (!pcontext->pIncc0)
  13. pcontext->pIncc0 = new CInccKscOut;
  14. if (FAILED(((CInccKscOut*)pcontext->pIncc0)->GetStringSizeA(pHangeul, Hangeul_len, &lConvertedSize)))
  15. return -1;
  16. } else {
  17. if (!pcontext->pIncc)
  18. pcontext->pIncc = new CInccKscOut;
  19. if (FAILED(((CInccKscOut*)pcontext->pIncc)->ConvertStringA(pHangeul, Hangeul_len, pKSC, KSC_len, &lConvertedSize)))
  20. return -1;
  21. }
  22. if (!pHangeul) {
  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. CInccKscOut::CInccKscOut()
  37. {
  38. fDoubleByte = FALSE;
  39. fIsoMode = FALSE;
  40. fKscMode = FALSE;
  41. }
  42. HRESULT CInccKscOut::ConvertByte(BYTE by)
  43. {
  44. HRESULT hr = S_OK;
  45. if (!fIsoMode) {
  46. (void)Output(ESC);
  47. (void)Output(IS2022_IN_CHAR);
  48. (void)Output(IS2022_IN_KSC_CHAR1);
  49. (void)Output(IS2022_IN_KSC_CHAR2);
  50. fIsoMode = TRUE;
  51. }
  52. if (!fDoubleByte) {
  53. if (by > 0x80) {
  54. fDoubleByte = TRUE;
  55. byLead = by;
  56. } else {
  57. if (fIsoMode && fKscMode) {
  58. (void)Output(SI);
  59. fKscMode = FALSE;
  60. }
  61. hr = Output(by);
  62. }
  63. } else {
  64. fDoubleByte = FALSE;
  65. if (by > 0x40) { // Check if trail byte indicates Hangeul
  66. if (!fKscMode) {
  67. (void)Output(SO);
  68. fKscMode = TRUE;
  69. }
  70. if (byLead > 0xa0 && by > 0xa0) { // Check if it's a Wansung
  71. (void)Output(byLead & 0x7f);
  72. hr = Output(by & 0x7f);
  73. } else {
  74. (void)Output(0x22); // Replace to inversed question mark
  75. hr = Output(0x2f);
  76. }
  77. } else {
  78. if (fIsoMode && fKscMode) {
  79. (void)Output(SI);
  80. fKscMode = FALSE;
  81. }
  82. (void)Output(byLead);
  83. hr = Output(by);
  84. }
  85. }
  86. return hr;
  87. }
  88. HRESULT CInccKscOut::CleanUp()
  89. {
  90. if (!fDoubleByte)
  91. return S_OK;
  92. else
  93. return Output(byLead);
  94. }