5 #include <sys/types.h> /* pid_t, ... */
7 #include <limits.h> /* PATH_MAX */
8 #include <locale.h> /* setlocale(), LC_ALL */
9 #include <unistd.h> /* chdir(), getcwd(), read(), close(), ... */
10 #include <dirent.h> /* DIR, struct dirent, opendir(), ... */
12 #include <fcntl.h> /* open() */
13 #include <sys/wait.h> /* waitpid() */
14 #include <signal.h> /* struct sigaction, sigaction() */
22 static char ROW[ROWSZ];
24 static char STATUS[STATUSSZ];
26 static char INPUT[INPUTSZ];
28 /* Argument buffers for execvp(). */
30 static char *ARGS[MAXARGS];
32 /* Listing view parameters. */
33 #define HEIGHT (LINES-4)
34 #define STATUSPOS (COLS-16)
36 /* Listing view flags. */
37 #define SHOW_FILES 0x01u
38 #define SHOW_DIRS 0x02u
39 #define SHOW_HIDDEN 0x04u
41 /* Marks parameters. */
43 #define BULK_THRESH 256
45 /* Information associated to each entry in listing. */
52 /* Dynamic array of marked entries. */
53 typedef struct Marks {
54 char dirpath[PATH_MAX];
60 /* Global state. Some basic info is allocated for ten tabs. */
69 char cwd[10][PATH_MAX];
73 /* Macros for accessing global state. */
74 #define ENAME(I) rover.rows[I].name
75 #define ESIZE(I) rover.rows[I].size
76 #define MARKED(I) rover.rows[I].marked
77 #define SCROLL rover.scroll[rover.tab]
78 #define ESEL rover.esel[rover.tab]
79 #define FLAGS rover.flags[rover.tab]
80 #define CWD rover.cwd[rover.tab]
83 #define MIN(A, B) ((A) < (B) ? (A) : (B))
84 #define MAX(A, B) ((A) > (B) ? (A) : (B))
85 #define ISDIR(E) (strchr((E), '/') != NULL)
87 typedef enum Color {DEFAULT, RED, GREEN, YELLOW, BLUE, CYAN, MAGENTA, WHITE} Color;
88 typedef int (*PROCESS)(const char *path);
91 init_marks(Marks *marks)
93 strcpy(marks->dirpath, "");
94 marks->bulk = BULK_INIT;
96 marks->entries = calloc(marks->bulk, sizeof *marks->entries);
99 /* Unmark all entries. */
101 mark_none(Marks *marks)
105 strcpy(marks->dirpath, "");
106 for (i = 0; i < marks->bulk && marks->nentries; i++)
107 if (marks->entries[i]) {
108 free(marks->entries[i]);
109 marks->entries[i] = NULL;
112 if (marks->bulk > BULK_THRESH) {
113 /* Reset bulk to free some memory. */
114 free(marks->entries);
115 marks->bulk = BULK_INIT;
116 marks->entries = calloc(marks->bulk, sizeof *marks->entries);
121 add_mark(Marks *marks, char *dirpath, char *entry)
125 if (!strcmp(marks->dirpath, dirpath)) {
126 /* Append mark to directory. */
127 if (marks->nentries == marks->bulk) {
128 /* Expand bulk to accomodate new entry. */
129 int extra = marks->bulk >> 1;
130 marks->bulk += extra; /* bulk *= 1.5; */
131 marks->entries = realloc(marks->entries,
132 marks->bulk * sizeof *marks->entries);
133 memset(&marks->entries[marks->nentries], 0,
134 extra * sizeof *marks->entries);
137 /* Search for empty slot (there must be one). */
138 for (i = 0; i < marks->bulk; i++)
139 if (!marks->entries[i])
143 /* Directory changed. Discard old marks. */
145 strcpy(marks->dirpath, dirpath);
148 marks->entries[i] = malloc(strlen(entry) + 1);
149 strcpy(marks->entries[i], entry);
154 del_mark(Marks *marks, char *entry)
158 if (marks->nentries > 1) {
159 for (i = 0; i < marks->bulk; i++)
160 if (marks->entries[i] && !strcmp(marks->entries[i], entry))
162 free(marks->entries[i]);
163 marks->entries[i] = NULL;
170 free_marks(Marks *marks)
174 for (i = 0; i < marks->bulk && marks->nentries; i++)
175 if (marks->entries[i]) {
176 free(marks->entries[i]);
179 free(marks->entries);
182 static void update_view();
184 /* SIGSEGV handler: clean up curses before exiting. */
190 fprintf(stderr, "Received SIGSEGV (segmentation fault).\n");
194 /* SIGWINCH handler: resize application according to new terminal settings. */
196 handle_winch(int sig)
199 delwin(rover.window);
203 rover.window = subwin(stdscr, LINES - 2, COLS, 1, 0);
212 memset(&sa, 0, sizeof (struct sigaction));
213 sa.sa_handler = handle_segv;
214 sigaction(SIGSEGV, &sa, NULL);
215 sa.sa_handler = handle_winch;
216 sigaction(SIGWINCH, &sa, NULL);
224 memset(&sa, 0, sizeof (struct sigaction));
225 sa.sa_handler = SIG_DFL;
226 sigaction(SIGSEGV, &sa, NULL);
227 sigaction(SIGWINCH, &sa, NULL);
230 /* Do a fork-exec to external program (e.g. $EDITOR). */
239 /* fork() succeeded. */
242 waitpid(pid, &status, 0);
244 kill(getpid(), SIGWINCH);
245 } else if (pid == 0) {
247 execvp(ARGS[0], ARGS);
255 setlocale(LC_ALL, "");
257 cbreak(); /* Get one character at a time. */
259 nonl(); /* No NL->CR/NL on output. */
260 intrflush(stdscr, FALSE);
261 keypad(stdscr, TRUE);
262 curs_set(FALSE); /* Hide blinking cursor. */
266 #ifdef NCURSES_EXT_FUNCS
267 use_default_colors();
272 init_pair(RED, COLOR_RED, bg);
273 init_pair(GREEN, COLOR_GREEN, bg);
274 init_pair(YELLOW, COLOR_YELLOW, bg);
275 init_pair(BLUE, COLOR_BLUE, bg);
276 init_pair(CYAN, COLOR_CYAN, bg);
277 init_pair(MAGENTA, COLOR_MAGENTA, bg);
278 init_pair(WHITE, COLOR_WHITE, bg);
280 atexit((void (*)(void)) endwin);
284 /* Update the listing view. */
293 mvhline(0, 0, ' ', COLS);
294 attr_on(A_BOLD, NULL);
295 color_set(RVC_TABNUM, NULL);
296 mvaddch(0, COLS - 2, rover.tab + '0');
297 color_set(DEFAULT, NULL);
298 attr_off(A_BOLD, NULL);
299 if (rover.marks.nentries) {
300 numsize = snprintf(STATUS, STATUSSZ, "%d", rover.marks.nentries);
301 color_set(RVC_NMARKS, NULL);
302 mvaddstr(0, COLS - 3 - numsize, STATUS);
303 color_set(DEFAULT, NULL);
306 color_set(RVC_CWD, NULL);
307 mvaddnstr(0, 0, CWD, COLS - 4 - numsize);
308 color_set(DEFAULT, NULL);
309 wcolor_set(rover.window, RVC_BORDER, NULL);
310 wborder(rover.window, 0, 0, 0, 0, 0, 0, 0, 0);
311 wcolor_set(rover.window, DEFAULT, NULL);
312 /* Selection might not be visible, due to cursor wrapping or window
313 shrinking. In that case, the scroll must be moved to make it visible. */
314 SCROLL = MAX(MIN(SCROLL, ESEL), ESEL - HEIGHT + 1);
315 marking = !strcmp(CWD, rover.marks.dirpath);
316 for (i = 0, j = SCROLL; i < HEIGHT && j < rover.nfiles; i++, j++) {
317 ishidden = ENAME(j)[0] == '.';
318 isdir = ISDIR(ENAME(j));
320 wattr_on(rover.window, A_REVERSE, NULL);
322 wcolor_set(rover.window, RVC_HIDDEN, NULL);
324 wcolor_set(rover.window, RVC_DIR, NULL);
326 wcolor_set(rover.window, RVC_FILE, NULL);
328 snprintf(ROW, ROWSZ, "%s%*d", ENAME(j),
329 (int) (COLS - strlen(ENAME(j)) - 4), (int) ESIZE(j));
331 strcpy(ROW, ENAME(j));
332 mvwhline(rover.window, i + 1, 1, ' ', COLS - 2);
333 if (marking && MARKED(j))
334 mvwaddch(rover.window, i + 1, 1, RVS_MARK);
336 mvwaddch(rover.window, i + 1, 1, ' ');
337 mvwaddnstr(rover.window, i + 1, 2, ROW, COLS - 4);
338 wcolor_set(rover.window, DEFAULT, NULL);
340 wattr_off(rover.window, A_REVERSE, NULL);
342 for (;i < HEIGHT; i++)
343 mvwhline(rover.window, i + 1, 1, ' ', COLS - 2);
344 if (rover.nfiles > HEIGHT) {
346 center = (SCROLL + (HEIGHT >> 1)) * HEIGHT / rover.nfiles;
347 height = (HEIGHT-1) * HEIGHT / rover.nfiles;
348 if (!height) height = 1;
349 wcolor_set(rover.window, RVC_BORDER, NULL);
350 wborder(rover.window, 0, 0, 0, 0, 0, 0, 0, 0);
351 wcolor_set(rover.window, RVC_SCROLLBAR, NULL);
352 mvwvline(rover.window, center-(height>>1)+1, COLS-1, RVS_SCROLLBAR, height);
353 wcolor_set(rover.window, DEFAULT, NULL);
355 STATUS[0] = FLAGS & SHOW_FILES ? 'F' : ' ';
356 STATUS[1] = FLAGS & SHOW_DIRS ? 'D' : ' ';
357 STATUS[2] = FLAGS & SHOW_HIDDEN ? 'H' : ' ';
361 snprintf(ROW, ROWSZ, "%d/%d", ESEL + 1, rover.nfiles);
362 snprintf(STATUS+3, STATUSSZ-3, "%12s", ROW);
363 color_set(RVC_STATUS, NULL);
364 mvaddstr(LINES - 1, STATUSPOS, STATUS);
365 color_set(DEFAULT, NULL);
366 wrefresh(rover.window);
369 /* Show a message on the status bar. */
371 message(const char *msg, Color color)
376 pos = (STATUSPOS - len) >> 1;
377 attr_on(A_BOLD, NULL);
378 color_set(color, NULL);
379 mvaddstr(LINES - 1, pos, msg);
380 color_set(DEFAULT, NULL);
381 attr_off(A_BOLD, NULL);
384 /* Clear message area, leaving only status info. */
388 mvhline(LINES - 1, 0, ' ', STATUSPOS);
391 /* Comparison used to sort listing entries. */
393 rowcmp(const void *a, const void *b)
395 int isdir1, isdir2, cmpdir;
398 isdir1 = ISDIR(r1->name);
399 isdir2 = ISDIR(r2->name);
400 cmpdir = isdir2 - isdir1;
401 return cmpdir ? cmpdir : strcoll(r1->name, r2->name);
404 /* Get all entries in current working directory. */
406 ls(Row **rowsp, uint8_t flags)
414 if(!(dp = opendir("."))) return -1;
415 n = -2; /* We don't want the entries "." and "..". */
416 while (readdir(dp)) n++;
418 rows = malloc(n * sizeof *rows);
420 while ((ep = readdir(dp))) {
421 if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
423 if (!(flags & SHOW_HIDDEN) && ep->d_name[0] == '.')
425 lstat(ep->d_name, &statbuf);
426 if (S_ISDIR(statbuf.st_mode)) {
427 if (flags & SHOW_DIRS) {
428 rows[i].name = malloc(strlen(ep->d_name) + 2);
429 strcpy(rows[i].name, ep->d_name);
430 strcat(rows[i].name, "/");
433 } else if (flags & SHOW_FILES) {
434 rows[i].name = malloc(strlen(ep->d_name) + 1);
435 strcpy(rows[i].name, ep->d_name);
436 rows[i].size = statbuf.st_size;
440 n = i; /* Ignore unused space in array caused by filters. */
441 qsort(rows, n, sizeof (*rows), rowcmp);
448 free_rows(Row **rowsp, int nfiles)
452 for (i = 0; i < nfiles; i++)
453 free((*rowsp)[i].name);
458 /* Change working directory to the path in CWD. */
464 message("Loading...", CYAN);
466 if (reset) ESEL = SCROLL = 0;
469 free_rows(&rover.rows, rover.nfiles);
470 rover.nfiles = ls(&rover.rows, FLAGS);
471 if (!strcmp(CWD, rover.marks.dirpath)) {
472 for (i = 0; i < rover.nfiles; i++) {
473 for (j = 0; j < rover.marks.bulk; j++)
475 rover.marks.entries[j] &&
476 !strcmp(rover.marks.entries[j], ENAME(i))
479 MARKED(i) = j < rover.marks.bulk;
482 for (i = 0; i < rover.nfiles; i++)
488 /* Select a target entry, if it is present. */
490 try_to_sel(const char *target)
494 while ((ESEL+1) < rover.nfiles && ISDIR(ENAME(ESEL)))
496 while ((ESEL+1) < rover.nfiles && strcoll(ENAME(ESEL), target) < 0)
498 if (rover.nfiles > HEIGHT) {
499 SCROLL = ESEL - (HEIGHT >> 1);
500 SCROLL = MIN(MAX(SCROLL, 0), rover.nfiles - HEIGHT);
504 /* Reload CWD, but try to keep selection. */
509 strcpy(INPUT, ENAME(ESEL));
517 /* Recursively process a source directory using CWD as destination root.
518 For each node (i.e. directory), do the following:
519 1. call pre(destination);
520 2. call proc() on every child leaf (i.e. files);
521 3. recurse into every child node;
523 E.g. to move directory /src/ (and all its contents) inside /dst/:
524 strcpy(CWD, "/dst/");
525 process_dir(adddir, movfile, deldir, "/src/"); */
527 process_dir(PROCESS pre, PROCESS proc, PROCESS pos, const char *path)
533 char subpath[PATH_MAX];
537 char dstpath[PATH_MAX];
538 strcpy(dstpath, CWD);
539 strcat(dstpath, path + strlen(rover.marks.dirpath));
542 if(!(dp = opendir(path))) return -1;
543 while ((ep = readdir(dp))) {
544 if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
546 snprintf(subpath, PATH_MAX, "%s%s", path, ep->d_name);
547 stat(subpath, &statbuf);
548 if (S_ISDIR(statbuf.st_mode)) {
549 strcat(subpath, "/");
550 ret |= process_dir(pre, proc, pos, subpath);
552 ret |= proc(subpath);
555 if (pos) ret |= pos(path);
559 /* Process all marked entries using CWD as destination root.
560 All marked entries that are directories will be recursively processed.
561 See process_dir() for details on the parameters. */
563 process_marked(PROCESS pre, PROCESS proc, PROCESS pos)
569 message("Processing...", CYAN);
571 for (i = 0; i < rover.marks.bulk; i++)
572 if (rover.marks.entries[i]) {
574 snprintf(path, PATH_MAX, "%s%s", rover.marks.dirpath, rover.marks.entries[i]);
575 if (ISDIR(rover.marks.entries[i])) {
576 if (!strncmp(path, CWD, strlen(path)))
579 ret = process_dir(pre, proc, pos, path);
582 if (!ret) del_mark(&rover.marks, rover.marks.entries[i]);
585 if (!rover.marks.nentries)
586 message("Done.", GREEN);
588 message("Some errors occured.", RED);
591 /* Wrappers for file operations. */
592 static PROCESS delfile = unlink;
593 static PROCESS deldir = rmdir;
594 static int addfile(const char *path) {
595 /* Using creat(2) because mknod(2) doesn't seem to be portable. */
598 ret = creat(path, 0644);
599 if (ret < 0) return ret;
602 static int cpyfile(const char *srcpath) {
607 char dstpath[PATH_MAX];
609 ret = src = open(srcpath, O_RDONLY);
610 if (ret < 0) return ret;
611 ret = fstat(src, &st);
612 if (ret < 0) return ret;
613 strcpy(dstpath, CWD);
614 strcat(dstpath, srcpath + strlen(rover.marks.dirpath));
615 ret = dst = creat(dstpath, st.st_mode);
616 if (ret < 0) return ret;
617 while ((size = read(src, buf, BUFSIZ)) > 0)
618 write(dst, buf, size);
623 static int adddir(const char *path) {
627 ret = stat(CWD, &st);
628 if (ret < 0) return ret;
629 return mkdir(path, st.st_mode);
631 static int movfile(const char *srcpath) {
633 char dstpath[PATH_MAX];
635 strcpy(dstpath, CWD);
636 strcat(dstpath, srcpath + strlen(rover.marks.dirpath));
637 ret = rename(srcpath, dstpath);
638 if (ret < 0 && errno == EXDEV) {
639 ret = cpyfile(srcpath);
640 if (ret < 0) return ret;
641 ret = delfile(srcpath);
646 /* Interactive getstr(). */
648 igetstr(char *buffer, int maxlen)
652 length = strlen(buffer);
655 if (ch == '\r' || ch == '\n' || ch == KEY_DOWN || ch == KEY_ENTER) {
658 } else if (ch == erasechar() || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
660 buffer[--length] = '\0';
661 } else if (ch == killchar()) {
664 } else if (length < maxlen - 1 && isprint(ch)) {
665 buffer[length++] = ch;
666 buffer[length] = '\0';
671 /* Update line input on the screen. */
673 update_input(char *prompt, Color color)
677 plen = strlen(prompt);
678 ilen = strlen(INPUT);
679 color_set(RVC_PROMPT, NULL);
680 mvaddstr(LINES - 1, 0, prompt);
681 color_set(color, NULL);
682 mvaddstr(LINES - 1, plen, INPUT);
683 mvaddch(LINES - 1, ilen + plen, ' ');
684 move(LINES - 1, ilen + plen);
685 color_set(DEFAULT, NULL);
689 main(int argc, char *argv[])
697 if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
698 printf("rover %s\n", RV_VERSION);
700 } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
702 "Usage: rover [DIRECTORY [DIRECTORY [DIRECTORY [...]]]]\n"
703 " or: rover [OPTION]\n"
704 "Browse current working directory or the ones specified.\n\n"
706 " -h, --help print this help message and exit\n"
707 " -v, --version print program version and exit\n\n"
708 "See rover(1) for more information.\n\n"
709 "Rover homepage: <https://github.com/lecram/rover>.\n"
716 for (i = 0; i < 10; i++) {
717 rover.esel[i] = rover.scroll[i] = 0;
718 rover.flags[i] = SHOW_FILES | SHOW_DIRS;
720 strcpy(rover.cwd[0], getenv("HOME"));
721 for (i = 1; i < argc && i < 10; i++) {
722 if ((d = opendir(argv[i]))) {
723 realpath(argv[i], rover.cwd[i]);
726 strcpy(rover.cwd[i], rover.cwd[0]);
728 getcwd(rover.cwd[i], PATH_MAX);
729 for (i++; i < 10; i++)
730 strcpy(rover.cwd[i], rover.cwd[i-1]);
731 for (i = 0; i < 10; i++)
732 if (rover.cwd[i][strlen(rover.cwd[i]) - 1] != '/')
733 strcat(rover.cwd[i], "/");
735 rover.window = subwin(stdscr, LINES - 2, COLS, 1, 0);
736 init_marks(&rover.marks);
742 if (!strcmp(key, RVK_QUIT)) break;
743 else if (ch >= '0' && ch <= '9') {
744 rover.tab = ch - '0';
746 } else if (!strcmp(key, RVK_HELP)) {
751 } else if (!strcmp(key, RVK_DOWN)) {
752 if (!rover.nfiles) continue;
753 ESEL = (ESEL + 1) % rover.nfiles;
755 } else if (!strcmp(key, RVK_UP)) {
756 if (!rover.nfiles) continue;
757 ESEL = ESEL ? ESEL - 1 : rover.nfiles - 1;
759 } else if (!strcmp(key, RVK_JUMP_DOWN)) {
760 if (!rover.nfiles) continue;
761 ESEL = MIN(ESEL + RV_JUMP, rover.nfiles - 1);
762 if (rover.nfiles > HEIGHT)
763 SCROLL = MIN(SCROLL + RV_JUMP, rover.nfiles - HEIGHT);
765 } else if (!strcmp(key, RVK_JUMP_UP)) {
766 if (!rover.nfiles) continue;
767 ESEL = MAX(ESEL - RV_JUMP, 0);
768 SCROLL = MAX(SCROLL - RV_JUMP, 0);
770 } else if (!strcmp(key, RVK_CD_DOWN)) {
771 if (!rover.nfiles || !ISDIR(ENAME(ESEL))) continue;
772 strcat(CWD, ENAME(ESEL));
774 } else if (!strcmp(key, RVK_CD_UP)) {
775 char *dirname, first;
776 if (!strcmp(CWD, "/")) continue;
777 CWD[strlen(CWD) - 1] = '\0';
778 dirname = strrchr(CWD, '/') + 1;
783 dirname[strlen(dirname)] = '/';
787 } else if (!strcmp(key, RVK_HOME)) {
788 strcpy(CWD, getenv("HOME"));
789 if (CWD[strlen(CWD) - 1] != '/')
792 } else if (!strcmp(key, RVK_SHELL)) {
793 program = getenv("SHELL");
800 } else if (!strcmp(key, RVK_VIEW)) {
801 if (!rover.nfiles || ISDIR(ENAME(ESEL))) continue;
802 program = getenv("PAGER");
805 ARGS[1] = ENAME(ESEL);
809 } else if (!strcmp(key, RVK_EDIT)) {
810 if (!rover.nfiles || ISDIR(ENAME(ESEL))) continue;
811 program = getenv("EDITOR");
814 ARGS[1] = ENAME(ESEL);
819 } else if (!strcmp(key, RVK_SEARCH)) {
820 int oldsel, oldscroll, length;
821 char *prompt = "search: ";
822 if (!rover.nfiles) continue;
826 update_input(prompt, DEFAULT);
827 while (igetstr(INPUT, INPUTSZ)) {
830 length = strlen(INPUT);
832 for (sel = 0; sel < rover.nfiles; sel++)
833 if (!strncmp(ENAME(sel), INPUT, length))
835 if (sel < rover.nfiles) {
838 if (rover.nfiles > HEIGHT) {
841 else if (sel - 3 > rover.nfiles - HEIGHT)
842 SCROLL = rover.nfiles - HEIGHT;
852 update_input(prompt, color);
856 } else if (!strcmp(key, RVK_TG_FILES)) {
859 } else if (!strcmp(key, RVK_TG_DIRS)) {
862 } else if (!strcmp(key, RVK_TG_HIDDEN)) {
863 FLAGS ^= SHOW_HIDDEN;
865 } else if (!strcmp(key, RVK_NEW_FILE)) {
867 char *prompt = "new file: ";
869 update_input(prompt, DEFAULT);
870 while (igetstr(INPUT, INPUTSZ)) {
871 int length = strlen(INPUT);
873 for (i = 0; i < rover.nfiles; i++) {
875 !strncmp(ENAME(i), INPUT, length) &&
876 (!strcmp(ENAME(i) + length, "") ||
877 !strcmp(ENAME(i) + length, "/"))
883 update_input(prompt, ok ? GREEN : RED);
893 message("File already exists.", RED);
895 } else if (!strcmp(key, RVK_NEW_DIR)) {
897 char *prompt = "new directory: ";
899 update_input(prompt, DEFAULT);
900 while (igetstr(INPUT, INPUTSZ)) {
901 int length = strlen(INPUT);
903 for (i = 0; i < rover.nfiles; i++) {
905 !strncmp(ENAME(i), INPUT, length) &&
906 (!strcmp(ENAME(i) + length, "") ||
907 !strcmp(ENAME(i) + length, "/"))
913 update_input(prompt, ok ? GREEN : RED);
923 message("File already exists.", RED);
925 } else if (!strcmp(key, RVK_RENAME)) {
927 char *prompt = "rename: ";
930 strcpy(INPUT, ENAME(ESEL));
931 last = INPUT + strlen(INPUT) - 1;
932 if ((isdir = *last == '/'))
934 update_input(prompt, RED);
935 while (igetstr(INPUT, INPUTSZ)) {
936 int length = strlen(INPUT);
938 for (i = 0; i < rover.nfiles; i++)
940 !strncmp(ENAME(i), INPUT, length) &&
941 (!strcmp(ENAME(i) + length, "") ||
942 !strcmp(ENAME(i) + length, "/"))
947 update_input(prompt, ok ? GREEN : RED);
954 if (!rename(ENAME(ESEL), INPUT) && MARKED(ESEL)) {
955 del_mark(&rover.marks, ENAME(ESEL));
956 add_mark(&rover.marks, CWD, INPUT);
962 message("File already exists.", RED);
964 } else if (!strcmp(key, RVK_TG_MARK)) {
966 del_mark(&rover.marks, ENAME(ESEL));
968 add_mark(&rover.marks, CWD, ENAME(ESEL));
969 MARKED(ESEL) = !MARKED(ESEL);
970 ESEL = (ESEL + 1) % rover.nfiles;
972 } else if (!strcmp(key, RVK_INVMARK)) {
973 for (i = 0; i < rover.nfiles; i++) {
975 del_mark(&rover.marks, ENAME(i));
977 add_mark(&rover.marks, CWD, ENAME(i));
978 MARKED(i) = !MARKED(i);
981 } else if (!strcmp(key, RVK_MARKALL)) {
982 for (i = 0; i < rover.nfiles; i++)
984 add_mark(&rover.marks, CWD, ENAME(i));
988 } else if (!strcmp(key, RVK_DELETE)) {
989 if (rover.marks.nentries) {
990 message("Delete marked entries? (Y to confirm)", YELLOW);
992 process_marked(NULL, delfile, deldir);
996 message("No entries marked for deletion.", RED);
997 } else if (!strcmp(key, RVK_COPY)) {
998 if (rover.marks.nentries)
999 process_marked(adddir, cpyfile, NULL);
1001 message("No entries marked for copying.", RED);
1002 } else if (!strcmp(key, RVK_MOVE)) {
1003 if (rover.marks.nentries)
1004 process_marked(adddir, movfile, deldir);
1006 message("No entries marked for moving.", RED);
1010 free_rows(&rover.rows, rover.nfiles);
1011 free_marks(&rover.marks);
1012 delwin(rover.window);