home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume16 / pcomm2 / part03 / chg_dir.c < prev    next >
C/C++ Source or Header  |  1988-09-14  |  1KB  |  62 lines

  1. /*
  2.  * Open a window to prompt for a new directory.  Checks to see you have
  3.  * search permission.
  4.  */
  5.  
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "misc.h"
  9.  
  10. void
  11. chg_dir()
  12. {
  13.     extern int fd;
  14.     WINDOW *ch_win, *newwin();
  15.     char *ans, *dir, *expand(), *cwd, *getcwd(), cwdbuf[200];
  16.     char *get_str();
  17.     void free_ptr();
  18.  
  19.     cwd = getcwd(cwdbuf, 200);
  20.  
  21.     ch_win = newwin(6, 70, 5, 5);
  22.  
  23.     mvwprintw(ch_win, 2, 4, "Current directory: %s", cwd);
  24.     mvwaddstr(ch_win, 3, 4, "New directory: ");
  25.     box(ch_win, VERT, HORZ);
  26.  
  27.     mvwattrstr(ch_win, 0, 3, A_BOLD, " Change directory ");
  28.     wmove(ch_win, 3, 19);
  29.     wrefresh(ch_win);
  30.                     /* get the answer */
  31.     while ((ans = get_str(ch_win, 60, "", "     ")) != NULL) {
  32.                     /* a CR means no change */
  33.         if (*ans == NULL)
  34.             break;
  35.                     /* expand the input */
  36.         dir = expand(ans);
  37.                     /* if you have search permission */
  38.         if (!access(dir, 1)) {
  39.             if (!chdir(dir)) {
  40.                 free_ptr(dir);
  41.                 break;
  42.             }
  43.         }
  44.         beep();
  45.         mvwattrstr(ch_win, 4, 15, A_BOLD, "No such directory or no access permission");
  46.         wrefresh(ch_win);
  47.         wait_key(ch_win, 3);
  48.                     /* clean up the mess */
  49.         clear_line(ch_win, 3, 19, 1);
  50.         clear_line(ch_win, 4, 14, 1);
  51.         wmove(ch_win, 3, 19);
  52.         wrefresh(ch_win);
  53.         free_ptr(dir);
  54.     }
  55.     if (fd == -1) {
  56.         werase(ch_win);
  57.         wrefresh(ch_win);
  58.     }
  59.     delwin(ch_win);
  60.     return;
  61. }
  62.