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

  1. /*
  2.  * The delete option of the dialing directory.  Prompts for saving
  3.  * changes to disk. A return code of 1 means that entries were deleted.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <curses.h>
  8. #include "dial_dir.h"
  9. #include "misc.h"
  10. #include "param.h"
  11.  
  12. int
  13. delete()
  14. {
  15.     WINDOW *d_win, *newwin();
  16.     int i, first, last;
  17.     void free_ptr();
  18.     extern char *null_ptr;
  19.     
  20.     d_win = newwin(6, 32, 10, 15);
  21.  
  22.     mvwaddstr(d_win, 2, 2, "Delete entry:     thru:");
  23.     box(d_win, '|', '-');
  24.     wmove(d_win, 2, 16);
  25.     wrefresh(d_win);
  26.                     /* get the first of the range */
  27.     while ((first = get_num(d_win, 3)) != -1) {
  28.         if (first > 0 && first <= NUM_DIR)
  29.             break;
  30.         mvwaddstr(d_win, 2, 16, "   ");
  31.         wmove(d_win, 2, 16);
  32.         beep();
  33.         wrefresh(d_win);
  34.     }
  35.     if (first == -1) {
  36.         delwin(d_win);
  37.         return(0);
  38.     }
  39.                     /* get the last of the range */
  40.     wmove(d_win, 2, 26);
  41.     wrefresh(d_win);
  42.     while ((last = get_num(d_win, 3)) != -1) {
  43.         if ((first <= last && last <= NUM_DIR) || last == 0)
  44.             break;
  45.         mvwaddstr(d_win, 2, 26, "   ");
  46.         wmove(d_win, 2, 26);
  47.         beep();
  48.         wrefresh(d_win);
  49.     }
  50.     if (last == -1) {
  51.         delwin(d_win);
  52.         return(0);
  53.     }
  54.                     /* if "last" omitted, echo "first" */
  55.     if (!last) {
  56.         last = first;
  57.         mvwprintw(d_win, 2, 26, "%d", first);
  58.         wrefresh(d_win);
  59.     }
  60.                     /* save to disk? */
  61.     if (yes_prompt(d_win, 3, 2, A_BOLD, "Are you sure")) {
  62.                     /* delete from the physical file */
  63.         if (del_dir(first, last)) {
  64.             touchwin(d_win);
  65.             wrefresh(d_win);
  66.         }
  67.         /*
  68.          * We don't really care if del_dir() fails because we still
  69.          * change the version in memory.
  70.          */
  71.         for (i=first; i<=last; i++) {
  72.             free_ptr(dir->name[i]);
  73.             free_ptr(dir->number[i]);
  74.             free_ptr(dir->index[i]);
  75.             dir->name[i] = null_ptr;
  76.             dir->number[i] = null_ptr;
  77.             dir->baud[i] = param->d_baud;
  78.             dir->parity[i] = param->d_parity;
  79.             dir->dbits[i] = param->d_dbits;
  80.             dir->sbits[i] = param->d_sbits;
  81.             dir->duplex[i] = *param->d_duplex;
  82.             dir->index[i] = null_ptr;
  83.         }
  84.         delwin(d_win);
  85.         return(1);
  86.     }
  87.     delwin(d_win);
  88.     return(0);
  89. }
  90.