home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / winkerm.zip / WINCON.C < prev    next >
C/C++ Source or Header  |  1986-10-10  |  3KB  |  133 lines

  1.  
  2. /***************************************************************************
  3. *
  4. * Wincon
  5. *
  6. * Dumb terminal emulation module
  7. *
  8. ***************************************************************************/
  9. #include <windows.h>
  10. #include "winkrm.h"
  11.      
  12. void NEAR DisplayBuf(char*, int);
  13.      
  14. /***************************************************************************
  15. *
  16. * connect
  17. *
  18. * Connect loop for Windows Kermit
  19. *
  20. * Entry: None.
  21. *
  22. * Exit: None.
  23. *
  24. ***************************************************************************/
  25. connect()
  26. {
  27.      
  28.     int length;
  29.     char RXBuf[RXSIZE];        /* holding buffer for display */
  30.      
  31.     ThisState = CONNECTSTATE;
  32.     while ((length = GetBuf(RXBuf)) > 0) {
  33.         HideCaret(hKermWnd);        /* hide caret, display buffer */
  34.         DisplayBuf(RXBuf,length);
  35.         SetCaretPos(Xpos,Ypos);        /* update caret, show caret */
  36.         ShowCaret(hKermWnd);
  37.     }
  38. }
  39.      
  40. /***************************************************************************
  41. *
  42. * DisplayBuf
  43. *
  44. * Display the current contents of the holding buffer and update screen buffer.
  45. *
  46. * Entry: Buffer and its size.
  47. *
  48. * Exit:  Character displayed on screen and screen memory buffer updated.
  49. *
  50. ***************************************************************************/
  51. void NEAR DisplayBuf(Buffer, count)
  52. char Buffer[];
  53. int count;
  54. {
  55.      
  56.     int k;
  57.     char ch;
  58.     static char ShortStr[2] = {0,0};    /* used for TextOut */
  59.      
  60.     k = 0;
  61.     SetTextColor(hKermDC, GetSysColor(COLOR_WINDOWTEXT));
  62.     while (count > 0) {
  63.     ch = Buffer[k++] & 127;        /* strip parity */
  64.     count -= 1;
  65.     switch(ch) {
  66.         case 7:            /* bell */
  67.         MessageBeep(0);
  68.         break;
  69.         case 10:            /* line feed */
  70.             Ypos += CharHeight;
  71.         CurrentLine += LineIncrement;
  72.         ScreenBuf[CurrentLine + PosInLine] = NULL;
  73.         if (PosInLine > 0) {
  74.             int i;
  75.             for (i = 0; i < PosInLine;i++)
  76.             ScreenBuf[CurrentLine + i] = ' ';
  77.         }
  78.         break;
  79.         case 13:            /* carriage return */
  80.             Xpos = 0;
  81.         PosInLine = 0;
  82.         break;
  83.         case 8:            /* delete and backspace */
  84.         case 127:
  85.             if (Xpos > 0) {
  86.                 Xpos -= CharWidth;
  87.             PosInLine -= 1;
  88.             ScreenBuf[CurrentLine + PosInLine] = NULL;
  89.         }
  90.         break;
  91.         default:
  92. /*
  93.  * Display other characters.  At the moment, control characters are
  94.  * being displayed.  Need to add a 'transparent' operation to menu.
  95. */
  96.             if (ch < 32) {
  97.             ShortStr[0] = ch;
  98.             TextOut(hKermDC, Xpos, Ypos, (LPSTR)ShortStr, 1);
  99.             Xpos += CharWidth;
  100.         }
  101.         else {
  102.             ShortStr[0] = ch;
  103.             TextOut(hKermDC, Xpos, Ypos, (LPSTR)ShortStr, 1);
  104.             Xpos += CharWidth;
  105.         }
  106.         ScreenBuf[CurrentLine + PosInLine++] = ch;
  107.         ScreenBuf[CurrentLine + PosInLine] = NULL;
  108.         break;
  109.     }
  110.     if (Xpos >= MaxDevCoorLen) {
  111.         Xpos = 0;
  112.         Ypos += CharHeight;
  113.         PosInLine = 0;
  114.         CurrentLine += LineIncrement;
  115.         ScreenBuf[CurrentLine] = NULL;
  116.     }
  117.     if (CurrentLine >= MaxChars) {
  118.         CurrentLine = 0;
  119.         ScreenBuf[CurrentLine] = NULL;
  120.     }
  121.     if (Ypos >= YClientSize) {
  122.         Xpos = 0;
  123.         Ypos = YClientSize - CharHeight;
  124.         PosInLine = 0;
  125.         FirstLine += LineIncrement;
  126.         if (FirstLine >= MaxChars)
  127.         FirstLine = 0;                
  128.         ScrollWindow(hKermWnd,0,-CharHeight, NULL, NULL);
  129.         UpdateWindow(hKermWnd);        /* needed after a scroll */
  130.     }
  131.     }
  132. }
  133.