home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / FLPROMPT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.8 KB  |  67 lines

  1. /**
  2. *
  3. * Name        FLPROMPT -- Get one-line response from standard input,
  4. *                displaying a prompt if appropriate.
  5. *
  6. * Synopsis    ercode = flprompt(pprompt,presp,resp_size);
  7. *
  8. *        int  ercode      0 if okay, 1 if end of file, 2 if error.
  9. *        const char *pprompt
  10. *                  The prompt to be displayed if the
  11. *                  standard input channel is a console.
  12. *        char *presp      Pointer to character buffer in which
  13. *                  to put response.
  14. *        int  resp_size      Size of response buffer (including
  15. *                  newline ('\n'), if any, and trailing
  16. *                  NUL ('\0')).
  17. *
  18. * Description    This function returns one line of text from standard
  19. *        input.    If standard input is a console, FLPROMPT first
  20. *        displays the prompt on the current console.
  21. *
  22. * Returns    ercode          0 if okay, 1 if end of file, 2 if error.
  23. *        *presp          Line from standard input, including
  24. *                  newline ('\n'), if any.
  25. *
  26. * Version    6.00 Copyright (C) Blaise Computing Inc. 1986, 1987, 1989
  27. *
  28. **/
  29.  
  30. #include <io.h>
  31. #include <stdio.h>
  32.  
  33. #include <bfiles.h>
  34.  
  35. #define  OK          0
  36. #define  END_OF_FILE  1
  37. #define  ERROR          2
  38.  
  39. int flprompt (pprompt, presp, resp_size)
  40. const char *pprompt;
  41. char       *presp;
  42. int        resp_size;
  43. {
  44.         /* Display a prompt if the standard input device is */
  45.         /* a "TTY".                                         */
  46.     if (isatty (fileno (stdin)))
  47.     {
  48.         /* First flush standard output channel.         */
  49.     fflush (stdout);
  50.         /* Put the prompt out to standard error channel.    */
  51.     fputs  (pprompt, stderr);
  52.         /* Flush standard error channel.            */
  53.     fflush (stderr);
  54.     }
  55.  
  56.         /* Get response from standard input channel.        */
  57.     if (fgets (presp, resp_size, stdin) == NULL)
  58.     {
  59.     if (feof (stdin))
  60.         return (END_OF_FILE);
  61.     else
  62.         return (ERROR);
  63.     }
  64.  
  65.     return (OK);
  66. }
  67.