home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name FLPROMPT -- Get one-line response from standard input,
- * displaying a prompt if appropriate.
- *
- * Synopsis ercode = flprompt(pprompt,presp,resp_size);
- *
- * int ercode 0 if okay, 1 if end of file, 2 if error.
- * const char *pprompt
- * The prompt to be displayed if the
- * standard input channel is a console.
- * char *presp Pointer to character buffer in which
- * to put response.
- * int resp_size Size of response buffer (including
- * newline ('\n'), if any, and trailing
- * NUL ('\0')).
- *
- * Description This function returns one line of text from standard
- * input. If standard input is a console, FLPROMPT first
- * displays the prompt on the current console.
- *
- * Returns ercode 0 if okay, 1 if end of file, 2 if error.
- * *presp Line from standard input, including
- * newline ('\n'), if any.
- *
- * Version 6.00 Copyright (C) Blaise Computing Inc. 1986, 1987, 1989
- *
- **/
-
- #include <io.h>
- #include <stdio.h>
-
- #include <bfiles.h>
-
- #define OK 0
- #define END_OF_FILE 1
- #define ERROR 2
-
- int flprompt (pprompt, presp, resp_size)
- const char *pprompt;
- char *presp;
- int resp_size;
- {
- /* Display a prompt if the standard input device is */
- /* a "TTY". */
- if (isatty (fileno (stdin)))
- {
- /* First flush standard output channel. */
- fflush (stdout);
- /* Put the prompt out to standard error channel. */
- fputs (pprompt, stderr);
- /* Flush standard error channel. */
- fflush (stderr);
- }
-
- /* Get response from standard input channel. */
- if (fgets (presp, resp_size, stdin) == NULL)
- {
- if (feof (stdin))
- return (END_OF_FILE);
- else
- return (ERROR);
- }
-
- return (OK);
- }