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.

188 lines
5.9 KiB

  1. /* File: D:\WACKER\emu\ansiinit.c (Created: 08-Dec-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 2 $
  7. * $Date: 7/23/01 6:57p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <tdll\stdtyp.h>
  12. #include <tdll\session.h>
  13. #include <tdll\cloop.h>
  14. #include <tdll\mc.h>
  15. #include <tdll\assert.h>
  16. #include <tdll\backscrl.h>
  17. #include "emu.h"
  18. #include "emu.hh"
  19. #include "emuid.h"
  20. #include "ansi.hh"
  21. #include "keytbls.h"
  22. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. * emuAnsiInit
  24. *
  25. * DESCRIPTION:
  26. * Sets up and installs the ANSI state table. Defines the ANSI
  27. * keyboard. Either resets the emulator completely or redefines emulator
  28. * conditions as they were when last saved.
  29. *
  30. * ARGUMENTS:
  31. *
  32. * RETURNS:
  33. * nothing
  34. */
  35. void emuAnsiInit(const HHEMU hhEmu)
  36. {
  37. PSTANSIPRIVATE pstPRI;
  38. static struct trans_entry const ansi_tbl[] =
  39. {
  40. {NEW_STATE, 0, 0, 0}, // State 0
  41. #if !defined(FAR_EAST)
  42. {0, ETEXT('\x20'), ETEXT('\xFF'), emuStdGraphic}, // Space - All
  43. #else
  44. {0, ETEXT('\x20'), 0xFFFF, emuStdGraphic}, // Space - All
  45. #endif
  46. {1, ETEXT('\x1B'), ETEXT('\x1B'), nothing}, // Esc
  47. {0, ETEXT('\x05'), ETEXT('\x05'), vt100_answerback}, // Ctrl-E
  48. {0, ETEXT('\x07'), ETEXT('\x07'), emu_bell}, // Ctrl-G
  49. {0, ETEXT('\x08'), ETEXT('\x08'), backspace}, // Backspace
  50. {0, ETEXT('\x09'), ETEXT('\x09'), tabn}, // Tab
  51. {0, ETEXT('\x0A'), ETEXT('\x0B'), emuLineFeed}, // NL - VT
  52. {0, ETEXT('\x0C'), ETEXT('\x0C'), AnsiFormFeed}, // Form Feed
  53. {0, ETEXT('\x0D'), ETEXT('\x0D'), carriagereturn}, // CR
  54. {3, ETEXT('\x18'), ETEXT('\x18'), EmuStdChkZmdm}, // Ctrl-X
  55. {0, ETEXT('\x00'), ETEXT('\x1F'), emuStdGraphic}, // All Ctrl's
  56. {NEW_STATE, 0, 0, 0}, // State 1 // Esc
  57. {2, ETEXT('\x5B'), ETEXT('\x5B'), ANSI_Pn_Clr}, // [
  58. {0, ETEXT('\x44'), ETEXT('\x44'), ANSI_IND}, // D
  59. {0, ETEXT('\x45'), ETEXT('\x45'), ANSI_NEL}, // E
  60. {0, ETEXT('\x48'), ETEXT('\x48'), ANSI_HTS}, // H
  61. {0, ETEXT('\x4D'), ETEXT('\x4D'), ANSI_RI}, // M
  62. {NEW_STATE, 0, 0, 0}, // State 2 // Esc[
  63. {2, ETEXT('\x30'), ETEXT('\x39'), ANSI_Pn}, // 0 - 9
  64. {2, ETEXT('\x3B'), ETEXT('\x3B'), ANSI_Pn_End}, // ;
  65. {5, ETEXT('\x3D'), ETEXT('\x3D'), nothing}, // =
  66. {2, ETEXT('\x3A'), ETEXT('\x3F'), ANSI_Pn}, // : - ?
  67. {0, ETEXT('\x41'), ETEXT('\x41'), ANSI_CUU}, // A
  68. {0, ETEXT('\x42'), ETEXT('\x42'), ANSI_CUD}, // B
  69. {0, ETEXT('\x43'), ETEXT('\x43'), ANSI_CUF}, // C
  70. {0, ETEXT('\x44'), ETEXT('\x44'), ANSI_CUB}, // D
  71. {0, ETEXT('\x48'), ETEXT('\x48'), ANSI_CUP}, // H
  72. {0, ETEXT('\x4A'), ETEXT('\x4A'), ANSI_ED}, // J
  73. {0, ETEXT('\x4B'), ETEXT('\x4B'), ANSI_EL}, // K
  74. {0, ETEXT('\x4C'), ETEXT('\x4C'), ANSI_IL}, // L
  75. {0, ETEXT('\x4D'), ETEXT('\x4D'), ANSI_DL}, // M
  76. {0, ETEXT('\x50'), ETEXT('\x50'), ANSI_DCH}, // P
  77. {0, ETEXT('\x5A'), ETEXT('\x5A'), ANSI_CBT}, // Z (Back tab (CBT))
  78. {0, ETEXT('\x66'), ETEXT('\x66'), ANSI_CUP}, // f
  79. {0, ETEXT('\x67'), ETEXT('\x67'), ANSI_TBC}, // g
  80. {0, ETEXT('\x68'), ETEXT('\x68'), ansi_setmode}, // h
  81. {0, ETEXT('\x69'), ETEXT('\x69'), vt100PrintCommands},// i
  82. {0, ETEXT('\x6C'), ETEXT('\x6C'), ansi_resetmode}, // l
  83. {0, ETEXT('\x6D'), ETEXT('\x6D'), ANSI_SGR}, // m
  84. {0, ETEXT('\x6E'), ETEXT('\x6E'), ANSI_DSR}, // n
  85. {0, ETEXT('\x70'), ETEXT('\x70'), nothing}, // p
  86. {0, ETEXT('\x72'), ETEXT('\x72'), vt_scrollrgn}, // r
  87. {0, ETEXT('\x73'), ETEXT('\x73'), ansi_savecursor}, // s
  88. {0, ETEXT('\x75'), ETEXT('\x75'), ansi_savecursor}, // u
  89. {NEW_STATE, 0, 0, 0}, // State 3 // Ctrl-X
  90. {3, ETEXT('\x00'), ETEXT('\xFF'), EmuStdChkZmdm}, // all codes
  91. {NEW_STATE, 0, 0, 0}, // State 4 // Ctrl-A
  92. {4, ETEXT('\x00'), ETEXT('\xFF'), nothing}, // all codes
  93. {NEW_STATE, 0, 0, 0}, // State 5 // Esc[=
  94. {5, ETEXT('\x32'), ETEXT('\x32'), ANSI_Pn}, // 2
  95. {5, ETEXT('\x35'), ETEXT('\x35'), ANSI_Pn}, // 5
  96. {0, ETEXT('\x68'), ETEXT('\x68'), DoorwayMode}, // h
  97. {0, ETEXT('\x6C'), ETEXT('\x6C'), DoorwayMode}, // l
  98. };
  99. emuInstallStateTable(hhEmu, ansi_tbl, DIM(ansi_tbl));
  100. // Allocate space for and initialize data that is used only by the
  101. // ANSI emulator.
  102. //
  103. hhEmu->pvPrivate = malloc(sizeof(ANSIPRIVATE));
  104. if (hhEmu->pvPrivate == 0)
  105. {
  106. assert(FALSE);
  107. return;
  108. }
  109. pstPRI = (PSTANSIPRIVATE)hhEmu->pvPrivate;
  110. memset(pstPRI, 0, sizeof(ANSIPRIVATE));
  111. // Initialize standard handle items.
  112. //
  113. hhEmu->emuResetTerminal = emuAnsiReset;
  114. emuKeyTableLoad(hhEmu, AnsiKeyTable,
  115. sizeof(AnsiKeyTable)/sizeof(KEYTBLSTORAGE),
  116. &hhEmu->stEmuKeyTbl);
  117. emuKeyTableLoad(hhEmu, IBMPCKeyTable,
  118. sizeof(IBMPCKeyTable)/sizeof(KEYTBLSTORAGE),
  119. &hhEmu->stEmuKeyTbl2);
  120. hhEmu->emu_kbdin = ansi_kbdin;
  121. hhEmu->emu_deinstall = emuAnsiUnload;
  122. emuAnsiReset(hhEmu, FALSE);
  123. #if !defined(FAR_EAST)
  124. hhEmu->emu_highchar = (TCHAR)0xFF;
  125. #else
  126. hhEmu->emu_highchar = (TCHAR)0xFFFF;
  127. #endif
  128. backscrlSetShowFlag(sessQueryBackscrlHdl(hhEmu->hSession), TRUE);
  129. return;
  130. }
  131. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  132. * emuAnsiReset
  133. *
  134. * DESCRIPTION:
  135. * Resets the ANSI emulator.
  136. *
  137. * ARGUMENTS:
  138. * fHostRequest - TRUE if result of codes from host
  139. *
  140. * RETURNS:
  141. * nothing
  142. */
  143. int emuAnsiReset(const HHEMU hhEmu, const int fHostRequest)
  144. {
  145. hhEmu->mode_KAM = hhEmu->mode_IRM = hhEmu->mode_VEM =
  146. hhEmu->mode_HEM = hhEmu->mode_LNM = hhEmu->mode_DECCKM =
  147. hhEmu->mode_DECOM = hhEmu->mode_DECCOLM = hhEmu->mode_DECPFF =
  148. hhEmu->mode_DECPEX = hhEmu->mode_DECSCNM =
  149. hhEmu->mode_25enab = hhEmu->mode_protect =
  150. hhEmu->mode_block = hhEmu->mode_local = RESET;
  151. hhEmu->mode_SRM = hhEmu->mode_DECTCEM = SET;
  152. hhEmu->mode_AWM = hhEmu->stUserSettings.fWrapLines;
  153. if (fHostRequest)
  154. {
  155. ANSI_Pn_Clr(hhEmu);
  156. ANSI_SGR(hhEmu);
  157. ANSI_RIS(hhEmu);
  158. }
  159. return 0;
  160. }
  161. /* end of ansiinit.c */