void read_info_file(int reread) { /* TODO: refactor this function read_info_file() */ FILE *fp; char info_file[PATH_MAX]; char *line = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; snprintf(info_file, sizeof(info_file), "%s/vifminfo", cfg.config_dir); if((fp = os_fopen(info_file, "r")) == NULL) return; while((line = read_vifminfo_line(fp, line)) != NULL) { const char type = line[0]; const char *const line_val = line + 1; if(type == LINE_TYPE_COMMENT || type == '\0') continue; if(type == LINE_TYPE_OPTION) { if(line_val[0] == '[' || line_val[0] == ']') { FileView *v = curr_view; curr_view = (line_val[0] == '[') ? &lwin : &rwin; process_set_args(line_val + 1, 1, 1); curr_view = v; } else { process_set_args(line_val, 1, 1); } } else if(type == LINE_TYPE_FILETYPE || type == LINE_TYPE_XFILETYPE) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { char *error; matcher_t *m; const int x = (type == LINE_TYPE_XFILETYPE); /* Prevent loading of old builtin fake associations. */ if(ends_with(line2, "}" VIFM_PSEUDO_CMD)) { continue; } m = matcher_alloc(line_val, 0, 1, &error); if(m == NULL) { /* Ignore error description. */ free(error); } else { ft_set_programs(m, line2, x, curr_stats.exec_env_type == EET_EMULATOR_WITH_X); } } } else if(type == LINE_TYPE_FILEVIEWER) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { char *error; matcher_t *const m = matcher_alloc(line_val, 0, 1, &error); if(m == NULL) { /* Ignore error description. */ free(error); } else { ft_set_viewers(m, line2); } } } else if(type == LINE_TYPE_COMMAND) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { char *cmdadd_cmd; if((cmdadd_cmd = format_str("command %s %s", line_val, line2)) != NULL) { exec_commands(cmdadd_cmd, curr_view, CIT_COMMAND); free(cmdadd_cmd); } } } else if(type == LINE_TYPE_MARK) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if((line3 = read_vifminfo_line(fp, line3)) != NULL) { const int timestamp = read_optional_number(fp); setup_user_mark(line_val[0], line2, line3, timestamp); } } } else if(type == LINE_TYPE_BOOKMARK) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { long timestamp; if((line3 = read_vifminfo_line(fp, line3)) != NULL && read_number(line3, ×tamp)) { (void)bmarks_setup(line_val, line2, (size_t)timestamp); } } } else if(type == LINE_TYPE_ACTIVE_VIEW) { /* Don't change active view on :restart command. */ if(line_val[0] == 'r' && !reread) { ui_views_update_titles(); curr_view = &rwin; other_view = &lwin; } } else if(type == LINE_TYPE_QUICK_VIEW_STATE) { const int i = atoi(line_val); curr_stats.view = (i == 1); } else if(type == LINE_TYPE_WIN_COUNT) { if(!reread) { const int i = atoi(line_val); curr_stats.number_of_windows = (i == 1) ? 1 : 2; } } else if(type == LINE_TYPE_SPLIT_ORIENTATION) { curr_stats.split = (line_val[0] == 'v') ? VSPLIT : HSPLIT; } else if(type == LINE_TYPE_SPLIT_POSITION) { curr_stats.splitter_pos = atof(line_val); } else if(type == LINE_TYPE_LWIN_SORT) { get_sort_info(&lwin, line_val); } else if(type == LINE_TYPE_RWIN_SORT) { get_sort_info(&rwin, line_val); } else if(type == LINE_TYPE_LWIN_HIST || type == LINE_TYPE_RWIN_HIST) { FileView *const view = (type == LINE_TYPE_LWIN_HIST ) ? &lwin : &rwin; if(line_val[0] == '\0') { if(!reread && view->history_num > 0) { copy_str(view->curr_dir, sizeof(view->curr_dir), view->history[view->history_pos].dir); } } else if((line2 = read_vifminfo_line(fp, line2)) != NULL) { const int pos = read_optional_number(fp); get_history(view, reread, line_val, line2, pos); } } else if(type == LINE_TYPE_CMDLINE_HIST) { append_to_history(&cfg.cmd_hist, cfg_save_command_history, line_val); } else if(type == LINE_TYPE_SEARCH_HIST) { append_to_history(&cfg.search_hist, cfg_save_search_history, line_val); } else if(type == LINE_TYPE_PROMPT_HIST) { append_to_history(&cfg.prompt_hist, cfg_save_prompt_history, line_val); } else if(type == LINE_TYPE_FILTER_HIST) { append_to_history(&cfg.filter_hist, cfg_save_filter_history, line_val); } else if(type == LINE_TYPE_DIR_STACK) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if((line3 = read_vifminfo_line(fp, line3)) != NULL) { if((line4 = read_vifminfo_line(fp, line4)) != NULL) { push_to_dirstack(line_val, line2, line3 + 1, line4); } } } } else if(type == LINE_TYPE_TRASH) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { char *const trash_name = convert_old_trash_path(line_val); (void)add_to_trash(line2, trash_name); free(trash_name); } } else if(type == LINE_TYPE_REG) { regs_append(line_val[0], line_val + 1); } else if(type == LINE_TYPE_LWIN_FILT) { (void)replace_string(&lwin.prev_manual_filter, line_val); (void)filter_set(&lwin.manual_filter, line_val); } else if(type == LINE_TYPE_RWIN_FILT) { (void)replace_string(&rwin.prev_manual_filter, line_val); (void)filter_set(&rwin.manual_filter, line_val); } else if(type == LINE_TYPE_LWIN_FILT_INV) { const int i = atoi(line_val); lwin.invert = (i != 0); } else if(type == LINE_TYPE_RWIN_FILT_INV) { const int i = atoi(line_val); rwin.invert = (i != 0); } else if(type == LINE_TYPE_USE_SCREEN) { const int i = atoi(line_val); cfg_set_use_term_multiplexer(i != 0); } else if(type == LINE_TYPE_COLORSCHEME) { copy_str(curr_stats.color_scheme, sizeof(curr_stats.color_scheme), line_val); } else if(type == LINE_TYPE_LWIN_SPECIFIC || type == LINE_TYPE_RWIN_SPECIFIC) { FileView *view = (type == LINE_TYPE_LWIN_SPECIFIC) ? &lwin : &rwin; set_view_property(view, line_val[0], line_val + 1); } } free(line); free(line2); free(line3); free(line4); fclose(fp); dir_stack_freeze(); }
void read_info_file(int reread) { /* TODO: refactor this function read_info_file() */ FILE *fp; char info_file[PATH_MAX]; char *line = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; snprintf(info_file, sizeof(info_file), "%s/vifminfo", cfg.config_dir); if((fp = fopen(info_file, "r")) == NULL) return; while((line = read_vifminfo_line(fp, line)) != NULL) { const char type = line[0]; const char *const line_val = line + 1; if(type == LINE_TYPE_COMMENT || type == '\0') continue; if(type == LINE_TYPE_OPTION) { if(line_val[0] == '[' || line_val[0] == ']') { FileView *v = curr_view; curr_view = (line_val[0] == '[') ? &lwin : &rwin; process_set_args(line_val + 1); curr_view = v; } else { process_set_args(line_val); } } else if(type == LINE_TYPE_FILETYPE) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { /* This is to prevent old builtin fake associations to be loaded. */ if(!ends_with(line2, "}" VIFM_PSEUDO_CMD)) { set_programs(line_val, line2, 0, curr_stats.env_type == ENVTYPE_EMULATOR_WITH_X); } } } else if(type == LINE_TYPE_XFILETYPE) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { set_programs(line_val, line2, 1, curr_stats.env_type == ENVTYPE_EMULATOR_WITH_X); } } else if(type == LINE_TYPE_FILEVIEWER) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { set_fileviewer(line_val, line2); } } else if(type == LINE_TYPE_COMMAND) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { char *cmdadd_cmd; if((cmdadd_cmd = format_str("command %s %s", line_val, line2)) != NULL) { exec_commands(cmdadd_cmd, curr_view, GET_COMMAND); free(cmdadd_cmd); } } } else if(type == LINE_TYPE_BOOKMARK) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if((line3 = read_vifminfo_line(fp, line3)) != NULL) { add_bookmark(line_val[0], line2, line3); } } } else if(type == LINE_TYPE_ACTIVE_VIEW) { /* don't change active view on :restart command */ if(line_val[0] == 'r' && !reread) { update_view_title(&lwin); update_view_title(&rwin); curr_view = &rwin; other_view = &lwin; } } else if(type == LINE_TYPE_QUICK_VIEW_STATE) { const int i = atoi(line_val); curr_stats.view = (i == 1); } else if(type == LINE_TYPE_WIN_COUNT) { const int i = atoi(line_val); cfg.show_one_window = (i == 1); curr_stats.number_of_windows = (i == 1) ? 1 : 2; } else if(type == LINE_TYPE_SPLIT_ORIENTATION) { curr_stats.split = (line_val[0] == 'v') ? VSPLIT : HSPLIT; } else if(type == LINE_TYPE_SPLIT_POSITION) { curr_stats.splitter_pos = atof(line_val); } else if(type == LINE_TYPE_LWIN_SORT) { get_sort_info(&lwin, line_val); } else if(type == LINE_TYPE_RWIN_SORT) { get_sort_info(&rwin, line_val); } else if(type == LINE_TYPE_LWIN_HIST) { int pos; if(line_val[0] == '\0') { if(reread) continue; if(lwin.history_num > 0) strcpy(lwin.curr_dir, lwin.history[lwin.history_pos].dir); continue; } if((line2 = read_vifminfo_line(fp, line2)) == NULL) continue; pos = read_possible_possible_pos(fp); get_history(&lwin, reread, line_val, line2, pos); } else if(type == LINE_TYPE_RWIN_HIST) { int pos; if(line_val[0] == '\0') { if(reread) continue; if(rwin.history_num > 0) strcpy(rwin.curr_dir, rwin.history[rwin.history_pos].dir); continue; } if((line2 = read_vifminfo_line(fp, line2)) == NULL) continue; pos = read_possible_possible_pos(fp); get_history(&rwin, reread, line_val, line2, pos); } else if(type == LINE_TYPE_CMDLINE_HIST) { inc_history(&cfg.cmd_history, &cfg.cmd_history_num, &cfg.history_len); save_command_history(line_val); } else if(type == LINE_TYPE_SEARCH_HIST) { inc_history(&cfg.search_history, &cfg.search_history_num, &cfg.history_len); save_search_history(line_val); } else if(type == LINE_TYPE_PROMPT_HIST) { inc_history(&cfg.prompt_history, &cfg.prompt_history_num, &cfg.history_len); save_prompt_history(line_val); } else if(type == LINE_TYPE_DIR_STACK) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if((line3 = read_vifminfo_line(fp, line3)) != NULL) { if((line4 = read_vifminfo_line(fp, line4)) != NULL) { push_to_dirstack(line_val, line2, line3 + 1, line4); } } } } else if(type == LINE_TYPE_TRASH) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if(!path_exists_at(cfg.trash_dir, line_val)) continue; add_to_trash(line2, line_val); } } else if(type == LINE_TYPE_REG) { append_to_register(line_val[0], line_val + 1); } else if(type == LINE_TYPE_LWIN_FILT) { (void)replace_string(&lwin.prev_filter, line_val); set_filename_filter(&lwin, line_val); } else if(type == LINE_TYPE_RWIN_FILT) { (void)replace_string(&rwin.prev_filter, line_val); set_filename_filter(&rwin, line_val); } else if(type == LINE_TYPE_LWIN_FILT_INV) { const int i = atoi(line_val); lwin.invert = (i != 0); } else if(type == LINE_TYPE_RWIN_FILT_INV) { const int i = atoi(line_val); rwin.invert = (i != 0); } else if(type == LINE_TYPE_USE_SCREEN) { const int i = atoi(line_val); set_use_screen(i != 0); } else if(type == LINE_TYPE_COLORSCHEME) { strcpy(curr_stats.color_scheme, line_val); } else if(type == LINE_TYPE_LWIN_SPECIFIC || type == LINE_TYPE_RWIN_SPECIFIC) { FileView *view = (type == LINE_TYPE_LWIN_SPECIFIC) ? &lwin : &rwin; set_view_property(view, line_val[0], line_val + 1); } } free(line); free(line2); free(line3); free(line4); fclose(fp); }