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

  1. /*
  2.  * Display the modem setup, query for changes.  A non-zero return code
  3.  * means something was changed.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <curses.h>
  8. #include "misc.h"
  9. #include "modem.h"
  10.  
  11. static int mod_prompt();
  12. static void disp_modem();
  13.  
  14. int
  15. modem_setup()
  16. {
  17.     WINDOW *mo_win, *newwin();
  18.     int i, j, ret_code;
  19.     char *ans, *str_rep(), *str_prompt(), *menu_prompt();
  20.     extern char *v_yn[];
  21.                     /* the current modem */
  22.     j = 0;
  23.     if (modem->m_cur != -1)
  24.         j = modem->m_cur;
  25.  
  26.     mo_win = newwin(23, 80, 0, 0);
  27.  
  28.     horizontal(mo_win, 0, 0, 33);
  29.     mvwattrstr(mo_win, 0, 34, A_BOLD, "Modem Setup");
  30.     horizontal(mo_win, 0, 46, 34);
  31.                     /* display the current settings */
  32.     disp_modem(mo_win, j);
  33.     horizontal(mo_win, 19, 0, 80);
  34.     mvwattrstr(mo_win, 20, 0, A_BOLD, "OPTION ==> ");
  35.     mvwaddstr(mo_win, 20, 58, "Press <ESC> to return");
  36.     wmove(mo_win, 20, 12);
  37.     touchwin(mo_win);
  38.     wrefresh(mo_win);
  39.                     /* get the option number */
  40.     ret_code = 0;
  41.     while ((i = get_num(mo_win, 2)) != -1) {
  42.         switch (i) {
  43.             case 1:
  44.                 j = mod_prompt(mo_win);
  45.                 break;
  46.             case 2:
  47.                 if ((ans = str_prompt(mo_win, 3, 39, "Modem init string", "sent to the modem once")) != NULL) {
  48.                     modem->init[j] = str_rep(modem->init[j], ans);
  49.                     ret_code++;
  50.                 }
  51.                 break;
  52.             case 3:
  53.                 if ((ans = str_prompt(mo_win, 4, 39, "Dialing command", "")) != NULL) {
  54.                     modem->dial[j] = str_rep(modem->dial[j], ans);
  55.                     ret_code++;
  56.                 }
  57.                 break;
  58.             case 4:
  59.                 if ((ans = str_prompt(mo_win, 5, 39, "Dialing cmd suffix", "typically the <CR> character")) != NULL) {
  60.                     modem->suffix[j] = str_rep(modem->suffix[j], ans);
  61.                     ret_code++;
  62.                 }
  63.                 break;
  64.             case 5:
  65.                 if ((ans = str_prompt(mo_win, 6, 39, "Hang up string", "")) != NULL) {
  66.                     modem->hang_up[j] = str_rep(modem->hang_up[j], ans);
  67.                     ret_code++;
  68.                 }
  69.                 break;
  70.             case 6:
  71.                 if ((ans = menu_prompt(mo_win, 7, 39, "Auto Baud detect", v_yn)) != NULL) {
  72.                     modem->auto_baud[j] = *ans;
  73.                     ret_code++;
  74.                 }
  75.                 break;
  76.             case 7:
  77.                 if ((ans = str_prompt(mo_win, 8, 39, "300 baud connect string", "")) != NULL) {
  78.                     modem->con_3[j] = str_rep(modem->con_3[j], ans);
  79.                     ret_code++;
  80.                 }
  81.                 break;
  82.             case 8:
  83.                 if ((ans = str_prompt(mo_win, 9, 39, "1200 baud connect string", "")) != NULL) {
  84.                     modem->con_12[j] = str_rep(modem->con_12[j], ans);
  85.                     ret_code++;
  86.                 }
  87.                 break;
  88.             case 9:
  89.                 if ((ans = str_prompt(mo_win, 10, 39, "2400 baud connect string", "")) != NULL) {
  90.                     modem->con_24[j] = str_rep(modem->con_24[j], ans);
  91.                     ret_code++;
  92.                 }
  93.                 break;
  94.             case 10:
  95.                 if ((ans = str_prompt(mo_win, 11, 39, "4800 baud connect string", "")) != NULL) {
  96.                     modem->con_48[j] = str_rep(modem->con_48[j], ans);
  97.                     ret_code++;
  98.                 }
  99.                 break;
  100.             case 11:
  101.                 if ((ans = str_prompt(mo_win, 12, 39, "9600 baud connect string", "")) != NULL) {
  102.                     modem->con_96[j] = str_rep(modem->con_96[j], ans);
  103.                     ret_code++;
  104.                 }
  105.                 break;
  106.             case 12:
  107.                 if ((ans = str_prompt(mo_win, 13, 39, "19200 baud connect string", "")) != NULL) {
  108.                     modem->con_192[j] = str_rep(modem->con_192[j], ans);
  109.                     ret_code++;
  110.                 }
  111.                 break;
  112.             case 13:
  113.                 if ((ans = str_prompt(mo_win, 14, 39, "38400 baud connect string", "")) != NULL) {
  114.                     modem->con_384[j] = str_rep(modem->con_384[j], ans);
  115.                     ret_code++;
  116.                 }
  117.                 break;
  118.             case 14:
  119.                 if ((ans = str_prompt(mo_win, 15, 39, "No connect string 1", "")) != NULL) {
  120.                     modem->no_con1[j] = str_rep(modem->no_con1[j], ans);
  121.                     ret_code++;
  122.                 }
  123.                 break;
  124.             case 15:
  125.                 if ((ans = str_prompt(mo_win, 16, 39, "No connect string 2", "")) != NULL) {
  126.                     modem->no_con2[j] = str_rep(modem->no_con2[j], ans);
  127.                     ret_code++;
  128.                 }
  129.                 break;
  130.             case 16:
  131.                 if ((ans = str_prompt(mo_win, 17, 39, "No connect string 3", "")) != NULL) {
  132.                     modem->no_con3[j] = str_rep(modem->no_con3[j], ans);
  133.                     ret_code++;
  134.                 }
  135.                 break;
  136.             case 17:
  137.                 if ((ans = str_prompt(mo_win, 18, 39, "No connect string 4", "")) != NULL) {
  138.                     modem->no_con4[j] = str_rep(modem->no_con4[j], ans);
  139.                     ret_code++;
  140.                 }
  141.                 break;
  142.             default:
  143.                 beep();
  144.         }
  145.                     /* clear the previous prompts */
  146.         mvwaddstr(mo_win, 20, 12, "   ");
  147.         clear_line(mo_win, 21, 0, FALSE);
  148.         clear_line(mo_win, 22, 0, FALSE);
  149.         wmove(mo_win, 20, 12);
  150.         wrefresh(mo_win);
  151.     }
  152.     delwin(mo_win);
  153.     return(ret_code);
  154. }
  155.  
  156. /*
  157.  * Prompts for the modem name.  The user selects the currently showing
  158.  * choice by hitting a carriage return.  Returns the modem entry number.
  159.  * DOES NOT change the value of modem->m_cur.
  160.  */
  161.  
  162. static int
  163. mod_prompt(win)
  164. WINDOW *win;
  165. {
  166.     char ans;
  167.     int i;
  168.     void disp_modem();
  169.                     /* print prompt lines */
  170.     mvwaddstr(win, 22, 0, "Press any key to change, or <CR> to accept");
  171.     mvwaddstr(win, 21, 0, "Modem name: ");
  172.                     /* show current choice */
  173.     i = 0;
  174.     if (modem->m_cur != -1)
  175.         i = modem->m_cur;
  176.     mvwprintw(win, 21, 12, "%-30.30s", modem->mname[i]);
  177.     wmove(win, 21, 12);
  178.     wrefresh(win);
  179.                     /* show the choices one at a time */
  180.     while ((ans = wgetch(win)) != '\r') {
  181.         i++;
  182.         if (*modem->mname[i] == '\0')
  183.             i = 0;
  184.         if (ans == ESC)
  185.             return(0);
  186.         mvwprintw(win, 21, 12, "%-30.30s", modem->mname[i]);
  187.         wmove(win, 21, 12);
  188.         wrefresh(win);
  189.     }
  190.                     /* display the new values */
  191.     disp_modem(win, i);
  192.                     /* display the name in bold */
  193.     clear_line(win, 2, 39, FALSE);
  194.     wrefresh(win);
  195.     mvwattrstr(win, 2, 39, A_BOLD, modem->mname[i]);
  196.     mvwprintw(win, 2, 25, "(%d of %d) ", i+1, modem->m_entries);
  197.  
  198.     return(i);
  199. }
  200.  
  201. /*
  202.  * Show the current settings for the given modem entry number.
  203.  */
  204.  
  205. static void
  206. disp_modem(w, i)
  207. WINDOW *w;
  208. int i;
  209. {
  210.     mvwprintw(w, 2, 11, "1) Modem name ............. %-39.39s", modem->mname[i]);
  211.     mvwprintw(w, 2, 25, "(%d of %d) ", i+1, modem->m_entries);
  212.     mvwprintw(w, 3, 11, "2) Modem init string ...... %-39.39s", modem->init[i]);
  213.     mvwprintw(w, 4, 11, "3) Dialing command ........ %-39.39s", modem->dial[i]);
  214.     mvwprintw(w, 5, 11, "4) Dialing cmd suffix ..... %-39.39s", modem->suffix[i]);
  215.     mvwprintw(w, 6, 11, "5) Hang up string ......... %-39.39s", modem->hang_up[i]);
  216.     mvwprintw(w, 7, 11, "6) Auto baud detect ....... %c", modem->auto_baud[i]);
  217.     mvwprintw(w, 8, 11, "7) 300 baud connect ....... %-39.39s", modem->con_3[i]);
  218.     mvwprintw(w, 9, 11, "8) 1200 baud connect ...... %-39.39s", modem->con_12[i]);
  219.     mvwprintw(w, 10, 11, "9) 2400 baud connect ...... %-39.39s", modem->con_24[i]);
  220.     mvwprintw(w, 11, 10, "10) 4800 baud connect ...... %-39.39s", modem->con_48[i]);
  221.     mvwprintw(w, 12, 10, "11) 9600 baud connect ...... %-39.39s", modem->con_96[i]);
  222.     mvwprintw(w, 13, 10, "12) 19200 baud connect ..... %-39.39s", modem->con_192[i]);
  223.     mvwprintw(w, 14, 10, "13) 38400 baud connect ..... %-39.39s", modem->con_384[i]);
  224.     mvwprintw(w, 15, 10, "14) No connect string 1 .... %-39.39s", modem->no_con1[i]);
  225.     mvwprintw(w, 16, 10, "15) No connect string 2 .... %-39.39s", modem->no_con2[i]);
  226.     mvwprintw(w, 17, 10, "16) No connect string 3 .... %-39.39s", modem->no_con3[i]);
  227.     mvwprintw(w, 18, 10, "17) No connect string 4 .... %-39.39s", modem->no_con4[i]);
  228.     return;
  229. }
  230.