home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / win100b / wktfns.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  21KB  |  1,085 lines

  1. /*
  2.  * Win100/Win600 support module
  3.  * 
  4.  * Copyright (c) 1990, 1991 by
  5.  * William S. Hall
  6.  * 3665 Benton Street  #66
  7.  * Santa Clara, CA 95051
  8.  *
  9.  */
  10.  
  11. #define NOKANJI
  12. #define NOATOM
  13. #define NOMINMAX
  14. #define NOSOUND
  15. #include <windows.h>
  16. #include <limits.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <io.h>
  20. #include <ascii.h>
  21. #include <stdio.h>
  22. #include <stdarg.h>
  23. #ifdef WIN600
  24. #include "grterm.h"
  25. #endif
  26. #ifdef COLUMBIA
  27. #include "wktsmt.h"
  28. #include "wkt100.h"
  29. #include "wktdlg.h"
  30. #else
  31. #include "smterm.h"
  32. #include "win600.h"
  33. #include "w600dg.h"
  34. #endif
  35. static void NEAR ShowFKeyString(char * keystr);
  36. static void NEAR LoadClipboardData(HWND hWnd);
  37. static void NEAR RecallSavedParams(HWND hWnd);
  38.  
  39. void FAR MakeCaret(BOOL make)
  40. {
  41.     HWND hWnd;
  42.     unsigned message;
  43.     WORD wparam;
  44.     LONG lparam;
  45.  
  46.     if (curproto.type == 'A') {
  47.     hWnd = hWndText;
  48.     message = SMT_CARETFUNCTION;
  49.     wparam = make ? SM_CREATECARET : SM_DESTROYCARET;
  50.     lparam = MAKELONG(MWnd.Cursor,MWnd.CursorType);
  51.         if (IsWindow(hWnd))
  52.             SendMessage(hWnd,message, wparam, lparam);
  53.     }
  54. #ifdef WIN600
  55.     else if (curproto.gtype == AG) {
  56.     hWnd = hWndGraph;
  57.     message = GRT_CARETFUNCTION;
  58.     wparam = make ? GR_CREATECARET : GR_DESTROYCARET;
  59.     lparam = 0;
  60.         if (IsWindow(hWnd))
  61.             SendMessage(hWnd,message, wparam, lparam);
  62.     }
  63. #endif
  64. }
  65.  
  66. /* repaint main window if iconic */
  67. void NEAR MainWndPaint(HWND hWnd, LPPAINTSTRUCT lpps)
  68. {
  69.  
  70.     SelectObject(lpps->hdc, MWnd.hBrush);
  71.     FillRect(lpps->hdc, (LPRECT)&lpps->rcPaint, MWnd.hBrush);
  72.  
  73.     if (IsIconic(hWnd)) {
  74.         RECT rIcon;
  75.     int color = (MWnd.Reverse ? MWnd.BGColor : MWnd.TextColor);
  76.     GetClientRect(hWnd, (LPRECT)&rIcon);
  77.     Rectangle(lpps->hdc, 0,0,rIcon.right, rIcon.bottom);
  78.     SetTextColor(lpps->hdc, ColorTable[color]);
  79.     SetBkMode(lpps->hdc, TRANSPARENT);
  80.         TextOut(lpps->hdc,2,rIcon.bottom/3,(LPSTR)szIcon,strlen(szIcon));
  81.     }
  82. }
  83.  
  84. /* close communications port */
  85. void CloseCommPort(HWND hWnd, int *pCid)
  86. {
  87.  
  88.     if (*pCid >=0) {
  89.         if (CloseComm(*pCid) >= 0)
  90.             *pCid = INT_MIN;
  91.     else 
  92.         ShowMessage(hWnd, IDS_CANNOTCLOSECOM, MB_OK | MB_ICONEXCLAMATION);
  93.     }
  94. }
  95.  
  96. /* show message box */
  97. int ShowMessage(HWND hWnd, int msgnum, WORD style)
  98. {
  99.  
  100.     char szMessage[MAXRCSTRLEN];
  101.     
  102.     LoadString(hInst, msgnum, (LPSTR)szMessage,sizeof(szMessage));
  103.     return (MessageBox(hWnd,(LPSTR)szMessage, (LPSTR)szAppName, style));
  104.  
  105. }
  106.  
  107. void BroadcastWinIniChange()
  108. {
  109.  
  110.     SendMessage((HWND)(-1), WM_WININICHANGE, 0, (LONG)(LPSTR)szAppName);
  111.         
  112. }
  113.  
  114. void NEAR WndCommand(HWND hWnd, WORD wParam, LONG lParam)
  115. {
  116.     HMENU hMenu = GetMenu(hWnd);
  117.     char str[80];
  118.  
  119.     switch(wParam) {
  120.  
  121.     case IDM_S_UP:
  122.         SendMessage(hWndText, SMT_COMMAND, SM_CURSORUP, 1);
  123.         break;
  124.  
  125.     case IDM_S_DOWN:
  126.         SendMessage(hWndText, SMT_COMMAND, SM_CURSORDOWN, 1);
  127.         break;
  128.  
  129.     case IDM_S_RIGHT:
  130.         SendMessage(hWndText, SMT_COMMAND, SM_CURSORRIGHT, 1);
  131.         break;
  132.  
  133.     case IDM_S_LEFT:
  134.         SendMessage(hWndText, SMT_COMMAND, SM_CURSORLEFT, 1);
  135.         break;
  136.  
  137.     case IDM_S_HOME:
  138.         SendMessage(hWndText, SMT_COMMAND, SM_CURSORHOME, 0);
  139.         break;
  140.  
  141.     case IDM_C_NUM8:
  142.     case IDM_C_UP:
  143.         SendMessage(hWndText, SMT_COMMAND, SM_SCROLLBACK,
  144.             MAKELONG(1, TRUE));
  145.         break;
  146.         
  147.     case IDM_C_NUM2:
  148.     case IDM_C_DOWN:
  149.         SendMessage(hWndText, SMT_COMMAND, SM_SCROLLBACK,
  150.             MAKELONG(1, FALSE));
  151.         break;
  152.  
  153.     case IDM_C_NUM9:
  154.     case IDM_C_PRIOR:
  155.         SendMessage(hWndText, SMT_COMMAND, SM_PAGEBACK,
  156.             MAKELONG(1, TRUE));
  157.         break;        
  158.  
  159.     case IDM_C_NUM3:
  160.     case IDM_C_NEXT:
  161.         SendMessage(hWndText, SMT_COMMAND, SM_PAGEBACK,
  162.             MAKELONG(1, FALSE));
  163.         break;        
  164.  
  165.     case IDM_C_HOME:
  166.     case IDM_C_NUM7:
  167.         SendMessage(hWndText, SMT_COMMAND, SM_HOMEEND,
  168.             MAKELONG(1, TRUE));
  169.         break;        
  170.  
  171.     case IDM_C_END:
  172.     case IDM_C_NUM1:
  173.         SendMessage(hWndText, SMT_COMMAND, SM_HOMEEND,
  174.             MAKELONG(1, FALSE));
  175.         break;        
  176.  
  177.     case IDM_MINI:
  178.         OpenDlgBox(hWnd, (FARPROC)MiniBoxProc, DT_MINI);
  179.         break;
  180.  
  181.     case IDM_ABOUT:
  182.         OpenDlgBox(hWnd, (FARPROC)AboutBoxProc, DT_ABOUT);
  183.         break;
  184.  
  185.     case IDM_MODEM:
  186.         OpenDlgBox(hWnd, (FARPROC)ModemBoxProc, DT_MODEM);
  187.         break;
  188.  
  189.     case IDM_DISPLAY:
  190.         OpenDlgBox(hWnd, (FARPROC)DisplayBoxProc, DT_DISPLAY);
  191.         break;
  192.  
  193.     case IDM_GENERAL:
  194.         OpenDlgBox(hWnd, (FARPROC)GeneralBoxProc, DT_GENERAL);
  195.         break;
  196.  
  197.     case IDM_KEYBOARD:
  198.         OpenDlgBox(hWnd, (FARPROC)KeyboardBoxProc, DT_KEYBOARD);
  199.         break;
  200.  
  201.     case IDM_COPYLINES:
  202.         OpenDlgBox(hWnd, (FARPROC)CopyBoxProc, DT_COPYLINES);
  203.         break;
  204.  
  205.     case IDM_FONTS:
  206.         OpenDlgBox(hWnd, (FARPROC)FontsBoxProc, DT_FONTS);
  207.         break;
  208.  
  209.     case IDM_PASTE:
  210.         LoadClipboardData(hWnd);
  211.         break;
  212.  
  213.     case IDM_CLEARCOM:
  214.         FlushComm(cid,0);
  215.         FlushComm(cid,1);
  216.         EscapeCommFunction(cid,SETXON);
  217.         if (LineState & LINE_ON)
  218.         TransmitCommChar(cid, XON);
  219.         break;
  220.  
  221.     case IDM_EDITFKEYS:
  222.         OpenDlgBox(hWnd, (FARPROC)EditFunctionKeys, DT_EDITFKEYS);
  223.         break;
  224.  
  225.     case IDM_RECALLSAVED:
  226.         RecallSavedParams(hWnd);
  227.         break;
  228.  
  229.     case IDM_GETFILE:
  230.         if (OpenDlgBox(hWnd, (FARPROC)LogFileBoxProc, DT_GETFILE)) {
  231.         LoadString(hInst, IDS_CLOSELOG, str, sizeof(str));
  232.             ChangeMenu(hMenu,wParam,str,IDM_CLOSEFILE,
  233.                         MF_BYCOMMAND | MF_CHANGE);
  234.         DrawMenuBar(hWnd);
  235.         }
  236.         break;
  237.  
  238.     case IDM_CLOSEFILE:
  239.         if (hLogFile > 0)
  240.         CloseLogFile();
  241.         LoadString(hInst, IDS_LOGSESSION, str, sizeof(str));
  242.         ChangeMenu(hMenu,wParam,str,IDM_GETFILE,
  243.                         MF_BYCOMMAND | MF_CHANGE);
  244.         DrawMenuBar(hWnd);
  245.         break;
  246.  
  247.     case IDM_HELP_HELP:
  248.         LoadString(hInst, IDS_WINHELPNAME, str, sizeof(str));
  249.         WinHelp(hWnd, str, HELP_INDEX, 0L);
  250.         break;
  251.  
  252.     case IDM_F5:
  253.         if (MWnd.BreakEnabled) {
  254.             if (!BreakState) {
  255.             BreakState = TRUE;
  256.                 SetCommBreak(cid);
  257.                 SetTimer(hWnd, wParam, 230, (FARPROC)NULL);
  258.             }
  259.         }
  260.         break;
  261.  
  262.     case IDM_F6:
  263.     case IDM_F7:
  264.     case IDM_F8:
  265.     case IDM_F9:
  266.     case IDM_F11:
  267.     case IDM_F12:
  268.         ShowFKeyString(szFKey[wParam - IDM_F1]);
  269.         break;
  270.  
  271.     case IDM_S_F1:
  272.     case IDM_S_F2:
  273.     case IDM_S_F3:
  274.     case IDM_S_F4:
  275.         ShowFKeyString(szSFKey[wParam - IDM_S_F1]);
  276.         break;
  277.  
  278.     case IDM_S_F5:
  279.         if (!BreakState) {
  280.             BreakState = TRUE;
  281.         EscapeCommFunction(cid, CLRDTR);
  282.         EscapeCommFunction(cid, CLRRTS);
  283.             SetCommBreak(cid);
  284.             SetTimer(hWnd, wParam, 1800, (FARPROC)NULL);
  285.         }
  286.         break;
  287.  
  288.     case IDM_S_F6:
  289.     case IDM_S_F7:
  290.     case IDM_S_F8:
  291.     case IDM_S_F9:
  292.     case IDM_S_F10:
  293.     case IDM_S_F11:
  294.     case IDM_S_F12:
  295.         ShowFKeyString(szSFKey[wParam - IDM_S_F1]);
  296.         break;
  297.  
  298.     case IDM_C_F1:
  299.     case IDM_C_F2:
  300.     case IDM_C_F3:
  301.     case IDM_C_F4:
  302.         ShowFKeyString(szCFKey[wParam - IDM_C_F1]);
  303.         break;
  304.  
  305.     case IDM_C_F5:        // show answerback message
  306.         ShowAnswerBack();
  307.         break;
  308.  
  309.     case IDM_C_F6:
  310.     case IDM_C_F7:
  311.     case IDM_C_F8:
  312.     case IDM_C_F9:
  313.     case IDM_C_F10:
  314.     case IDM_C_F11:
  315.     case IDM_C_F12:
  316.         ShowFKeyString(szCFKey[wParam - IDM_C_F1]);
  317.         break;
  318.  
  319.     case IDM_CS_F1:
  320.     case IDM_CS_F2:
  321.     case IDM_CS_F3:
  322.     case IDM_CS_F4:
  323.     case IDM_CS_F5:
  324.     case IDM_CS_F6:
  325.     case IDM_CS_F7:
  326.     case IDM_CS_F8:
  327.     case IDM_CS_F9:
  328.     case IDM_CS_F10:
  329.     case IDM_CS_F11:
  330.     case IDM_CS_F12:
  331.         ShowFKeyString(szCSFKey[wParam - IDM_CS_F1]);
  332.         break;
  333.  
  334.     default:
  335.         (*curproto.spkeys)((int)wParam);
  336.         break;
  337.     }
  338. }
  339.  
  340. void ShowAnswerBack()
  341. {
  342.     char str[20];
  343.  
  344.     LoadString(hInst, IDS_ANSWERBACKKEY, str, sizeof(str));
  345.     ShowFKeyString(str);
  346. }
  347.  
  348. static void NEAR RecallSavedParams(HWND hWnd)
  349. {
  350.     int result;
  351.  
  352.     MWnd.AutoAnswer = Initdata.AutoAnswer;
  353.     MWnd.BreakEnabled = Initdata.BreakEnabled;
  354.     MWnd.DeleteKey = Initdata.DeleteKey;
  355.     MWnd.CurKeyMode = Initdata.CursorKeys;
  356.     MWnd.ApplMode = Initdata.AltKeypad;
  357.     MWnd.WarningBell = Initdata.WarningBell;
  358.     MWnd.LFCR = Initdata.LFCR;
  359.  
  360.     if (curproto.type == 'A') {
  361.     curproto.mask = Initdata.EWidth == 7 ? 0x7f : 0xff;
  362.         SetAlphaParams(Initdata.AlphaEmulation);
  363.     }
  364.     MWnd.BGColor = Initdata.BGColor;
  365.     MWnd.TextColor = Initdata.TextColor;
  366.     MWnd.Reverse = Initdata.ReverseVideo;
  367.     InvertScreen(MWnd.Reverse);
  368.     MWnd.CursorType = Initdata.CursorType;
  369.     MWnd.Cursor = Initdata.Cursor;
  370.     if (MWnd.hWnd == GetFocus())
  371.     MakeCaret(TRUE);
  372.  
  373.     SendMessage(hWndText,SMT_SETATTRIBUTE,SM_MARGINBELL,
  374.         (LONG)Initdata.MarginBell);
  375.  
  376.     MWnd.Wrap = Initdata.Wrap;
  377.     SendMessage(hWndText, SMT_SETATTRIBUTE, SM_AUTOWRAP, (LONG)Initdata.Wrap);
  378.  
  379.     MWnd.ControlRep = Initdata.ControlRep;
  380.     if (MWnd.ControlRep) {
  381.     if (curproto.atype == 52)
  382.           vt52SetState(-1);
  383.     else
  384.         vt100SetState(-1);
  385.         SendMessage(hWndActive, SMT_SETATTRIBUTE, SM_AUTOWRAP, (LONG)TRUE);
  386.     }
  387.  
  388.     SendMessage(hWndText,SMT_SETATTRIBUTE,SM_SMOOTHSCROLL,
  389.         (LONG)Initdata.SmoothScroll);
  390.     SendMessage(hWndText,SMT_SETATTRIBUTE,SM_SCROLLUNITS,
  391.         (LONG)Initdata.ScrollUnits);
  392.  
  393.     SetCols(Initdata.TermCols);
  394.     LocalEcho = Initdata.LocalEcho;
  395.     if (Initdata.LocalMode) {
  396.     LineState = LOCAL_ON;
  397.     DoMessage = DoGetMessage;
  398.     } else {
  399.     LineState = LINE_ON + LocalEcho;
  400.     DoMessage = DoPeekMessage;
  401.     }
  402.     CommData.BaudRate = Initdata.BaudRate;
  403.     CommData.ByteSize = Initdata.ByteSize;
  404.     CommData.Parity = Initdata.Parity;
  405.     CommData.StopBits = 
  406.         (BYTE)(Initdata.StopBits == 1 ? ONESTOPBIT : TWOSTOPBITS);
  407.     CommData.fParity = Initdata.fParity;
  408.     CommData.fPeChar = Initdata.fParity;
  409.     CommData.fOutX = CommData.fInX = Initdata.XonXoff;
  410.     CommData.XoffLim = DEFRXQUE - Initdata.XoffLim;
  411.     if ((result = SetCommState((DCB FAR *)&CommData)) < 0)
  412.     ShowMessage(hWnd, result, MB_OK | MB_ICONASTERISK);
  413.  
  414. }
  415.  
  416. static void NEAR LoadClipboardData(HWND hWnd)
  417. {
  418.     HANDLE hClipData;
  419.     LPSTR lpClip, lpDest;
  420.     register BYTE ch;
  421.     LONG size;
  422.     HMENU hMenu = GetMenu(hWnd);
  423.  
  424.     if (OpenClipboard(hWnd)) {
  425.     hClipData = GetClipboardData(CF_TEXT);
  426.     if (GB.hBuf == NULL) {
  427.         size = GlobalSize(hClipData);
  428.             GB.hBuf = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size);
  429.         if (GB.hBuf != NULL) {
  430.             if (lpClip = GlobalLock(hClipData)) {
  431.             if (lpDest = GlobalLock(GB.hBuf)) {
  432.             GB.lBufHead = GB.lBufTail = 0;
  433.             GB.lBufSize = size;
  434.                     while(ch = *lpClip++) {
  435.                     if ((ch != LF) || ((ch == LF) && (MWnd.LFCR))) {
  436.                         *lpDest++ = ch;
  437.                         GB.lBufTail += 1;
  438.                     }
  439.                 }
  440.             EnableMenuItem(hMenu, IDM_PASTE, MF_GRAYED);
  441.             GlobalUnlock(GB.hBuf);
  442.             }
  443.             GlobalUnlock(hClipData);
  444.             }
  445.             }
  446.     }
  447.      CloseClipboard();
  448.     }
  449. }
  450.  
  451. static void NEAR ShowFKeyString(char *keystr)
  452. {
  453.  
  454.     BYTE buf1[80], buf2[80];
  455.     register int i, j;
  456.     BYTE ch;
  457.     int len = GetPrivateProfileString(szAppName, keystr, "", 
  458.                       buf1, sizeof(buf1), szIniName);
  459.  
  460.     for (i = 0, j = 0; i < len; i++) {
  461.     if ((ch = buf1[i]) == '$') {
  462.         ch = buf1[++i];
  463.         ch = (BYTE)toupper(ch);
  464.         if (('@' <= ch) && (ch <= '_'))
  465.         ch ^= 64;
  466.     }
  467.     buf2[j++] = ch;
  468.      }
  469.      buf2[j] = NUL;
  470.  
  471.     WriteToComm(buf2, j);
  472. }
  473.  
  474. void NEAR WndTimer(HWND hWnd, WORD id)
  475. {
  476.  
  477.     switch(id) {
  478.  
  479.     case IDM_F5:
  480.             KillTimer(hWnd, id);
  481.         ClearCommBreak(cid);
  482.         BreakState = FALSE;
  483.         break;
  484.  
  485.     case IDM_S_F5:
  486.             KillTimer(hWnd, id);
  487.         ClearCommBreak(cid);
  488.         EscapeCommFunction(cid, SETDTR);
  489.         EscapeCommFunction(cid, SETRTS);
  490.         BreakState = FALSE;
  491.         break;
  492.     }        
  493. }
  494.  
  495. void NEAR WriteClipData()
  496. {
  497.  
  498.     BYTE FAR *tbuf;
  499.     LONG BufBytesRemaining;
  500.     register int count, room;
  501.     COMSTAT comdata;
  502.  
  503.     GetCommError(cid, &comdata);
  504.     room = DEFTXQUE - comdata.cbOutQue;
  505.     BufBytesRemaining = GB.lBufTail - GB.lBufHead;
  506.     if ((BufBytesRemaining > 0) && (room > 80)) {
  507.         if (tbuf = GlobalLock(GB.hBuf) + GB.lBufHead) {
  508.         if (BufBytesRemaining > INT_MAX)
  509.             count = 80;
  510.         else
  511.             count = min(80, (int)LOWORD(BufBytesRemaining));
  512.         WriteComm(cid, tbuf, count);
  513.         GB.lBufHead += count;
  514.         BufBytesRemaining = GB.lBufTail - GB.lBufHead;
  515.             GlobalUnlock(GB.hBuf);
  516.     }
  517.     }
  518.     if (BufBytesRemaining <= 0) {
  519.         GB.hBuf = GlobalFree(GB.hBuf);
  520.     EnableMenuItem(GetMenu(MWnd.hWnd), IDM_PASTE, MF_ENABLED);
  521.     }
  522. }
  523.  
  524. void WriteToComm(BYTE *buf, int len)
  525. {
  526.  
  527.     if (LineState & LINE_ON)
  528.     WriteComm(cid, (LPSTR)buf, len);
  529.     if (LineState & LOCAL_ON) {
  530.         CharBuf.ptr = buf;
  531.         CharBuf.len = len;
  532.         pBuf = &CharBuf;
  533.     (*curproto.pf)();
  534.     }
  535. }
  536.  
  537. void InvertScreen(BOOL flag)
  538. {
  539.  
  540.     LONG Colors[2];
  541.     FARPROC fp;
  542.  
  543.     if (flag) {
  544.     Colors[0] = ColorTable[MWnd.BGColor];
  545.     Colors[1] = ColorTable[MWnd.TextColor];
  546.     } else {
  547.     Colors[0] = ColorTable[MWnd.TextColor];
  548.     Colors[1] = ColorTable[MWnd.BGColor];
  549.     }
  550.     DeleteObject(MWnd.hBrush);
  551.     MWnd.hBrush = CreateSolidBrush(Colors[1]);
  552.     
  553.     fp = MakeProcInstance((FARPROC)ColorChange,hInst);
  554.     EnumChildWindows(MWnd.hWnd, fp, (LONG)(LONG FAR *)Colors);
  555.     FreeProcInstance(fp);
  556.  
  557.     InvalidateRect(MWnd.hWnd, (LPRECT)NULL, TRUE);
  558. }
  559.  
  560. void IdentifyTerm(short id)
  561. {
  562.     switch(id) {
  563.     case 52:
  564.         WriteToComm("\033/Z", 3);
  565.         break;
  566.     case 100:
  567.         WriteToComm("\033[?1;0c", 7);
  568.         break;
  569.     }
  570. }
  571.  
  572. void ReportCursorPos(int r, int c)
  573. {
  574.     char buf[40];
  575.     char intbuf[20];
  576.  
  577.     memset(buf, 0, sizeof(buf));
  578.  
  579.     buf[0] = ESC;
  580.     buf[1] = '[';
  581.     itoa(r, intbuf, 10);
  582.     strcat(buf, intbuf);
  583.     buf[strlen(buf)] = ';';
  584.     itoa(c, intbuf, 10);
  585.     strcat(buf, intbuf);
  586.     buf[strlen(buf)] = 'R';
  587.     WriteToComm(buf, strlen(buf));
  588.  
  589. }
  590.  
  591. void NEAR ProcessChars(BYTE ch, int count)
  592. {
  593. #define KBDBUFSIZE    32
  594.  
  595.     register BYTE buf[KBDBUFSIZE + 1];
  596.     int lim = 0;
  597.     register int i;
  598.  
  599.     if (MWnd.DeleteKey) {
  600.     if (ch == BS)
  601.         ch = DEL;
  602.     else if (ch == DEL)
  603.         ch = BS;
  604.     }
  605.     
  606.     do {
  607.     i = 0;
  608.     while (i < KBDBUFSIZE) {
  609.         buf[i++] = ch;
  610.         if (MWnd.LFCR && (ch == CR))
  611.         buf[i++] = LF;
  612.         if (++lim >= count)
  613.         break;
  614.     }
  615.     WriteToComm(buf, i);
  616.     } while (lim < count);
  617. }
  618.  
  619. void SetCols(WORD cols)
  620. {
  621.  
  622.     LONG lParam = MAKELONG(MWnd.rect.right, MWnd.rect.bottom);
  623.     LONG range;
  624.  
  625.     SendMessage(hWndText, SMT_COMMAND, SM_SETCOLS, (LONG)cols);
  626.     if (curproto.type == 'A') {
  627.         if (MWnd.hWnd == GetFocus())
  628.         MakeCaret(TRUE);
  629.         range = SendMessage(hWndText, SMT_SIZEPARENT, (WORD)hWndText, lParam);
  630.         SetScrollPos(MWnd.hWnd, SB_HORZ, 0, FALSE);
  631.         SetScrollRange(MWnd.hWnd, SB_HORZ, 0, LOWORD(range), TRUE);
  632.     }
  633. }
  634.  
  635. void NEAR CloseLogFile()
  636. {
  637.      long size = lseek(hLogFile, 0L, SEEK_END);
  638.      hLogFile = close(hLogFile);
  639.      if (size == 0)
  640.     unlink(ofLogFile.szPathName);
  641.  
  642. }
  643.  
  644. void FAR pushback()
  645. {
  646.     pBuf->len++;
  647.     pBuf->ptr--;
  648.  
  649. }
  650.  
  651. void FAR SetAlphaParams(int type)
  652. {
  653.  
  654.     curproto.atype = type;
  655.  
  656.     switch(curproto.atype) {
  657.     case 100:
  658.     default:
  659.         curproto.pf = vt100;
  660. //        curproto.mask = 0x7f;
  661.         curproto.spkeys = ANSISpecialKeys;
  662.         vt100SetState(0);
  663.         break;
  664.     case 52:
  665.         curproto.pf = vt52;
  666. //        curproto.mask = 0x7f;
  667.         curproto.spkeys = VT52SpecialKeys;
  668.         vt52SetState(0);
  669.         break;
  670.     }
  671. }
  672.  
  673. int FAR yywrap()
  674. {
  675.     return 1;
  676. }
  677.  
  678. #if defined(WIN3)
  679. /* 
  680.  * This function replaces printf.
  681.  * To use this function you must load the device driver OX.SYS
  682.  * Do NOT run Windows with redirection to AUX.
  683.  * Use dbf just like printf.  There is no function prototype.
  684.  * Example dbf("function foo %d %s, myint, mystring);
  685.  */
  686. void FAR _cdecl dbs(const char *fmt, ...)
  687. {
  688.     char buf[255];
  689.  
  690.     va_list arg_ptr;
  691.  
  692.     va_start(arg_ptr, fmt);
  693.     vsprintf(buf, fmt, arg_ptr);
  694.     va_end(arg_ptr);
  695.  
  696.     OutputDebugString(buf);
  697.  
  698. }
  699. #endif
  700.  
  701. #ifdef WIN600
  702. void NEAR XCSpecialKeys(int item)
  703. {
  704.     WORD index;
  705.     int dist;
  706.  
  707.     switch (item) {
  708.     case IDM_UP:
  709.         index = 'D';
  710.         dist = 1;
  711.         break;
  712.     case IDM_DOWN:
  713.          index = 'H';
  714.          dist = 1;
  715.          break;
  716.     case IDM_RIGHT:
  717.         index = 'A';
  718.          dist = 1;
  719.          break;
  720.     case IDM_LEFT:
  721.         index = 'B';
  722.         dist = 1;
  723.         break;
  724.     case IDM_HOME:
  725.         index = 'F';
  726.         dist = 1;
  727.         break;
  728.     case IDM_END:
  729.         index = 'J';
  730.         dist = 1;
  731.         break;
  732.     case IDM_PRIOR:
  733.         index = 'E';
  734.         dist = 1;
  735.         break;
  736.     case IDM_NEXT:
  737.         index = 'I';
  738.         dist = 1;
  739.         break;
  740.  
  741.     case IDM_S_UP:
  742.         index = 'D';
  743.         dist = 8;
  744.         break;
  745.     case IDM_S_DOWN:
  746.          index = 'H';
  747.          dist = 8;
  748.          break;
  749.     case IDM_S_RIGHT:
  750.         index = 'A';
  751.          dist = 8;
  752.          break;
  753.     case IDM_S_LEFT:
  754.         index = 'B';
  755.         dist = 8;
  756.         break;
  757.     case IDM_S_HOME:
  758.         index = 'F';
  759.         dist = 8;
  760.         break;
  761.     case IDM_S_END:
  762.         index = 'J';
  763.         dist = 8;
  764.         break;
  765.     case IDM_S_PRIOR:
  766.         index = 'E';
  767.         dist = 8;
  768.         break;
  769.     case IDM_S_NEXT:
  770.         index = 'I';
  771.         dist = 8;
  772.         break;
  773.     default:
  774.         return;
  775.         break;
  776.     }
  777.     SendMessage(hWndActive, GRT_MOVEXHAIR, index, (LONG)dist);
  778. }
  779.  
  780. void NEAR AGSpecialKeys(int item)
  781. {
  782.  
  783.     int index;
  784.     BOOL internal = FALSE;
  785.  
  786.     static char *AGKeys[] = {
  787.         "\v",
  788.     "\n",
  789.     "\t",
  790.     "\b",
  791.     "@",
  792.     "A",
  793.     "B",
  794.     "C",
  795.     "D",
  796.     "E",
  797.     "F",
  798.     "G",
  799.     "H",
  800.     "I",
  801.     "L",
  802.     "<",
  803.     "=",
  804.     ">",
  805.     "?",
  806.     };
  807.     
  808.     switch(item) {
  809.     case IDM_UP:
  810.         internal = TRUE;
  811.         index = 0;
  812.         break;
  813.  
  814.     case IDM_DOWN:
  815.         internal = TRUE;
  816.         index = 1;
  817.         break;
  818.  
  819.     case IDM_RIGHT:
  820.         internal = TRUE;
  821.         index = 2;
  822.         break;
  823.  
  824.     case IDM_LEFT:
  825.         internal = TRUE;
  826.         index = 3;
  827.         break;
  828.  
  829.     case IDM_NUM0:
  830.         index = 4;
  831.         break;
  832.  
  833.     case IDM_NUM1:
  834.         index = 5;
  835.         break;
  836.  
  837.     case IDM_NUM2:
  838.         index = 6;
  839.         break;
  840.  
  841.     case IDM_NUM3:
  842.         index = 7;
  843.         break;
  844.  
  845.     case IDM_NUM4:
  846.         index = 8;
  847.         break;
  848.  
  849.     case IDM_NUM5:
  850.         index = 9;
  851.         break;
  852.  
  853.     case IDM_NUM6:
  854.         index = 10;
  855.         break;
  856.  
  857.     case IDM_NUM7:
  858.         index = 11;
  859.         break;
  860.  
  861.     case IDM_NUM8:
  862.         index = 12;
  863.         break;
  864.  
  865.     case IDM_NUM9:
  866.         index = 13;
  867.         break;
  868.  
  869.     case IDM_DECIMAL:
  870.         index = 14;
  871.         break;
  872.  
  873.     case IDM_F1:
  874.         index = 15;
  875.         break;
  876.  
  877.     case IDM_F2:
  878.         index = 16;
  879.         break;
  880.  
  881.     case IDM_F3:
  882.         index = 17;
  883.         break;
  884.  
  885.     case IDM_F4:
  886.         index = 18;
  887.         break;
  888.  
  889.     default:
  890.         return;
  891.     }
  892.     if (internal)
  893.     goto local;
  894.  
  895.     if (LineState & LINE_ON)
  896.     WriteComm(cid, (LPSTR)AGKeys[index], 1);
  897.     if (LineState & LOCAL_ON) {
  898. local:
  899.     CharBuf.ptr = AGKeys[index];
  900.     CharBuf.len = 1;
  901.     pBuf = &CharBuf;
  902.     yylex();
  903.     }
  904. }
  905.  
  906. void NEAR IPPSpecialKeys(int item)
  907. {
  908.  
  909.     int index;
  910.     static char *IPPKeys[] = {
  911.     " ",
  912.     "J",
  913.     "H",
  914.     "I",
  915.     "B",
  916.     " ",
  917.     "A",
  918.     "F",
  919.     "D",
  920.     "E",
  921.     "L",
  922.     "J",
  923.     "K",
  924.     "M",
  925.     "<",
  926.     "=",
  927.     ">",
  928.     "?",
  929.     "i",
  930.     "j",
  931.     "k",
  932.     "l",
  933.     "m",
  934.     "n"
  935.     };
  936.  
  937.     switch(item) {
  938.     case IDM_NUM0:
  939.     case IDM_C_NUM0:
  940.     case IDM_S_NUM0:
  941.     case IDM_CS_NUM0:
  942.         index = 0;
  943.         break;
  944.     case IDM_NUM1:    
  945.     case IDM_S_NUM1:    
  946.     case IDM_C_NUM1:    
  947.     case IDM_CS_NUM1:    
  948.         index = 1;
  949.         break;
  950.     case IDM_NUM2:    
  951.     case IDM_S_NUM2:    
  952.     case IDM_C_NUM2:    
  953.     case IDM_CS_NUM2:    
  954.         index = 2;
  955.         break;
  956.     case IDM_NUM3:
  957.     case IDM_S_NUM3:    
  958.     case IDM_C_NUM3:    
  959.     case IDM_CS_NUM3:    
  960.         index = 3;
  961.         break;
  962.     case IDM_NUM4:
  963.     case IDM_S_NUM4:    
  964.     case IDM_C_NUM4:    
  965.     case IDM_CS_NUM4:    
  966.         index = 4;
  967.         break;
  968.     case IDM_NUM5:
  969.     case IDM_S_NUM5:    
  970.     case IDM_C_NUM5:    
  971.     case IDM_CS_NUM5:    
  972.         index = 5;
  973.         break;
  974.     case IDM_NUM6:
  975.     case IDM_S_NUM6:    
  976.     case IDM_C_NUM6:    
  977.     case IDM_CS_NUM6:    
  978.         index = 6;
  979.         break;
  980.     case IDM_NUM7:    
  981.     case IDM_S_NUM7:    
  982.     case IDM_C_NUM7:    
  983.     case IDM_CS_NUM7:    
  984.         index = 7;
  985.         break;
  986.     case IDM_NUM8:
  987.     case IDM_S_NUM8:    
  988.     case IDM_C_NUM8:    
  989.     case IDM_CS_NUM8:    
  990.         index = 8;
  991.         break;
  992.     case IDM_NUM9:
  993.     case IDM_S_NUM9:    
  994.     case IDM_C_NUM9:    
  995.     case IDM_CS_NUM9:    
  996.         index = 9;
  997.         break;
  998.     case IDM_DECIMAL:
  999.     case IDM_S_DECIMAL:
  1000.     case IDM_C_DECIMAL:
  1001.     case IDM_CS_DECIMAL:
  1002.         index = 10;
  1003.         break;
  1004.     case IDM_SUBTRACT:
  1005.     case IDM_S_SUBTRACT:
  1006.     case IDM_C_SUBTRACT:
  1007.     case IDM_CS_SUBTRACT:
  1008.         index = 11;
  1009.         break;            
  1010.     case IDM_ADD:
  1011.     case IDM_S_ADD:
  1012.     case IDM_C_ADD:
  1013.     case IDM_CS_ADD:
  1014.         index = 12;
  1015.         break;
  1016.     case IDM_MULTIPLY:
  1017.     case IDM_S_MULTIPLY:
  1018.     case IDM_C_MULTIPLY:
  1019.     case IDM_CS_MULTIPLY:
  1020.         index = 13;
  1021.         break;
  1022.     case IDM_F1:
  1023.     case IDM_C_F1:
  1024.         index = 14;
  1025.         break;
  1026.     case IDM_F2:
  1027.     case IDM_C_F2:
  1028.         index = 15;
  1029.         break;
  1030.     case IDM_F3:
  1031.     case IDM_C_F3:
  1032.         index = 16;
  1033.         break;
  1034.     case IDM_F4:
  1035.     case IDM_C_F4:
  1036.         index = 17;
  1037.         break;
  1038.     case IDM_INSERT:
  1039.         index = 18;
  1040.         break;
  1041.     case IDM_HOME:
  1042.         index = 19;
  1043.         break;
  1044.     case IDM_PRIOR:
  1045.         index = 20;
  1046.         break;
  1047.     case IDM_DELETE:
  1048.         index = 21;
  1049.         break;
  1050.     case IDM_END:
  1051.         index = 22;
  1052.         break;
  1053.     case IDM_NEXT:
  1054.         index = 23;
  1055.         break;
  1056.     default:
  1057.         return;
  1058.     }
  1059.     WriteToComm(IPPKeys[index], 1);
  1060. }
  1061.  
  1062. void AnswerEnq(BYTE lead, int mode)
  1063. {
  1064.     BYTE buffer[10];
  1065.     long pos;
  1066.     WORD x,y;
  1067.  
  1068.     buffer[0] = lead;
  1069.     pos = SendMessage(hWndActive, GRT_COMMAND, GR_QUERYPOS, (LONG)mode);
  1070.     x = LOWORD(pos);
  1071.     buffer[2] = (BYTE)(x & 0x1f) + SP;
  1072.     buffer[1] = (BYTE)((x >> 5) & 0x1f) + SP;
  1073.     y = HIWORD(pos);
  1074.     buffer[4] = (BYTE)(y & 0x1f) + SP;
  1075.     buffer[3] = (BYTE)((y >> 5) & 0x1f) + SP;
  1076.  
  1077.     buffer[5] = CR;
  1078.     buffer[6] = EOT;
  1079.  
  1080.     if (LineState & LINE_ON)
  1081.         WriteToComm(buffer, 7);
  1082. }
  1083. #endif
  1084.  
  1085.