home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
windows
/
winkerm.zip
/
WINMSC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-10-10
|
11KB
|
405 lines
/***************************************************************************
*
* Winmsc.c
*
* This module contains utility routines used by other modules
*
***************************************************************************/
#include <windows.h>
#include "winkrm.h"
/***************************************************************************
*
* About
*
* Displays an 'About' box
*
* Entry: Standard windows function parameters
*
* Exit: About box taken down (WM_COMMAND message) or default action.
*
* Note: This is the window procedure for the About dialog box.
*
***************************************************************************/
BOOL FAR PASCAL About(hDlg, message, wParam,lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{
if (message == WM_COMMAND) {
EndDialog(hDlg, TRUE);
return(TRUE);
}
else if (message == WM_INITDIALOG)
return(TRUE);
else
return(FALSE);
}
/***************************************************************************
*
* cinchr
*
* cinchr gets a character from the communications port and adds its value
* to the current checksum.
*
* Entry: None
*
* Exit: Next character returned and checksum updated.
*
* Notes: This reoutine is called during a protocol file transfer
*
***************************************************************************/
cinchr()
{
char ch;
ch = inchar(); /* get the character */
cchksum += ch; /* add to checksum */
return(ch);
}
/***************************************************************************
*
* inchar
*
* inchar is called during a protocol file transfer to return the next
* character in the holding buffer. If the buffer is empty, inchar attempts
* to replenish it from the communications buffer.
*
* Entry: None
*
* Exit: Returns next character, or EOF if no more available.
*
***************************************************************************/
inchar()
{
static char RXBuf[100]; /* holding buffer */
static int RXBufCount = 0; /* holding buffer counter */
static int RXBufPos; /* holding buffer pointer */
if (RXBufCount <= 0) {
if ((RXBufCount = GetBuf(RXBuf)) == 0)
return(EOF);
RXBufPos = 0;
}
RXBufCount -= 1;
return(RXBuf[RXBufPos++]);
}
/***************************************************************************
*
* GetBuf
*
* This important routine fills a buffer passed to it from the commications
* port buffer.
*
* Entry: character buffer
*
* Exit: number of characters placed in buffer or zero.
*
* Notes: GetBuf is also responsible for calling the Windows message function.
* If there are no messages, it checks the port for characters, and
* if found, it fills the buffer with as many characters as possible.
*
* If there are no data from the commications port, GetBuf will simply
* read and dispatch messages. The function never returns a zero
* value unless CurrentState, as selected by the user from the state menu
* is no longer equal to the state (RECEIVE or SEND) of the calling
* module. When the latter occurs, GetBuf returns with 0. Any function
* calling GetBuf, such as inchar above, must then act accordingly
* (such as returning EOF) since this is a signal that the user has
* selected a new state or is toggling the current state off.
*
* Any errors in reading the comm port are ignored.
***************************************************************************/
GetBuf(Buffer)
char Buffer[];
{
COMSTAT ComStatus;
int num, result;
/*
wait in this loop until either the buffer can be filled or
the selected state is changed. If there are messages to process,
do them first.
*/
while (CurrentState == ThisState) {
if (!DoMessage()) { /* read messages */
/* see if anything in comm buffer */
GetCommError(cid, (COMSTAT FAR *)&ComStatus);
/* if found, retrieve them */
if ((num = ComStatus.cbInQue) != 0) {
result = ReadComm(cid,(LPSTR)Buffer,num >RXSIZE ? RXSIZE : num);
if (result)
/*
non-zero result means data found. If negative, error
occurred, but ignore it in this implementation and return
number of characters found.
*/
return(result > 0 ? result : -result);
}
}
}
return(0); /* forced out of while loop, return 0 */
}
/***************************************************************************
*
* spar
*
* fill a data packet with my send-init characters.
*
* Entry: data packet to be filled.
*
* Exit: data packet filled with my parameters.
*
* Note: used by foreign host to prepare a packet sent to me
* during a protocol file transfer.
*
***************************************************************************/
spar(data)
char data[];
{
data[0] = tochar(MAXPACKSIZ); /* my max packet size */
data[1] = tochar(MYTIME); /* my time out */
data[2] = tochar(MYPAD); /* my number of pad characters */
data[3] = ctl(MYPCHAR); /* my padding character */
data[4] = tochar(MYEOL); /* my end of line character */
data[5] = MYQUOTE; /* my quote character */
}
/***************************************************************************
*
* rpar
*
* get the other side's send-init parameters.
*
* Entry: a data packet filled with the send-init parameters wanted
* by the other side during a protocol file transfer.
*
* Exit: packet variables updated to those needed by the other side.
*
***************************************************************************/
rpar(data)
char data[];
{
spsiz = unchar(data[0]); /* max size of packet to send */
timint = unchar(data[1]); /* wait this long before timing out other side */
pad = unchar(data[2]); /* no. of pad chars to send */
padchar = ctl(data[3]); /* which padding char to send */
eol = unchar(data[4]); /* end of line char to send */
quote = data[5]; /* quote char other size wants */
}
/***************************************************************************
*
* dopar
*
* currently a dummy routine
*
***************************************************************************/
dopar(ch)
char ch;
{
return (ch);
}
/***************************************************************************
*
*
***************************************************************************/
spack(type, num ,len, data)
char type, *data;
int num, len;
{
int i, k;
BYTE chksum;
char buffer[100];
char ShortStr[2];
if (debug) {
if (data != NULL)
data[len] = '\0';
printf("spack type: %c\n", type);
printf(" num: %d\n", num);
printf(" len: %d\n", len);
if (data != NULL)
printf(" data: \"%s\"\n", data);
}
k = 0;
ShortStr[1] = '\0';
for (i = 1; i <= pad; i++) {
ShortStr[0] = padchar;
WriteComm(cid, (LPSTR)ShortStr,1);
}
buffer[k++] = dopar(SOH);
buffer[k++] = dopar(tochar(len+3));
chksum = tochar(len+3);
buffer[k++] = dopar(tochar(num));
chksum += tochar(num);
buffer[k++] = dopar(type);
chksum += type;
for (i = 0; i < len; i++) {
buffer[k++] = dopar(data[i]);
chksum += data[i];
}
chksum = (((chksum & 0300) >> 6) + chksum)&077;
buffer[k++] = dopar(tochar(chksum));
buffer[k++] = dopar(eol);
buffer[k] = '\0';
if (pktdeb)
fprintf(dpfp,"\r\nSpack:%s", buffer);
WriteComm(cid, (LPSTR)buffer, strlen(buffer));
}
/***************************************************************************
*
*
***************************************************************************/
rpack(len,num,data)
int *len, *num;
char data[];
{
int i, done;
int t;
char type;
BYTE rchksum;
if (pktdeb)
fprintf(dpfp, "\r\nRpack:");
while ((t = inchar()) != SOH)
if (t == EOF)
return(FALSE);
done = FALSE;
while (!done) {
cchksum = 0;
if ((t = cinchr()) == SOH)
continue;
if (t == EOF)
return(FALSE);
*len = unchar(t) - 3;
if ((t = cinchr()) == SOH)
continue;
if (t == EOF)
return(FALSE);
*num = unchar(t);
if ((t = cinchr()) == SOH)
continue;
if (t == EOF)
return(FALSE);
type = t;
for (i = 0; i < *len; i++) {
if ((t = cinchr()) == SOH)
continue;
if (t == EOF)
return(FALSE);
data[i] = t;
}
data[*len] = '\0';
if ((t = inchar()) == SOH)
continue;
if (t == EOF)
return(FALSE);
rchksum = unchar(t);
done = TRUE;
}
if (debug) {
if (data != NULL)
data[*len] = '\0';
printf("rpack type: %c\n", type);
printf(" num: %d\n", *num);
printf(" len: %d\n", *len);
if (data != NULL)
printf(" data: \"%s\"\n", data);
}
cchksum = (((cchksum&0300) >> 6)+cchksum)&077;
if (cchksum != rchksum)
return (FALSE);
return(type);
}
/***************************************************************************
*
*
***************************************************************************/
printmsg(mess)
char *mess;
{
MessageBox(hKermWnd, (LPSTR)mess,
(LPSTR)szWinTitle, MB_OK | MB_ICONEXCLAMATION);
}
/***************************************************************************
*
*
***************************************************************************/
prerrpkt(msg)
char msg[];
{
MessageBox(hKermWnd, (LPSTR)msg,
(LPSTR)"Kermit Abort", MB_OK | MB_ICONEXCLAMATION);
}
/***************************************************************************
*
*
***************************************************************************/
GrayMenuItems(hWnd)
HWND hWnd;
{
HMENU hMenu = GetMenu(hWnd);
EnableMenuItem(hMenu, CONNECTSTATE, MF_GRAYED);
EnableMenuItem(hMenu, RECEIVESTATE, MF_GRAYED);
EnableMenuItem(hMenu, SENDSTATE, MF_GRAYED);
EnableMenuItem(hMenu, BAUD2400, MF_GRAYED);
EnableMenuItem(hMenu, BAUD1200, MF_GRAYED);
EnableMenuItem(hMenu, BAUD300, MF_GRAYED);
}
/***************************************************************************
*
*
***************************************************************************/
UnGrayMenuItems(hMenu)
HANDLE hMenu;
{
EnableMenuItem(hMenu, CONNECTSTATE, MF_ENABLED);
EnableMenuItem(hMenu, RECEIVESTATE, MF_ENABLED);
EnableMenuItem(hMenu, SENDSTATE, MF_ENABLED);
EnableMenuItem(hMenu, BAUD2400, MF_ENABLED);
EnableMenuItem(hMenu, BAUD1200, MF_ENABLED);
EnableMenuItem(hMenu, BAUD300, MF_ENABLED);
}