home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / pcomm2 / part03 / d_prompt.c < prev    next >
C/C++ Source or Header  |  1988-09-14  |  6KB  |  242 lines

  1. /*
  2.  * Prompt for directory entry changes.  Copies the original values in
  3.  * case you change your mind half way thru.  A return code of 1 means
  4.  * the entry was changed.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <curses.h>
  9. #include "config.h"
  10. #include "dial_dir.h"
  11. #include "misc.h"
  12.  
  13. int
  14. prompt_lib(win, i)
  15. WINDOW *win;
  16. int i;
  17. {
  18.     extern int xmc;
  19.     extern char *null_ptr;
  20.     int n, baud, dbits, sbits, spot;
  21.     static int valid_baud[6] = {300, 1200, 2400, 4800, 9600, 19200};
  22.     static char *valid_parity[3] = {"Even", "Odd", "None"};
  23.     char *ans, *get_str(), c, temp, name[40], number[40], index[40];
  24.     char parity, duplex, *strdup(), *strcpy(), buf[40];
  25.     void free_ptr();
  26.                     /* make copies */
  27.     strcpy(name, dir->name[i]);
  28.     strcpy(number, dir->number[i]);
  29.     baud = dir->baud[i];
  30.     parity = dir->parity[i];
  31.     dbits = dir->dbits[i];
  32.     sbits = dir->sbits[i];
  33.     duplex = dir->duplex[i];
  34.     strcpy(index, dir->index[i]);
  35.                     /* display original values */
  36.     werase(win);
  37.     mvwprintw(win, 2, 5, "%-20.20s %18.18s  %5d-%c-%d-%d  %c  %-14.14s\n",
  38.      dir->name[i], dir->number[i], dir->baud[i], dir->parity[i],
  39.      dir->dbits[i], dir->sbits[i], dir->duplex[i], dir->index[i]);
  40.     box(win, VERT, HORZ);
  41.  
  42.                     /* prompt for name */
  43.     mvwaddstr(win, 4, 4, "Name: ");
  44.     wrefresh(win);
  45.  
  46.     if ((ans = get_str(win, 20, "", ";")) == NULL)
  47.         return(0);
  48.     if (*ans != NULL) {
  49.         strcpy(name, ans);
  50.         mvwaddstr(win, 2, 5, "                    ");
  51.         wrefresh(win);
  52.         mvwattrstr(win, 2, 5, A_BOLD, name);
  53.     }
  54.                     /* prompt for number */
  55.     clear_line(win, 4, 4, 1);
  56.     waddstr(win, "Number: ");
  57.     wrefresh(win);
  58.  
  59.     if ((ans = get_str(win, 18, "", ";")) == NULL)
  60.         return(0);
  61.     if (*ans != NULL) {
  62.         strcpy(number, ans);
  63.         mvwaddstr(win, 2, 26, "                  ");
  64.         wrefresh(win);
  65.         /*
  66.          * Should be right justified, but we don't wanna to have
  67.          * the attribute turned on for blanks.
  68.          */
  69.         spot = 26 + 18 - strlen(number);
  70.         mvwattrstr(win, 2, spot, A_BOLD, number);
  71.     }
  72.                     /* template for next few */
  73.     clear_line(win, 4, 4, 1);
  74.     mvwaddstr(win, 4, 31, "(Any key to change, <CR> to accept)");
  75.  
  76.     /*
  77.      * These next few prompts display a series of choices and allow
  78.      * the user to hit a return to accept the currently showing
  79.      * value.  The first value displayed is always the current value.
  80.      */
  81.                     /* choose from baud menu */
  82.     for (n=0; n<6; n++) {
  83.         if (valid_baud[n] == baud)
  84.             break;
  85.     }
  86.     mvwprintw(win, 4, 4, "Baud: %-5d", valid_baud[n]);
  87.     wmove(win, 4, 10);
  88.     wrefresh(win);
  89.  
  90.     while ((c = wgetch(win)) != '\r') {
  91.         if (c == ESC)
  92.             return(0);
  93.         n = (n == 5) ? 0 : n+1;
  94.         mvwprintw(win, 4, 4, "Baud: %-5d", valid_baud[n]);
  95.         wmove(win, 4, 10);
  96.         wrefresh(win);
  97.     }
  98.     if (baud != valid_baud[n]) {
  99.         baud = valid_baud[n];
  100.         sprintf(buf, "%5d", baud);
  101.         if (xmc > 0) {
  102.             sprintf(buf, "%5d-%c-%d-%d", baud, parity, dbits, sbits);
  103.             mvwaddstr(win, 2, 46, "           ");
  104.             wrefresh(win);
  105.         }
  106.         mvwattrstr(win, 2, 46, A_BOLD, buf);
  107.     }
  108.                     /* choose from parity menu */
  109.     for (n=0; n<3; n++) {
  110.         if (*valid_parity[n] == parity)
  111.             break;
  112.     }
  113.     mvwprintw(win, 4, 4, "Parity: %-5.5s", valid_parity[n]);
  114.     wmove(win, 4, 12);
  115.     wrefresh(win);
  116.  
  117.     while ((c = wgetch(win)) != '\r') {
  118.         if (c == ESC)
  119.             return(0);
  120.         n = (n == 2) ? 0 : n+1;
  121.         mvwprintw(win, 4, 4, "Parity: %-5.5s", valid_parity[n]);
  122.         wmove(win, 4, 12);
  123.         wrefresh(win);
  124.     }
  125.     if (parity != *valid_parity[n]) {
  126.         parity = *valid_parity[n];
  127.         if (xmc > 0) {
  128.             sprintf(buf, "%5d-%c-%d-%d", baud, parity, dbits, sbits);
  129.             mvwaddstr(win, 2, 46, "           ");
  130.             wrefresh(win);
  131.             mvwattrstr(win, 2, 46, A_BOLD, buf);
  132.         }
  133.         else
  134.             mvwattrch(win, 2, 52, A_BOLD, parity);
  135.     }
  136.                     /* choose from data bits menu */
  137.     n = dbits;
  138.     mvwprintw(win, 4, 4, "Data Bits: %d    ", n);
  139.     wmove(win, 4, 15);
  140.     wrefresh(win);
  141.  
  142.     while ((c = wgetch(win)) != '\r') {
  143.         if (c == ESC)
  144.             return(0);
  145.         n = (n == 8) ? 7 : 8;
  146.         mvwprintw(win, 4, 4, "Data Bits: %d    ", n);
  147.         wmove(win, 4, 15);
  148.         wrefresh(win);
  149.     }
  150.     if (dbits != n) {
  151.         dbits = n;
  152.         if (xmc > 0) {
  153.             sprintf(buf, "%5d-%c-%d-%d", baud, parity, dbits, sbits);
  154.             mvwaddstr(win, 2, 46, "           ");
  155.             wrefresh(win);
  156.             mvwattrstr(win, 2, 46, A_BOLD, buf);
  157.         }
  158.         else
  159.             mvwattrnum(win, 2, 54, A_BOLD, dbits);
  160.     }
  161.                     /* choose from stop bits menu */
  162.     n = sbits;
  163.     mvwprintw(win, 4, 4, "Stop Bits: %d    ", n);
  164.     wmove(win, 4, 15);
  165.     wrefresh(win);
  166.  
  167.     while ((c = wgetch(win)) != '\r') {
  168.         if (c == ESC)
  169.             return(0);
  170.         n = (n == 2) ? 1 : 2;
  171.         mvwprintw(win, 4, 4, "Stop Bits: %d    ", n);
  172.         wmove(win, 4, 15);
  173.         wrefresh(win);
  174.     }
  175.     if (sbits != n) {
  176.         sbits = n;
  177.         if (xmc > 0) {
  178.             sprintf(buf, "%5d-%c-%d-%d", baud, parity, dbits, sbits);
  179.             mvwaddstr(win, 2, 46, "           ");
  180.             wrefresh(win);
  181.             mvwattrstr(win, 2, 46, A_BOLD, buf);
  182.         }
  183.         else
  184.             mvwattrnum(win, 2, 56, A_BOLD, sbits);
  185.     }
  186.                     /* choose from duplex menu */
  187.     temp = duplex;
  188.     mvwprintw(win, 4, 4, "Duplex: %c    ", temp);
  189.     wmove(win, 4, 12);
  190.     wrefresh(win);
  191.  
  192.     while ((c = wgetch(win)) != '\r') {
  193.         if (c == ESC)
  194.             return(0);
  195.         temp = (temp == 'F') ? 'H' : 'F';
  196.         mvwprintw(win, 4, 4, "Duplex: %c    ", temp);
  197.         wmove(win, 4, 12);
  198.         wrefresh(win);
  199.     }
  200.     if (duplex != temp) {
  201.         duplex = temp;
  202.         mvwattrch(win, 2, 59, A_BOLD, duplex);
  203.     }
  204.                     /* prompt for command line index */
  205.     clear_line(win, 4, 4, 1);
  206.     waddstr(win, "Command line index (or TTY): ");
  207.     wrefresh(win);
  208.  
  209.     if ((ans = get_str(win, 14, "", ";")) == NULL)
  210.         return(0);
  211.     if (*ans != NULL) {
  212.         strcpy(index, ans);
  213.         mvwaddstr(win, 2, 62, "              ");
  214.         wrefresh(win);
  215.         mvwattrstr(win, 2, 62, A_BOLD, index);
  216.     }
  217.                     /* store 'em for real */
  218.     free_ptr(dir->name[i]);
  219.     free_ptr(dir->number[i]);
  220.     free_ptr(dir->index[i]);
  221.  
  222.     if (!strcmp(name, " "))
  223.         dir->name[i] = null_ptr;
  224.     else
  225.         dir->name[i] = strdup(name);
  226.     if (!strcmp(number, " "))
  227.         dir->number[i] = null_ptr;
  228.     else
  229.         dir->number[i] = strdup(number);
  230.     dir->baud[i] = baud;
  231.     dir->parity[i] = parity;
  232.     dir->dbits[i] = dbits;
  233.     dir->sbits[i] = sbits;
  234.     dir->duplex[i] = duplex;
  235.     if (!strcmp(index, " "))
  236.         dir->index[i] = null_ptr;
  237.     else
  238.         dir->index[i] = strdup(index);
  239.  
  240.     return(1);
  241. }
  242.