home *** CD-ROM | disk | FTP | other *** search
- /*
- * _ASCIIS.C
- *
- * Contains: _AsciiSend()
- * _AsciiSendExecuteLineDelay()
- * _AsciiSendLoadUpBuffer()
- * _AsciiSendTheBuffer()
- * _AsciiSendEchoSomeCharacters()
- *
- *
- * The Greenleaf Comm Library
- *
- * Copyright (C) 1989-90 Greenleaf Software Inc. All Rights Reserved.
- *
- */
-
- #include <stdio.h>
- #include "gf.h"
- #include "asiports.h"
- #include "xfer.h"
- #include "_xfer.h"
-
- /*
- * Local prototypes for static routines.
- */
-
- static int GF_CONV _AsciiSendExecuteLineDelay(XFER *ascii);
- static int GF_CONV _AsciiSendLoadUpBuffer(XFER *ascii);
- static int GF_CONV _AsciiSendTheBuffer(XFER *ascii);
- static int GF_CONV _AsciiSendEchoSomeCharacters(XFER *ascii);
-
-
- /*
- * int _AsciiSend( XFER *ascii )
- *
- * ARGUMENTS
- *
- * XFER *ascii: This is a pointer to an XFER block that
- * keeps track of how things are set up
- * for the file transfer.
- *
- * DESCRIPTION
- *
- * This routine is the private driver for performing an ascii file send.
- * The logic for the routine is fairly simple. The routine sits in a
- * big loop where it first fills up the buffer with a line of data. A line
- * is ended by either the first CR or LF, or when the line gets too long.
- * The line is then stuffed out into the transmit buffer. This continues
- * until the entire file has been transmitted. Although there is no
- * handshaking in place, a user defined delay is executed after each line
- * is transmitted.
- *
- * SIDE EFFECTS
- *
- * File may have been transfered.
- *
- * RETURNS
- *
- * The routine returns one of the defined XFER_RETURN codes defined
- * in XFER.H.
- *
- * AUTHOR
- * Mark Nelson 29-Aug-1989 20:57:40.92
- *
- * MODIFICATIONS
- *
- */
- int GF_CONV _AsciiSend( XFER *ascii )
- {
- ascii -> sending = TRUE;
- if ( !_XferInitialize( ascii ) )/* The initialization routine sets up the */
- return( FALSE ); /* buffers and some other stuff. */
-
- if ( !_XferOpenFile( ascii ) ) /* Here is where I open the file to send. */
- return( FALSE );
- /*
- * This big loop is real easy. Load a buffer up with file data, send it, then
- * execute a fixed length delay. Do it enough times and the whole file is gone.
- */
-
- for ( ; ; ) {
- if ( !_AsciiSendLoadUpBuffer( ascii ) )
- return( TRUE );
- if ( !_AsciiSendTheBuffer( ascii ) )
- return( FALSE );
- if ( !_AsciiSendExecuteLineDelay( ascii ) )
- return( FALSE );
- }
- }
-
- /*
- * static int _AsciiSendExecuteLineDelay( XFER *ascii )
- *
- * ARGUMENTS
- *
- * XFER *ascii: This is a pointer to an XFER block that
- * keeps track of how things are set up
- * for the file transfer.
- *
- * DESCRIPTION
- *
- * This routine is a private subroutine for the _AsciiSend driver. Its job
- * is to execute a fixed length delay that is specified in the parameter
- * block. All it has to do while this is going on is to make sure nobody
- * presses the abort key.
- *
- * SIDE EFFECTS
- *
- *
- * RETURNS
- *
- * This routine returns FALSE if an abort has occurred, otherwise it
- * returns a TRUE.
- *
- * AUTHOR
- * Mark Nelson 27-Sep-1989 20:57:40.92
- *
- * MODIFICATIONS
- *
- */
- static int GF_CONV _AsciiSendExecuteLineDelay( XFER *ascii )
- {
- int seconds_left;
-
- seconds_left = ascii->x.ascii.delay_ticks_per_line;
- while ( seconds_left > 0 ) {
- if ( _XferAbortKeyPressed( ascii ) )
- return( FALSE );
- timer( 1 );
- seconds_left--;
- }
- return( TRUE );
- }
-
- /*
- * static int _AsciiSendLoadUpBuffer( XFER *ascii )
- *
- *
- * ARGUMENTS
- *
- * XFER *ascii: This is a pointer to an XFER block that
- * keeps track of how things are set up
- * for the file transfer.
- *
- * DESCRIPTION
- *
- * This routine is a private subroutine for the _AsciiSend driver. Its job
- * is to fill up the buffer in the parameter block with a line full of data.
- * A line is defined as a sequence of characters terminated by a '\n', or a
- * '\r', or 81 characters.
- *
- * SIDE EFFECTS
- *
- * The file pointer has been advanced, and the data moved into the buffer.
- *
- * RETURNS
- *
- * In the usual sense, this guy returns a FALSE if it is time to stop
- * processing. However, in this case the FALSE means that a normal exit
- * needs to occur because we have reached an EOF. There is no error exit
- * from this routine.
- *
- * AUTHOR
- * Mark Nelson 27-Sep-1989 20:57:40.92
- *
- * MODIFICATIONS
- *
- */
- static int GF_CONV _AsciiSendLoadUpBuffer( XFER *ascii )
- {
- int count;
- int c;
- /*
- * This is another forever loop. The only way out is when the line is
- * full. This happens when an EOF is hit, or an end of line condition
- * occurs.
- */
-
- count = 0;
- for ( ; ; ) {
- c = getc( ascii->file );
- if ( c == EOF ) {
- if ( count == 0 ) {
- _XferCleanup( ascii );
- return( FALSE );
- }
- else
- break;
- }
- ascii->byte_count++;
- if ( !ascii->x.ascii.strip_lf || c != '\n' )
- ascii->buffer[ count++ ] = ( char ) c;
- else
- continue;
- if ( count > 81 )
- break;
- if ( c == '\r' )
- break;
- }
- ascii->current_block_size = count;
- return( TRUE );
- }
-
- /*
- * static int _AsciiSendTheBuffer( XFER *ascii )
- *
- *
- * ARGUMENTS
- *
- * XFER *ascii: This is a pointer to an XFER block that
- * keeps track of how things are set up
- * for the file transfer.
- *
- * DESCRIPTION
- *
- * This routine is a private subroutine for the _AsciiSend driver. Its job
- * is to send the data in the buffer out through the com port. While it is
- * doing that, it also echoes any data that comes back from the remote end,
- * using the user specified echo routine. In addition, it does the usual
- * checking for error conditions.
- *
- * SIDE EFFECTS
- *
- *
- * RETURNS
- *
- * In the usual sense, this guy returns a FALSE if it is time to stop
- * processing. This can be because any one of several abort conditions
- * have occurred. A TRUE means everything is okay, and processing should
- * continue.
- *
- * AUTHOR
- * Mark Nelson 27-Sep-1989 20:57:40.92
- *
- * MODIFICATIONS
- *
- */
-
- static int GF_CONV _AsciiSendTheBuffer( XFER *ascii )
- {
- int count;
-
- count = 0;
- while ( count < ascii->current_block_size ) {
- if ( _XferAbortKeyPressed( ascii ) )
- return( FALSE );
- /*
- * While the buffer isn't full, output characters from the buffer. While
- * I am doing it I am still checking for the abort key. If the buffer gets
- * fill, I fall down to the next part of this loop where I read characters in.
- */
- while ( !istxfull( ascii->port ) ) {
- if ( _XferAbortKeyPressed( ascii ) )
- return( FALSE );
- if ( asiputc( ascii->port, ascii->buffer[ count++ ] ) != ASSUCCESS ) {
- ascii->return_status = XFER_RETURN_CANT_PUT_CHAR;
- _XferCleanup( ascii );
- return( FALSE );
- }
- if ( count >= ascii->current_block_size )
- break;
- }
- if ( !_AsciiSendEchoSomeCharacters( ascii ) )
- return( FALSE );
- }
- return( TRUE );
- }
-
- /*
- * static int _AsciiSendEchoSomeCharacters( XFER *ascii )
- *
- *
- * ARGUMENTS
- *
- * XFER *ascii: This is a pointer to an XFER block that
- * keeps track of how things are set up
- * for the file transfer.
- *
- * DESCRIPTION
- *
- * This routine is a private subroutine for the _AsciiSend driver. Its job
- * is to echo any data coming back from the remote end. It does this by
- * repeatedly calling the user specified echo routine.
- *
- * SIDE EFFECTS
- *
- *
- * RETURNS
- *
- * In the usual sense, this guy returns a FALSE if it is time to stop
- * processing. This is usually because of a keyboard abort key.
- * A TRUE means everything is okay, and processing should
- * continue.
- *
- * AUTHOR
- * Mark Nelson 27-Sep-1989 20:57:40.92
- *
- * MODIFICATIONS
- *
- */
- static int GF_CONV _AsciiSendEchoSomeCharacters( XFER *ascii )
- {
- while ( !isrxempty( ascii->port ) ) {
- if ( _XferAbortKeyPressed( ascii ) )
- return( FALSE );
- if ( ascii->x.ascii.received_character_printer != NULL )
- ascii->x.ascii.received_character_printer( asigetc( ascii->port ) );
- }
- return( TRUE );
- }
-