home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / pcomm / part04 / redial.c < prev   
Encoding:
C/C++ Source or Header  |  1988-05-17  |  2.2 KB  |  96 lines

  1. /*
  2.  * The redial option (actually a misnomer, it's really a queuing system).
  3.  * We expect a space-separated list of dialing directory entries (although
  4.  * new users always try to put in a phone number).  A return code of 1
  5.  * means we're ready to dial.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <curses.h>
  10. #include "dial_dir.h"
  11. #include "misc.h"
  12.  
  13. int
  14. redial(fd)
  15. int fd;
  16. {
  17.     WINDOW *rd_win, *newwin();
  18.     char *ans, *entry, *get_str(), *strchr(), *strtok();
  19.     int i, oops, number, ret_code;
  20.     
  21.     rd_win = newwin(6, 70, 5, 5);
  22.  
  23.     mvwaddstr(rd_win, 4, 23, "(CR for previous numbers)");
  24.     mvwaddstr(rd_win, 2, 4, "Directory Entry Number(s): ");
  25.     box(rd_win, '|', '-');
  26.  
  27.     mvwattrstr(rd_win, 0, 3, A_BOLD, " Redial Queue ");
  28.     wmove(rd_win, 2, 31);
  29.     wrefresh(rd_win);
  30.                     /* get the string of numbers */
  31.     ret_code = 0;
  32.     while ((ans = get_str(rd_win, 35, "0123456789+-@# ", NULL)) != NULL) {
  33.         oops = 0;
  34.         if (*ans == NULL) {
  35.                     /* use previous queue */
  36.             if (dir->q_num[0] != -1) {
  37.                 ret_code = 1;
  38.                 break;
  39.             }
  40.                     /* there is no previous queue */
  41.             beep();
  42.             mvwattrstr(rd_win, 3, 4, A_BOLD, "No previous numbers");
  43.             wrefresh(rd_win);
  44.             wait_key(rd_win, 3);
  45.             clear_line(rd_win, 3, 4, 1);
  46.             wmove(rd_win, 2, 31);
  47.             wrefresh(rd_win);
  48.             continue;
  49.         }
  50.                     /* parse the queue values */
  51.         entry = strtok(ans, "     ");
  52.         for (i=0; i<NUM_QUEUE; i++) {
  53.             if (*entry == NULL) {
  54.                 dir->q_num[i] = -1;
  55.                 continue;
  56.             }
  57.                     /* is there a LD code ? */
  58.             dir->q_ld[i] = NULL;
  59.             if (strchr("+-@#", *entry)) {
  60.                 dir->q_ld[i] = *entry;
  61.                 entry++;
  62.             }
  63.  
  64.             /*
  65.              * Zero is valid here, because it means use
  66.              * the current entry information.
  67.              */
  68.             number = atoi(entry);
  69.             if (number < -1 || number > NUM_DIR) {
  70.                 beep();
  71.                 mvwattrstr(rd_win, 3, 4, A_BOLD, "Invalid directory entry number");
  72.                 wrefresh(rd_win);
  73.                 wait_key(rd_win, 3);
  74.                 clear_line(rd_win, 3, 4, 1);
  75.                 clear_line(rd_win, 2, 31, 1);
  76.                 wrefresh(rd_win);
  77.                 oops++;
  78.                 break;
  79.             }
  80.                     /* store the number in the queue */
  81.             dir->q_num[i] = number;
  82.             entry = strtok((char *) NULL, "     ");
  83.         }
  84.         if (oops)
  85.             continue;
  86.         ret_code = 1;
  87.         break;
  88.     }
  89.     if (fd == -1) {
  90.         werase(rd_win);
  91.         wrefresh(rd_win);
  92.     }
  93.     delwin(rd_win);
  94.     return(ret_code);
  95. }
  96.