5 #include <sys/types.h> /* pid_t, ... */
6 #include <stdio.h> /* FILENAME_MAX */
7 #include <locale.h> /* setlocale(), LC_ALL */
8 #include <unistd.h> /* chdir(), getcwd(), read(), close(), ... */
9 #include <dirent.h> /* DIR, struct dirent, opendir(), ... */
11 #include <fcntl.h> /* open() */
12 #include <sys/wait.h> /* waitpid() */
13 #include <signal.h> /* struct sigaction, sigaction() */
20 static char ROW[ROWSZ];
22 static char STATUS[STATUSSZ];
24 static char INPUT[INPUTSZ];
26 /* Argument buffers for execvp(). */
28 static char *ARGS[MAXARGS];
30 /* Listing view parameters. */
31 #define HEIGHT (LINES-4)
32 #define STATUSPOS (COLS-16)
34 /* Listing view flags. */
35 #define SHOW_FILES 0x01u
36 #define SHOW_DIRS 0x02u
37 #define SHOW_HIDDEN 0x04u
39 /* Marks parameters. */
41 #define BULK_THRESH 256
43 /* Information associated to each entry in listing. */
50 /* Dynamic array of marked entries. */
52 char dirpath[FILENAME_MAX];
58 /* Global state. Some basic info is allocated for ten tabs. */
59 static struct rover_t {
67 char cwd[10][FILENAME_MAX];
71 /* Macros for accessing global state. */
72 #define ENAME(I) rover.rows[I].name
73 #define ESIZE(I) rover.rows[I].size
74 #define MARKED(I) rover.rows[I].marked
75 #define SCROLL rover.scroll[rover.tab]
76 #define ESEL rover.esel[rover.tab]
77 #define FLAGS rover.flags[rover.tab]
78 #define CWD rover.cwd[rover.tab]
81 #define MIN(A, B) ((A) < (B) ? (A) : (B))
82 #define MAX(A, B) ((A) > (B) ? (A) : (B))
83 #define ISDIR(E) (strchr((E), '/') != NULL)
85 typedef enum {DEFAULT, RED, GREEN, YELLOW, BLUE, CYAN, MAGENTA, WHITE} color_t;
86 typedef int (*PROCESS)(const char *path);
89 init_marks(marks_t *marks)
91 strcpy(marks->dirpath, "");
92 marks->bulk = BULK_INIT;
94 marks->entries = (char **) calloc(marks->bulk, sizeof(char *));
97 /* Unmark all entries. */
99 mark_none(marks_t *marks)
103 strcpy(marks->dirpath, "");
104 for (i = 0; i < marks->bulk && marks->nentries; i++)
105 if (marks->entries[i]) {
106 free(marks->entries[i]);
107 marks->entries[i] = NULL;
110 if (marks->bulk > BULK_THRESH) {
111 /* Reset bulk to free some memory. */
112 free(marks->entries);
113 marks->bulk = BULK_INIT;
114 marks->entries = (char **) calloc(marks->bulk, sizeof(char *));
119 add_mark(marks_t *marks, char *dirpath, char *entry)
123 if (!strcmp(marks->dirpath, dirpath)) {
124 /* Append mark to directory. */
125 if (marks->nentries == marks->bulk) {
126 /* Expand bulk to accomodate new entry. */
127 int extra = marks->bulk >> 1;
128 marks->bulk += extra; /* bulk *= 1.5; */
129 marks->entries = (char **) realloc(
130 marks->entries, marks->bulk * sizeof(char *)
132 memset(&marks->entries[marks->nentries], 0, extra * sizeof(char *));
135 /* Search for empty slot (there must be one). */
136 for (i = 0; i < marks->bulk; i++)
137 if (!marks->entries[i])
141 /* Directory changed. Discard old marks. */
143 strcpy(marks->dirpath, dirpath);
146 marks->entries[i] = (char *) malloc(strlen(entry) + 1);
147 strcpy(marks->entries[i], entry);
152 del_mark(marks_t *marks, char *entry)
156 if (marks->nentries > 1) {
157 for (i = 0; i < marks->bulk; i++)
158 if (marks->entries[i] && !strcmp(marks->entries[i], entry))
160 free(marks->entries[i]);
161 marks->entries[i] = NULL;
168 free_marks(marks_t *marks)
172 for (i = 0; i < marks->bulk && marks->nentries; i++)
173 if (marks->entries[i]) {
174 free(marks->entries[i]);
177 free(marks->entries);
180 static void message(const char *msg, color_t color);
181 static void clear_message();
183 static void handle_segv(int sig);
184 static void handle_winch(int sig);
192 setlocale(LC_ALL, "");
194 cbreak(); /* Get one character at a time. */
196 nonl(); /* No NL->CR/NL on output. */
197 intrflush(stdscr, FALSE);
198 keypad(stdscr, TRUE);
199 curs_set(FALSE); /* Hide blinking cursor. */
200 memset(&sa, 0, sizeof(struct sigaction));
201 /* Setup SIGSEGV handler. */
202 sa.sa_handler = handle_segv;
203 sigaction(SIGSEGV, &sa, NULL);
204 /* Setup SIGWINCH handler. */
205 sa.sa_handler = handle_winch;
206 sigaction(SIGWINCH, &sa, NULL);
209 init_pair(RED, COLOR_RED, COLOR_BLACK);
210 init_pair(GREEN, COLOR_GREEN, COLOR_BLACK);
211 init_pair(YELLOW, COLOR_YELLOW,COLOR_BLACK);
212 init_pair(BLUE, COLOR_BLUE, COLOR_BLACK);
213 init_pair(CYAN, COLOR_CYAN, COLOR_BLACK);
214 init_pair(MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
215 init_pair(WHITE, COLOR_WHITE, COLOR_BLACK);
217 atexit((void (*)(void)) endwin);
220 /* Update the listing view. */
228 mvhline(0, 0, ' ', COLS);
229 color_set(RVC_CWD, NULL);
230 mvaddnstr(0, 0, CWD, COLS);
231 color_set(DEFAULT, NULL);
232 attr_on(A_BOLD, NULL);
233 color_set(RVC_TABNUM, NULL);
234 mvaddch(0, COLS-4, rover.tab + '0');
235 color_set(DEFAULT, NULL);
236 attr_off(A_BOLD, NULL);
237 wclear(rover.window);
238 wcolor_set(rover.window, RVC_BORDER, NULL);
239 wborder(rover.window, 0, 0, 0, 0, 0, 0, 0, 0);
240 wcolor_set(rover.window, DEFAULT, NULL);
241 /* Selection might not be visible, due to cursor wrapping or window
242 shrinking. In that case, the scroll must be moved to make it visible. */
243 SCROLL = MAX(MIN(SCROLL, ESEL), ESEL - HEIGHT + 1);
244 marking = !strcmp(CWD, rover.marks.dirpath);
245 for (i = 0, j = SCROLL; i < HEIGHT && j < rover.nfiles; i++, j++) {
246 ishidden = ENAME(j)[0] == '.';
247 isdir = ISDIR(ENAME(j));
249 wattr_on(rover.window, A_REVERSE, NULL);
251 wcolor_set(rover.window, RVC_HIDDEN, NULL);
253 wcolor_set(rover.window, RVC_DIR, NULL);
255 wcolor_set(rover.window, RVC_FILE, NULL);
257 sprintf(ROW, "%s%*d", ENAME(j),
258 COLS - strlen(ENAME(j)) - 4, (int) ESIZE(j));
260 strcpy(ROW, ENAME(j));
261 mvwhline(rover.window, i + 1, 1, ' ', COLS - 2);
262 if (marking && MARKED(j))
263 mvwaddch(rover.window, i + 1, 1, RVS_MARK);
265 mvwaddch(rover.window, i + 1, 1, ' ');
266 mvwaddnstr(rover.window, i + 1, 2, ROW, COLS - 4);
267 wcolor_set(rover.window, DEFAULT, NULL);
269 wattr_off(rover.window, A_REVERSE, NULL);
271 if (rover.nfiles > HEIGHT) {
273 center = (SCROLL + (HEIGHT >> 1)) * HEIGHT / rover.nfiles;
274 height = (HEIGHT-1) * HEIGHT / rover.nfiles;
275 if (!height) height = 1;
276 wcolor_set(rover.window, RVC_BORDER, NULL);
277 wborder(rover.window, 0, 0, 0, 0, 0, 0, 0, 0);
278 wcolor_set(rover.window, RVC_SCROLLBAR, NULL);
279 mvwvline(rover.window, center-(height>>1)+1, COLS-1, RVS_SCROLLBAR, height);
280 wcolor_set(rover.window, DEFAULT, NULL);
282 wrefresh(rover.window);
283 if (rover.marks.nentries) {
284 sprintf(STATUS, "%7d)", rover.marks.nentries);
285 *strrchr(STATUS, ' ') = '(';
286 color_set(RVC_NMARKS, NULL);
287 mvaddstr(0, COLS-15, STATUS);
288 color_set(DEFAULT, NULL);
290 STATUS[0] = FLAGS & SHOW_FILES ? 'F' : ' ';
291 STATUS[1] = FLAGS & SHOW_DIRS ? 'D' : ' ';
292 STATUS[2] = FLAGS & SHOW_HIDDEN ? 'H' : ' ';
296 sprintf(ROW, "%d/%d", ESEL + 1, rover.nfiles);
297 sprintf(STATUS+3, "%12s", ROW);
298 color_set(RVC_STATUS, NULL);
299 mvaddstr(LINES - 1, STATUSPOS, STATUS);
300 color_set(DEFAULT, NULL);
304 /* SIGSEGV handler: clean up curses before exiting. */
310 puts("Received SIGSEGV (segmentation fault).");
314 /* SIGWINCH handler: resize application according to new terminal settings. */
316 handle_winch(int sig)
319 delwin(rover.window);
323 rover.window = subwin(stdscr, LINES - 2, COLS, 1, 0);
327 /* Comparison used to sort listing entries. */
329 rowcmp(const void *a, const void *b)
331 int isdir1, isdir2, cmpdir;
334 isdir1 = ISDIR(r1->name);
335 isdir2 = ISDIR(r2->name);
336 cmpdir = isdir2 - isdir1;
337 return cmpdir ? cmpdir : strcoll(r1->name, r2->name);
340 /* Get all entries for a given path (usually cwd). */
342 ls(char *path, row_t **rowsp, uint8_t flags)
350 if(!(dp = opendir(path))) return -1;
351 n = -2; /* We don't want the entries "." and "..". */
352 while (readdir(dp)) n++;
354 rows = (row_t *) malloc(n * sizeof(row_t));
356 while ((ep = readdir(dp))) {
357 if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
359 if (!(flags & SHOW_HIDDEN) && ep->d_name[0] == '.')
361 /* FIXME: ANSI C doesn't have lstat(). How do we handle symlinks? */
362 stat(ep->d_name, &statbuf);
363 if (S_ISDIR(statbuf.st_mode)) {
364 if (flags & SHOW_DIRS) {
365 rows[i].name = (char *) malloc(strlen(ep->d_name) + 2);
366 strcpy(rows[i].name, ep->d_name);
367 strcat(rows[i].name, "/");
370 } else if (flags & SHOW_FILES) {
371 rows[i].name = (char *) malloc(strlen(ep->d_name) + 1);
372 strcpy(rows[i].name, ep->d_name);
373 rows[i].size = statbuf.st_size;
377 n = i; /* Ignore unused space in array caused by filters. */
378 qsort(rows, n, sizeof(row_t), rowcmp);
385 free_rows(row_t **rowsp, int nfiles)
389 for (i = 0; i < nfiles; i++)
390 free((*rowsp)[i].name);
395 /* Change working directory. */
396 /* NOTE: The caller needs to write the new path to CWD
397 * *before* calling this function. */
403 message("Loading...", CYAN);
405 if (reset) ESEL = SCROLL = 0;
408 free_rows(&rover.rows, rover.nfiles);
409 rover.nfiles = ls(CWD, &rover.rows, FLAGS);
410 if (!strcmp(CWD, rover.marks.dirpath)) {
411 for (i = 0; i < rover.nfiles; i++) {
412 for (j = 0; j < rover.marks.bulk; j++)
414 rover.marks.entries[j] &&
415 !strcmp(rover.marks.entries[j], ENAME(i))
418 MARKED(i) = j < rover.marks.bulk;
421 for (i = 0; i < rover.nfiles; i++)
427 /* Select a target entry, if it is present. */
429 try_to_sel(const char *target)
432 while ((ESEL+1) < rover.nfiles && strcoll(ENAME(ESEL), target) < 0)
434 if (rover.nfiles > HEIGHT) {
435 SCROLL = ESEL - (HEIGHT >> 1);
436 SCROLL = MIN(MAX(SCROLL, 0), rover.nfiles - HEIGHT);
440 /* Reload CWD, but try to keep selection. */
445 strcpy(INPUT, ENAME(ESEL));
453 /* Recursively process a source directory using CWD as destination root.
454 * For each node (i.e. directory), do the following:
455 * 1. call pre(destination);
456 * 2. call proc() on every child leaf (i.e. files);
457 * 3. recurse into every child node;
458 * 4. call pos(source).
459 * E.g. to move directory /src/ (and all its contents) inside /dst/:
460 * strcpy(CWD, "/dst/");
461 * process_dir(adddir, movfile, deldir, "/src/");
464 process_dir(PROCESS pre, PROCESS proc, PROCESS pos, const char *path)
470 char subpath[FILENAME_MAX];
474 char dstpath[FILENAME_MAX];
475 strcpy(dstpath, CWD);
476 strcat(dstpath, path + strlen(rover.marks.dirpath));
479 if(!(dp = opendir(path))) return -1;
480 while ((ep = readdir(dp))) {
481 if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
483 sprintf(subpath, "%s%s", path, ep->d_name);
484 stat(subpath, &statbuf);
485 if (S_ISDIR(statbuf.st_mode)) {
486 strcat(subpath, "/");
487 ret |= process_dir(pre, proc, pos, subpath);
489 ret |= proc(subpath);
492 if (pos) ret |= pos(path);
496 /* Process all marked entries using CWD as destination root.
497 * All marked entries that are directories will be recursively processed.
498 * See process_dir() for details on the parameters.
501 process_marked(PROCESS pre, PROCESS proc, PROCESS pos)
504 char path[FILENAME_MAX];
507 message("Processing...", CYAN);
509 for (i = 0; i < rover.marks.bulk; i++)
510 if (rover.marks.entries[i]) {
512 sprintf(path, "%s%s", rover.marks.dirpath, rover.marks.entries[i]);
513 if (ISDIR(rover.marks.entries[i])) {
514 if (!strncmp(path, CWD, strlen(path)))
517 ret = process_dir(pre, proc, pos, path);
520 if (!ret) del_mark(&rover.marks, rover.marks.entries[i]);
523 if (!rover.marks.nentries)
524 message("Done.", GREEN);
526 message("Some errors occured.", RED);
529 /* Wrappers for file operations. */
530 static PROCESS delfile = unlink;
531 static PROCESS deldir = rmdir;
532 static int addfile(const char *path) {
533 /* Using creat(2) because mknod(2) doesn't seem to be portable. */
536 ret = creat(path, 0644);
537 if (ret < 0) return ret;
540 static int cpyfile(const char *srcpath) {
545 char dstpath[FILENAME_MAX];
547 ret = src = open(srcpath, O_RDONLY);
548 if (ret < 0) return ret;
549 ret = fstat(src, &st);
550 if (ret < 0) return ret;
551 strcpy(dstpath, CWD);
552 strcat(dstpath, srcpath + strlen(rover.marks.dirpath));
553 ret = dst = creat(dstpath, st.st_mode);
554 if (ret < 0) return ret;
555 while ((size = read(src, buf, BUFSIZ)) > 0)
556 write(dst, buf, size);
561 static int adddir(const char *path) {
565 ret = stat(CWD, &st);
566 if (ret < 0) return ret;
567 return mkdir(path, st.st_mode);
569 static int movfile(const char *srcpath) {
570 char dstpath[FILENAME_MAX];
572 strcpy(dstpath, CWD);
573 strcat(dstpath, srcpath + strlen(rover.marks.dirpath));
574 return rename(srcpath, dstpath);
577 /* Do a fork-exec to external program (e.g. $EDITOR). */
586 /* fork() succeeded. */
588 waitpid(pid, &status, 0);
591 } else if (pid == 0) {
593 execvp(ARGS[0], ARGS);
597 /* Interactive getstr(). */
599 igetstr(char *buffer, int maxlen)
603 length = strlen(buffer);
606 if (ch == '\r' || ch == '\n' || ch == KEY_DOWN || ch == KEY_ENTER) {
609 } else if (ch == erasechar() || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
611 buffer[--length] = '\0';
612 } else if (ch == killchar()) {
615 } else if (length < maxlen - 1 && isprint(ch)) {
616 buffer[length++] = ch;
617 buffer[length] = '\0';
622 /* Update line input on the screen. */
624 update_input(char *prompt, color_t color)
628 plen = strlen(prompt);
629 ilen = strlen(INPUT);
630 color_set(RVC_PROMPT, NULL);
631 mvaddstr(LINES - 1, 0, prompt);
632 color_set(color, NULL);
633 mvaddstr(LINES - 1, plen, INPUT);
634 mvaddch(LINES - 1, ilen + plen, ' ');
635 move(LINES - 1, ilen + plen);
636 color_set(DEFAULT, NULL);
639 /* Show a message on the status bar. */
641 message(const char *msg, color_t color)
646 pos = (STATUSPOS - len) >> 1;
647 attr_on(A_BOLD, NULL);
648 color_set(color, NULL);
649 mvaddstr(LINES - 1, pos, msg);
650 color_set(DEFAULT, NULL);
651 attr_off(A_BOLD, NULL);
654 /* Clear message area, leaving only status info. */
658 mvhline(LINES - 1, 0, ' ', STATUSPOS);
662 main(int argc, char *argv[])
669 if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
670 printf("rover %s\n", RV_VERSION);
672 } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
674 "Usage: rover [DIRECTORY [DIRECTORY [DIRECTORY [...]]]]\n"
675 " or: rover [OPTION]\n"
676 "Browse current working directory or the ones specified.\n\n"
678 " -h, --help print this help message and exit\n"
679 " -v, --version print program version and exit\n\n"
680 "See rover(1) for more information.\n\n"
681 "Rover homepage: <https://github.com/lecram/rover>.\n"
688 for (i = 0; i < 10; i++) {
689 rover.esel[i] = rover.scroll[i] = 0;
690 rover.flags[i] = SHOW_FILES | SHOW_DIRS;
692 strcpy(rover.cwd[0], getenv("HOME"));
693 for (i = 1; i < argc && i < 10; i++) {
694 if ((d = opendir(argv[i]))) {
695 strcpy(rover.cwd[i], argv[i]);
698 strcpy(rover.cwd[i], rover.cwd[0]);
700 getcwd(rover.cwd[i], FILENAME_MAX);
701 for (i++; i < 10; i++)
702 strcpy(rover.cwd[i], rover.cwd[i-1]);
703 for (i = 0; i < 10; i++)
704 if (rover.cwd[i][strlen(rover.cwd[i]) - 1] != '/')
705 strcat(rover.cwd[i], "/");
707 rover.window = subwin(stdscr, LINES - 2, COLS, 1, 0);
708 init_marks(&rover.marks);
714 if (!strcmp(key, RVK_QUIT)) break;
715 else if (ch >= '0' && ch <= '9') {
716 rover.tab = ch - '0';
718 } else if (!strcmp(key, RVK_HELP)) {
723 } else if (!strcmp(key, RVK_DOWN)) {
724 if (!rover.nfiles) continue;
725 ESEL = (ESEL + 1) % rover.nfiles;
727 } else if (!strcmp(key, RVK_UP)) {
728 if (!rover.nfiles) continue;
729 ESEL = ESEL ? ESEL - 1 : rover.nfiles - 1;
731 } else if (!strcmp(key, RVK_JUMP_DOWN)) {
732 if (!rover.nfiles) continue;
733 ESEL = MIN(ESEL + RV_JUMP, rover.nfiles - 1);
734 if (rover.nfiles > HEIGHT)
735 SCROLL = MIN(SCROLL + RV_JUMP, rover.nfiles - HEIGHT);
737 } else if (!strcmp(key, RVK_JUMP_UP)) {
738 if (!rover.nfiles) continue;
739 ESEL = MAX(ESEL - RV_JUMP, 0);
740 SCROLL = MAX(SCROLL - RV_JUMP, 0);
742 } else if (!strcmp(key, RVK_CD_DOWN)) {
743 if (!rover.nfiles || !ISDIR(ENAME(ESEL))) continue;
744 strcat(CWD, ENAME(ESEL));
746 } else if (!strcmp(key, RVK_CD_UP)) {
747 char *dirname, first;
748 if (!strcmp(CWD, "/")) continue;
749 CWD[strlen(CWD) - 1] = '\0';
750 dirname = strrchr(CWD, '/') + 1;
755 dirname[strlen(dirname)] = '/';
759 } else if (!strcmp(key, RVK_HOME)) {
760 strcpy(CWD, getenv("HOME"));
761 if (CWD[strlen(CWD) - 1] != '/')
764 } else if (!strcmp(key, RVK_SHELL)) {
765 program = getenv("SHELL");
772 } else if (!strcmp(key, RVK_VIEW)) {
773 if (!rover.nfiles || ISDIR(ENAME(ESEL))) continue;
774 program = getenv("PAGER");
777 ARGS[1] = ENAME(ESEL);
781 } else if (!strcmp(key, RVK_EDIT)) {
782 if (!rover.nfiles || ISDIR(ENAME(ESEL))) continue;
783 program = getenv("EDITOR");
786 ARGS[1] = ENAME(ESEL);
791 } else if (!strcmp(key, RVK_SEARCH)) {
792 int oldsel, oldscroll, length;
793 char *prompt = "search: ";
794 if (!rover.nfiles) continue;
798 update_input(prompt, DEFAULT);
799 while (igetstr(INPUT, INPUTSZ)) {
802 length = strlen(INPUT);
804 for (sel = 0; sel < rover.nfiles; sel++)
805 if (!strncmp(ENAME(sel), INPUT, length))
807 if (sel < rover.nfiles) {
810 if (rover.nfiles > HEIGHT) {
813 else if (sel - 3 > rover.nfiles - HEIGHT)
814 SCROLL = rover.nfiles - HEIGHT;
824 update_input(prompt, color);
828 } else if (!strcmp(key, RVK_TG_FILES)) {
831 } else if (!strcmp(key, RVK_TG_DIRS)) {
834 } else if (!strcmp(key, RVK_TG_HIDDEN)) {
835 FLAGS ^= SHOW_HIDDEN;
837 } else if (!strcmp(key, RVK_NEW_FILE)) {
839 char *prompt = "new file: ";
841 update_input(prompt, DEFAULT);
842 while (igetstr(INPUT, INPUTSZ)) {
843 int length = strlen(INPUT);
845 for (i = 0; i < rover.nfiles; i++) {
847 !strncmp(ENAME(i), INPUT, length) &&
848 (!strcmp(ENAME(i) + length, "") ||
849 !strcmp(ENAME(i) + length, "/"))
855 update_input(prompt, ok ? GREEN : RED);
865 message("File already exists.", RED);
867 } else if (!strcmp(key, RVK_NEW_DIR)) {
869 char *prompt = "new directory: ";
871 update_input(prompt, DEFAULT);
872 while (igetstr(INPUT, INPUTSZ)) {
873 int length = strlen(INPUT);
875 for (i = 0; i < rover.nfiles; i++) {
877 !strncmp(ENAME(i), INPUT, length) &&
878 (!strcmp(ENAME(i) + length, "") ||
879 !strcmp(ENAME(i) + length, "/"))
885 update_input(prompt, ok ? GREEN : RED);
895 message("File already exists.", RED);
897 } else if (!strcmp(key, RVK_RENAME)) {
899 char *prompt = "rename: ";
900 strcpy(INPUT, ENAME(ESEL));
901 update_input(prompt, RED);
902 while (igetstr(INPUT, INPUTSZ)) {
903 int length = strlen(INPUT);
905 for (i = 0; i < rover.nfiles; i++) {
907 !strncmp(ENAME(i), INPUT, length) &&
908 (!strcmp(ENAME(i) + length, "") ||
909 !strcmp(ENAME(i) + length, "/"))
915 update_input(prompt, ok ? GREEN : RED);
920 rename(ENAME(ESEL), INPUT);
925 message("File already exists.", RED);
927 } else if (!strcmp(key, RVK_TG_MARK)) {
929 del_mark(&rover.marks, ENAME(ESEL));
931 add_mark(&rover.marks, CWD, ENAME(ESEL));
932 MARKED(ESEL) = !MARKED(ESEL);
933 ESEL = (ESEL + 1) % rover.nfiles;
935 } else if (!strcmp(key, RVK_INVMARK)) {
936 for (i = 0; i < rover.nfiles; i++) {
938 del_mark(&rover.marks, ENAME(i));
940 add_mark(&rover.marks, CWD, ENAME(i));
941 MARKED(i) = !MARKED(i);
944 } else if (!strcmp(key, RVK_MARKALL)) {
945 for (i = 0; i < rover.nfiles; i++)
947 add_mark(&rover.marks, CWD, ENAME(i));
951 } else if (!strcmp(key, RVK_DELETE)) {
952 if (rover.marks.nentries) {
953 message("Delete marked entries? (Y to confirm)", YELLOW);
955 process_marked(NULL, delfile, deldir);
959 message("No entries marked for deletion.", RED);
960 } else if (!strcmp(key, RVK_COPY)) {
961 if (rover.marks.nentries)
962 process_marked(adddir, cpyfile, NULL);
964 message("No entries marked for copying.", RED);
965 } else if (!strcmp(key, RVK_MOVE)) {
966 if (rover.marks.nentries)
967 process_marked(adddir, movfile, deldir);
969 message("No entries marked for moving.", RED);
973 free_rows(&rover.rows, rover.nfiles);
974 free_marks(&rover.marks);
975 delwin(rover.window);