home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / pcomm2 / part06 / s_modem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-14  |  6.7 KB  |  235 lines

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