home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part05 / s_prompt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  3.3 KB  |  148 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.
  13.  */
  14.  
  15. char *
  16. str_prompt(win, y, x, p1, p2)
  17. WINDOW *win;
  18. int y, x;
  19. char *p1, *p2;
  20. {
  21.     char *ans, *get_str();
  22.     extern char *null_ptr;
  23.                     /* print first prompt last */
  24.     mvwaddstr(win, 22, 0, p2);
  25.     mvwaddstr(win, 21, 0, p1);
  26.     waddstr(win, ": ");
  27.     wrefresh(win);
  28.  
  29.     if ((ans = get_str(win, 39, NULL, NULL)) == NULL)
  30.         return(NULL);
  31.                     /* check the value */
  32.     if (!strcmp(ans, " "))
  33.         ans = null_ptr;
  34.                     /* display the value in bold */
  35.     clear_line(win, y, x, 0);
  36.     wattrstr(win, A_BOLD, ans);
  37.  
  38.     return(ans);
  39. }
  40.  
  41. /*
  42.  * Same as above, except we return a single character.
  43.  */
  44.  
  45. char
  46. chr_prompt(win, y, x, p1, p2)
  47. WINDOW *win;
  48. int y, x;
  49. char *p1, *p2;
  50. {
  51.     char *ans, *get_str();
  52.                     /* print first prompt last */
  53.     mvwaddstr(win, 22, 0, p2);
  54.     mvwaddstr(win, 21, 0, p1);
  55.     waddstr(win, ": ");
  56.     wrefresh(win);
  57.  
  58.     if ((ans = get_str(win, 1, NULL, NULL)) == NULL)
  59.         return(NULL);
  60.                     /* display the value in bold */
  61.     mvwaddstr(win, y, x, "  ");
  62.     wrefresh(win);
  63.     mvwattrstr(win, y, x, A_BOLD, ans);
  64.  
  65.     return(*ans);
  66. }
  67.  
  68. /*
  69.  * Same as above, except that it prompts for a three digit number.
  70.  */
  71.  
  72. int
  73. num_prompt(win, y, x, p1, p2)
  74. WINDOW *win;
  75. int y, x;
  76. char *p1, *p2;
  77. {
  78.     int i, get_num();
  79.                     /* print first prompt last */
  80.     mvwaddstr(win, 22, 0, p2);
  81.     mvwaddstr(win, 21, 0, p1);
  82.     waddstr(win, ": ");
  83.     wrefresh(win);
  84.  
  85.     if ((i = get_num(win, 3)) == -1)
  86.         return(-1);
  87.                     /* display the value in bold */
  88.     mvwaddstr(win, y, x, "    ");
  89.     wrefresh(win);
  90.     mvwattrnum(win, y, x, A_BOLD, i);
  91.                     /* return the number */
  92.     return(i);
  93. }
  94.  
  95. /*
  96.  * Prompts for a selection from a menu.  We display the prompt lines,
  97.  * and show the choices one at a time.  The user selects the currently
  98.  * showing choice by hitting a carriage return.  Unlike the similar
  99.  * routines in d_prompt(), the first choice shown is not necessarily
  100.  * the current.
  101.  */
  102.  
  103. char *v_yes[3] = {"YES", "NO", NULL};
  104. char *v_crio[3] = {"CR", "CR/LF", NULL};
  105. char *v_cr[4] = {"NONE", "STRIP", "ADD LF", NULL};
  106. char *v_lf[4] = {"NONE", "STRIP", "ADD CR", NULL};
  107. char *v_abort[3] = {"KEEP", "DELETE", NULL};
  108. char *v_duplex[3] = {"FULL", "HALF", NULL};
  109. char *v_flow[3] = {"NONE", "XON/XOFF", NULL};
  110. char *v_baud[7] = {"300", "1200", "2400", "4800", "9600", "19200", NULL};
  111. char *v_delay[4] = {"0", "100", "150", NULL};
  112.  
  113. char *
  114. menu_prompt(win, y, x, p, menu)
  115. WINDOW *win;
  116. int y, x;
  117. char *p, *menu[];
  118. {
  119.     char ans;
  120.     int i, cy, cx;
  121.                     /* print first prompt last */
  122.     mvwaddstr(win, 22, 0, "Press any key to change, or <CR> to accept");
  123.     mvwaddstr(win, 21, 0, p);
  124.     waddstr(win, ": ");
  125.                     /* show first choice */
  126.     i = 0;
  127.     getyx(win, cy, cx);
  128.     mvwprintw(win, cy, cx, "%-30.30s", menu[i]);
  129.     wmove(win, cy, cx);
  130.     wrefresh(win);
  131.                     /* show the choices one at a time */
  132.     while ((ans = wgetch(win)) != '\r') {
  133.         i++;
  134.         if (*menu[i] == NULL)
  135.             i = 0;
  136.         if (ans == 27)
  137.             return(NULL);
  138.         mvwprintw(win, cy, cx, "%-30.30s", menu[i]);
  139.         wmove(win, cy, cx);
  140.         wrefresh(win);
  141.     }
  142.                     /* display the value in bold */
  143.     clear_line(win, y, x, 0);
  144.     wattrstr(win, A_BOLD, menu[i]);
  145.                     /* return the value */
  146.     return(menu[i]);
  147. }
  148.