home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name aprdtext -- Display a prompt and accept a text line
- *
- * Synopsis rlen = aprdtext(pmsg,presp,resplen);
- *
- * int rlen The length of the string returned
- * char *pmsg String to be displayed as a prompt
- * char *presp Pointer to the response string
- * int resplen The size of presp. No more than
- * (resplen - 1) characters are moved to
- * presp, plus a trailing NUL ('\0').
- *
- * Description This function displays a prompt to the current console
- * and returns the input string, but no more than
- * (resplen - 1) characters, plus a trailing NUL ('\0').
- *
- * The user's input is collected up to the first ENTER or
- * CTRL-M pressed. If this input is longer than
- * (resplen - 1) characters, then the remaining characters
- * will remain in a buffer and will be read by subsequent
- * functions that read from the console.
- *
- * Returns rlen The number of characters returned
- * *presp The returned string of characters
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <string.h>
-
- #include <bapplic.h>
- #include <bfile.h>
-
- #define LF 10
- #define CR 13
-
- int aprdtext(pmsg,presp,resplen)
- char *pmsg;
- register char *presp;
- int resplen;
- {
- ADS prompt_ads,resp_ads;
- int nwrote,nread;
- register char c;
- char *begin_resp;
-
- utabsptr(pmsg,&prompt_ads);
- if (flwrite(2,&prompt_ads,(int) strlen(pmsg),&nwrote))
- return 0;
-
- utabsptr(presp,&resp_ads);
- if (flread(2,&resp_ads,resplen - 1,&nread))
- return 0;
- presp[nread] = '\0';
-
- begin_resp = presp;
- /* Truncate response at first */
- /* carriage return or linefeed. */
- for (c = *presp; c != '\0' && c != LF && c != CR; c = *++presp)
- ;
- *presp = '\0';
-
- return (int) strlen(begin_resp);
- }