home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / pcomm2 / part03 / d_delete.c < prev    next >
C/C++ Source or Header  |  1988-09-14  |  2KB  |  91 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 "config.h"
  9. #include "dial_dir.h"
  10. #include "misc.h"
  11. #include "param.h"
  12.  
  13. int
  14. delete()
  15. {
  16.     extern char *null_ptr;
  17.     WINDOW *d_win, *newwin();
  18.     int i, first, last;
  19.     void free_ptr();
  20.  
  21.     d_win = newwin(6, 32, 10, 15);
  22.  
  23.     mvwaddstr(d_win, 2, 2, "Delete entry:     thru:");
  24.     box(d_win, VERT, HORZ);
  25.     wmove(d_win, 2, 16);
  26.     wrefresh(d_win);
  27.                     /* get the first of the range */
  28.     while ((first = get_num(d_win, 3)) != -1) {
  29.         if (first > 0 && first <= NUM_DIR)
  30.             break;
  31.         mvwaddstr(d_win, 2, 16, "   ");
  32.         wmove(d_win, 2, 16);
  33.         beep();
  34.         wrefresh(d_win);
  35.     }
  36.     if (first == -1) {
  37.         delwin(d_win);
  38.         return(0);
  39.     }
  40.                     /* get the last of the range */
  41.     wmove(d_win, 2, 26);
  42.     wrefresh(d_win);
  43.     while ((last = get_num(d_win, 3)) != -1) {
  44.         if ((first <= last && last <= NUM_DIR) || last == 0)
  45.             break;
  46.         mvwaddstr(d_win, 2, 26, "   ");
  47.         wmove(d_win, 2, 26);
  48.         beep();
  49.         wrefresh(d_win);
  50.     }
  51.     if (last == -1) {
  52.         delwin(d_win);
  53.         return(0);
  54.     }
  55.                     /* if "last" omitted, echo "first" */
  56.     if (!last) {
  57.         last = first;
  58.         mvwprintw(d_win, 2, 26, "%d", first);
  59.         wrefresh(d_win);
  60.     }
  61.                     /* save to disk? */
  62.     if (yes_prompt(d_win, 3, 2, A_BOLD, "Are you sure")) {
  63.                     /* delete from the physical file */
  64.         if (del_dir(first, last)) {
  65.             touchwin(d_win);
  66.             wrefresh(d_win);
  67.         }
  68.         /*
  69.          * We don't really care if del_dir() fails because we still
  70.          * change the version in memory.
  71.          */
  72.         for (i=first; i<=last; i++) {
  73.             free_ptr(dir->name[i]);
  74.             free_ptr(dir->number[i]);
  75.             free_ptr(dir->index[i]);
  76.             dir->name[i] = null_ptr;
  77.             dir->number[i] = null_ptr;
  78.             dir->baud[i] = param->d_baud;
  79.             dir->parity[i] = param->d_parity;
  80.             dir->dbits[i] = param->d_dbits;
  81.             dir->sbits[i] = param->d_sbits;
  82.             dir->duplex[i] = *param->d_duplex;
  83.             dir->index[i] = null_ptr;
  84.         }
  85.         delwin(d_win);
  86.         return(1);
  87.     }
  88.     delwin(d_win);
  89.     return(0);
  90. }
  91.