Category : C Source Code
Archive   : WINKERM.ZIP
Filename : KERMTERM.C

 
Output of file : KERMTERM.C contained in archive : WINKERM.ZIP
/*******************************************************************************
** **
** Kermit for Microsoft Windows **
** ---------------------------- **
** KERMTERM.C **
** **
** This module contains the terminal emulation procedures. A 24 X 80 TTY **
** is currently the only emulation supported (more to come). **
** **
*******************************************************************************/

// INCLUDES -------------------------------------------------------------------

#include "kermit.h"
#include

//-----------------------------------------------------------------------------
VOID NEAR GetTermFontMetrics(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
HDC hDC;
TEXTMETRIC tm;

hDC = GetDC(hAppWnd);
SelectObject(hDC, hTermFont);
GetTextMetrics(hDC, &tm);
ReleaseDC(hAppWnd, hDC);

xTermChar = tm.tmAveCharWidth;
yTermChar = tm.tmHeight + tm.tmExternalLeading;
}

//-----------------------------------------------------------------------------
VOID NEAR CreateTermFont(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
LOGFONT lf;

lf.lfHeight = 8;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = 0;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = OEM_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
lf.lfFaceName[0] = '\0';

hTermFont = CreateFontIndirect(&lf);
}

//-----------------------------------------------------------------------------
VOID MoveCursor(int Col, int Row)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
SetCaretPos((nCurCol*xTermChar)-xOffset,
(nCurRow*yTermChar)-yOffset);
}

//-----------------------------------------------------------------------------
VOID WriteTermChar(char TermChar, BOOL Raw)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
static BOOL bEscape = FALSE;
static BOOL bEscSeq = FALSE;
static int nParmCnt;
static char szEscSeq[80];
static int nParm[10];
static int nSavRow, nSavCol;

if (bEscape) {
if (TermChar == '[') {
bEscSeq = TRUE;
nParmCnt = 0;
memset(szEscSeq, '\0', sizeof(szEscSeq));
}
bEscape = FALSE;
return;
}

if (bEscSeq) {
if (isdigit(TermChar)) {
szEscSeq[strlen(szEscSeq)] = TermChar;
return;
}

nParm[nParmCnt++] = atoi(szEscSeq);
memset(szEscSeq, '\0', sizeof(szEscSeq));

switch (TermChar) {
case ';':
return;

case 'H':
case 'f':
nCurRow = min(TERMROWS - 1, max(0, nParm[0] - 1));
nCurCol = min(TERMCOLS - 1, max(0, nParm[1] - 1));
break;

case 'A':
nCurRow = max(0, nCurRow - max(1, nParm[0]));
break;

case 'B':
nCurRow = min(TERMROWS - 1, nCurRow + max(1, nParm[0]));
break;

case 'C':
nCurCol = min(TERMCOLS - 1, nCurCol + max(1, nParm[0]));
break;

case 'D':
nCurCol = max(0, nCurCol - max(1, nParm[0]));
break;

case 's':
nSavRow = nCurRow;
nSavCol = nCurCol;
break;

case 'u':
nCurRow = nSavRow;
nCurCol = nSavCol;
break;

case 'J':
if (nParm[0] == 2) {
memset(Screen, 0, TERMROWS * TERMCOLS);
nCurRow = 0;
nCurCol = 0;
InvalidateRect(hAppWnd, NULL, FALSE);
}
break;

case 'K':
memset(&Screen[nCurRow] [nCurCol], ' ', TERMCOLS - nCurCol);
InvalidateRect(hAppWnd, NULL, FALSE);
break;
}

bEscSeq = FALSE;
return;
}

if (Raw || TermChar >= 32) {
RECT rectTerm;

rectTerm.left = (nCurCol * xTermChar) - xOffset;
rectTerm.top = (nCurRow * yTermChar) - yOffset;
rectTerm.right = rectTerm.left + xTermChar;
rectTerm.bottom = rectTerm.top + yTermChar;
InvalidateRect(hAppWnd, &rectTerm, FALSE);

Screen [nCurRow] [nCurCol] = TermChar;

if (nCurCol < (TERMCOLS-1))
nCurCol += 1;
else if (TermSet.LineWrap)
WriteTermStr("\r\n", 2, FALSE);

return;
}

