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.

217 lines
8.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /**[txh]********************************************************************
  2. Copyright 1996-2003 by Salvador Eduardo Tropea (SET)
  3. This file is covered by the GPL license.
  4. Module: TVCodePage
  5. ***************************************************************************/
  6. #if defined(Uses_TVCodePage) && !defined(TVCodePage_Included)
  7. #define TVCodePage_Included 1
  8. class TVCodePageCol;
  9. class TStringCollection;
  10. struct stIntCodePairs
  11. {
  12. uint16 unicode,code;
  13. };
  14. // This is the internal structure used to describe a code page
  15. struct CodePage
  16. {
  17. char Name[28]; // Descriptive name
  18. int id; // Unique ID to identify it
  19. ushort Font[128]; // High 128 symbols
  20. char *UpLow; // Lowecase/Uppercase pairs
  21. char *MoreLetters; // Other symbols that should be treat as letters but doesn't
  22. // have lowecase/uppercase pair.
  23. int LowRemapNum; // Most code pages are plain ASCII in the first 128 symbols
  24. ushort *LowRemap; // and we don't define them. This information is used when
  25. // symbols under 128 needs special treatment.
  26. };
  27. typedef void (*TVCodePageCallBack)(ushort *map);
  28. const unsigned rbgDontRemapLow32=1, rbgOnlySelected=2;
  29. class TVCodePage
  30. {
  31. public:
  32. TVCodePage(int idApp, int idScr, int idInp);
  33. ~TVCodePage();
  34. static ccIndex IDToIndex(int id);
  35. static int IndexToID(ccIndex index);
  36. static ushort *GetTranslate(int id);
  37. static void SetCodePage(int idApp, int idScr, int idInp);
  38. // Helpers to call SetCodePage
  39. static void SetCodePage(int idCP) { SetCodePage(idCP,idCP,idCP); };
  40. static void SetScreenCodePage(int idCP) { SetCodePage(curAppCP,idCP,curInpCP); };
  41. static void SetInputCodePage(int idCP) { SetCodePage(curAppCP,curScrCP,idCP); };
  42. static TStringCollection
  43. *GetList(void);
  44. static uchar RemapChar(uchar c, ushort *map);
  45. static void RemapString(uchar *n, uchar *o, ushort *map);
  46. static void RemapNString(uchar *n, uchar *o, ushort *map, int len);
  47. static void RemapBufferGeneric(int sourID, int destID, uchar *buffer, unsigned len,
  48. unsigned ops);
  49. static void FillGenericRemap(int sourID, int destID, uchar *buffer, unsigned ops=0);
  50. static char toUpper(char val)
  51. { return (char)toUpperTable[(uchar)val]; }
  52. static char toLower(char val)
  53. { return (char)toLowerTable[(uchar)val]; }
  54. static int isAlpha(char val)
  55. { return AlphaTable[(uchar)val] & alphaChar; }
  56. static int isAlNum(char val)
  57. { return AlphaTable[(uchar)val] & (alphaChar | digitChar); }
  58. static int isLower(char val)
  59. { return AlphaTable[(uchar)val] & lowerChar; }
  60. static int isUpper(char val)
  61. { return AlphaTable[(uchar)val] & upperChar; }
  62. static int InternalCodeForUnicode(uint16 unicode);
  63. static uint16 UnicodeForInternalCode(uint16 code);
  64. static void GetUnicodesForCP(int id, stIntCodePairs *unicodes);
  65. static TVCodePageCallBack SetCallBack(TVCodePageCallBack map);
  66. static Boolean OnTheFlyRemapNeeded() { return NeedsOnTheFlyRemap ? True : False; }
  67. static uchar OnTheFlyRemap(uchar val) { return OnTheFlyMap[val]; }
  68. static Boolean OnTheFlyRemapInpNeeded() { return NeedsOnTheFlyInpRemap ? True : False; }
  69. static uchar OnTheFlyInpRemap(uchar val) { return OnTheFlyInpMap[val]; }
  70. static void CreateCPFromUnicode(CodePage *cp, int id, const char *name,
  71. ushort *unicodes);
  72. static ccIndex AddCodePage(CodePage *cp);
  73. static void GetCodePages(int &idScr, int &idApp, int &idInp)
  74. { idApp=curAppCP; idScr=curScrCP; idInp=curInpCP; }
  75. static int GetAppCodePage() { return curAppCP; }
  76. static int GetScrCodePage() { return curScrCP; }
  77. static int GetInpCodePage() { return curInpCP; }
  78. static void GetDefaultCodePages(int &idScr, int &idApp, int &idInp)
  79. { idApp=defAppCP; idScr=defScrCP; idInp=defInpCP; }
  80. static int LookSimilarInRange(int code, int last);
  81. // TView helpers
  82. static void *convertBufferU16_2_CP(void *dest, const void *orig, unsigned count);
  83. static void *convertBufferCP_2_U16(void *dest, const void *orig, unsigned count);
  84. static void *convertStrU16_2_CP(void *dest, const void *orig, unsigned len);
  85. static void *convertStrCP_2_U16(void *dest, const void *orig, unsigned len);
  86. static char convertU16_2_CP(uint16 val);
  87. static uint16 convertCP_2_U16(char val);
  88. static char convertU16_2_InpCP(uint16 val);
  89. static uint16 convertInpCP_2_U16(char val);
  90. // Arbitrary names for the supported code pages
  91. // Just to avoid using the magics, look in codepage.cc for more information
  92. enum
  93. {
  94. PC437=437, PC737=737, PC775=775, PC850=850, PC852=852, PC855=855, PC857=857,
  95. PC860=860, PC861=861, PC863=863, PC865=865, PC866=866, PC869=869, CP1250=1250,
  96. CP1251=1251, CP1252=1252, CP1253=1253, CP1254=1254, CP1257=1257, MacCyr=10007,
  97. ISOLatin1=88791, ISOLatin2=88792, ISOLatin3=88593, ISOLatin4=88594,
  98. ISORussian=88595, ISOGreek=88597, ISO9=88599, ISOLatin1Linux=885901,
  99. ISOLatin1uLinux=885911, ISO14=885914, ISOIceland=885915,
  100. ISOLatin2uLinux=885921, ISOLatin2Linux=885920, ISOLatin2Sun=885922,
  101. ISOLatin2eLinux=885923, KOI8r=100000, KOI8_CRL_NMSU=100001,
  102. MacOSUkrainian=100072, OsnovnojVariantRussian=885951,
  103. AlternativnyjVariantRU=885952, UcodeRussian=885953, Mazovia=1000000,
  104. ISO5427=3604494, ECMACyr=17891342, ISOIR146=21364750, ISOIR147=21430286,
  105. ISOIR153=22216718,
  106. LinuxACM=0x7FFF0000, LinuxSFM=0x7FFF0001
  107. };
  108. // Be careful with this table is public just to simplify the code.
  109. static stIntCodePairs InternalMap[];
  110. static stIntCodePairs InternalMapBrokenLinux[];
  111. static const int providedUnicodes;
  112. static const int providedUnicodesBL;
  113. protected:
  114. static CodePage *CodePageOfID(int id);
  115. static void RemapTVStrings(ushort *map);
  116. static void FillTables(int id);
  117. static void CreateOnTheFlyRemap(int idApp, int idScr);
  118. static void CreateOnTheFlyInpRemap(int idInp, int idApp);
  119. static void CreateRemap(int idSource, int idDest, uchar *table);
  120. static void CreateCodePagesCol();
  121. static void ChangeDefaultCodePages(int idScr, int idApp)
  122. { defAppCP=idApp; defScrCP=idScr; }
  123. static void SetDefaultCodePages(int idScr, int idApp, int idInp)
  124. { defAppCP=idApp; defScrCP=idScr; defInpCP=idInp; }
  125. enum { alphaChar=1, lowerChar=2, upperChar=4, digitChar=8 };
  126. static TVCodePageCol *CodePages;
  127. static ushort CPTable[257];
  128. static int curAppCP,curScrCP,curInpCP;
  129. static int defAppCP,defScrCP,defInpCP;
  130. static uchar toUpperTable[256];
  131. static uchar toLowerTable[256];
  132. static uchar AlphaTable[256];
  133. static uchar Similar[];
  134. static ushort Similar2[];
  135. static char NeedsOnTheFlyRemap;
  136. static uchar OnTheFlyMap[256];
  137. static char NeedsOnTheFlyInpRemap;
  138. static uchar OnTheFlyInpMap[256];
  139. static TVCodePageCallBack UserHook;
  140. static uint16 appToUnicode[256];
  141. static TVPartitionTree556 *unicodeToApp;
  142. static uint16 inpToUnicode[256];
  143. static TVPartitionTree556 *unicodeToInp;
  144. // CodePage structures
  145. static CodePage stPC437;
  146. static CodePage stPC775;
  147. static CodePage stPC850;
  148. static CodePage stPC852;
  149. static CodePage stPC857;
  150. static CodePage stPC860;
  151. static CodePage stPC861;
  152. static CodePage stPC863;
  153. static CodePage stPC865;
  154. static CodePage ISO8879_1;
  155. static CodePage ISO8859_1_Lat1;
  156. static CodePage ISO8859_1u_Lat1;
  157. static CodePage ISO8879_2;
  158. static CodePage ISO8859_2_Lat2;
  159. static CodePage ISO8859_2u_Lat2;
  160. static CodePage ISO8859_2_Sun;
  161. static CodePage ISO8859_2e_Lat2;
  162. static CodePage ISO8859_3;
  163. static CodePage ISO8859_4;
  164. static CodePage ISO8859_9;
  165. static CodePage ISO8859_14;
  166. static CodePage ISO8859_15;
  167. static CodePage stPC1250;
  168. static CodePage stPC1252;
  169. static CodePage stPC1254;
  170. static CodePage stPC1257;
  171. static CodePage stMazovia;
  172. static CodePage stPC855;
  173. static CodePage stPC866;
  174. static CodePage ISO8859_5;
  175. static CodePage KOI_8r;
  176. static CodePage KOI_8crl;
  177. static CodePage PC1251;
  178. static CodePage ISO_IR_111;
  179. static CodePage ISO_IR_153;
  180. static CodePage CP10007;
  181. static CodePage CP100072;
  182. static CodePage OVR;
  183. static CodePage AVR;
  184. static CodePage U_CodeR;
  185. static CodePage KOI_7;
  186. static CodePage ISO_IR_147;
  187. static CodePage ISO_IR_146;
  188. static CodePage stPC737;
  189. static CodePage stPC869;
  190. static CodePage stPC1253;
  191. static CodePage ISO8859_7;
  192. static ushort LowCrazyCharsRemaped[];
  193. static ushort Low32CharsRemaped[];
  194. static ushort tbKOI7[];
  195. static ushort tbISOIR147[];
  196. static ushort tbISOIR146[];
  197. static uchar High32FramesSwap[];
  198. friend class TScreen;
  199. friend class TDisplay;
  200. };
  201. #endif