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 message(const char *msg, Color color);
183 static void clear_message();
185 static void handle_segv(int sig);
186 static void handle_winch(int sig);
194 setlocale(LC_ALL, "");
196 cbreak(); /* Get one character at a time. */
198 nonl(); /* No NL->CR/NL on output. */
199 intrflush(stdscr, FALSE);
200 keypad(stdscr, TRUE);
201 curs_set(FALSE); /* Hide blinking cursor. */
205 #ifdef NCURSES_EXT_FUNCS
206 use_default_colors();
211 init_pair(RED, COLOR_RED, bg);
212 init_pair(GREEN, COLOR_GREEN, bg);
213 init_pair(YELLOW, COLOR_YELLOW, bg);
214 init_pair(BLUE, COLOR_BLUE, bg);
215 init_pair(CYAN, COLOR_CYAN, bg);
216 init_pair(MAGENTA, COLOR_MAGENTA, bg);
217 init_pair(WHITE, COLOR_WHITE, bg);
219 atexit((void (*)(void)) endwin);
220 memset(&sa, 0, sizeof (struct sigaction));
221 /* Setup SIGSEGV handler. */
222 sa.sa_handler = handle_segv;
223 sigaction(SIGSEGV, &sa, NULL);
224 /* Setup SIGWINCH handler. */
225 sa.sa_handler = handle_winch;
226 sigaction(SIGWINCH, &sa, NULL);
229 /* Update the listing view. */
238 mvhline(0, 0, ' ', COLS);
239 attr_on(A_BOLD, NULL);
240 color_set(RVC_TABNUM, NULL);
241 mvaddch(0, COLS - 2, rover.tab + '0');
242 color_set(DEFAULT, NULL);
243 attr_off(A_BOLD, NULL);
244 if (rover.marks.nentries) {
245 numsize = snprintf(STATUS, STATUSSZ, "%d", rover.marks.nentries);
246 color_set(RVC_NMARKS, NULL);
247 mvaddstr(0, COLS - 3 - numsize, STATUS);
248 color_set(DEFAULT, NULL);
251 color_set(RVC_CWD, NULL);
252 mvaddnstr(0, 0, CWD, COLS - 4 - numsize);
253 color_set(DEFAULT, NULL);
254 wcolor_set(rover.window, RVC_BORDER, NULL);
255 wborder(rover.window, 0, 0, 0, 0, 0, 0, 0, 0);
256 wcolor_set(rover.window, DEFAULT, NULL);
257 /* Selection might not be visible, due to cursor wrapping or window
258 shrinking. In that case, the scroll must be moved to make it visible. */
259 SCROLL = MAX(MIN(SCROLL, ESEL), ESEL - HEIGHT + 1);
260 marking = !strcmp(CWD, rover.marks.dirpath);
261 for (i = 0, j = SCROLL; i < HEIGHT && j < rover.nfiles; i++, j++) {
262 ishidden = ENAME(j)[0] == '.';
263 isdir = ISDIR(ENAME(j));
265 wattr_on(rover.window, A_REVERSE, NULL);
267 wcolor_set(rover.window, RVC_HIDDEN, NULL);
269 wcolor_set(rover.window, RVC_DIR, NULL);
271 wcolor_set(rover.window, RVC_FILE, NULL);
273 snprintf(ROW, ROWSZ, "%s%*d", ENAME(j),
274 (int) (COLS - strlen(ENAME(j)) - 4), (int) ESIZE(j));
276 strcpy(ROW, ENAME(j));
277 mvwhline(rover.window, i + 1, 1, ' ', COLS - 2);
278 if (marking && MARKED(j))
279 mvwaddch(rover.window, i + 1, 1, RVS_MARK);
281 mvwaddch(rover.window, i + 1, 1, ' ');
282 mvwaddnstr(rover.window, i + 1, 2, ROW, COLS - 4);
283 wcolor_set(rover.window, DEFAULT, NULL);
285 wattr_off(rover.window, A_REVERSE, NULL);
287 for (;i < HEIGHT; i++)
288 mvwhline(rover.window, i + 1, 1, ' ', COLS - 2);
289 if (rover.nfiles > HEIGHT) {
291 center = (SCROLL + (HEIGHT >> 1)) * HEIGHT / rover.nfiles;
292 height = (HEIGHT-1) * HEIGHT / rover.nfiles;
293 if (!height) height = 1;
294 wcolor_set(rover.window, RVC_BORDER, NULL);
295 wborder(rover.window, 0, 0, 0, 0, 0, 0, 0, 0);
296 wcolor_set(rover.window, RVC_SCROLLBAR, NULL);
297 mvwvline(rover.window, center-(height>>1)+1, COLS-1, RVS_SCROLLBAR, height);
298 wcolor_set(rover.window, DEFAULT, NULL);
300 STATUS[0] = FLAGS & SHOW_FILES ? 'F' : ' ';
301 STATUS[1] = FLAGS & SHOW_DIRS ? 'D' : ' ';
302 STATUS[2] = FLAGS & SHOW_HIDDEN ? 'H' : ' ';
306 snprintf(ROW, ROWSZ, "%d/%d", ESEL + 1, rover.nfiles);
307 snprintf(STATUS+3, STATUSSZ-3, "%12s", ROW);
308 color_set(RVC_STATUS, NULL);
309 mvaddstr(LINES - 1, STATUSPOS, STATUS);
310 color_set(DEFAULT, NULL);
311 wrefresh(rover.window);
314 /* SIGSEGV handler: clean up curses before exiting. */
320 fprintf(stderr, "Received SIGSEGV (segmentation fault).\n");
324 /* SIGWINCH handler: resize application according to new terminal settings. */
326 handle_winch(int sig)
329 delwin(rover.window);
333 rover.window = subwin(stdscr, LINES - 2, COLS, 1, 0);
337 /* Comparison used to sort listing entries. */
339 rowcmp(const void *a, const void *b)
341 int isdir1, isdir2, cmpdir;
344 isdir1 = ISDIR(r1->name);
345 isdir2 = ISDIR(r2->name);
346 cmpdir = isdir2 - isdir1;
347 return cmpdir ? cmpdir : strcoll(r1->name, r2->name);
350 /* Get all entries in current working directory. */
352 ls(Row **rowsp, uint8_t flags)
360 if(!(dp = opendir("."))) return -1;
361 n = -2; /* We don't want the entries "." and "..". */
362 while (readdir(dp)) n++;
364 rows = malloc(n * sizeof *rows);
366 while ((ep = readdir(dp))) {
367 if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
369 if (!(flags & SHOW_HIDDEN) && ep->d_name[0] == '.')
371 lstat(ep->d_name, &statbuf);
372 if (S_ISDIR(statbuf.st_mode)) {
373 if (flags & SHOW_DIRS) {
374 rows[i].name = malloc(strlen(ep->d_name) + 2);
375 strcpy(rows[i].name, ep->d_name);
376 strcat(rows[i].name, "/");
379 } else if (flags & SHOW_FILES) {
380 rows[i].name = malloc(strlen(ep->d_name) + 1);
381 strcpy(rows[i].name, ep->d_name);
382 rows[i].size = statbuf.st_size;
386 n = i; /* Ignore unused space in array caused by filters. */
387 qsort(rows, n, sizeof (*rows), rowcmp);
394 free_rows(Row **rowsp, int nfiles)
398 for (i = 0; i < nfiles; i++)
399 free((*rowsp)[i].name);
404 /* Change working directory to the path in CWD. */
410 message("Loading...", CYAN);
412 if (reset) ESEL = SCROLL = 0;
415 free_rows(&rover.rows, rover.nfiles);
416 rover.nfiles = ls(&rover.rows, FLAGS);
417 if (!strcmp(CWD, rover.marks.dirpath)) {
418 for (i = 0; i < rover.nfiles; i++) {
419 for (j = 0; j < rover.marks.bulk; j++)
421 rover.marks.entries[j] &&
422 !strcmp(rover.marks.entries[j], ENAME(i))
425 MARKED(i) = j < rover.marks.bulk;
428 for (i = 0; i < rover.nfiles; i++)
434 /* Select a target entry, if it is present. */
436 try_to_sel(const char *target)
440 while ((ESEL+1) < rover.nfiles && ISDIR(ENAME(ESEL)))
442 while ((ESEL+1) < rover.nfiles && strcoll(ENAME(ESEL), target) < 0)
444 if (rover.nfiles > HEIGHT) {
445 SCROLL = ESEL - (HEIGHT >> 1);
446 SCROLL = MIN(MAX(SCROLL, 0), rover.nfiles - HEIGHT);
450 /* Reload CWD, but try to keep selection. */
455 strcpy(INPUT, ENAME(ESEL));
463 /* Recursively process a source directory using CWD as destination root.
464 For each node (i.e. directory), do the following:
465 1. call pre(destination);
466 2. call proc() on every child leaf (i.e. files);
467 3. recurse into every child node;
469 E.g. to move directory /src/ (and all its contents) inside /dst/:
470 strcpy(CWD, "/dst/");
471 process_dir(adddir, movfile, deldir, "/src/"); */
473 process_dir(PROCESS pre, PROCESS proc, PROCESS pos, const char *path)
479 char subpath[PATH_MAX];
483 char dstpath[PATH_MAX];
484 strcpy(dstpath, CWD);
485 strcat(dstpath, path + strlen(rover.marks.dirpath));
488 if(!(dp = opendir(path))) return -1;
489 while ((ep = readdir(dp))) {
490 if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
492 snprintf(subpath, PATH_MAX, "%s%s", path, ep->d_name);
493 stat(subpath, &statbuf);
494 if (S_ISDIR(statbuf.st_mode)) {
495 strcat(subpath, "/");
496 ret |= process_dir(pre, proc, pos, subpath);
498 ret |= proc(subpath);
501 if (pos) ret |= pos(path);
505 /* Process all marked entries using CWD as destination root.
506 All marked entries that are directories will be recursively processed.
507 See process_dir() for details on the parameters. */
509 process_marked(PROCESS pre, PROCESS proc, PROCESS pos)
515 message("Processing...", CYAN);
517 for (i = 0; i < rover.marks.bulk; i++)
518 if (rover.marks.entries[i]) {
520 snprintf(path, PATH_MAX, "%s%s", rover.marks.dirpath, rover.marks.entries[i]);
521 if (ISDIR(rover.marks.entries[i])) {
522 if (!strncmp(path, CWD, strlen(path)))
525 ret = process_dir(pre, proc, pos, path);
528 if (!ret) del_mark(&rover.marks, rover.marks.entries[i]);
531 if (!rover.marks.nentries)
532 message("Done.", GREEN);
534 message("Some errors occured.", RED);
537 /* Wrappers for file operations. */
538 static PROCESS delfile = unlink;
539 static PROCESS deldir = rmdir;
540 static int addfile(const char *path) {
541 /* Using creat(2) because mknod(2) doesn't seem to be portable. */
544 ret = creat(path, 0644);
545 if (ret < 0) return ret;
548 static int cpyfile(const char *srcpath) {
553 char dstpath[PATH_MAX];
555 ret = src = open(srcpath, O_RDONLY);
556 if (ret < 0) return ret;
557 ret = fstat(src, &st);
558 if (ret < 0) return ret;
559 strcpy(dstpath, CWD);
560 strcat(dstpath, srcpath + strlen(rover.marks.dirpath));
561 ret = dst = creat(dstpath, st.st_mode);
562 if (ret < 0) return ret;
563 while ((size = read(src, buf, BUFSIZ)) > 0)
564 write(dst, buf, size);
569 static int adddir(const char *path) {
573 ret = stat(CWD, &st);
574 if (ret < 0) return ret;
575 return mkdir(path, st.st_mode);
577 static int movfile(const char *srcpath) {
579 char dstpath[PATH_MAX];
581 strcpy(dstpath, CWD);
582 strcat(dstpath, srcpath + strlen(rover.marks.dirpath));
583 ret = rename(srcpath, dstpath);
584 if (ret < 0 && errno == EXDEV) {
585 ret = cpyfile(srcpath);
586 if (ret < 0) return ret;
587 ret = delfile(srcpath);
592 /* Do a fork-exec to external program (e.g. $EDITOR). */
602 /* fork() succeeded. */
603 memset(&sa, 0, sizeof (struct sigaction));
604 sa.sa_handler = SIG_DFL;
605 sigaction(SIGSEGV, &sa, NULL);
606 sigaction(SIGWINCH, &sa, NULL);
608 waitpid(pid, &status, 0);
611 } else if (pid == 0) {
613 execvp(ARGS[0], ARGS);
617 /* Interactive getstr(). */
619 igetstr(char *buffer, int maxlen)
623 length = strlen(buffer);
626 if (ch == '\r' || ch == '\n' || ch == KEY_DOWN || ch == KEY_ENTER) {
629 } else if (ch == erasechar() || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
631 buffer[--length] = '\0';
632 } else if (ch == killchar()) {
635 } else if (length < maxlen - 1 && isprint(ch)) {
636 buffer[length++] = ch;
637 buffer[length] = '\0';
642 /* Update line input on the screen. */
644 update_input(char *prompt, Color color)
648 plen = strlen(prompt);
649 ilen = strlen(INPUT);
650 color_set(RVC_PROMPT, NULL);
651 mvaddstr(LINES - 1, 0, prompt);
652 color_set(color, NULL);
653 mvaddstr(LINES - 1, plen, INPUT);
654 mvaddch(LINES - 1, ilen + plen, ' ');
655 move(LINES - 1, ilen + plen);
656 color_set(DEFAULT, NULL);
659 /* Show a message on the status bar. */
661 message(const char *msg, Color color)
666 pos = (STATUSPOS - len) >> 1;
667 attr_on(A_BOLD, NULL);
668 color_set(color, NULL);
669 mvaddstr(LINES - 1, pos, msg);
670 color_set(DEFAULT, NULL);
671 attr_off(A_BOLD, NULL);
674 /* Clear message area, leaving only status info. */
678 mvhline(LINES - 1, 0, ' ', STATUSPOS);
682 main(int argc, char *argv[])
690 if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
691 printf("rover %s\n", RV_VERSION);
693 } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
695 "Usage: rover [DIRECTORY [DIRECTORY [DIRECTORY [...]]]]\n"
696 " or: rover [OPTION]\n"
697 "Browse current working directory or the ones specified.\n\n"
699 " -h, --help print this help message and exit\n"
700 " -v, --version print program version and exit\n\n"
701 "See rover(1) for more information.\n\n"
702 "Rover homepage: <https://github.com/lecram/rover>.\n"
709 for (i = 0; i < 10; i++) {
710 rover.esel[i] = rover.scroll[i] = 0;
711 rover.flags[i] = SHOW_FILES | SHOW_DIRS;
713 strcpy(rover.cwd[0], getenv("HOME"));
714 for (i = 1; i < argc && i < 10; i++) {
715 if ((d = opendir(argv[i]))) {
716 realpath(argv[i], rover.cwd[i]);
719 strcpy(rover.cwd[i], rover.cwd[0]);
721 getcwd(rover.cwd[i], PATH_MAX);
722 for (i++; i < 10; i++)
723 strcpy(rover.cwd[i], rover.cwd[i-1]);
724 for (i = 0; i < 10; i++)
725 if (rover.cwd[i][strlen(rover.cwd[i]) - 1] != '/')
726 strcat(rover.cwd[i], "/");
728 rover.window = subwin(stdscr, LINES - 2, COLS, 1, 0);
729 init_marks(&rover.marks);
735 if (!strcmp(key, RVK_QUIT)) break;
736 else if (ch >= '0' && ch <= '9') {
737 rover.tab = ch - '0';
739 } else if (!strcmp(key, RVK_HELP)) {
744 } else if (!strcmp(key, RVK_DOWN)) {
745 if (!rover.nfiles) continue;
746 ESEL = (ESEL + 1) % rover.nfiles;
748 } else if (!strcmp(key, RVK_UP)) {
749 if (!rover.nfiles) continue;
750 ESEL = ESEL ? ESEL - 1 : rover.nfiles - 1;
752 } else if (!strcmp(key, RVK_JUMP_DOWN)) {
753 if (!rover.nfiles) continue;
754 ESEL = MIN(ESEL + RV_JUMP, rover.nfiles - 1);
755 if (rover.nfiles > HEIGHT)
756 SCROLL = MIN(SCROLL + RV_JUMP, rover.nfiles - HEIGHT);
758 } else if (!strcmp(key, RVK_JUMP_UP)) {
759 if (!rover.nfiles) continue;
760 ESEL = MAX(ESEL - RV_JUMP, 0);
761 SCROLL = MAX(SCROLL - RV_JUMP, 0);
763 } else if (!strcmp(key, RVK_CD_DOWN)) {
764 if (!rover.nfiles || !ISDIR(ENAME(ESEL))) continue;
765 strcat(CWD, ENAME(ESEL));
767 } else if (!strcmp(key, RVK_CD_UP)) {
768 char *dirname, first;
769 if (!strcmp(CWD, "/")) continue;
770 CWD[strlen(CWD) - 1] = '\0';
771 dirname = strrchr(CWD, '/') + 1;
776 dirname[strlen(dirname)] = '/';
780 } else if (!strcmp(key, RVK_HOME)) {
781 strcpy(CWD, getenv("HOME"));
782 if (CWD[strlen(CWD) - 1] != '/')
785 } else if (!strcmp(key, RVK_SHELL)) {
786 program = getenv("SHELL");
793 } else if (!strcmp(key, RVK_VIEW)) {
794 if (!rover.nfiles || ISDIR(ENAME(ESEL))) continue;
795 program = getenv("PAGER");
798 ARGS[1] = ENAME(ESEL);
802 } else if (!strcmp(key, RVK_EDIT)) {
803 if (!rover.nfiles || ISDIR(ENAME(ESEL))) continue;
804 program = getenv("EDITOR");
807 ARGS[1] = ENAME(ESEL);
812 } else if (!strcmp(key, RVK_SEARCH)) {
813 int oldsel, oldscroll, length;
814 char *prompt = "search: ";
815 if (!rover.nfiles) continue;
819 update_input(prompt, DEFAULT);
820 while (igetstr(INPUT, INPUTSZ)) {
823 length = strlen(INPUT);
825 for (sel = 0; sel < rover.nfiles; sel++)
826 if (!strncmp(ENAME(sel), INPUT, length))
828 if (sel < rover.nfiles) {
831 if (rover.nfiles > HEIGHT) {
834 else if (sel - 3 > rover.nfiles - HEIGHT)
835 SCROLL = rover.nfiles - HEIGHT;
845 update_input(prompt, color);
849 } else if (!strcmp(key, RVK_TG_FILES)) {
852 } else if (!strcmp(key, RVK_TG_DIRS)) {
855 } else if (!strcmp(key, RVK_TG_HIDDEN)) {
856 FLAGS ^= SHOW_HIDDEN;
858 } else if (!strcmp(key, RVK_NEW_FILE)) {
860 char *prompt = "new file: ";
862 update_input(prompt, DEFAULT);
863 while (igetstr(INPUT, INPUTSZ)) {
864 int length = strlen(INPUT);
866 for (i = 0; i < rover.nfiles; i++) {
868 !strncmp(ENAME(i), INPUT, length) &&
869 (!strcmp(ENAME(i) + length, "") ||
870 !strcmp(ENAME(i) + length, "/"))
876 update_input(prompt, ok ? GREEN : RED);
886 message("File already exists.", RED);
888 } else if (!strcmp(key, RVK_NEW_DIR)) {
890 char *prompt = "new directory: ";
892 update_input(prompt, DEFAULT);
893 while (igetstr(INPUT, INPUTSZ)) {
894 int length = strlen(INPUT);
896 for (i = 0; i < rover.nfiles; i++) {
898 !strncmp(ENAME(i), INPUT, length) &&
899 (!strcmp(ENAME(i) + length, "") ||
900 !strcmp(ENAME(i) + length, "/"))
906 update_input(prompt, ok ? GREEN : RED);
916 message("File already exists.", RED);
918 } else if (!strcmp(key, RVK_RENAME)) {
920 char *prompt = "rename: ";
923 strcpy(INPUT, ENAME(ESEL));
924 last = INPUT + strlen(INPUT) - 1;
925 if ((isdir = *last == '/'))
927 update_input(prompt, RED);
928 while (igetstr(INPUT, INPUTSZ)) {
929 int length = strlen(INPUT);
931 for (i = 0; i < rover.nfiles; i++)
933 !strncmp(ENAME(i), INPUT, length) &&
934 (!strcmp(ENAME(i) + length, "") ||
935 !strcmp(ENAME(i) + length, "/"))
940 update_input(prompt, ok ? GREEN : RED);
947 if (!rename(ENAME(ESEL), INPUT) && MARKED(ESEL)) {
948 del_mark(&rover.marks, ENAME(ESEL));
949 add_mark(&rover.marks, CWD, INPUT);
955 message("File already exists.", RED);
957 } else if (!strcmp(key, RVK_TG_MARK)) {
959 del_mark(&rover.marks, ENAME(ESEL));
961 add_mark(&rover.marks, CWD, ENAME(ESEL));
962 MARKED(ESEL) = !MARKED(ESEL);
963 ESEL = (ESEL + 1) % rover.nfiles;
965 } else if (!strcmp(key, RVK_INVMARK)) {
966 for (i = 0; i < rover.nfiles; i++) {
968 del_mark(&rover.marks, ENAME(i));
970 add_mark(&rover.marks, CWD, ENAME(i));
971 MARKED(i) = !MARKED(i);
974 } else if (!strcmp(key, RVK_MARKALL)) {
975 for (i = 0; i < rover.nfiles; i++)
977 add_mark(&rover.marks, CWD, ENAME(i));
981 } else if (!strcmp(key, RVK_DELETE)) {
982 if (rover.marks.nentries) {
983 message("Delete marked entries? (Y to confirm)", YELLOW);
985 process_marked(NULL, delfile, deldir);
989 message("No entries marked for deletion.", RED);
990 } else if (!strcmp(key, RVK_COPY)) {
991 if (rover.marks.nentries)
992 process_marked(adddir, cpyfile, NULL);
994 message("No entries marked for copying.", RED);
995 } else if (!strcmp(key, RVK_MOVE)) {
996 if (rover.marks.nentries)
997 process_marked(adddir, movfile, deldir);
999 message("No entries marked for moving.", RED);
1003 free_rows(&rover.rows, rover.nfiles);
1004 free_marks(&rover.marks);
1005 delwin(rover.window);