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 / ASPUTS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  3.7 KB  |  103 lines

  1. /* asputs.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  unsigned asputs( port, str, option)
  8. *  int port;            - Port 0..MAX_PORT-1
  9. *  char *str;           - String to transmit
  10. *  int option;          - Defines termination sent, see below.
  11. *
  12. * DESCRIPTION
  13. *  This function transmits a string using the polled mode.
  14. *  The source string (pointed to by "str") must be NULL terminated.
  15. *  Characters are read from the source string and transmitted one at
  16. *  a time until the NULL is read.  Then the "option" argument determines
  17. *  what is sent next.
  18. *       option value    What is sent
  19. *               -1              Nothing
  20. *               -2              Carriage Return/Line Feed sequence
  21. *                               (0x0D,0x0A)
  22. *       0x00..0xff              value of option itself (00..ff)
  23. *
  24. * SIDE EFFECTS
  25. *  This function simply calls the asputc() function for each character
  26. *  transmitted.  All optional modes set for asputc() also apply for asputs().
  27. *
  28. * RETURNS
  29. *  The return value always indicates the number of characters SUCCESSFULLY
  30. *  transmitted.  The global variable _aserror can be examined to determine
  31. *  if an error was detected.  _aserror == 0 if no errors were detected.
  32. *
  33. *       _aserror =
  34. *
  35. *       Value           Meaning
  36. *       ------          -------
  37. *       ASSUCCESS       No errors
  38. *       ASINVPORT       Requested port is out of range
  39. *       ASNOTSETUP      Requested port not setup with asifirst()
  40. *       ASTIMEOUT       Function timed out waiting for character
  41. *       ASNOCD          CD (Carrier detect) not active
  42. *       ASNODSR         DSR (Data set ready) not active
  43. *
  44. * MODIFICATIONS
  45. *  10-29-85     ""
  46. *               Modified for release 2.0
  47. */
  48. #include <stdio.h>
  49. #include "gf.h"
  50. #include "asiports.h"
  51.  
  52. unsigned GF_CONV asputs(port,string,option)
  53. int port,option;
  54. char *string;
  55. {
  56.         unsigned xmit_count;
  57.  
  58.  
  59.         if (option < -2 || option > 255) {
  60.                 _aserror = ASINVPAR;
  61.                 return (0);
  62.                 }
  63.  
  64.         /********************************************************
  65.         *  First, send all the characters you can.  If there is *
  66.         *  an error, return then with the count so far.         *
  67.         ********************************************************/
  68.         for(xmit_count=0;*string;++string,++xmit_count) {
  69.                 if ((_aserror=asputc(port,(int)*string&255))!=ASSUCCESS)
  70.                         return(xmit_count);
  71.                 }
  72.  
  73.         /********************************************************
  74.         * If option is 00..FF, send it and bump counter         *
  75.         ********************************************************/
  76.         if(option >= 0) {
  77.                 if ((_aserror=asputc(port,option))!=ASSUCCESS)
  78.                         return(xmit_count);
  79.                 else
  80.                         ++xmit_count;
  81.         }
  82.  
  83.         /********************************************************
  84.         * If option is -2, send CR,LF sequence now              *
  85.         ********************************************************/
  86.         if(option == -2) {
  87.                 if ((_aserror=asputc(port,0x0d))!=ASSUCCESS)
  88.                         return(xmit_count);
  89.                 else
  90.                         ++xmit_count;
  91.                 if ((_aserror=asputc(port,0x0a))!=ASSUCCESS)
  92.                         return(xmit_count);
  93.                 else
  94.                         ++xmit_count;
  95.         }
  96.  
  97.         /********************************************************
  98.         * Option is -1 so send nothing further.                 *
  99.         ********************************************************/
  100.         return (xmit_count);
  101. }
  102.  
  103.