home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name aprdnum -- Display a prompt and get an integer response
- *
- * Synopsis rint = aprdnum(pmsg);
- *
- * int rint The integer returned
- * char *pmsg The message to be displayed
- *
- * Description APRDNUM displays the message on the active page of the
- * current display device, appends a colon and a blank
- * (": "), and accepts an integer response. If an integer
- * is not entered, the cursor is set to a full box and the
- * response is requested again.
- *
- * See APQUERY for a description of the screen effects of
- * various keystrokes as the response is entered.
- *
- * Returns rint The integer entered.
- *
- * Version 3.0 Copyright (C) Blaise Computing Inc. 1986
- *
- **/
-
- #include <stdio.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) */
-
- int aprdnum(pmsg)
- char *pmsg;
- {
- int result;
- int old_page,mode,columns,act_page;
- int row,col,end_row,end_col,num_scrolled;
- int done,scan;
- char response[40];
-
- 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);
-
- sccurpos(&end_row,&end_col);
-
- row -= num_scrolled; /* Compensate for scrolled */
- /* screen. */
-
- stpcvt(response,RLWHITE + RTWHITE);
-
- 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);
-
- /* Validate & extract result. */
- done = (sscanf(response,"%d",&result) > 0);
-
- if (!done)
- {
- sccurset(row,col); /* Move back to beginning. */
- scpgcur(0,0,13,CUR_ADJUST); /* Set cursor to full block. */
- }
-
- } while (!done); /* Try again. */
-
- scttywrt(CR,1);
- scttywrt(LF,1);
-
- scpage(old_page); /* Restore current display page */
-
- return result;
- }