home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name apyesno -- Display a prompt and accept a YES/NO response
- *
- * Synopsis resp = apyesno(pmsg,def_resp);
- *
- * int resp The value of the response: 0 = NO,
- * 1 = YES
- * char *pmsg Message to be displayed
- * int def_resp Indicator of how the null response is
- * to be interpreted:
- * 0 = interpret null as NO;
- * 1 = interpret null as YES;
- * other values reject null responses.
- *
- * Description This function displays the message, appends a question
- * mark and a blank ("? "), and then accepts a response.
- * The response must be either "YES", "NO", or the null
- * response (just a carriage return, possibly preceded by
- * spaces and tabs).
- *
- * The null response is interpreted according the default
- * setting. If an unacceptable response is entered, the
- * previous response is erased, the cursor is set to a full
- * box, and the response is requested again.
- *
- * Letter case is ignored in the response. Only the first
- * nonspace character of the response is examined (so, for
- * example, " yak" is interpreted as "YES").
- *
- * See APQUERY for a description of the screen effects of
- * various keystrokes as the response is entered.
- *
- * Returns resp The value of the response: 0 = NO;
- * 1 = YES.
- *
- * Version 3.0 Copyright (C) Blaise Computing Inc. 1986
- *
- **/
-
- #include <string.h>
-
- #include <bapplic.h>
- #include <bkeybd.h>
- #include <bscreen.h>
- #include <bstring.h>
-
- #define LF ((char) 10) /* Line feed (CTRL-J) */
- #define CR ((char) 13) /* Carriage return (CTRL-M) */
-
- #define YES 1
- #define NO 0
-
- int apyesno(pmsg,def_resp)
- char *pmsg;
- int def_resp;
- {
- int result;
- int old_page,mode,columns,act_page;
- int row,col,end_row,end_col,num_scrolled;
- int done,scan;
- char response[10];
-
- old_page = b_curpage; /* Save former display page. */
- scmode(&mode,&columns,&act_page);
- scpage(act_page); /* Direct I/O to active page. */
-
- /* Write the message. */
- sccurpos(&row,&col);
- scwrstr(row,col,0,pmsg,-1,-1,CHARS_ONLY + MOVE_CUR + CUR_AFTER);
- sccurpos(&row,&col);
- scwrstr(row,col,2,"? ",-1,-1,CHARS_ONLY + MOVE_CUR + CUR_AFTER);
- sccurpos(&row,&col);
-
- /* Now "row" and "col" mark the */
- /* beginning of the user's response on */
- /* the screen. */
- do
- { /* Get one response. */
- apquery(response,sizeof(response),&scan,&num_scrolled);
-
- stpcvt(response,RLWHITE + RTWHITE + REDUCE + TOUP);
-
- if ( strlen(response) <= 0
- && (def_resp == YES || def_resp == NO))
- { /* Null response is acceptable: */
- result = def_resp; /* infer default. */
- done = 1;
- }
- else
- { /* Non-null response: */
- /* redisplay and test it. */
- sccurpos(&end_row,&end_col);
-
- row -= num_scrolled; /* Compensate for scrolled */
- /* screen. */
-
- sccurset(row,col); /* Clear response. */
- scwrite((char) ' ',
- (end_col - col)
- + (columns * (end_row - row)));
-
- /* Rewrite converted response. */
- scwrstr(row,col,0,response,-1,-1, CHARS_ONLY
- + MOVE_CUR
- + CUR_AFTER);
- scttywrt(CR,1);
- scttywrt(LF,1);
-
- /* Validate & extract result. */
- if (response[0] == 'Y')
- {
- result = YES;
- done = 1;
- }
- else if (response[0] == 'N')
- {
- result = NO;
- done = 1;
- }
- else
- {
- sccurset(row,col); /* Move back to beginning. */
- /* Set cursor to full block. */
- scpgcur(0,0,13,CUR_ADJUST);
- done = 0;
- }
- }
- } while (!done); /* Try again. */
-
- scpage(old_page); /* Restore current display page */
-
- return result;
- }