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

  1. /*
  2.  * Routines for the dialing directory menu.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "dial_dir.h"
  9. #include "misc.h"
  10. #include "param.h"
  11.  
  12. static int current = 1;
  13. static void dir_scroll(), active_ld(), disp_ld();
  14.  
  15. /*
  16.  * Display the dialing directory and prompt for options.  A non-zero return
  17.  * code means we're ready to dial.
  18.  */
  19.  
  20. int
  21. dial_menu()
  22. {
  23.     extern int xmc;
  24.     WINDOW *dm_win, *newwin();
  25.     char buf[5], ld_code;
  26.     int ans, start, needs_repair, count, x, y, i, ret_code;
  27.     void print_dir(), st_line();
  28.  
  29.     touchwin(stdscr);
  30.     refresh();
  31.     st_line("");
  32.  
  33.     dm_win = newwin(22, 78, 1, 1);
  34.     mvwattrstr(dm_win, 1, 20, A_BOLD, "D I A L I N G       D I R E C T O R Y");
  35.     horizontal(dm_win, 2, 0, 78);
  36.     mvwattrstr(dm_win, 3, 0, A_STANDOUT, "           Name                   Number        Baud P D S Dpx  Auxiliary     ");
  37.                     /* show 10 entries */
  38.     dir_scroll(dm_win, current);
  39.  
  40.     mvwaddstr(dm_win, 15, 4, "==>");
  41.     mvwattrch(dm_win, 15, 14, A_BOLD, 'R');
  42.     waddstr(dm_win, " Revise");
  43.     mvwattrch(dm_win, 15, 34, A_BOLD, 'M');
  44.     waddstr(dm_win, " Manual Dialing");
  45.     mvwaddstr(dm_win, 15, 55, "Entry to Dial");
  46.  
  47.     mvwattrch(dm_win, 16, 14, A_BOLD, 'P');
  48.     waddstr(dm_win, " LD Codes");
  49.     mvwattrch(dm_win, 16, 34, A_BOLD, 'D');
  50.     waddstr(dm_win, " Delete Entry");
  51.     mvwattrstr(dm_win, 16, 55, A_BOLD, "<CR>");
  52.     waddstr(dm_win, " Scroll Down");
  53.  
  54. #ifdef OLDCURSES
  55.     mvwattrstr(dm_win, 17, 14, A_BOLD, "U/N");
  56. #else /* OLDCURSES */
  57.     mvwattrstr(dm_win, 17, 14, A_BOLD, "<up>/<down>");
  58. #endif /* OLDCURSES */
  59.     waddstr(dm_win, " Page");
  60.     mvwattrch(dm_win, 17, 34, A_BOLD, 'L');
  61.     waddstr(dm_win, " Print Entries");
  62.     mvwattrstr(dm_win, 17, 55, A_BOLD, "<ESC>");
  63.     waddstr(dm_win, " Exit");
  64.  
  65.     mvwaddstr(dm_win, 19, 4, "LD Codes Active:");
  66.                     /* show which LD codes are active */
  67.     active_ld(dm_win);
  68.  
  69.     box(dm_win, VERT, HORZ);
  70.     y = 15;
  71.     x = 8;
  72.     wmove(dm_win, 15, 8);
  73.     wrefresh(dm_win);
  74.  
  75. #ifndef OLDCURSES
  76.     keypad(dm_win, TRUE);
  77. #endif /* OLDCURSES */
  78.                     /* prompt for options */
  79.     count = 0;
  80.     ld_code = '\0';
  81.     ret_code = 0;
  82.     do {
  83.         needs_repair = 0;
  84.         ans = wgetch(dm_win);
  85.                     /* get an entry number */
  86.         if (ans >= '0' && ans <= '9') {
  87.             if (count > 2) {
  88.                 beep();
  89.                 continue;
  90.             }
  91.             buf[count] = (char) ans;
  92.             waddch(dm_win, (chtype) ans);
  93.             wrefresh(dm_win);
  94.             count++;
  95.             continue;
  96.         }
  97.         switch (ans) {
  98.             case DEL:
  99.             case BS:    /* do our own backspace */
  100.                 if (!count) {
  101.                     beep();
  102.                     break;
  103.                 }
  104.                 count--;
  105.                 if (!count)
  106.                     ld_code = '\0';
  107.                 buf[count] = '\0';
  108.                 getyx(dm_win, y, x);
  109.                 x--;
  110.                 wmove(dm_win, y, x);
  111.                 waddch(dm_win, (chtype) ' ');
  112.                 wmove(dm_win, y, x);
  113.                 wrefresh(dm_win);
  114.                 break;
  115. #ifndef OLDCURSES
  116.             case KEY_UP:
  117. #endif /* OLDCURSES */
  118.             case 'u':
  119.             case 'U':    /* up arrow key */
  120.                 if (current == 1) {
  121.                     beep();
  122.                     break;
  123.                 }
  124.                 start = current - 10;
  125.                 if (start < 1)
  126.                     start = 1;
  127.                 current = start;
  128.                 dir_scroll(dm_win, start);
  129.                 break;
  130. #ifndef OLDCURSES
  131.             case KEY_DOWN:
  132.             case '\n':
  133. #endif /* OLDCURSES */
  134.             case 'n':
  135.             case 'N':    /* down arrow key */
  136.                 if (current == NUM_DIR-9) {
  137.                     beep();
  138.                     break;
  139.                 }
  140.                 start = current + 10;
  141.                 if (start > NUM_DIR-9)
  142.                     start = NUM_DIR-9;
  143.                 current = start;
  144.                 dir_scroll(dm_win, start);
  145.                 break;
  146.             case '\r':    /* <CR> key */
  147.                 if (!count) {
  148.                     if (current == NUM_DIR-9) {
  149.                         beep();
  150.                         break;
  151.                     }
  152.                     current++;
  153.                     if (current > NUM_DIR-9)
  154.                         current = NUM_DIR-9;
  155.                     dir_scroll(dm_win, current);
  156.                 }
  157.                 /*
  158.                  * The <CR> is used for the scroll-down-one-line
  159.                  * function, and to terminate numeric input.
  160.                  */
  161.                 else {
  162.                     buf[count] = '\0';
  163.                     i = atoi(buf);
  164.                     if (!i || i > NUM_DIR) {
  165.                         beep();
  166.                         mvwaddstr(dm_win, 15, 8, "   ");
  167.                         x = 8;
  168.                         count = 0;
  169.                         break;
  170.                     }
  171.                     dir->q_ld[0] = ld_code;
  172.                     dir->q_num[0] = i;
  173.                     dir->d_cur = i;
  174.  
  175.                     /* end of queue marker */
  176.                     dir->q_num[1] = -1;
  177.  
  178.                     ret_code++;
  179.                     break;
  180.                 }
  181.                 break;
  182.             case 'r':
  183.             case 'R':    /* revise */
  184.                 if (revise()) {
  185.                     active_ld(dm_win);
  186.                     dir_scroll(dm_win, current);
  187.                 }
  188.                 touchwin(dm_win);
  189.                 break;
  190.             case 'p':    /* display LD codes */
  191.             case 'P':
  192.                 disp_ld();
  193.                 touchwin(dm_win);
  194.                 needs_repair++;
  195.                 break;
  196.             case 'd':
  197.             case 'D':    /* delete a range of entries */
  198.                 if (delete())
  199.                     dir_scroll(dm_win, current);
  200.                 touchwin(dm_win);
  201.                 break;
  202.             case 'm':
  203.             case 'M':    /* manual dial */
  204.                 if (manual()) {
  205.                     ret_code++;
  206.                     break;
  207.                 }
  208.                 touchwin(dm_win);
  209.                 needs_repair++;
  210.                 break;
  211.             case 'l':
  212.             case 'L':    /* print the entries */
  213.                 print_dir();
  214.                 touchwin(dm_win);
  215.                 needs_repair++;
  216.                 break;
  217.             case '+':    /* LD codes */
  218.             case '-':
  219.             case '@':
  220.             case '#':
  221.                 waddch(dm_win, (chtype) ans);
  222.                 wrefresh(dm_win);
  223.                 ld_code = (char) ans;
  224.                 continue;
  225.             case ESC:    /* <ESC> key (exit) */
  226.                 break;
  227.             default:
  228.                 beep();
  229.         }
  230.         if (ret_code)
  231.             break;
  232.                     /* magic cookie terminal? */
  233.         if (xmc > 0 && needs_repair) {
  234.             clear_line(dm_win, 1, 0, FALSE);
  235.             clear_line(dm_win, 3, 0, FALSE);
  236.             wrefresh(dm_win);
  237.             mvwattrstr(dm_win, 1, 20, A_BOLD, "D I A L I N G       D I R E C T O R Y");
  238.             mvwattrstr(dm_win, 3, 0, A_STANDOUT, "           Name                   Number        Baud P D S Dpx  Auxiliary     ");
  239.             box(dm_win, VERT, HORZ);
  240.         }
  241.         wmove(dm_win, y, x);
  242.         wrefresh(dm_win);
  243.     } while (ans != ESC);
  244.  
  245.     werase(dm_win);
  246.     wrefresh(dm_win);
  247.     delwin(dm_win);
  248.     if (ret_code) {
  249.         touchwin(stdscr);
  250.         refresh();
  251.     }
  252.     return(ret_code);
  253. }
  254.  
  255. /*
  256.  * Scroll the dialing directory.  Actually, we're not doing a real scroll
  257.  * function on the screen, we're just repainting 10 lines.
  258.  */
  259.  
  260. static void
  261. dir_scroll(win, start)
  262. WINDOW *win;
  263. int start;
  264. {
  265.     int i;
  266.  
  267.     wmove(win, 4, 0);
  268.     for (i=start; i<start+10; i++)
  269.         wprintw(win,
  270.          "%4d- %-20.20s %18.18s  %5d-%c-%d-%d  %c  %-14.14s\n", i,
  271.          dir->name[i], dir->number[i], dir->baud[i], dir->parity[i],
  272.          dir->data_bits[i], dir->stop_bits[i], dir->duplex[i],
  273.          dir->aux[i]);
  274.     box(win, VERT, HORZ);
  275.     return;
  276. }
  277.  
  278. /*
  279.  * Display the Long Distance codes.  Press any key to continue.
  280.  */
  281.  
  282. static void
  283. disp_ld()
  284. {
  285.     WINDOW *ld_win, *newwin();
  286.  
  287.     ld_win = newwin(12, 30, 0, 0);
  288.     mvwaddstr(ld_win, 1, 5, "Long Distance Codes\n");
  289.     horizontal(ld_win, 2, 0, 30);
  290.     mvwprintw(ld_win, 3, 2, "+ %-20.20s", param->ld_plus);
  291.     mvwprintw(ld_win, 5, 2, "- %-20.20s", param->ld_minus);
  292.     mvwprintw(ld_win, 7, 2, "@ %-20.20s", param->ld_at);
  293.     mvwprintw(ld_win, 9, 2, "# %-20.20s", param->ld_pound);
  294.     box(ld_win, VERT, HORZ);
  295.  
  296.     mvwaddstr(ld_win, 11, 8, " Press any key ");
  297.     wmove(ld_win, 11, 29);
  298.     wrefresh(ld_win);
  299.     wgetch(ld_win);
  300.                     /* it overlaps, so erase it */
  301.     werase(ld_win);
  302.     wrefresh(ld_win);
  303.     delwin(ld_win);
  304.     return;
  305. }
  306.  
  307. /*
  308.  * Display which of the Long Distance codes are active.
  309.  */
  310.  
  311. static void
  312. active_ld(win)
  313. WINDOW *win;
  314. {
  315.     mvwaddstr(win, 19, 21, "        ");
  316.     wmove(win, 19, 21);
  317.                     /* a NULL means it's not active */
  318.     if (*param->ld_plus != '\0')
  319.         waddstr(win, "+ ");
  320.     if (*param->ld_minus != '\0')
  321.         waddstr(win, "- ");
  322.     if (*param->ld_at != '\0')
  323.         waddstr(win, "@ ");
  324.     if (*param->ld_pound != '\0')
  325.         waddstr(win, "# ");
  326.     return;
  327. }
  328.