home *** CD-ROM | disk | FTP | other *** search
- /*
- * _ASCIIR.C
- *
- * Contains: _AsciiReceive()
- * _AsciiReceiveReadData()
- * _AsciiReceiveWaitForRxData()
- *
- * 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:
- */
-
- static int GF_CONV _AsciiReceiveReadData( XFER *ascii );
- static int GF_CONV _AsciiReceiveWaitForRxData( XFER *ascii );
-
- /*
- * int _AsciiReceive( 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 receive.
- * The logic for the routine is fairly simple. After getting set up,
- * the routine reads in, echoes, and stores characters as long
- * as they are coming in. While characters are not coming in, the timeout
- * timer runs. The only ways out of this private driver are with a fatal
- * error, a keyboard abort, or a timeout.
- * Be sure to note that there is no built-in handshaking going on here.
- * If XON/XOFF handshaking is turned on for the port in question, it will
- * work fine during the transfer.
- *
- * 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 28-Aug-1989 20:57:40.92
- *
- * MODIFICATIONS
- *
- */
- int GF_CONV _AsciiReceive( XFER *ascii )
- {
-
- ascii->sending = FALSE;
- if ( !_XferInitialize( ascii ) ) /* The initialize routine sets up the */
- return( FALSE ); /* the buffers and other odds and ends*/
-
- if ( !_XferOpenFile( ascii ) ) /* This routine opens up the file that*/
- return( FALSE ); /* will be received. */
- /*
- * This is the big loop where the file gets loaded. In this case since
- * the loop is a forever loop the only way out is a return statement.
- * And you only get one of those when there is an error or a user abort.
- */
- for (;;) {
- if ( !_AsciiReceiveReadData( ascii ) )
- return( FALSE );
- if ( !_AsciiReceiveWaitForRxData( ascii ) )
- return( FALSE );
- }
- }
-
- /*
- * static int _AsciiReceiveReadData( 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 support routine used by the Ascii Receive
- * program. All it does is read in characters from the com port and store
- * them. Once in a while it checks for keyboard abort codes. It exits when
- * the rx buffer is empty. It can also exit when something goes wrong
- * or the user aborts the whole deal.
- *
- * SIDE EFFECTS
- *
- *
- * RETURNS
- *
- * The routine returns TRUE or FALSE. TRUE means keep processing. FALSE
- * means time to quit.
- *
- * AUTHOR
- * Mark Nelson 29-Sep-1989 20:57:40.92
- *
- * MODIFICATIONS
- *
- */
-
- static int GF_CONV _AsciiReceiveReadData( XFER *ascii )
- {
- int c;
-
- while ( !isrxempty( ascii->port ) ) {
- c=asigetc( ascii->port );
- if ( c < ASSUCCESS ) {
- ascii->return_status = XFER_RETURN_CANT_GET_CHAR;
- _XferCleanup( ascii );
- return( FALSE );
- }
- if ( ascii->x.ascii.received_character_printer != NULL )
- ascii->x.ascii.received_character_printer( c );
- ascii->byte_count++;
- /*
- * If characters are coming in like crazy, I still need to check for the
- * abort key once in a while. This code here makes sure that I check for
- * an abort key at least once every 256 characters.
- */
- if ( (ascii->byte_count & 0xff) == 0 )
- if ( _XferAbortKeyPressed( ascii ) )
- return( FALSE );
- /*
- * Here is where I store the character. I do the stripping of line feeds
- * here if the user asked for it.
- */
- if ( c != '\n' || !ascii->x.ascii.strip_lf )
- if ( putc( c, ascii->file ) != c ) {
- ascii->return_status = XFER_RETURN_FILE_ERROR;
- _XferCleanup( ascii );
- return( FALSE );
- }
- }
- return( TRUE );
- }
-
- /*
- * static int _AsciiReceiveWaitForRxData( 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 receiver used by the Ascii Receive program.
- * Its job is wait for there to be stuff in the rx buffer. When there is
- * stuff ready to receive it returns. It also can timeout waiting for
- * data, and it can abort for the usual reasons.
- *
- * SIDE EFFECTS
- *
- *
- * RETURNS
- *
- * The routine returns TRUE or FALSE. TRUE means keep processing. FALSE
- * means time to quit.
- *
- * AUTHOR
- * Mark Nelson 29-Sep-1989 20:57:40.92
- *
- * MODIFICATIONS
- *
- */
- static int GF_CONV _AsciiReceiveWaitForRxData( XFER *ascii )
- {
- int timeout_timer;
-
- timeout_timer = ASCII_RECEIVE_TIMEOUT*TICKS_PER_SECOND;
- while ( isrxempty( ascii->port ) ) {
- if ( _XferAbortKeyPressed( ascii ) )
- return( FALSE );
- timer( 1 );
- timeout_timer--;
- if ( isrxempty( ascii->port ) && timeout_timer <= 0 ) {
- ascii->return_status = XFER_RETURN_ASCII_TIMEOUT;
- _XferCleanup( ascii );
- return( FALSE );
- }
- }
- return( TRUE );
- }