home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / APRDTEXT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.8 KB  |  67 lines

  1. /**
  2. *
  3. * Name        aprdtext -- Display a prompt and accept a text line
  4. *
  5. * Synopsis    rlen = aprdtext(pmsg,presp,resplen);
  6. *
  7. *        int  rlen      The length of the string returned
  8. *        char *pmsg      String to be displayed as a prompt
  9. *        char *presp      Pointer to the response string
  10. *        int  resplen      The size of presp.  No more than
  11. *                  (resplen - 1) characters are moved to
  12. *                  presp, plus a trailing NUL ('\0').
  13. *
  14. * Description    This function displays a prompt to the current console
  15. *        and returns the input string, but no more than
  16. *        (resplen - 1) characters, plus a trailing NUL ('\0').
  17. *
  18. *        The user's input is collected up to the first ENTER or
  19. *        CTRL-M pressed.  If this input is longer than
  20. *        (resplen - 1) characters, then the remaining characters
  21. *        will remain in a buffer and will be read by subsequent
  22. *        functions that read from the console.
  23. *
  24. * Returns    rlen          The number of characters returned
  25. *        *presp          The returned string of characters
  26. *
  27. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1986
  28. *
  29. **/
  30.  
  31. #include <string.h>
  32.  
  33. #include <bapplic.h>
  34. #include <bfile.h>
  35.  
  36. #define   LF    10
  37. #define   CR    13
  38.  
  39. int aprdtext(pmsg,presp,resplen)
  40. char          *pmsg;
  41. register char *presp;
  42. int          resplen;
  43. {
  44.     ADS      prompt_ads,resp_ads;
  45.     int      nwrote,nread;
  46.     register char c;
  47.     char     *begin_resp;
  48.  
  49.     utabsptr(pmsg,&prompt_ads);
  50.     if (flwrite(2,&prompt_ads,(int) strlen(pmsg),&nwrote))
  51.     return 0;
  52.  
  53.     utabsptr(presp,&resp_ads);
  54.     if (flread(2,&resp_ads,resplen - 1,&nread))
  55.     return 0;
  56.     presp[nread] = '\0';
  57.  
  58.     begin_resp = presp;
  59.                       /* Truncate response at first   */
  60.                       /* carriage return or linefeed. */
  61.     for (c = *presp; c != '\0' && c != LF && c != CR; c = *++presp)
  62.     ;
  63.     *presp = '\0';
  64.  
  65.     return (int) strlen(begin_resp);
  66. }
  67.