home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / WGETST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  3.4 KB  |  105 lines

  1. /* wgetst.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  unsigned asiwgets(port,string,length,opt,stat,ticks)
  8. *  int port;            - Port 0..MAX_PORT-1
  9. *  char *string;        - String to transfer
  10. *  unsigned length;     - Maximum number of characters to transfer.
  11. *  int opt;             - Terminating character to watch for.
  12. *  char *stat;          - Array of Char for Status, NULL for none.
  13. *  int ticks            - The number of ticks that pass before a timeout
  14. *
  15. * DESCRIPTION
  16. *  a string is transferred one character at a time from the receive
  17. *  queue to the specified user buffer.  The status for each character
  18. *  is transferred to a user buffer (unless NULL is specified). Also a
  19. *  terminating null is appended to the user buffer.  If the port doesn't
  20. *  have any character, the tick counter is decremented until either
  21. *  more characters are ready or a timeout occurs.
  22. *  are read in,
  23. *
  24. * SIDE EFFECTS
  25. *  none
  26. *
  27. * RETURNS
  28. *  Always returns the number of characters transferred to the user
  29. *  buffer NOT INCLUDING the terminating null.  For example if only
  30. *  one character was received from the receive queue a null would
  31. *  be added to the second position of the buffer and a value of 1
  32. *  would be returned.  The global variable _aserror can be examined to
  33. *  determine if an error was detected.  _aserror == 0 if no errors were
  34. *  detected.
  35. *
  36. *       _aserror =
  37. *
  38. *       Value           Meaning
  39. *     -------          --------
  40. *       ASSUCCESS       port initialized (no error)
  41. *       ASINVPORT       Requested port is out of range
  42. *       ASNOTSETUP      Requested port not setup with asifirst()
  43. *       ASINVPAR        Option parameter invalid
  44. *       ASBUFREMPTY     Buffer is empty
  45. *       ASNOWIDERX      Wide Track Receive buffer is not enabled
  46. *
  47. * MODIFICATIONS
  48. *
  49. *  11-01-85     ""
  50. *               Modified for release 2.0
  51. *
  52. *  Mark Nelson       07-DEC-1989
  53. *       Converted to use timed option in 3.0
  54. */
  55. #include <stdio.h>
  56. #include "gf.h"
  57. #include "asiports.h"
  58.  
  59. unsigned int GF_CONV asiwgets_timed( int port,
  60.                              char *string,
  61.                              unsigned int length,
  62.                              int opt,
  63.                              char *stat,
  64.                              int ticks)
  65. {
  66.     int previous=0;
  67.     unsigned rx_count = 0;
  68.  
  69.     if ( length < 2 || opt > 255 || opt < -2 ) {
  70.         _aserror = ASINVPAR;
  71.         return( 0 );
  72.     }
  73.     --length;                       /* Allow 1 space for null               */
  74.  
  75.     if ( opt == -1 )                /* This simplifies things a little      */
  76.         opt = 0;
  77.  
  78.     while ( length != 0 ) {
  79.         _aserror = asiwgetc( port, stat );
  80.         if ( _aserror >= 0 ) {
  81.             if ( _aserror == opt )
  82.                 break;
  83.             if ( opt == -2 && _aserror == 0x0a && previous == 0x0d )
  84.                 break;
  85.             previous = _aserror;
  86.             *string++ = ( char ) _aserror;
  87.             if ( stat != NULL )
  88.                 stat++;
  89.             rx_count++;
  90.             length--;
  91.         } else {
  92.             if ( _aserror == ASBUFREMPTY ) {
  93.                 if ( ticks <= 0 )
  94.                     return( rx_count );
  95.                 ticks--;
  96.                 timer(1);
  97.             } else
  98.                 return( rx_count );
  99.         }
  100.     }
  101.     _aserror = ASSUCCESS;
  102.     *string = '\0';
  103.     return( rx_count );
  104. }
  105.