home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name apprompt -- Get one-line response from standard input,
- * displaying a prompt if appropriate.
- *
- * Synopsis ercode = apprompt(pprompt,presp,resp_size);
- *
- * int ercode 0 if okay, 1 if end of file, 2 if error.
- * 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, APPROMPT 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 3.0 Copyright (C) Blaise Computing Inc. 1986
- *
- * Version 3.02 March 23, 1987
- * Forced stdout and stderr to be flushed.
- *
- **/
-
- #include <stdio.h>
-
- #include <compiler.h>
- #include <bapplic.h>
-
- #if MSC300
- #include <io.h>
- #else
- #include <stdlib.h>
- #endif
-
- #define OK 0
- #define END_OF_FILE 1
- #define ERROR 2
-
- int apprompt(pprompt,presp,resp_size)
- char *pprompt,*presp;
- int resp_size;
- {
- if (isatty((int) fileno(stdin)))
- {
- fflush(stdout);
- fputs(pprompt,stderr); /* Display prompt. */
- fflush(stderr);
- }
-
- if (fgets(presp,resp_size,stdin) == NULL)
- {
- if (feof(stdin))
- return END_OF_FILE;
- else
- return ERROR;
- }
- return OK;
- }