switch(TermChar) {
case 7: /* bell */
MessageBeep(0);
break;

case 8: /* backspace */
if (nCurCol > 0)
nCurCol -= 1;
break;

case 9: /* tab */
do
WriteTermChar(' ', TRUE);
while ((nCurCol % 8) && (nCurCol < (TERMROWS - 1)));
break;

case 10: /* line feed */
if (++nCurRow == TERMROWS) {
memmove(Screen, Screen[1], (TERMROWS-1)*TERMCOLS);
memset(Screen[TERMROWS-1], 0, TERMCOLS);
// ScrollWindow(hAppWnd, 0, -yTermChar, NULL, NULL);
InvalidateRect(hAppWnd, NULL, FALSE);
nCurRow -= 1;
}
break;

case 12: /* form feed */
memset(Screen, 0, TERMROWS*TERMCOLS);
nCurRow = 0;
nCurCol = 0;
InvalidateRect(hAppWnd, NULL, FALSE);
break;

case 13: /* carriage return */
nCurCol = 0;
if (!TermSet.NewLine)
break;

case 27: /* escape */
bEscape = TRUE;
break;

default:
WriteTermChar(TermChar, TRUE);
break;
}
}

//-----------------------------------------------------------------------------
VOID WriteTermStr(LPSTR TermStr, int StrLen, BOOL Raw)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
int i;

for (i = 0; i < StrLen; i++)
WriteTermChar(TermStr[i], Raw);
}

//-----------------------------------------------------------------------------
VOID WriteTermFmt(PSTR pszFmt, ...)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
char sWork[128];
va_list pArg;
int nLen;

va_start(pArg, pszFmt);
nLen = vsprintf(sWork, pszFmt, pArg);
va_end(pArg);

WriteTermStr(sWork, nLen, FALSE);
}

//-----------------------------------------------------------------------------
VOID ProcessTermLine(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
int nLength;
char RXBuf[64];

while ((nLength = ReadCommStr(RXBuf, sizeof(RXBuf), TRUE)) > 0)
WriteTermStr(RXBuf, nLength, FALSE);

MoveCursor(nCurCol, nCurRow);
}

//-----------------------------------------------------------------------------
VOID ProcessTermChar(char cChar)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
if (bConnected && !bKermit) {
WriteCommChar(cChar);
if (TermSet.LocalEcho)
WriteTermChar(cChar, FALSE);
}
}

//-----------------------------------------------------------------------------
VOID ProcessTermKey(WORD cKey)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
char szWorkStr[16];

switch (cKey) {
case VK_LEFT:
strcpy(szWorkStr, " [D");
break;

case VK_UP:
strcpy(szWorkStr, " [A");
break;

case VK_RIGHT:
strcpy(szWorkStr, " [C");
break;

case VK_DOWN:
strcpy(szWorkStr, " [B");
break;


default:
return;
}

szWorkStr[0] = 27;

if (bConnected && !bKermit) {
WriteCommStr(szWorkStr, strlen(szWorkStr));
if (TermSet.LocalEcho)
WriteTermStr(szWorkStr, strlen(szWorkStr), FALSE);
}
}

//-----------------------------------------------------------------------------
VOID InitTerm(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
xTermSize = 0;
yTermSize = 0;

xScroll = 0;
xScroll = 0;

xOffset = 0;
yOffset = 0;

memset(Screen, 0, TERMROWS*TERMCOLS);
nCurRow = 0;
nCurCol = 0;
}

//-----------------------------------------------------------------------------
VOID OpenTerm(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
CreateTermFont();
GetTermFontMetrics();

CreateCaret(hAppWnd, NULL, xTermChar, yTermChar);
ShowCaret(hAppWnd);
}

//-----------------------------------------------------------------------------
VOID CloseTerm(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
HideCaret(hAppWnd);
DestroyCaret();
}



  3 Responses to “Category : C Source Code
Archive   : WINKERM.ZIP
Filename : KERMTERM.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/