home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / pcomm2 / part05 / redial.c < prev   
Encoding:
C/C++ Source or Header  |  1988-09-14  |  2.2 KB  |  97 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 non-zero return code
  5.  * means we're ready to dial.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <curses.h>
  10. #include "config.h"
  11. #include "dial_dir.h"
  12. #include "misc.h"
  13.  
  14. int
  15. redial()
  16. {
  17.     extern int fd;
  18.     WINDOW *rd_win, *newwin();
  19.     char *ans, *entry, *get_str(), *strchr(), *strtok();
  20.     int i, oops, number, ret_code;
  21.  
  22.     rd_win = newwin(6, 70, 5, 5);
  23.  
  24.     mvwaddstr(rd_win, 4, 23, "(<CR> for previous numbers)");
  25.     mvwaddstr(rd_win, 2, 4, "Directory Entry Number(s): ");
  26.     box(rd_win, VERT, HORZ);
  27.  
  28.     mvwattrstr(rd_win, 0, 3, A_BOLD, " Redial Queue ");
  29.     wmove(rd_win, 2, 31);
  30.     wrefresh(rd_win);
  31.                     /* get the string of numbers */
  32.     ret_code = 0;
  33.     while ((ans = get_str(rd_win, 35, "0123456789+-@# ", "")) != NULL) {
  34.         oops = 0;
  35.         if (*ans == NULL) {
  36.                     /* use previous queue */
  37.             if (dir->q_num[0] != -1) {
  38.                 ret_code++;
  39.                 break;
  40.             }
  41.                     /* there is no previous queue */
  42.             beep();
  43.             mvwattrstr(rd_win, 3, 4, A_BOLD, "No previous numbers");
  44.             wrefresh(rd_win);
  45.             wait_key(rd_win, 3);
  46.             clear_line(rd_win, 3, 4, 1);
  47.             wmove(rd_win, 2, 31);
  48.             wrefresh(rd_win);
  49.             continue;
  50.         }
  51.                     /* parse the queue values */
  52.         entry = strtok(ans, "     ");
  53.         for (i=0; i<NUM_QUEUE; i++) {
  54.             if (*entry == NULL) {
  55.                 dir->q_num[i] = -1;
  56.                 continue;
  57.             }
  58.                     /* is there a LD code? */
  59.             dir->q_ld[i] = NULL;
  60.             if (strchr("+-@#", *entry)) {
  61.                 dir->q_ld[i] = *entry;
  62.                 entry++;
  63.             }
  64.  
  65.             /*
  66.              * Zero is valid here, because it means use
  67.              * the current entry information.
  68.              */
  69.             number = atoi(entry);
  70.             if (number < -1 || number > NUM_DIR) {
  71.                 beep();
  72.                 mvwattrstr(rd_win, 3, 4, A_BOLD, "Invalid directory entry number");
  73.                 wrefresh(rd_win);
  74.                 wait_key(rd_win, 3);
  75.                 clear_line(rd_win, 3, 4, 1);
  76.                 clear_line(rd_win, 2, 31, 1);
  77.                 wrefresh(rd_win);
  78.                 oops++;
  79.                 break;
  80.             }
  81.                     /* store the number in the queue */
  82.             dir->q_num[i] = number;
  83.             entry = strtok((char *) NULL, "     ");
  84.         }
  85.         if (oops)
  86.             continue;
  87.         ret_code++;
  88.         break;
  89.     }
  90.     if (fd == -1) {
  91.         werase(rd_win);
  92.         wrefresh(rd_win);
  93.     }
  94.     delwin(rd_win);
  95.     return(ret_code);
  96. }
  97.