Example #1
0
DECODE_REF
copen (PVOID InStream, STREAM_TYPE SType, STREAM_MODE SMode)
{
	MEM_HANDLE h;
	DWORD StreamLength;

	_StreamType = SType;
	_Stream = InStream;
	if (SMode == STREAM_WRITE) /* writing */
	{
		OutChar (0); /* skip future StreamLength */
		OutChar (0);
		OutChar (0);
		OutChar (0);

		StreamLength = 0;
	}
	else /* reading */
	{
		BYTE lobyte, hibyte;
		UWORD loword, hiword;

		lobyte = (BYTE)InChar ();
		hibyte = (BYTE)InChar ();
		loword = MAKE_WORD (lobyte, hibyte);
		lobyte = (BYTE)InChar ();
		hibyte = (BYTE)InChar ();
		hiword = MAKE_WORD (lobyte, hibyte);

		StreamLength = MAKE_DWORD (loword, hiword);
	}

	h = 0;
	if (StreamLength == 0xFFFFFFFF
			|| (h = AllocCodeDesc ()) == 0
			|| (_lpCurCodeDesc = LockCodeDesc (h)) == 0)
	{
		_lpCurCodeDesc = 0;
		FreeCodeDesc (h);
	}
	else
	{
		_lpCurCodeDesc->fh = h;
		_lpCurCodeDesc->Stream = _Stream;
		_lpCurCodeDesc->StreamType = _StreamType;
		_lpCurCodeDesc->StreamMode = SMode;
		_lpCurCodeDesc->StreamLength = StreamLength;
		_lpCurCodeDesc->buf_index = N - F;
		memset ((PBYTE)&_lpCurCodeDesc->text_buf[0], ' ', N - F);

		StartHuff ();
	}

	return ((DECODE_REF)_lpCurCodeDesc);
}
Example #2
0
/**
Begin the Y-Modem transfer.

@param timeout	Time in milliseconds to wait receiver to become ready.

@return Zero if transfer initialisation was successful, or an error code on failure.
*/
int QymodemTx::SendInitialise(unsigned timeout)
        {
    emit Information("Waiting for Receiver",QymodemTx::InfoSending);
        if(timeout<SendTimeout)
                timeout = SendTimeout;

        while(InChar(-1)>=0) // flush input buffers
                {}

        CancelCount = 0;

        int c;
        for(;;)
                {
                const unsigned timeoutStep = 100;
                c = InChar(timeoutStep);
                if(c=='G')
                        {
                        SendCRC = true;
                        WaitForBlockACK = false;
                        break;
                        }
                else if(c=='C')
                        {
                        SendCRC = true;
                        WaitForBlockACK = true;
                        break;
                        }
                else if(c==NAK)
                        {
                        SendCRC = false;
                        WaitForBlockACK = true;
                        break;
                        }
                if(c<0 && c!=ErrorTimeout)
                        return c;
                if(timeout<timeoutStep)
                        return ErrorTimeout;
                timeout -= timeoutStep;
                }

        ModeChar = c;
        return 0;
        }
Example #3
0
void ReadDefinition(FILE *f)
/*   --------------  */
{
    Boolean	LastWasPeriod=false;
    char	c;

    Buff = Alloc(BuffSize=50, char);
    BN = 0;

    while ( true )
    {
	c = InChar(f);

	if ( c == '|' ) SkipComment;

	if ( c == EOF || c == '\n' && LastWasPeriod )
	{
	    /*  The definition is complete.  Add a period if it's
		not there already and terminate the string  */

	    if ( ! LastWasPeriod ) Append('.');
	    Append(0);

	    return;
	}

	if ( Space(c) )
	{
	    Append(' ');
	}
	else
	if ( c == '\\' )
	{
	    /*  Escaped character -- bypass any special meaning  */

	    Append(InChar(f));
	}
	else
	{
	    LastWasPeriod = ( c == '.' );
	    Append(c);
	}
    }
}
Example #4
0
int QymodemTx::SendY(const char* fileName, size_t size, InStream& in, unsigned timeout)
        {
        Use1KBlocks = true;
        quint8 buffer[128];
        int result = MakeBlock0(buffer,fileName,size);
        if(result<0)
                return result;

        result = SendInitialise(timeout);
        if(result<0 && result!=ErrorBlockRetriesExceded)
                return result;
        emit Information("Sending "+QString(fileName),QymodemTx::InfoSending);
        BlockNumber = 0;
        result = SendBlock(buffer,sizeof(buffer));
        if(result<0)
                return result;

        result = InChar(SendTimeout);
        if(result<0)
                return result;
        if(result!=ModeChar)
                return ErrorReceiverNotBehaving;

        result = SendAll(in);
        if(result<0)
                return result;

        result = InChar(SendTimeout);
        if(result<0)
                return result;
        if(result!=ModeChar)
                return ErrorReceiverNotBehaving;

        memset(buffer,0,sizeof(buffer));
        BlockNumber = 0;
        result = SendBlock(buffer,sizeof(buffer));
        if(result<0)
                return result;
        emit Percent(100);
        return 0;
        }
Example #5
0
static UWORD
GetBits (BYTE num_bits)
{
	SWORD i;

	while (_workbuflen <= 8)
	{
		if ((i = InChar ()) < 0)
			i = 0;
		_workbuf |= i << (8 - _workbuflen);
		_workbuflen += 8;
	}
	i = (_workbuf & 0xFFFF) >> (16 - num_bits);
	_workbuf = (_workbuf << num_bits) & 0xFFFF;
	_workbuflen -= num_bits;

	return (i);
}
Example #6
0
/* get one bit */
static SWORD
GetBit (void)
{
	SWORD i;

	while (_workbuflen <= 8)
	{
		if ((i = InChar ()) < 0)
			i = 0;
		_workbuf |= i << (8 - _workbuflen);
		_workbuflen += 8;
	}
	i = (_workbuf & 0xFFFF) >> (16 - 1);
	_workbuf = (_workbuf << 1) & 0xFFFF;
	_workbuflen--;

	return (i);
}