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