home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / pcomm-2.0.2 / part02 / s_prompt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-13  |  3.0 KB  |  142 lines

  1. /*
  2.  * Prompting routines used in the setup menus.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "misc.h"
  8.  
  9. /*
  10.  * Prompt for a string at line 21 (with optional line 22 for additional
  11.  * information).  Display the new string in bold at its original location
  12.  * in the menu.  Used in virtually all of the *_setup() routines.  Since
  13.  * it uses get_str(), the return value points to a static area.
  14.  */
  15.  
  16. char *
  17. str_prompt(win, y, x, p1, p2)
  18. WINDOW *win;
  19. int y, x;
  20. char *p1, *p2;
  21. {
  22.     extern char *null_ptr;
  23.     char *ans, *get_str();
  24.                     /* print first prompt last */
  25.     mvwaddstr(win, 22, 0, p2);
  26.     mvwaddstr(win, 21, 0, p1);
  27.     waddstr(win, ": ");
  28.     wrefresh(win);
  29.  
  30.     if ((ans = get_str(win, 80, "", ";\n")) == NULL)
  31.         return(NULL);
  32.                     /* check the value */
  33.     if (!strcmp(ans, " "))
  34.         ans = null_ptr;
  35.                     /* display the value in bold */
  36.     clear_line(win, y, x, FALSE);
  37.     wattrstr(win, A_BOLD, ans);
  38.  
  39.     return(ans);
  40. }
  41.  
  42. /*
  43.  * Same as above, except we return a single character.
  44.  */
  45.  
  46. char
  47. chr_prompt(win, y, x, p1, p2)
  48. WINDOW *win;
  49. int y, x;
  50. char *p1, *p2;
  51. {
  52.     char *ans, *get_str();
  53.                     /* print first prompt last */
  54.     mvwaddstr(win, 22, 0, p2);
  55.     mvwaddstr(win, 21, 0, p1);
  56.     waddstr(win, ": ");
  57.     wrefresh(win);
  58.  
  59.     if ((ans = get_str(win, 1, "", "\n")) == NULL)
  60.         return('\0');
  61.                     /* display the value in bold */
  62.     mvwaddstr(win, y, x, "  ");
  63.     wrefresh(win);
  64.     mvwattrstr(win, y, x, A_BOLD, ans);
  65.  
  66.     return((char) *ans);
  67. }
  68.  
  69. /*
  70.  * Same as above, except that it prompts for a three digit number.
  71.  */
  72.  
  73. int
  74. num_prompt(win, y, x, p1, p2)
  75. WINDOW *win;
  76. int y, x;
  77. char *p1, *p2;
  78. {
  79.     int i;
  80.                     /* print first prompt last */
  81.     mvwaddstr(win, 22, 0, p2);
  82.     mvwaddstr(win, 21, 0, p1);
  83.     waddstr(win, ": ");
  84.     wrefresh(win);
  85.  
  86.     if ((i = get_num(win, 3)) == -1)
  87.         return(-1);
  88.                     /* display the value in bold */
  89.     mvwaddstr(win, y, x, "    ");
  90.     wrefresh(win);
  91.     mvwattrnum(win, y, x, A_BOLD, i);
  92.                     /* return the number */
  93.     return(i);
  94. }
  95.  
  96. /*
  97.  * Prompts for a selection from a menu.  We display the prompt lines,
  98.  * and show the choices one at a time.  The user selects the currently
  99.  * showing choice by hitting a carriage return.  Unlike the similar
  100.  * routines in d_prompt(), the first choice shown is not necessarily
  101.  * the current.
  102.  */
  103.  
  104. char *v_yes[3] = {"YES", "NO", NULL};
  105. char *v_yn[3] = {"Y", "N", NULL};
  106.  
  107. char *
  108. menu_prompt(win, y, x, p, menu)
  109. WINDOW *win;
  110. int y, x;
  111. char *p, *menu[];
  112. {
  113.     char ans;
  114.     int i, cy, cx;
  115.                     /* print first prompt last */
  116.     mvwaddstr(win, 22, 0, "Press any key to change, or <CR> to accept");
  117.     mvwaddstr(win, 21, 0, p);
  118.     waddstr(win, ": ");
  119.                     /* show first choice */
  120.     i = 0;
  121.     getyx(win, cy, cx);
  122.     mvwprintw(win, cy, cx, "%-30.30s", menu[i]);
  123.     wmove(win, cy, cx);
  124.     wrefresh(win);
  125.                     /* show the choices one at a time */
  126.     while ((ans = wgetch(win)) != '\r') {
  127.         i++;
  128.         if (menu[i] == NULL)
  129.             i = 0;
  130.         if (ans == ESC)
  131.             return(NULL);
  132.         mvwprintw(win, cy, cx, "%-30.30s", menu[i]);
  133.         wmove(win, cy, cx);
  134.         wrefresh(win);
  135.     }
  136.                     /* display the value in bold */
  137.     clear_line(win, y, x, FALSE);
  138.     wattrstr(win, A_BOLD, menu[i]);
  139.                     /* return the value */
  140.     return(menu[i]);
  141. }
  142.