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

 
Output of file : KERMIT.C contained in archive : WINKERM.ZIP
/*******************************************************************************
** **
** Kermit for Microsoft Windows **
** ---------------------------- **
** KERMIT.C **
** **
** Version 0.50 - Developmental **
** Requires Microsoft Windows 2.X **
** Author: Wayne Warthen **
** **
** Primary application source file containing the WinMain() and the client **
** Window message handling procedure and support functions. **
** **
*******************************************************************************/

// DEFINITIONS ----------------------------------------------------------------

#define STATIC

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

#include "kermit.h"
#include "kermprot.h"

//-----------------------------------------------------------------------------
int FAR PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int cmdShow)

// Top level application function called by MS Windows
// when Kermit is executed. Returns program result code.

// Param(s): hInstance.......Handle to this instance.
// hPrevInstance...Handle to previous instance (if any).
// lpszCmdLine.....Command line parms.
// cmdShow.........Window type requested.

// Returns: Kermit program result code (not used).

{
MSG Msg;

DEBSTMT(DebugInit(hInstance, hPrevInstance, lpszCmdLine, cmdShow);)

if (!KermitInit(hInstance, hPrevInstance, lpszCmdLine, cmdShow))
return(FALSE);

while (TRUE) {
while (PeekMessage (&Msg, NULL, 0, 0, PM_REMOVE)) {
if (Msg.message == WM_QUIT) {
DEBSTMT(DebugTerm();)
return(Msg.wParam);
}
if (!bKermit || !IsDialogMessage(hXfrWnd, &Msg)) {
if (!TranslateAccelerator (hAppWnd, hMenuAccel, &Msg)) {
if (!bKermit || !TranslateAccelerator(hAppWnd,
hXferAccel, &Msg)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
}
}
if (bKermit)
DoKermit();
else if (bConnected)
ProcessTermLine();
}
}

//-----------------------------------------------------------------------------
VOID NEAR KermPaint(HWND hWnd)

// Description of what function does.

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

// Returns: Result description.

{
PAINTSTRUCT ps;
HDC hDC;
RECT Rect;
int Row, Col, EndRow, EndCol, Count, HorzPos, VertPos;

hDC = BeginPaint(hWnd, &ps);
Rect = ps.rcPaint;
SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
SelectObject(hDC, hTermFont);

Row = max(0, (Rect.top+yOffset)/yTermChar);
EndRow = min(TERMROWS-1, (Rect.bottom+yOffset)/yTermChar);
Col = max(0, (Rect.left+xOffset)/xTermChar);
EndCol = min(TERMCOLS-1, (Rect.right+xOffset)/xTermChar);
Count = EndCol-Col+1;

// fprintf(stdprn, "Painting Columns %i-%i, Rows %i-%i\r\n",
// Col, EndCol, Row, EndRow);
// fflush(stdprn);

HorzPos = (Col*xTermChar)-xOffset;
VertPos = (Row*yTermChar)-yOffset;

for (; Row<=EndRow; Row++) {
TextOut(hDC, HorzPos, VertPos, &Screen [Row] [Col], Count);
VertPos += yTermChar;
}

EndPaint(hWnd, &ps);
}

//-----------------------------------------------------------------------------
BOOL NEAR KermSize(HWND hWnd, WORD wNewVertSize, WORD wNewHorzSize)

// Description of what function does.

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

// Returns: Result description.

{
int nScrollAmt;

if (yTermSize != wNewVertSize) {
yTermSize = wNewVertSize;
yScroll = max(0, (TERMROWS * yTermChar) - yTermSize);
nScrollAmt = min(yScroll, yOffset) - yOffset;
ScrollWindow(hWnd, 0, -nScrollAmt, NULL, NULL);
yOffset = yOffset + nScrollAmt;
SetScrollPos(hWnd, SB_VERT, yOffset, FALSE);
SetScrollRange(hWnd, SB_VERT, 0, yScroll, TRUE);
}

if (xTermSize != wNewHorzSize) {
xTermSize = wNewHorzSize;
xScroll = max(0, (TERMCOLS * xTermChar) - xTermSize);
nScrollAmt = min(xScroll, xOffset) - xOffset;
ScrollWindow(hWnd, -nScrollAmt, 0, NULL, NULL);
xOffset = xOffset + nScrollAmt;
SetScrollPos(hWnd, SB_HORZ, xOffset, FALSE);
SetScrollRange(hWnd, SB_HORZ, 0, xScroll, TRUE);
}

return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL NEAR KermVScroll(HWND hWnd, WORD wScrollCmd, WORD wScrollPos)

// Description of what function does.

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

// Returns: Result description.

{
int nScrollAmt;

switch (wScrollCmd) {
case SB_TOP:
nScrollAmt = -yOffset;
break;
case SB_BOTTOM:
nScrollAmt = yScroll - yOffset;
break;
case SB_PAGEUP:
nScrollAmt = -yTermSize;
break;
case SB_PAGEDOWN:
nScrollAmt = yTermSize;
break;
case SB_LINEUP:
nScrollAmt = -yTermChar;
break;
case SB_LINEDOWN:
nScrollAmt = yTermChar;
break;
case SB_THUMBPOSITION:
nScrollAmt = wScrollPos - yOffset;
break;
default:
return(FALSE);
break;
}
if ((yOffset + nScrollAmt) > yScroll)
nScrollAmt = yScroll - yOffset;
if ((yOffset + nScrollAmt) < 0)
nScrollAmt = -yOffset;
ScrollWindow(hWnd, 0, -nScrollAmt, NULL, NULL);
yOffset = yOffset + nScrollAmt;
SetScrollPos(hWnd, SB_VERT, yOffset, TRUE);
return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL NEAR KermHScroll(HWND hWnd, WORD wScrollCmd, WORD wScrollPos)

// Description of what function does.

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

// Returns: Result description.

{
int nScrollAmt;

switch (wScrollCmd) {
case SB_TOP:
nScrollAmt = -xOffset;
break;
case SB_BOTTOM:
nScrollAmt = xScroll - xOffset;
break;
case SB_PAGEUP:
nScrollAmt = -xTermSize;
break;
case SB_PAGEDOWN:
nScrollAmt = xTermSize;
break;
case SB_LINEUP:
nScrollAmt = -xTermChar;
break;
case SB_LINEDOWN:
nScrollAmt = xTermChar;
break;
case SB_THUMBPOSITION:
nScrollAmt = wScrollPos - xOffset;
break;
default:
return(FALSE);
break;
}
if ((xOffset + nScrollAmt) > xScroll)
nScrollAmt = xScroll - xOffset;
if ((xOffset + nScrollAmt) < 0)
nScrollAmt = -xOffset;
ScrollWindow(hWnd, -nScrollAmt, 0, NULL, NULL);
xOffset = xOffset + nScrollAmt;
SetScrollPos(hWnd, SB_HORZ, xOffset, TRUE);
return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL NEAR KermitCommand(HWND hWnd, WORD cmd, LONG lParam)

// Description of what function does.

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

// Returns: Result description.

{
switch (cmd) {
case IDM_ABOUT:
GoDialogBox(hAppInst, "AboutDlgBox", hWnd, AboutDlgProc);
break;

case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;

case IDM_TERMINAL:
GoDialogBox(hAppInst, "TermDlgBox", hWnd, TermDlgProc);
break;

case IDM_COMMUNICATIONS:
GoDialogBox(hAppInst, "CommDlgBox", hWnd, CommDlgProc);
break;

case IDM_MODEM:
GoDialogBox(hAppInst, "ModemDlgBox", hWnd, ModemDlgProc);
break;

case IDM_PROTOCOL:
GoDialogBox(hAppInst, "ProtocolDlgBox", hWnd, ProtocolDlgProc);
break;

case IDM_PACKETS:
GoDialogBox(hAppInst, "PacketsDlgBox", hWnd, PacketsDlgProc);
break;

case IDM_LOGGING:
GoDialogBox(hAppInst, "LoggingDlgBox", hWnd, LoggingDlgProc);
break;

case IDM_CONNECT:
if (bConnected)
Disconnect(FALSE);
else
Connect();
break;

case IDM_PRINT:
break;

case IDM_BREAK:
if (bConnected) {
clock_t wTime;
SetCommBreak(nCid);
for (wTime = clock(); (clock() - wTime) < (CLK_TCK / 4););
ClearCommBreak(nCid);
}
break;

case IDM_TRANSMIT:
break;

case IDM_CAPTURE:
break;

case IDM_SEND:
KermitSend();
break;

case IDM_RECEIVE:
KermitReceive();
break;

case IDM_SERVER:
KermitServer();
break;

case IDM_GET:
KermitGet();
break;

case IDM_HOST:
KermitHost();
break;

case IDM_GENERIC:
KermitGeneric();
break;

case IDM_CANFILE:
case IDM_CANBATCH:
case IDM_RETRY:
case IDM_STOP:
case IDM_ABORT:
KermitUserInt(cmd);
break;

case IDM_DEBDCB:
if (bConnected)
DebugComm();
else
MessageBeep(0);
break;

case IDM_DEBTEST1:
DEBASSERT(1==2)
break;

case IDM_DEBTEST2:
DEBTRACE(2, "Hello There")
break;

case IDM_DEBTEST3:
DEBPRINT(2, "Hello Again")
break;

case IDM_DEBTEST4:
case IDM_DEBTEST5:
case IDM_DEBTEST6:
break;

default:
return(FALSE);
}
return(TRUE);
}

//-----------------------------------------------------------------------------
LONG FAR PASCAL KermitWndProc(HWND hWnd, unsigned message,
WORD wParam, LONG lParam)

// Description of what function does.

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

// Returns: Result description.

{
switch (message) {

case WM_COMMAND:
return(KermitCommand(hWnd, wParam, lParam));
break;

case WM_SYSCOMMAND:
return(DefWindowProc(hWnd, message, wParam, lParam));
break;

case WM_SIZE:
return(KermSize(hWnd, HIWORD(lParam), LOWORD(lParam)));

case WM_VSCROLL:
return(KermVScroll(hWnd, wParam, LOWORD(lParam)));

case WM_HSCROLL:
return(KermHScroll(hWnd, wParam, LOWORD(lParam)));

case WM_CLOSE:
if (bConnected && !Disconnect(TRUE))
break;
DestroyWindow(hWnd);
hWnd = NULL;
break;

case WM_QUERYENDSESSION:
if (bConnected)
return(Disconnect(TRUE));
else
return(TRUE);

case WM_DESTROY:
PostQuitMessage(0);
break;

case WM_CHAR:
ProcessTermChar(LOBYTE(wParam));
break;

case WM_KEYDOWN:
ProcessTermKey(wParam);
break;

case WM_SETFOCUS:
if (bConnected) {
CreateCaret(hWnd, NULL, xTermChar, yTermChar);
MoveCursor(nCurCol, nCurRow);
ShowCaret(hWnd);
}
break;

case WM_KILLFOCUS:
if (bConnected) {
HideCaret(hWnd);
DestroyCaret();
}
break;

case WM_PAINT:
KermPaint(hWnd);
MoveCursor(nCurCol, nCurRow);
break;

default:
return(DefWindowProc(hWnd, message, wParam, lParam));
break;
}
return(TRUE);
}


  3 Responses to “Category : C Source Code
Archive   : WINKERM.ZIP
Filename : KERMIT.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/