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

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