int swap_dirs(void) { stack_entry_t item; if(stack_top == 0) return -1; item = stack[--stack_top]; if(pushd() != 0) { free_entry(&item); return -1; } if(change_directory(&lwin, item.lpane_dir) >= 0) load_dir_list(&lwin, 0); if(change_directory(&rwin, item.rpane_dir) >= 0) load_dir_list(&rwin, 0); fview_cursor_redraw(curr_view); refresh_view_win(other_view); free_entry(&item); return 0; }
void filters_invert(view_t *view) { view->invert = !view->invert; load_dir_list(view, 1); fpos_set_pos(view, 0); }
/* Navigates the view to a given dir/file combination specified by the path. */ static void navigate_to_selected_file(FileView *view, const char path[]) { char name[NAME_MAX]; char *dir = strdup(path); char *const last_slash = find_slashr(dir); if(last_slash == NULL) { copy_str(name, sizeof(name), dir); } else { *last_slash = '\0'; copy_str(name, sizeof(name), last_slash + 1); } if(change_directory(view, dir) >= 0) { ui_sb_quick_msgf("%s", "Finding the correct directory..."); load_dir_list(view, 0); (void)ensure_file_is_selected(view, name); } else { show_error_msgf("Invalid path", "Cannot change dir to \"%s\"", dir); } free(dir); }
/* Navigates the view to given mark if it's valid. Returns new value for * save_msg flag. */ static int navigate_to_bookmark(FileView *view, char mark) { const bookmark_t *const bmark = get_bookmark(mark); if(is_bmark_valid(bmark)) { if(change_directory(view, bmark->directory) >= 0) { load_dir_list(view, 1); (void)ensure_file_is_selected(view, bmark->file); } } else { if(!char_is_one_of(valid_bookmarks, mark)) status_bar_message("Invalid mark name"); else if(is_bmark_empty(bmark)) status_bar_message("Mark is not set"); else status_bar_message("Mark is invalid"); move_to_list_pos(view, view->list_pos); return 1; } return 0; }
TEST(reload_does_not_remove_broken_symlinks, IF(not_windows)) { char test_file[PATH_MAX]; assert_non_null(os_realpath(TEST_DATA_PATH "/existing-files/a", test_file)); assert_success(chdir(SANDBOX_PATH)); /* symlink() is not available on Windows, but other code is fine. */ #ifndef _WIN32 assert_success(symlink("/wrong/path", "broken-link")); #endif assert_false(flist_custom_active(&lwin)); flist_custom_start(&lwin, "test"); flist_custom_add(&lwin, test_file); flist_custom_add(&lwin, "./broken-link"); assert_true(flist_custom_finish(&lwin, 0) == 0); assert_int_equal(2, lwin.list_rows); load_dir_list(&lwin, 1); assert_int_equal(2, lwin.list_rows); assert_success(remove("broken-link")); }
/* Goes one directory up from current location. Returns zero unless it won't * make sense to continue going up (like on error or reaching root). */ static int cd_to_parent_dir(FileView *view) { char dir_name[strlen(view->curr_dir) + 1]; int ret; /* Return to original directory from custom view. */ if(flist_custom_active(view)) { navigate_to(view, view->custom.orig_dir); return 0; } /* Do nothing in root. */ if(is_root_dir(view->curr_dir)) { return 1; } dir_name[0] = '\0'; extract_last_path_component(view->curr_dir, dir_name); ret = change_directory(view, "../"); if(ret == -1) { return 1; } if(ret == 0) { load_dir_list(view, 0); flist_set_pos(view, find_file_pos_in_list(view, dir_name)); } return 0; }
/* leaves properties change dialog */ static void leave_attr_mode(void) { vle_mode_set(NORMAL_MODE, VMT_PRIMARY); curr_stats.use_input_bar = 1; clean_selected_files(view); load_dir_list(view, 1); move_to_list_pos(view, view->list_pos); update_all_windows(); }
void execute_volumes_cb(FileView *view, menu_info *m) { char path_buf[4]; snprintf(path_buf, 4, "%s", m->items[m->pos]); if(change_directory(view, path_buf) < 0) return; load_dir_list(view, 0); move_to_list_pos(view, 0); }
static int load_filenames (void) { int rc = HEAP_OK; file_list = load_dir_list (path, "t"); if (! file_list) rc = HEAP_MEMORY_ERROR; return rc; }
int popd(void) { if(stack_top == 0) return -1; stack_top--; if(change_directory(&lwin, stack[stack_top].lpane_dir) >= 0) load_dir_list(&lwin, 0); if(change_directory(&rwin, stack[stack_top].rpane_dir) >= 0) load_dir_list(&rwin, 0); fview_cursor_redraw(curr_view); refresh_view_win(other_view); free_entry(&stack[stack_top]); return 0; }
static void leave_attr_mode(void) { *mode = NORMAL_MODE; curs_set(FALSE); curr_stats.use_input_bar = 1; clean_selected_files(view); load_dir_list(view, 1); move_to_list_pos(view, view->list_pos); update_all_windows(); }
static void leave_attr_mode(void) { vle_mode_set(NORMAL_MODE, VMT_PRIMARY); curs_set(0); curr_stats.use_input_bar = 1; clean_selected_files(view); load_dir_list(view, 1); fview_cursor_redraw(view); update_all_windows(); }
void show_hidden_cb (void) { gint last_selected_row; last_selected_row = curr_view->row; if (cfg.show_hidden) cfg.show_hidden = FALSE; else cfg.show_hidden = TRUE; gtk_clist_freeze(GTK_CLIST(curr_view->clist)); gtk_clist_freeze(GTK_CLIST(other_view->clist)); load_dir_list(other_view); load_dir_list(curr_view); focus_on_row (curr_view, (last_selected_row < GTK_CLIST (curr_view->clist)->rows ? last_selected_row : GTK_CLIST (curr_view->clist)->rows - 1)); gtk_clist_thaw(GTK_CLIST(other_view->clist)); gtk_clist_thaw(GTK_CLIST(curr_view->clist)); }
static void updir_from_mount(FileView *view, fuse_mount_t *runner) { char *file; int pos; if(change_directory(view, runner->source_file_dir) < 0) return; load_dir_list(view, 0); file = runner->source_file_name; file += strlen(runner->source_file_dir) + 1; pos = find_file_pos_in_list(view, file); flist_set_pos(view, pos); }
static void check_path_for_file(FileView *view, const char *path, int handle) { if(path[0] != '\0' && !is_dir(path)) { const char *slash = strrchr(path, '/'); if(slash == NULL) slash = path - 1; load_dir_list(view, !(cfg.vifm_info&VIFMINFO_SAVEDIRS)); if(ensure_file_is_selected(view, slash + 1)) { if(handle) handle_file(view, 0, 0); } } }
/* Navigates to/opens (handles) file specified by the path (and file only, no * directories). */ static void check_path_for_file(FileView *view, const char path[], int handle) { if(path[0] == '\0' || is_dir(path) || strcmp(path, "-") == 0) { return; } load_dir_list(view, !(cfg.vifm_info&VIFMINFO_SAVEDIRS)); if(ensure_file_is_selected(view, after_last(path, '/'))) { if(handle) { open_file(view, FHE_RUN); } } }
/* Navigates to/opens (handles) file specified by the path (and file only, no * directories). */ static void check_path_for_file(view_t *view, const char path[], int handle) { if(path[0] == '\0' || is_dir(path) || (handle && strcmp(path, "-") == 0)) { return; } load_dir_list(view, 1); if(fpos_ensure_selected(view, after_last(path, '/'))) { if(handle) { open_file(view, FHE_RUN); } } }
int heap_recover ( const char *heappath) { int rc = HEAP_OK; if (file_exists (heappath)) { if (!file_is_directory (heappath)) rc = HEAP_INVALID_PATH; } else { if (make_dir (heappath) != 0) rc = HEAP_CANNOT_CREATE_PATH; } if (! rc) { path = mem_strdup (heappath); if (!path) rc = HEAP_MEMORY_ERROR; } if (! rc) { file_list = load_dir_list (path, "t"); if (!file_list) rc = HEAP_MEMORY_ERROR; } for (file_info = (FILEINFO *) file_list-> next; file_info != (FILEINFO *) file_list; file_info = file_info-> next) { rc = file_recover (file_info); if (rc) break; } free_dir_list (file_list); return rc; }
/* Navigates the view to a given dir/file combination specified by the path. */ static void navigate_to_selected_file(FileView *view, const char path[]) { /* Check whether target path is directory while we don't change current * working directory by invoking change_directory() function below. */ const int dst_is_dir = is_dir(path); char name[NAME_MAX]; char *dir = strdup(path); char *const last_slash = find_slashr(dir); if(last_slash == NULL) { copy_str(name, sizeof(name), dir); } else { *last_slash = '\0'; copy_str(name, sizeof(name), last_slash + 1); } if(change_directory(view, dir) >= 0) { status_bar_message("Finding the correct directory..."); wrefresh(status_bar); load_dir_list(view, 0); if(dst_is_dir) { strcat(name, "/"); } (void)ensure_file_is_selected(view, name); } else { show_error_msgf("Invalid path", "Cannot change dir to \"%s\"", dir); } free(dir); }
void enter_attr_mode(FileView *active_view) { int i; mode_t fmode; mode_t diff; uid_t uid = geteuid(); if(curr_stats.load_stage < 2) return; view = active_view; memset(perms, 0, sizeof(perms)); diff = 0; i = 0; while(i < view->list_rows && !view->dir_entry[i].selected) i++; file_is_dir = 0; if(i == view->list_rows) { i = view->list_pos; file_is_dir = is_dir(view->dir_entry[i].name); } fmode = view->dir_entry[i].mode; if(uid != 0 && view->dir_entry[i].uid != uid) { show_error_msgf("Access error", "You are not owner of %s", view->dir_entry[i].name); clean_selected_files(view); load_dir_list(view, 1); move_to_list_pos(view, view->list_pos); return; } while(i < view->list_rows) { if(view->dir_entry[i].selected) { diff |= (view->dir_entry[i].mode ^ fmode); file_is_dir = file_is_dir || is_dir(view->dir_entry[i].name); if(uid != 0 && view->dir_entry[i].uid != uid) { show_error_msgf("Access error", "You are not owner of %s", view->dir_entry[i].name); return; } } i++; } *mode = ATTR_MODE; clear_input_bar(); curr_stats.use_input_bar = 0; perms[0] = !(diff & S_IRUSR) ? (int)(fmode & S_IRUSR) : -1; perms[1] = !(diff & S_IWUSR) ? (int)(fmode & S_IWUSR) : -1; perms[2] = !(diff & S_IXUSR) ? (int)(fmode & S_IXUSR) : -1; perms[3] = !(diff & S_ISUID) ? (int)(fmode & S_ISUID) : -1; perms[4] = !(diff & S_IRGRP) ? (int)(fmode & S_IRGRP) : -1; perms[5] = !(diff & S_IWGRP) ? (int)(fmode & S_IWGRP) : -1; perms[6] = !(diff & S_IXGRP) ? (int)(fmode & S_IXGRP) : -1; perms[7] = !(diff & S_ISGID) ? (int)(fmode & S_ISGID) : -1; perms[8] = !(diff & S_IROTH) ? (int)(fmode & S_IROTH) : -1; perms[9] = !(diff & S_IWOTH) ? (int)(fmode & S_IWOTH) : -1; perms[10] = !(diff & S_IXOTH) ? (int)(fmode & S_IXOTH) : -1; perms[11] = !(diff & S_ISVTX) ? (int)(fmode & S_ISVTX) : -1; adv_perms[0] = 0; adv_perms[1] = 0; adv_perms[2] = 0; memcpy(origin_perms, perms, sizeof(perms)); top = 3; bottom = file_is_dir ? 18 : 16; curr = 3; permnum = 0; step = 1; while(perms[permnum] < 0 && curr <= bottom) { inc_curr(); permnum++; } if(curr > bottom) { show_error_msg("Permissions change error", "Selected files have no common access state"); leave_attr_mode(); return; } col = 9; changed = 0; redraw_attr_dialog(); }
int main(int argc, char *argv[]) { char dir[PATH_MAX]; char config_dir[PATH_MAX]; char *console = NULL; int x; int rwin_args = 0; int lwin_args = 0; struct stat stat_buf; setlocale(LC_ALL, ""); getcwd(dir, sizeof(dir)); /* Window initializations */ rwin.curr_line = 0; rwin.top_line = 0; rwin.list_rows = 0; rwin.list_pos = 0; rwin.selected_filelist = NULL; rwin.history_num = 0; rwin.invert = 0; rwin.color_scheme = 0; lwin.curr_line = 0; lwin.top_line = 0; lwin.list_rows = 0; lwin.list_pos = 0; lwin.selected_filelist = NULL; lwin.history_num = 0; lwin.invert = 0; lwin.color_scheme = 0; /* These need to be initialized before reading the configuration file */ cfg.command_num = 0; cfg.filetypes_num = 0; cfg.nmapped_num = 0; cfg.vim_filter = 0; cfg.show_one_window = 0; command_list = NULL; filetypes = NULL; cfg.search_history_len = 15; cfg.search_history_num = -1; cfg.search_history = (char **)calloc(cfg.search_history_len, sizeof(char*)); cfg.cmd_history_len = 15; cfg.cmd_history_num = -1; cfg.cmd_history = (char **)calloc(cfg.cmd_history_len, sizeof(char *)); cfg.auto_execute = 0; cfg.color_scheme_num = 0; cfg.color_pairs_num = 0; col_schemes = malloc(sizeof(Col_scheme) * 8); /* Maximum argument length to pass to the shell */ if (! (cfg.max_args = sysconf(_SC_ARG_MAX)) > 0) cfg.max_args = 4096; /* POSIX MINIMUM */ init_config(); set_config_dir(); read_config_file(); /* Safety check for existing vifmrc file without FUSE_HOME */ if (cfg.fuse_home == NULL) cfg.fuse_home = strdup("/tmp/vifm_FUSE"); /* Misc configuration */ lwin.prev_invert = lwin.invert; lwin.hide_dot = 1; strncpy(lwin.regexp, "\\..~$", sizeof(lwin.regexp)); rwin.prev_invert = rwin.invert; rwin.hide_dot = 1; strncpy(rwin.regexp, "\\..~$", sizeof(rwin.regexp)); cfg.timer = 10; curr_stats.yanked_files = NULL; curr_stats.num_yanked_files = 0; curr_stats.need_redraw = 0; curr_stats.getting_input = 0; curr_stats.menu = 0; curr_stats.redraw_menu = 0; curr_stats.is_updir = 0; curr_stats.last_char = 0; curr_stats.is_console = 0; curr_stats.search = 0; curr_stats.save_msg = 0; curr_stats.use_register = 0; curr_stats.curr_register = -1; curr_stats.register_saved = 0; curr_stats.show_full = 0; curr_stats.view = 0; if (cfg.show_one_window) curr_stats.number_of_windows = 1; else curr_stats.number_of_windows = 2; snprintf(config_dir, sizeof(config_dir), "%s/vifmrc", cfg.config_dir); if(stat(config_dir, &stat_buf) == 0) curr_stats.config_file_mtime = stat_buf.st_mtime; else curr_stats.config_file_mtime = 0; /* Check if running in X */ console = getenv("DISPLAY"); if(!console || !*console) curr_stats.is_console = 1; /* Setup the ncurses interface. */ if(!setup_ncurses_interface()) return -1; /* Load the initial directory */ snprintf(rwin.curr_dir, sizeof(rwin.curr_dir), "%s", dir); snprintf(lwin.curr_dir, sizeof(lwin.curr_dir), "%s", dir); rwin.dir_entry = (dir_entry_t *)malloc(sizeof(dir_entry_t)); lwin.dir_entry = (dir_entry_t *)malloc(sizeof(dir_entry_t)); rwin.dir_entry[0].name = malloc(sizeof("../") +1); lwin.dir_entry[0].name = malloc(sizeof("../") +1); strcpy(rwin.dir_entry[0].name, "../"); strcpy(lwin.dir_entry[0].name, "../"); change_directory(&rwin, dir); change_directory(&lwin, dir); other_view = &lwin; curr_view = &rwin; /* Get Command Line Arguments */ for(x = 1; x < argc; x++) { if(argv[x] != NULL) { if(!strcmp(argv[x], "-f")) { cfg.vim_filter = 1; } else if(!strcmp(argv[x], "--version")) { endwin(); printf("\n\nvifm %s\n\n", VERSION); exit(0); } else if(!strcmp(argv[x], "--help")) { endwin(); show_help_msg(); exit(0); } else if(is_dir(argv[x])) { if(lwin_args) { snprintf(rwin.curr_dir, sizeof(rwin.curr_dir), "%s", argv[x]); rwin_args++; } else { snprintf(lwin.curr_dir, sizeof(lwin.curr_dir), "%s", argv[x]); lwin_args++; } } else { endwin(); show_help_msg(); exit(0); } } } load_dir_list(&rwin, 0); if (rwin_args) { change_directory(&rwin, rwin.curr_dir); load_dir_list(&rwin, 0); } mvwaddstr(rwin.win, rwin.curr_line, 0, "*"); wrefresh(rwin.win); /* This is needed for the sort_dir_list() which uses curr_view */ switch_views(); load_dir_list(&lwin, 0); if (lwin_args) { change_directory(&lwin, lwin.curr_dir); load_dir_list(&lwin, 0); } moveto_list_pos(&lwin, 0); update_all_windows(); setup_signals(); werase(status_bar); wnoutrefresh(status_bar); /* Need to wait until both lists are loaded before changing one of the * lists to show the file stats. This is only used for starting vifm * from the vifm.vim script */ if(cfg.vim_filter) curr_stats.number_of_windows = 1; /* Enter the main loop. */ main_key_press_cb(curr_view); return 0; }
void redraw_window(void) { int screen_x, screen_y; int x, y; struct winsize ws; curr_stats.freeze = 1; ioctl(0, TIOCGWINSZ, &ws); // changed for pdcurses resize_term(ws.ws_row, ws.ws_col); getmaxyx(stdscr, screen_y, screen_x); if (screen_y < 10) finish("Terminal is too small to run vifm\n"); if (screen_x < 30) finish("Terminal is too small to run vifm\n"); wclear(stdscr); wclear(lwin.title); wclear(lwin.win); wclear(rwin.title); wclear(rwin.win); wclear(stat_win); wclear(status_bar); wclear(pos_win); wclear(num_win); wclear(rborder); wclear(mborder); wclear(lborder); wclear(change_win); wclear(sort_win); wresize(stdscr, screen_y, screen_x); mvwin(sort_win, (screen_y - 14)/2, (screen_x -30)/2); mvwin(change_win, (screen_y - 10)/2, (screen_x -30)/2); wresize(menu_win, screen_y - 1, screen_x); wresize(error_win, (screen_y -10)/2, screen_x -2); mvwin(error_win, (screen_y -10)/2, 1); wresize(lborder, screen_y -2, 1); if (curr_stats.number_of_windows == 1) { wresize(lwin.title, 1, screen_x -1); wresize(lwin.win, screen_y -3, screen_x -2); getmaxyx(lwin.win, y, x); lwin.window_width = x -1; lwin.window_rows = y -1; wresize(rwin.title, 1, screen_x -1); mvwin(rwin.title, 0, 1); wresize(rwin.win, screen_y -3, screen_x -2); mvwin(rwin.win, 1, 1); getmaxyx(rwin.win, y, x); rwin.window_width = x -1; rwin.window_rows = y -1; } else { wresize(lwin.title, 1, screen_x/2 -2); wresize(lwin.win, screen_y -3, screen_x/2 -2); getmaxyx(lwin.win, y, x); lwin.window_width = x -1; lwin.window_rows = y -1; mvwin(mborder, 0, screen_x/2 -1); wresize(mborder, screen_y, 2); wresize(rwin.title, 1, screen_x/2 -2); mvwin(rwin.title, 0, screen_x/2 +1); wresize(rwin.win, screen_y -3, screen_x/2 -2); mvwin(rwin.win, 1, screen_x/2 +1); getmaxyx(rwin.win, y, x); rwin.window_width = x -1; rwin.window_rows = y -1; } /* For FreeBSD */ keypad(lwin.win, TRUE); keypad(rwin.win, TRUE); if (screen_x % 2) { wresize(rborder, screen_y -2, 2); mvwin(rborder, 0, screen_x -2); } else { wresize(rborder, screen_y -2, 1); mvwin(rborder, 0, screen_x -1); } wresize(stat_win, 1, screen_x); mvwin(stat_win, screen_y -2, 0); wresize(status_bar, 1, screen_x -19); /* For FreeBSD */ keypad(status_bar, TRUE); mvwin(status_bar, screen_y -1, 0); wresize(pos_win, 1, 13); mvwin(pos_win, screen_y -1, screen_x -13); wresize(num_win, 1, 6); mvwin(num_win, screen_y -1, screen_x -19); curs_set(0); change_directory(&rwin, rwin.curr_dir); load_dir_list(&rwin, 0); change_directory(&lwin, lwin.curr_dir); load_dir_list(&lwin, 0); if(curr_stats.view) { wclear(other_view->win); change_directory(curr_view, curr_view->curr_dir); load_dir_list(curr_view, 0); quick_view_file(curr_view); } else change_directory(curr_view, curr_view->curr_dir); update_stat_window(curr_view); if (curr_view->selected_files) { char status_buf[24]; snprintf(status_buf, sizeof(status_buf), "%d %s Selected", curr_view->selected_files, curr_view->selected_files == 1 ? "File" : "Files"); status_bar_message(status_buf); } else status_bar_message(" "); update_pos_window(curr_view); update_all_windows(); moveto_list_pos(curr_view, curr_view->list_pos); wrefresh(curr_view->win); curr_stats.freeze = 0; curr_stats.need_redraw = 0; }