home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / win100b / wktv52.l < prev    next >
Text File  |  1991-10-19  |  8KB  |  496 lines

  1. /*
  2.  * VT52 protocol module
  3.  * This file must be processed by MKS Lex
  4.  * 
  5.  * Copyright (c) 1990, 1991 by
  6.  * William S. Hall
  7.  * 3665 Benton Street  #66
  8.  * Santa Clara, CA 95051
  9.  *
  10.  */
  11.  
  12. %{
  13. #define NOKANJI
  14. #define NOATOM
  15. #define NOMINMAX
  16. #define NOSOUND
  17. #include <windows.h>
  18. #ifdef COLUMBIA
  19. #include "wktsmt.h"
  20. #include "wkt100.h"
  21. #else
  22. #include "smterm.h"
  23. #include "win600.h"
  24. #endif
  25. #ifdef WIN600
  26. #include "grterm.h"
  27. #endif
  28.  
  29. #undef YYLEX
  30. #define YYLEX vt52
  31.  
  32. #undef YYLMAX
  33. #define YYLMAX (BUFSIZE + 1)
  34.  
  35. #define YY_PRESERVE
  36.  
  37. #undef YY_INTERACTIVE
  38. #define YY_INTERACTIVE    0
  39.  
  40. #undef output
  41. #define output    ;
  42.  
  43. #undef yygetc
  44. #define yygetc mygetc
  45.  
  46. #undef YY_FATAL
  47. #define YY_FATAL(msg) {HWND hError = GetTopWindow(MWnd.hWnd); \
  48.                if (!hError) hError = MWnd.hWnd; \
  49.                MessageBox(hError,msg,szAppName, \
  50.                   MB_OK | MB_ICONEXCLAMATION); \
  51.                PostMessage(MWnd.hWnd, WM_SYSCOMMAND, SC_CLOSE, 0L); \
  52. }
  53.  
  54. static int NEAR mygetc(void);
  55. static short currow;
  56.  
  57. %}
  58.  
  59. ENQ    [\005]
  60. BEL    [\007]
  61. BS    [\010]
  62. HT    [\011]
  63. LF    [\012]
  64. VT    [\013]
  65. FF    [\014]
  66. CR    [\015]
  67. SO    [\016]
  68. SI    [\017]
  69. CAN    [\030]
  70. EM    [\031]
  71. SUB    [\032]
  72. ESC    [\033]
  73. FS    [\034]
  74. GS    [\035]
  75. RS    [\036]
  76. US    [\037]
  77. SPC    [\040]
  78. DEL    [\177]
  79. ANSI    [\040-\176\221-\222\240-\377]
  80. CTRL    [\000-\037\177\200-\220\223-\237]
  81.  
  82. %s esc row rowesc col
  83. %x ctrl
  84.  
  85. %%
  86.  
  87. <ctrl>[\012-\014] {
  88.     SendMessage(hWndText,SMT_STRINGINPUT,yyleng,(LONG)(LPSTR)yytext);
  89.     SendMessage(hWndText, SMT_COMMAND, SM_NEXTLINE, (LONG)yyleng);
  90. }
  91.  
  92. <ctrl>[\000-\011\015-\377]+ {
  93.     SendMessage(hWndText,SMT_STRINGINPUT,yyleng,(LONG)(LPSTR)yytext);
  94. }
  95.  
  96. {ENQ}+ {
  97.     if (MWnd.AutoAnswer) {
  98.     while (yyleng--)
  99.         ShowAnswerBack();
  100.     }
  101. }
  102.  
  103. {BEL}+ {
  104.     if (MWnd.WarningBell) {
  105.     while (yyleng--)
  106.         MessageBeep(0);
  107.     }
  108. }
  109.  
  110. {BS}+ {
  111.     SendMessage(hWndActive, SMT_COMMAND, SM_BKSP, (LONG)yyleng);
  112. }    
  113.  
  114. {HT}+ {
  115.     SendMessage(hWndActive, SMT_COMMAND, SM_TAB, (LONG)yyleng);
  116. }    
  117.  
  118. [\012-\014]+ {
  119.     SendMessage(hWndActive, SMT_COMMAND,
  120.         MWnd.LFCR ? SM_NEXTLINE : SM_INDEX, (LONG)yyleng);
  121. }
  122.  
  123. {CR}+ {
  124.     SendMessage(hWndActive, SMT_COMMAND, SM_LEFTMARGIN, (LONG)yyleng);
  125. }
  126.  
  127. {CAN}+ {
  128.     BEGIN 0;
  129. }
  130.  
  131. {SUB}+ {
  132.     SendMessage(hWndActive,SMT_STRINGINPUT,yyleng,(LONG)(LPSTR)yytext);
  133.     BEGIN 0;
  134. }
  135.  
  136. <0>{ESC} {
  137.     BEGIN esc;
  138. }
  139.  
  140. {CTRL} {
  141.     ;
  142. }
  143.  
  144. <0>{ANSI}+ {
  145.     SendMessage(hWndActive,SMT_STRINGINPUT,yyleng,(LONG)(LPSTR)yytext);
  146. }
  147.  
  148. <esc>{ESC} {
  149.     ;
  150. }
  151.  
  152. <esc>\< {
  153.     SendMessage(hWndActive,SMT_COMMAND,SM_SETCHARSET,(LONG)ANSI_CHARSET);
  154.     SetAlphaParams(100);
  155.     if (input() != EOF)
  156.         pushback();
  157.     return 1;
  158. }
  159.  
  160. <esc>= {
  161.     MWnd.ApplMode = TRUE;
  162.     BEGIN 0;
  163. }
  164.  
  165. <esc>\> {
  166.     MWnd.ApplMode = FALSE;
  167.     BEGIN 0;
  168. }
  169.  
  170. <esc>A {
  171.     SendMessage(hWndActive, SMT_COMMAND, SM_CURSORUP,1L);
  172.     BEGIN 0;
  173. }
  174.     
  175. <esc>B {
  176.     SendMessage(hWndActive, SMT_COMMAND, SM_CURSORDOWN,1L);
  177.     BEGIN 0;
  178. }
  179.     
  180. <esc>C {
  181.     SendMessage(hWndActive, SMT_COMMAND, SM_CURSORRIGHT,1L);
  182.     BEGIN 0;
  183. }
  184.     
  185. <esc>D {
  186.     SendMessage(hWndActive, SMT_COMMAND, SM_CURSORLEFT,1L);
  187.     BEGIN 0;
  188. }
  189.  
  190. <esc>F {
  191.     // Enter line drawing graphics
  192.     SendMessage(hWndActive,SMT_COMMAND,SM_SETCHARSET,(LONG)SYMBOL_CHARSET);
  193.     BEGIN 0;
  194. }
  195.  
  196. <esc>G {
  197.     // Exit line drawing graphics
  198.     SendMessage(hWndActive,SMT_COMMAND,SM_SETCHARSET,(LONG)0);
  199.     BEGIN 0;
  200. }
  201.  
  202. <esc>H {
  203.     SendMessage(hWndActive, SMT_COMMAND, SM_CURSORHOME,0L);
  204.     BEGIN 0;
  205. }
  206.  
  207. <esc>I {
  208.     SendMessage(hWndActive, SMT_COMMAND, SM_REVERSEINDEX, 1L);
  209.     BEGIN 0;
  210. }
  211.  
  212. <esc>J {
  213.     SendMessage(hWndActive, SMT_COMMAND, SM_CLRTOENDOFPAGE,0L);
  214.     BEGIN 0;
  215. }
  216.  
  217. <esc>K {
  218.     SendMessage(hWndActive, SMT_COMMAND, SM_CLRTOENDOFLINE, 0L);
  219.     BEGIN 0;
  220. }
  221.  
  222. <esc>V {
  223.     // Print line of cursor
  224.     BEGIN 0;
  225. }
  226.  
  227. <esc>W {
  228.     // enter printer controller mode
  229.     BEGIN 0;
  230. }
  231.  
  232. <esc>X {
  233.     // exit printer controller mode
  234.     BEGIN 0;
  235. }
  236.  
  237. <esc>Y {
  238.     BEGIN row;
  239. }
  240.  
  241. <esc>Z {
  242.     IdentifyTerm(52);
  243.     BEGIN 0;
  244. }
  245.  
  246. <esc>\] {
  247.     // Print page
  248.     BEGIN 0;
  249. }
  250.  
  251. <esc>\^ {
  252.     // enter autoprint mode
  253.     BEGIN 0;
  254. }
  255.  
  256. <esc>\_ {
  257.     // exit autoprint mode
  258.     BEGIN 0;
  259. }
  260.  
  261. <esc>{ANSI} {
  262.     BEGIN 0;
  263. }
  264.  
  265. <row>{ESC} {
  266.     BEGIN rowesc;
  267. }
  268.  
  269. <row>{ANSI} {
  270.     currow = *yytext - 31;
  271.     BEGIN col;
  272. }
  273.  
  274. <rowesc>{ESC} {
  275.     ;
  276. }
  277.  
  278. <rowesc>{ANSI} {
  279.     BEGIN row;
  280. }
  281.  
  282. <col>{ESC} {
  283.     BEGIN rowesc;
  284. }
  285.  
  286. <col>{ANSI} {
  287.     SendMessage(hWndActive,SMT_COMMAND,SM_POSITIONCURSOR,
  288.                     MAKELONG(currow, *yytext - 31));
  289.     BEGIN 0;
  290. }
  291.  
  292. %%
  293.  
  294. void FAR vt52SetState(int state)
  295. {
  296.     if (state < 0)
  297.     BEGIN ctrl;
  298.     else
  299.         BEGIN state;
  300. }
  301.  
  302. static int NEAR mygetc()
  303. {
  304.  
  305.     if (pBuf->len > 0) {
  306.     pBuf->len--;
  307.     return (*pBuf->ptr++) & curproto.mask;
  308.     }    
  309.     else
  310.     return EOF;
  311.     
  312. }
  313.  
  314. void FAR VT52SpecialKeys(int item)
  315. {
  316.  
  317.     int index;
  318.  
  319.     static char *VT52Keys[] = {
  320.         "\033A","\033B","\033C","\033D","\033H",    // 4
  321.     "\033P","\033Q","\033R","\033S",        // 8
  322.     "\033?p","0",
  323.     "\033?q","1",
  324.     "\033?r","2",
  325.     "\033?s","3",
  326.     "\033?t","4",
  327.     "\033?u","5",
  328.     "\033?v","6",
  329.     "\033?w","7",
  330.     "\033?x","8",
  331.     "\033?y","9",
  332.     "\033?l","+",    // 29
  333.     "\033?m","-",
  334.     "\033?n",".",
  335.     "\033?M","*",
  336.     };
  337.  
  338.     switch(item) {
  339.     case IDM_UP:
  340.     case IDM_S_UP:
  341.     case IDM_C_UP:
  342.     case IDM_CS_UP:
  343.         index = 0;
  344.         break;
  345.  
  346.     case IDM_DOWN:
  347.     case IDM_S_DOWN:
  348.     case IDM_C_DOWN:
  349.     case IDM_CS_DOWN:
  350.         index = 1;
  351.         break;
  352.  
  353.     case IDM_RIGHT:
  354.     case IDM_S_RIGHT:
  355.     case IDM_C_RIGHT:
  356.     case IDM_CS_RIGHT:
  357.         index = 2;
  358.         break;
  359.  
  360.     case IDM_LEFT:
  361.     case IDM_S_LEFT:
  362.     case IDM_C_LEFT:
  363.     case IDM_CS_LEFT:
  364.         index = 3;
  365.         break;
  366.  
  367.     case IDM_HOME:
  368.     case IDM_S_HOME:
  369.     case IDM_C_HOME:
  370.     case IDM_CS_HOME:
  371.         index = 4;
  372.         break;
  373.  
  374.     case IDM_F1:
  375.         index = 5;
  376.         break;
  377.  
  378.     case IDM_F2:
  379.         index = 6;
  380.         break;
  381.  
  382.     case IDM_F3:
  383.         index = 7;
  384.         break;
  385.  
  386.     case IDM_F4:
  387.         index = 8;
  388.         break;
  389.  
  390.     case IDM_NUM0:
  391. //    case IDM_S_NUM0:
  392.     case IDM_C_NUM0:
  393. //    case IDM_CS_NUM0:
  394.         index = (MWnd.ApplMode ? 9 : 10);
  395.         break;
  396.  
  397.     case IDM_NUM1:
  398. //    case IDM_S_NUM1:
  399.     case IDM_C_NUM1:
  400. //    case IDM_CS_NUM1:
  401.         index = (MWnd.ApplMode ? 11 : 12);
  402.         break;
  403.  
  404.     case IDM_NUM2:
  405. //    case IDM_S_NUM2:
  406.     case IDM_C_NUM2:
  407. //    case IDM_CS_NUM2:
  408.         index = (MWnd.ApplMode ? 13 : 14);
  409.         break;
  410.  
  411.     case IDM_NUM3:
  412. //    case IDM_S_NUM3:
  413.     case IDM_C_NUM3:
  414. //    case IDM_CS_NUM3:
  415.         index = (MWnd.ApplMode ? 15 : 16);
  416.         break;
  417.  
  418.     case IDM_NUM4:
  419. //    case IDM_S_NUM4:
  420.     case IDM_C_NUM4:
  421. //    case IDM_CS_NUM4:
  422.         index = (MWnd.ApplMode ? 17 : 18);
  423.         break;
  424.  
  425.     case IDM_NUM5:
  426. //    case IDM_S_NUM5:
  427.     case IDM_C_NUM5:
  428. //    case IDM_CS_NUM5:
  429.         index = (MWnd.ApplMode ? 19 : 20);
  430.         break;
  431.  
  432.     case IDM_NUM6:
  433. //    case IDM_S_NUM6:
  434.     case IDM_C_NUM6:
  435. //    case IDM_CS_NUM6:
  436.         index = (MWnd.ApplMode ? 21 : 22);
  437.         break;
  438.  
  439.     case IDM_NUM7:
  440. //    case IDM_S_NUM7:
  441.     case IDM_C_NUM7:
  442. //    case IDM_CS_NUM7:
  443.         index = (MWnd.ApplMode ? 23 : 24);
  444.         break;
  445.  
  446.     case IDM_NUM8:
  447. //    case IDM_S_NUM8:
  448.     case IDM_C_NUM8:
  449. //    case IDM_CS_NUM8:
  450.         index = (MWnd.ApplMode ? 25 : 26);
  451.         break;
  452.  
  453.     case IDM_NUM9:
  454. //    case IDM_S_NUM9:
  455.     case IDM_C_NUM9:
  456. //    case IDM_CS_NUM9:
  457.         index = (MWnd.ApplMode ? 27 : 28);
  458.         break;
  459.  
  460.     case IDM_ADD:        // replacing VT100 keypad comma for keypad
  461. //    case IDM_S_ADD:
  462.     case IDM_C_ADD:
  463. //    case IDM_CS_ADD:
  464.         index = 
  465.         (MWnd.ApplMode && (GetKeyState(VK_NUMLOCK) & 1) ? 29 : 30);
  466.         break;
  467.  
  468.     case IDM_SUBTRACT:
  469. //    case IDM_S_SUBTRACT:
  470.     case IDM_C_SUBTRACT:
  471. //    case IDM_CS_SUBTRACT:
  472.         index = 
  473.         (MWnd.ApplMode && (GetKeyState(VK_NUMLOCK) & 1) ? 31 : 32);
  474.         break;
  475.  
  476.     case IDM_DECIMAL:
  477. //    case IDM_S_DECIMAL:
  478.     case IDM_C_DECIMAL:
  479. //    case IDM_CS_DECIMAL:
  480.         index = (MWnd.ApplMode ? 33 : 34);
  481.         break;
  482.  
  483.     case IDM_MULTIPLY:    // replacing VT100 enter key for keypad
  484. //    case IDM_S_MULTIPLY:
  485.     case IDM_C_MULTIPLY:
  486. //    case IDM_CS_MULTIPLY:
  487.         index = 
  488.         (MWnd.ApplMode && (GetKeyState(VK_NUMLOCK) & 1) ? 35 : 36);
  489.         break;
  490.  
  491.     default:
  492.         return;
  493.     }
  494.     WriteToComm(VT52Keys[index], strlen(VT52Keys[index]));
  495. }
  496.