home *** CD-ROM | disk | FTP | other *** search
- /* wgetst.c
- *
- * The Greenleaf Comm Library
- *
- * Copyright (C) 1985-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- * unsigned asiwgets(port,string,length,opt,stat,ticks)
- * int port; - Port 0..MAX_PORT-1
- * char *string; - String to transfer
- * unsigned length; - Maximum number of characters to transfer.
- * int opt; - Terminating character to watch for.
- * char *stat; - Array of Char for Status, NULL for none.
- * int ticks - The number of ticks that pass before a timeout
- *
- * DESCRIPTION
- * a string is transferred one character at a time from the receive
- * queue to the specified user buffer. The status for each character
- * is transferred to a user buffer (unless NULL is specified). Also a
- * terminating null is appended to the user buffer. If the port doesn't
- * have any character, the tick counter is decremented until either
- * more characters are ready or a timeout occurs.
- * are read in,
- *
- * SIDE EFFECTS
- * none
- *
- * RETURNS
- * Always returns the number of characters transferred to the user
- * buffer NOT INCLUDING the terminating null. For example if only
- * one character was received from the receive queue a null would
- * be added to the second position of the buffer and a value of 1
- * would be returned. The global variable _aserror can be examined to
- * determine if an error was detected. _aserror == 0 if no errors were
- * detected.
- *
- * _aserror =
- *
- * Value Meaning
- * ------- --------
- * ASSUCCESS port initialized (no error)
- * ASINVPORT Requested port is out of range
- * ASNOTSETUP Requested port not setup with asifirst()
- * ASINVPAR Option parameter invalid
- * ASBUFREMPTY Buffer is empty
- * ASNOWIDERX Wide Track Receive buffer is not enabled
- *
- * MODIFICATIONS
- *
- * 11-01-85 ""
- * Modified for release 2.0
- *
- * Mark Nelson 07-DEC-1989
- * Converted to use timed option in 3.0
- */
- #include <stdio.h>
- #include "gf.h"
- #include "asiports.h"
-
- unsigned int GF_CONV asiwgets_timed( int port,
- char *string,
- unsigned int length,
- int opt,
- char *stat,
- int ticks)
- {
- int previous=0;
- unsigned rx_count = 0;
-
- if ( length < 2 || opt > 255 || opt < -2 ) {
- _aserror = ASINVPAR;
- return( 0 );
- }
- --length; /* Allow 1 space for null */
-
- if ( opt == -1 ) /* This simplifies things a little */
- opt = 0;
-
- while ( length != 0 ) {
- _aserror = asiwgetc( port, stat );
- if ( _aserror >= 0 ) {
- if ( _aserror == opt )
- break;
- if ( opt == -2 && _aserror == 0x0a && previous == 0x0d )
- break;
- previous = _aserror;
- *string++ = ( char ) _aserror;
- if ( stat != NULL )
- stat++;
- rx_count++;
- length--;
- } else {
- if ( _aserror == ASBUFREMPTY ) {
- if ( ticks <= 0 )
- return( rx_count );
- ticks--;
- timer(1);
- } else
- return( rx_count );
- }
- }
- _aserror = ASSUCCESS;
- *string = '\0';
- return( rx_count );
- }