home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part02 / d_menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-17  |  6.7 KB  |  310 lines

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