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