home *** CD-ROM | disk | FTP | other *** search
- /*
- * Open a window to prompt for a new directory. Checks to see if the
- * directory exists, but doesn't move to there (yet). Returns the path
- * to the new directory, or NULL if you chickened out.
- */
-
- #include <curses.h>
- #include "misc.h"
-
- char *
- change_dir(fd)
- int fd;
- {
- WINDOW *ch_win, *newwin();
- int got_it;
- char *ans, *dir, *expand(), *cwd, *getcwd(), cwdbuf[200];
- char *get_str();
- void free_ptr();
-
- cwd = getcwd(cwdbuf, 200);
-
- ch_win = newwin(6, 70, 5, 5);
-
- mvwprintw(ch_win, 2, 4, "Current directory: %s", cwd);
- mvwaddstr(ch_win, 3, 4, "New directory: ");
- box(ch_win, '|', '-');
-
- mvwattrstr(ch_win, 0, 3, A_BOLD, " Change directory ");
- wmove(ch_win, 3, 19);
- wrefresh(ch_win);
- /* get the answer */
- got_it = 0;
- while ((ans = get_str(ch_win, 60, NULL, " ")) != NULL) {
- if (*ans == NULL)
- break;
- /* expand the input */
- dir = expand(ans);
- /* if it exists */
- if (!access(dir, 1)) {
- got_it++;
- break;
- }
- beep();
- mvwattrstr(ch_win, 4, 15, A_BOLD, "No such directory or no access permission");
- wrefresh(ch_win);
- wait_key(ch_win, 3);
- /* cleanup the mess */
- clear_line(ch_win, 3, 19, 1);
- clear_line(ch_win, 4, 14, 1);
- wmove(ch_win, 3, 19);
- wrefresh(ch_win);
- free_ptr(dir);
- }
- if (fd == -1) {
- werase(ch_win);
- wrefresh(ch_win);
- }
- delwin(ch_win);
- if (got_it)
- return(dir);
- return(NULL);
- }
-