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.

458 lines
14 KiB

  1. /* File: D:\WACKER\emu\vt_chars.c (Created: 27-Dec-1993)
  2. *
  3. * Copyright 1994, 1998 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 3 $
  7. * $Date: 5/07/02 1:25p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <tdll\assert.h>
  12. #include <tdll\stdtyp.h>
  13. #include <tdll\session.h>
  14. #include <tdll\print.h>
  15. #include <tdll\capture.h>
  16. #include <tdll\mc.h>
  17. #include "emu.h"
  18. #include "emu.hh"
  19. #include "emudec.hh"
  20. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  21. * vt_charset
  22. *
  23. * DESCRIPTION: initialize character set mappings for VT terms
  24. *
  25. * ARGUMENTS:
  26. *
  27. * RETURNS:
  28. *
  29. */
  30. void vt_charset_init(const HHEMU hhEmu)
  31. {
  32. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  33. if (hhEmu->mode_vt220 || hhEmu->mode_vt320)
  34. /* started as a 320 or 220 even if now 100 */
  35. {
  36. pstPRI->vt_charset[0] = pstPRI->vt_charset[1] = ETEXT('B'); /* ASCII char set */
  37. pstPRI->vt_charset[2] = pstPRI->vt_charset[3] = ETEXT('<'); /* DEC supplemental char set */
  38. pstPRI->gl = 0;
  39. pstPRI->gr = 2;
  40. }
  41. else if (hhEmu->mode_vt280)
  42. /* Kanji or Katakana terminal support */
  43. {
  44. pstPRI->vt_charset[0] = ETEXT('B'); /* ASCII char set */
  45. pstPRI->vt_charset[1] = ETEXT('B'); /* ASCII char set */
  46. pstPRI->vt_charset[2] = ETEXT('B'); /* ASCII char set */
  47. pstPRI->vt_charset[3] = ETEXT('0'); /* DEC special graphics set */
  48. pstPRI->gl = 0;
  49. pstPRI->gr = 2;
  50. }
  51. else
  52. {
  53. pstPRI->vt_charset[0] = ETEXT('B'); /* ASCII char set */
  54. pstPRI->vt_charset[1] = ETEXT('0'); /* DEC special graphics set */
  55. pstPRI->gl = 0;
  56. pstPRI->gr = 1;
  57. }
  58. vt_dsptbl(hhEmu, pstPRI->vt_charset[pstPRI->gl], pstPRI->vt_charset[pstPRI->gr]);
  59. }
  60. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  61. * vt_charset
  62. *
  63. * DESCRIPTION:
  64. *
  65. * ARGUMENTS:
  66. *
  67. * RETURNS:
  68. *
  69. */
  70. void vt_charset_save(const HHEMU hhEmu)
  71. {
  72. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  73. MemCopy(pstPRI->vt_sv_charset, pstPRI->vt_charset, sizeof(pstPRI->vt_sv_charset));
  74. pstPRI->sv_gl = pstPRI->gl;
  75. pstPRI->sv_gr = pstPRI->gr;
  76. }
  77. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  78. * vt_charset_restore
  79. *
  80. * DESCRIPTION:
  81. *
  82. * ARGUMENTS:
  83. *
  84. * RETURNS:
  85. *
  86. */
  87. void vt_charset_restore(const HHEMU hhEmu)
  88. {
  89. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  90. MemCopy(pstPRI->vt_charset, pstPRI->vt_sv_charset, sizeof(pstPRI->vt_charset));
  91. pstPRI->gl = pstPRI->sv_gl;
  92. pstPRI->gr = pstPRI->sv_gr;
  93. vt_dsptbl(hhEmu, pstPRI->vt_charset[pstPRI->gl], pstPRI->vt_charset[pstPRI->gr]);
  94. }
  95. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  96. * vt_scs1
  97. *
  98. * DESCRIPTION:
  99. * Sets up the type of character set to be loaded next.
  100. *
  101. * ARGUMENTS:
  102. * none
  103. *
  104. * RETURNS:
  105. * nothing
  106. */
  107. void vt_scs1(const HHEMU hhEmu)
  108. {
  109. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  110. switch (hhEmu->emu_code)
  111. {
  112. case ETEXT('(') :
  113. pstPRI->gn = 0;
  114. break;
  115. case ETEXT(')') :
  116. pstPRI->gn = 1;
  117. break;
  118. case ETEXT('*') :
  119. pstPRI->gn = 2;
  120. break;
  121. case ETEXT('+') :
  122. pstPRI->gn = 3;
  123. break;
  124. default:
  125. break;
  126. }
  127. }
  128. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  129. * vt_scs2
  130. *
  131. * DESCRIPTION:
  132. * Loads another character set.
  133. *
  134. * ARGUMENTS:
  135. * none
  136. *
  137. * RETURNS:
  138. * nothing
  139. */
  140. void vt_scs2(const HHEMU hhEmu)
  141. {
  142. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  143. pstPRI->vt_charset[pstPRI->gn] = hhEmu->emu_code;
  144. vt_dsptbl(hhEmu,
  145. pstPRI->vt_charset[pstPRI->gl],
  146. pstPRI->vt_charset[pstPRI->gr]);
  147. }
  148. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  149. * vt_setkanji
  150. *
  151. * DESCRIPTION:
  152. * Sets the display mode to Kanji/Katakana
  153. *
  154. * ARGUMENTS:
  155. *
  156. *
  157. * RETURNS:
  158. * nothing
  159. */
  160. void vt_setkanji(const HHEMU hhEmu, const int nSetKanji)
  161. {
  162. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  163. if (nSetKanji)
  164. {
  165. pstPRI->vt_charset[0] = ETEXT('B'); /* ASCII char set */
  166. pstPRI->vt_charset[1] = ETEXT('0'); /* DEC special graphics set */
  167. pstPRI->vt_charset[2] = ETEXT('B'); /* ASCII char set */
  168. pstPRI->vt_charset[3] = ETEXT('Y'); /* Kanji char set */
  169. pstPRI->gl = 0;
  170. pstPRI->gr = 2;
  171. }
  172. else
  173. {
  174. pstPRI->vt_charset[0] = ETEXT('B'); /* ASCII char set */
  175. pstPRI->vt_charset[1] = ETEXT('B'); /* ASCII char set */
  176. pstPRI->vt_charset[2] = ETEXT('B'); /* ASCII char set */
  177. pstPRI->vt_charset[3] = ETEXT('0'); /* DEC special graphics set */
  178. pstPRI->gl = 0;
  179. pstPRI->gr = 2;
  180. }
  181. }
  182. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  183. * vt_charshift
  184. *
  185. * DESCRIPTION:
  186. * Loads another character set.
  187. *
  188. * ARGUMENTS:
  189. * none
  190. *
  191. * RETURNS:
  192. * nothing
  193. */
  194. void vt_charshift(const HHEMU hhEmu)
  195. {
  196. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  197. switch(hhEmu->emu_code)
  198. {
  199. case 0x0F : /* LS0 */
  200. case ETEXT('G') : /* vt52 use ASCII */
  201. pstPRI->gl = 0;
  202. break;
  203. case 0x0E : /* LS1 */
  204. case ETEXT('F') : /* vt52 use graphics */
  205. pstPRI->gl = 1;
  206. break;
  207. case ETEXT('~') : /* LS1R */
  208. pstPRI->gr = 1;
  209. break;
  210. case ETEXT('n') : /* LS2 */
  211. pstPRI->gl = 2;
  212. break;
  213. case ETEXT('}') : /* LS2R */
  214. pstPRI->gr = 2;
  215. break;
  216. case ETEXT('o') : /* LS3 */
  217. pstPRI->gl = 3;
  218. break;
  219. case ETEXT('|') : /* LS3R */
  220. pstPRI->gr = 3;
  221. break;
  222. case 0x8E : /* SS2 */
  223. case ETEXT('N') : /* ESC N */
  224. pstPRI->old_gl = pstPRI->gl;
  225. pstPRI->gl = 2;
  226. hhEmu->emu_datain = vt_char_emulatecmd;
  227. break;
  228. case 0x8F : /* SS3 */
  229. case ETEXT('O') : /* ESC O */
  230. pstPRI->old_gl = pstPRI->gl;
  231. pstPRI->gl = 3;
  232. hhEmu->emu_datain = vt_char_emulatecmd;
  233. break;
  234. default:
  235. break;
  236. }
  237. vt_dsptbl(hhEmu,
  238. pstPRI->vt_charset[pstPRI->gl],
  239. pstPRI->vt_charset[pstPRI->gr]);
  240. }
  241. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  242. * vt_char_emulatecmd
  243. *
  244. * DESCRIPTION:
  245. *
  246. * ARGUMENTS:
  247. *
  248. * RETURNS:
  249. *
  250. */
  251. #if defined(EXTENDED_FEATURES)
  252. int vt_char_emulatecmd(const HHEMU hhEmu, const ECHAR ccode)
  253. {
  254. struct trans_entry *tptr;
  255. int ntrans;
  256. #else
  257. int vt_char_emulatecmd(const HEMU hEmu, const ECHAR ccode)
  258. {
  259. struct trans_entry *tptr;
  260. int ntrans;
  261. const HHEMU hhEmu = (HHEMU)hEmu;
  262. #endif
  263. const PSTDECPRIVATE pstPRI = (PSTDECPRIVATE)hhEmu->pvPrivate;
  264. emuLock((HEMU)hhEmu);
  265. hhEmu->emu_code = ccode;
  266. if (hhEmu->state == 0)
  267. {
  268. if (IN_RANGE(ccode, ETEXT(' '), 0x7F) || IN_RANGE(ccode, 0xA0, 0xFF))
  269. {
  270. (*hhEmu->emu_graphic)(hhEmu);
  271. CaptureChar(sessQueryCaptureFileHdl(hhEmu->hSession),
  272. CF_CAP_CHARS, ccode);
  273. printEchoChar(hhEmu->hPrintEcho, ccode);
  274. goto reset;
  275. }
  276. if (ccode == ETEXT('\r'))
  277. {
  278. carriagereturn(hhEmu);
  279. CaptureChar(sessQueryCaptureFileHdl(hhEmu->hSession),
  280. CF_CAP_CHARS, ccode);
  281. printEchoChar(hhEmu->hPrintEcho, ccode);
  282. emuUnlock((HEMU)hhEmu);
  283. return(0);
  284. }
  285. if (ccode == ETEXT('\n'))
  286. {
  287. emuLineFeed(hhEmu);
  288. CaptureChar(sessQueryCaptureFileHdl(hhEmu->hSession),
  289. CF_CAP_CHARS, ccode);
  290. printEchoChar(hhEmu->hPrintEcho, ccode);
  291. emuUnlock((HEMU)hhEmu);
  292. return(0);
  293. }
  294. }
  295. /* Seek next state by finding character range */
  296. tptr = hhEmu->state_tbl[hhEmu->state].first_trans;
  297. ntrans = hhEmu->state_tbl[hhEmu->state].number_trans;
  298. for (; ntrans > 0; ntrans--, ++tptr)
  299. if (ccode >= tptr->lochar && ccode <= tptr->hichar)
  300. break;
  301. if (ntrans <= 0)
  302. {
  303. commanderror(hhEmu);
  304. CaptureChar(sessQueryCaptureFileHdl(hhEmu->hSession),
  305. CF_CAP_CHARS, ccode);
  306. printEchoChar(hhEmu->hPrintEcho, ccode);
  307. emuUnlock((HEMU)hhEmu);
  308. return (0);
  309. }
  310. hhEmu->state = tptr->next_state;
  311. (*tptr->funct_ptr)(hhEmu);
  312. if (hhEmu->state == 0)
  313. {
  314. hhEmu->num_param_cnt = hhEmu->selector_cnt = hhEmu->selector[0] =
  315. hhEmu->num_param[0] = 0;
  316. hhEmu->DEC_private = FALSE;
  317. }
  318. if (tptr->funct_ptr != hhEmu->emu_graphic)
  319. {
  320. emuUnlock((HEMU)hhEmu);
  321. return(0);
  322. }
  323. reset:
  324. #if defined(EXTENDED_FEATURES)
  325. hhEmu->emu_datain = emuStdDataIn;
  326. #else
  327. hhEmu->emu_datain = emuDataIn;
  328. #endif
  329. pstPRI->gl = pstPRI->old_gl;
  330. // Restore the character set.
  331. //
  332. vt_dsptbl(hhEmu,
  333. pstPRI->vt_charset[pstPRI->gl],
  334. pstPRI->vt_charset[pstPRI->gr]);
  335. emuUnlock((HEMU)hhEmu);
  336. return (0);
  337. }
  338. void vt_dsptbl(const HHEMU hhEmu, ECHAR left, ECHAR right)
  339. {
  340. // Copy the appropriate characters into the display character table.
  341. //
  342. // The 2nd arg was changed from FALSE to TRUE to allow UTF8 to
  343. // display extended ASCII. I don't think it should cause any
  344. // problems 7 May 2002 RDE
  345. std_dsptbl(hhEmu, TRUE); /* start off from known condition */
  346. vt_setdtbl(hhEmu, &hhEmu->dspchar[0], left); /* install gl chars. */
  347. vt_setdtbl(hhEmu, &hhEmu->dspchar[128], right); /* install gr chars. */
  348. }
  349. /* ARGSUSED*/
  350. void vt_setdtbl(const HHEMU hhEmu, ECHAR tbl[], ECHAR cset)
  351. {
  352. switch (cset)
  353. {
  354. case ETEXT('A'): /* British */
  355. tbl[0x23]=0x9C; /* replace # with British pound sign */
  356. break;
  357. case ETEXT('R'): /* French */
  358. tbl[0x23]=0x9C; tbl[0x40]=0x85; tbl[0x5B]=0xF8; tbl[0x5C]=0x87;
  359. tbl[0x5D]=0x15; tbl[0x7B]=0x82; tbl[0x7C]=0x97; tbl[0x7D]=0x8A;
  360. tbl[0x7E]=0xF9;
  361. break;
  362. case ETEXT('Q'): /* French Canadian */
  363. tbl[0x40]=0x85; tbl[0x5B]=0x83; tbl[0x5C]=0x87; tbl[0x5D]=0x88;
  364. tbl[0x5E]=0x8C; tbl[0x60]=0x93; tbl[0x7B]=0x82; tbl[0x7C]=0x97;
  365. tbl[0x7D]=0x8A; tbl[0x7E]=0x96;
  366. break;
  367. case ETEXT('K'): /* German */
  368. tbl[0x40]=0x15; tbl[0x5B]=0x8E; tbl[0x5C]=0x99; tbl[0x5D]=0x9A;
  369. tbl[0x7B]=0x84; tbl[0x7C]=0x94; tbl[0x7D]=0x81; tbl[0x7E]=0xE1;
  370. break;
  371. case ETEXT('0'): /* DEC special graphics */
  372. tbl[0x5F]=' ';
  373. tbl[0x60]=0x04; tbl[0x61]=0xB1; tbl[0x62]='H'; tbl[0x63]='F';
  374. tbl[0x64]='R'; tbl[0x65]='L'; tbl[0x66]=0xF8; tbl[0x67]=0xF1;
  375. tbl[0x68]='N'; tbl[0x69]='V'; tbl[0x6A]=0xD9; tbl[0x6B]=0xBF;
  376. tbl[0x6C]=0xDA; tbl[0x6D]=0xC0; tbl[0x6E]=0xC5; tbl[0x6F]=0xC4;
  377. tbl[0x70]=0xC4; tbl[0x71]=0xC4; tbl[0x72]=0xC4; tbl[0x73]=0xC4;
  378. tbl[0x74]=0xC3; tbl[0x75]=0xB4; tbl[0x76]=0xC1; tbl[0x77]=0xC2;
  379. tbl[0x78]=0xB3; tbl[0x79]=0xF3; tbl[0x7A]=0xF2; tbl[0x7B]=0xE3;
  380. tbl[0x7C]=0xF0; tbl[0x7D]=0x9C; tbl[0x7E]=0xFA;
  381. break;
  382. case ETEXT('<'): /* DEC supplemental graphics */
  383. tbl[0x20]=' '; tbl[0x21]=0xAD; tbl[0x22]=0x9B; tbl[0x23]=0x9C;
  384. tbl[0x24]=' '; tbl[0x25]=0x9D; tbl[0x26]=' '; tbl[0x27]=0x15;
  385. tbl[0x28]=0x0F; tbl[0x29]='C'; tbl[0x2A]=0xA6; tbl[0x2B]=0xAE;
  386. tbl[0x2C]=' '; tbl[0x2D]=' '; tbl[0x2E]=' '; tbl[0x2F]=' ';
  387. tbl[0x30]=0xF8; tbl[0x31]=0xF1; tbl[0x32]=0xFD; tbl[0x33]='3';
  388. tbl[0x34]=' '; tbl[0x35]=0xE6; tbl[0x36]=0x14; tbl[0x37]=0xFA;
  389. tbl[0x38]=' '; tbl[0x39]='1'; tbl[0x3A]=0xA7; tbl[0x3B]=0xAF;
  390. tbl[0x3C]=0xAC; tbl[0x3D]=0xAB; tbl[0x3E]=' '; tbl[0x3F]=0xA8;
  391. tbl[0x40]='A'; tbl[0x41]='A'; tbl[0x42]='A'; tbl[0x43]='A';
  392. tbl[0x44]=0x8E; tbl[0x45]=0x8F; tbl[0x46]=0x92; tbl[0x47]=0x80;
  393. tbl[0x48]='E'; tbl[0x49]=0x90; tbl[0x4A]='E'; tbl[0x4B]='E';
  394. tbl[0x4C]='I'; tbl[0x4D]='I'; tbl[0x4E]='I'; tbl[0x4F]='I';
  395. tbl[0x50]=' '; tbl[0x51]=0xA5; tbl[0x52]='O'; tbl[0x53]='O';
  396. tbl[0x54]='O'; tbl[0x55]='O'; tbl[0x56]=0x99; tbl[0x57]='O';
  397. tbl[0x58]=0xED; tbl[0x59]='U'; tbl[0x5A]='U'; tbl[0x5B]='U';
  398. tbl[0x5C]=0x9A; tbl[0x5D]='Y'; tbl[0x5E]=' '; tbl[0x5F]=0xE1;
  399. tbl[0x60]=0x85; tbl[0x61]=0xA0; tbl[0x62]=0x83; tbl[0x63]='a';
  400. tbl[0x64]=0x84; tbl[0x65]=0x86; tbl[0x66]=0x91; tbl[0x67]=0x87;
  401. tbl[0x68]=0x8A; tbl[0x69]=0x82; tbl[0x6A]=0x88; tbl[0x6B]=0x89;
  402. tbl[0x6C]=0x8D; tbl[0x6D]=0xA1; tbl[0x6E]=0x8C; tbl[0x6F]=0x8B;
  403. tbl[0x70]=' '; tbl[0x71]=0xA4; tbl[0x72]=0x95; tbl[0x73]=0xA2;
  404. tbl[0x74]=0x93; tbl[0x75]='o' ; tbl[0x76]=0x94; tbl[0x77]='o';
  405. tbl[0x78]='o'; tbl[0x79]=0x97; tbl[0x7A]=0xA3; tbl[0x7B]=0x96;
  406. tbl[0x7C]=0x81; tbl[0x7D]=0x98; tbl[0x7E]=' '; tbl[0x7F]=' ';
  407. break;
  408. case ETEXT('B'): /* normal ASCII */
  409. case ETEXT('Y') : /* KANJI */
  410. default : /* unimplemented */
  411. break; /* leave as is */
  412. }
  413. }
  414. /* end of vt_chars.c */