home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / APRDNUM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  2.6 KB  |  97 lines

  1. /**
  2. *
  3. * Name        aprdnum -- Display a prompt and get an integer response
  4. *
  5. * Synopsis    rint = aprdnum(pmsg);
  6. *
  7. *        int  rint      The integer returned
  8. *        char *pmsg      The message to be displayed
  9. *
  10. * Description    APRDNUM displays the message on the active page of the
  11. *        current display device, appends a colon and a blank
  12. *        (": "), and accepts an integer response.  If an integer
  13. *        is not entered, the cursor is set to a full box and the
  14. *        response is requested again.
  15. *
  16. *        See APQUERY for a description of the screen effects of
  17. *        various keystrokes as the response is entered.
  18. *
  19. * Returns    rint          The integer entered.
  20. *
  21. * Version    3.0 Copyright (C) Blaise Computing Inc. 1986
  22. *
  23. **/
  24.  
  25. #include <stdio.h>
  26.  
  27. #include <bapplic.h>
  28. #include <bkeybd.h>
  29. #include <bscreen.h>
  30. #include <bstring.h>
  31.  
  32. #define  LF    ((char) 10)    /* Line feed     (CTRL-J)          */
  33. #define  CR    ((char) 13)    /* Carriage return (CTRL-M)          */
  34.  
  35. int  aprdnum(pmsg)
  36. char *pmsg;
  37. {
  38.     int  result;
  39.     int  old_page,mode,columns,act_page;
  40.     int  row,col,end_row,end_col,num_scrolled;
  41.     int  done,scan;
  42.     char response[40];
  43.  
  44.     old_page = b_curpage;          /* Save former display page.    */
  45.     scmode(&mode,&columns,&act_page);
  46.     scpage(act_page);              /* Direct I/O to active page.   */
  47.  
  48.                       /* Write the message.          */
  49.     sccurpos(&row,&col);
  50.     scwrstr(row,col,0,pmsg,-1,-1,CHARS_ONLY + MOVE_CUR + CUR_AFTER);
  51.     sccurpos(&row,&col);
  52.     scwrstr(row,col,2,": ",-1,-1,CHARS_ONLY + MOVE_CUR + CUR_AFTER);
  53.     sccurpos(&row,&col);
  54.  
  55.                   /* Now "row" and "col" mark the         */
  56.                   /* beginning of the user's response on  */
  57.                   /* the screen.                  */
  58.     do
  59.     {                      /* Get one response.          */
  60.     apquery(response,sizeof(response),&scan,&num_scrolled);
  61.  
  62.     sccurpos(&end_row,&end_col);
  63.  
  64.     row -= num_scrolled;          /* Compensate for scrolled      */
  65.                       /* screen.              */
  66.  
  67.     stpcvt(response,RLWHITE + RTWHITE);
  68.  
  69.     sccurset(row,col);          /* Clear response.          */
  70.     scwrite((char) ' ',
  71.           (end_col - col)
  72.         + (columns * (end_row - row)));
  73.  
  74.                       /* Rewrite converted response.  */
  75.     scwrstr(row,col,0,response,-1,-1,  CHARS_ONLY
  76.                      + MOVE_CUR
  77.                      + CUR_AFTER);
  78.  
  79.                       /* Validate & extract result.   */
  80.     done = (sscanf(response,"%d",&result) > 0);
  81.  
  82.     if (!done)
  83.     {
  84.         sccurset(row,col);          /* Move back to beginning.      */
  85.         scpgcur(0,0,13,CUR_ADJUST); /* Set cursor to full block.  */
  86.     }
  87.  
  88.     } while (!done);              /* Try again.              */
  89.  
  90.     scttywrt(CR,1);
  91.     scttywrt(LF,1);
  92.  
  93.     scpage(old_page);              /* Restore current display page */
  94.  
  95.     return result;
  96. }
  97.