/* Callback that is invoked when menu item is selected. Should return non-zero * to stay in menu mode. */ static int execute_history_cb(FileView *view, menu_info *m) { const char *const line = m->items[m->pos]; switch((HistoryType)m->extra_data) { case CMDHISTORY: cfg_save_command_history(line); exec_commands(line, view, CIT_COMMAND); break; case FSEARCHHISTORY: cfg_save_search_history(line); exec_commands(line, view, CIT_FSEARCH_PATTERN); break; case BSEARCHHISTORY: cfg_save_search_history(line); exec_commands(line, view, CIT_BSEARCH_PATTERN); break; case FILTERHISTORY: cfg_save_filter_history(line); exec_commands(line, view, CIT_FILTER_PATTERN); break; case PROMPTHISTORY: /* Can't replay prompt input. */ break; } return 0; }
TEST(mediaprg, IF(not_windows)) { assert_success(exec_commands("set mediaprg=prg", &lwin, CIT_COMMAND)); assert_string_equal("prg", cfg.media_prg); assert_success(exec_commands("set mediaprg=", &lwin, CIT_COMMAND)); assert_string_equal("", cfg.media_prg); }
TEST(symlinks_in_paths_are_not_resolved, IF(not_windows)) { char canonic_path[PATH_MAX + 1]; char buf[PATH_MAX + 1]; assert_success(os_mkdir(SANDBOX_PATH "/dir1", 0700)); assert_success(os_mkdir(SANDBOX_PATH "/dir1/dir2", 0700)); /* symlink() is not available on Windows, but the rest of the code is fine. */ #ifndef _WIN32 { char src[PATH_MAX + 1], dst[PATH_MAX + 1]; make_abs_path(src, sizeof(src), SANDBOX_PATH, "dir1/dir2", saved_cwd); make_abs_path(dst, sizeof(dst), SANDBOX_PATH, "dir-link", saved_cwd); assert_success(symlink(src, dst)); } #endif assert_success(chdir(SANDBOX_PATH "/dir-link")); make_abs_path(buf, sizeof(buf), SANDBOX_PATH, "dir-link", saved_cwd); to_canonic_path(buf, "/fake-root", lwin.curr_dir, sizeof(lwin.curr_dir)); to_canonic_path(sandbox, "/fake-root", canonic_path, sizeof(canonic_path)); /* :mkdir */ (void)exec_commands("mkdir ../dir", &lwin, CIT_COMMAND); restore_cwd(saved_cwd); saved_cwd = save_cwd(); assert_success(rmdir(SANDBOX_PATH "/dir")); /* :clone file name. */ create_file(SANDBOX_PATH "/dir-link/file"); populate_dir_list(&lwin, 1); (void)exec_commands("clone ../file-clone", &lwin, CIT_COMMAND); restore_cwd(saved_cwd); saved_cwd = save_cwd(); assert_success(remove(SANDBOX_PATH "/file-clone")); assert_success(remove(SANDBOX_PATH "/dir-link/file")); /* :colorscheme */ make_abs_path(cfg.colors_dir, sizeof(cfg.colors_dir), TEST_DATA_PATH, "scripts/", saved_cwd); snprintf(buf, sizeof(buf), "colorscheme set-env %s/../dir-link/..", sandbox); assert_success(exec_commands(buf, &lwin, CIT_COMMAND)); cs_load_defaults(); /* :cd */ assert_success(exec_commands("cd ../dir-link/..", &lwin, CIT_COMMAND)); assert_string_equal(canonic_path, lwin.curr_dir); restore_cwd(saved_cwd); saved_cwd = save_cwd(); assert_success(remove(SANDBOX_PATH "/dir-link")); assert_success(rmdir(SANDBOX_PATH "/dir1/dir2")); assert_success(rmdir(SANDBOX_PATH "/dir1")); }
static void prvHouseKeepTask(void *pvParameters ) { configASSERT( ( ( unsigned long ) pvParameters ) == HK_PARAMETER ); /* As SysTick will be approx. 1kHz, Num = 1000 * 60 * 60 = 1 hour.*/ int x; uint8_t i; uint8_t command; uint8_t passkey = 1234, addr = 0x80; new_hk_msg_high = 0; new_hk_msg_low = 0; current_hk_fullf = 0; current_hk_definitionf = 0; // Default definition param_report_requiredf = 0; collection_interval0 = 30; collection_interval1 = 30; clear_current_hk(); clear_current_command(); setup_default_definition(); set_definition(DEFAULT); clear_alternate_hk_definition(); set_hk_mem_offset(); /* @non-terminating@ */ for( ;; ) { exec_commands(); request_housekeeping_all(); store_housekeeping(); send_hk_as_tm(); if(param_report_requiredf) send_param_report(); } }
/* Returns non-zero on error. */ static int source_file_internal(FILE *fp, const char filename[]) { char line[MAX_VIFMRC_LINE_LEN + 1]; char *next_line = NULL; int line_num; if(fgets(line, sizeof(line), fp) == NULL) { /* File is empty. */ return 0; } chomp(line); line_num = 1; for(;;) { char *p; int line_num_delta = 0; while((p = next_line = read_line(fp, next_line)) != NULL) { line_num_delta++; p = skip_whitespace(p); if(*p == '"') continue; else if(*p == '\\') strncat(line, p + 1, sizeof(line) - strlen(line) - 1); else break; } if(exec_commands(line, curr_view, GET_COMMAND) < 0) { show_sourcing_error(filename, line_num); } if(curr_stats.sourcing_state == SOURCING_FINISHING) break; if(p == NULL) { /* Artificially increment line number to simulate as if all that happens * after the loop relates to something past end of the file. */ line_num++; break; } copy_str(line, sizeof(line), p); line_num += line_num_delta; } free(next_line); if(commands_block_finished() != 0) { show_sourcing_error(filename, line_num); } return 0; }
/* Windows has various limitations on characters used in file names. */ TEST(tilde_is_expanded_after_negation, IF(not_windows)) { char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/~", sandbox); assert_success(exec_commands("let $a = 'x'", &lwin, CIT_COMMAND)); assert_success(os_mkdir(path, 0700)); assert_success(exec_commands("auto DirEnter !~ let $a = 1", &lwin, CIT_COMMAND)); assert_string_equal("x", env_get("a")); assert_true(change_directory(curr_view, path) >= 0); assert_string_equal("1", env_get("a")); assert_success(rmdir(path)); }
/* Executes list of startup commands. */ static void exec_startup_commands(const args_t *args) { size_t i; for(i = 0; i < args->ncmds; ++i) { (void)exec_commands(args->cmds[i], curr_view, CIT_COMMAND); } }
TEST(pattern_anding_and_orring, IF(has_mime_type_detection)) { char cmd[1024]; assoc_records_t ft; ft_init(&prog_exists); snprintf(cmd, sizeof(cmd), "filetype {two-lines}<text/plain>,<%s>{binary-data} app", get_mimetype(TEST_DATA_PATH "/read/binary-data")); assert_success(exec_commands(cmd, &lwin, CIT_COMMAND)); snprintf(cmd, sizeof(cmd), "fileviewer {two-lines}<text/plain>,<%s>{binary-data} viewer", get_mimetype(TEST_DATA_PATH "/read/binary-data")); assert_success(exec_commands(cmd, &lwin, CIT_COMMAND)); ft = ft_get_all_programs(TEST_DATA_PATH "/read/two-lines"); assert_int_equal(1, ft.count); if(ft.count == 1) { assert_string_equal("app", ft.list[0].command); } ft_assoc_records_free(&ft); ft = ft_get_all_programs(TEST_DATA_PATH "/read/binary-data"); assert_int_equal(1, ft.count); if(ft.count == 1) { assert_string_equal("app", ft.list[0].command); } ft_assoc_records_free(&ft); ft = ft_get_all_programs(TEST_DATA_PATH "/read/utf8-bom"); assert_int_equal(0, ft.count); ft_assoc_records_free(&ft); assert_string_equal("viewer", ft_get_viewer(TEST_DATA_PATH "/read/two-lines")); assert_string_equal("viewer", ft_get_viewer(TEST_DATA_PATH "/read/binary-data")); assert_string_equal(NULL, ft_get_viewer(TEST_DATA_PATH "/read/utf8-bom")); ft_reset(0); }
REGISTER_MAIN_END /* ========================================================================= */ int main(){ ::MaxApplZone(); for (int i = 1; i <= 10; i++) ::MoreMasters(); (void) exec_commands(); return 0; }
/* Executes list of startup commands. */ static void exec_startup_commands(const args_t *args) { size_t i; for(i = 0; i < args->ncmds; ++i) { /* Make sure we're executing commands in correct directory. */ (void)vifm_chdir(flist_get_dir(curr_view)); (void)exec_commands(args->cmds[i], curr_view, CIT_COMMAND); } }
/* Executes the command of the type. */ static void execute_extcmd(const char command[], CmdInputType type) { if(type == CIT_COMMAND) { curr_stats.save_msg = exec_commands(command, curr_view, type); } else { curr_stats.save_msg = exec_command(command, curr_view, type); } }
TEST(find_command, IF(not_windows)) { opt_handlers_setup(); replace_string(&cfg.shell, "/bin/sh"); assert_success(chdir(TEST_DATA_PATH)); strcpy(lwin.curr_dir, test_data); assert_success(exec_commands("set findprg='find %s %a %u'", &lwin, CIT_COMMAND)); /* Nothing to repeat. */ assert_failure(exec_commands("find", &lwin, CIT_COMMAND)); assert_success(exec_commands("find a", &lwin, CIT_COMMAND)); assert_int_equal(3, lwin.list_rows); assert_success(exec_commands("find . -name aaa", &lwin, CIT_COMMAND)); assert_int_equal(1, lwin.list_rows); assert_success(exec_commands("find -name '*.vifm'", &lwin, CIT_COMMAND)); assert_int_equal(4, lwin.list_rows); view_teardown(&lwin); view_setup(&lwin); /* Repeat last search. */ strcpy(lwin.curr_dir, test_data); assert_success(exec_commands("find", &lwin, CIT_COMMAND)); assert_int_equal(4, lwin.list_rows); opt_handlers_teardown(); }
TEST(grep_command, IF(not_windows)) { opt_handlers_setup(); replace_string(&cfg.shell, "/bin/sh"); assert_success(chdir(TEST_DATA_PATH "/scripts")); assert_non_null(get_cwd(lwin.curr_dir, sizeof(lwin.curr_dir))); assert_success(exec_commands("set grepprg='grep -n -H -r %i %a %s %u'", &lwin, CIT_COMMAND)); /* Nothing to repeat. */ assert_failure(exec_commands("grep", &lwin, CIT_COMMAND)); assert_success(exec_commands("grep command", &lwin, CIT_COMMAND)); assert_int_equal(2, lwin.list_rows); /* Repeat last grep. */ assert_success(exec_commands("grep!", &lwin, CIT_COMMAND)); assert_int_equal(1, lwin.list_rows); opt_handlers_teardown(); }
static void prvMemoryManageTask(void *pvParameters ) { configASSERT( ( ( unsigned long ) pvParameters ) == MM_PARAMETER ); minute_count = 0; clear_current_command(); SPI_HEALTH1 = 1; SPI_HEALTH2 = 1; SPI_HEALTH3 = 1; memory_wash(); // This will cause the SPI health variables to be updated immediately. /* @non-terminating@ */ for( ;; ) { minute_count++; if(minute_count == 90) // Maximum wait time for a wash would be 90 minutes. memory_wash(); exec_commands(); } }
/* Initiates leaving of command-line mode and reverting related changes in other * parts of the interface. */ static void cmd_ctrl_c(key_info_t key_info, keys_info_t *keys_info) { stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if(input_stat.line != NULL) { char *mbstr = to_multibyte(input_stat.line); save_input_to_history(keys_info, mbstr); free(mbstr); input_stat.line[0] = L'\0'; } if(sub_mode != FILTER_SUBMODE) { input_line_changed(); } leave_cmdline_mode(); if(prev_mode == VISUAL_MODE) { if(!input_stat.search_mode) { leave_visual_mode(curr_stats.save_msg, 1, 1); move_to_list_pos(curr_view, check_mark_directory(curr_view, '<')); } } if(sub_mode == CMD_SUBMODE) { curr_stats.save_msg = exec_commands("", curr_view, GET_COMMAND); } else if(sub_mode == FILTER_SUBMODE) { local_filter_cancel(curr_view); curr_view->top_line = input_stat.old_top; curr_view->list_pos = input_stat.old_pos; redraw_current_view(); } }
int main(void) { int exec_ret; while (1) { fputs("$", stdout); input = read_input(); if (input == NULL) { /* user entered ctrl+D, exit gracefully */ cleanup_and_exit(EXIT_SUCCESS); } if (strlen(input) > 0 && !is_blank(input) && input[0] != '|') { char *linecopy = strdup(input); struct commands *commands = parse_commands_with_pipes(input); /* add pipeline cmds & other commands to history */ if (commands->cmd_count > 1 || !is_history(input)) add_to_history(linecopy); free(linecopy); exec_ret = exec_commands(commands); cleanup_commands(commands); } free(input); /* get ready to exit */ if (exec_ret == -1) break; } cleanup_and_exit(EXIT_SUCCESS); return 0; }
TEST(symlinks_are_not_resolved_in_cwd, IF(not_windows)) { #ifndef _WIN32 assert_success(symlink(TEST_DATA_PATH "/existing-files", SANDBOX_PATH "/link")); #endif lwin.list_rows = 1; lwin.list_pos = 0; lwin.dir_entry = dynarray_cextend(NULL, lwin.list_rows*sizeof(*lwin.dir_entry)); lwin.dir_entry[0].name = strdup("a"); lwin.dir_entry[0].origin = &lwin.curr_dir[0]; lwin.dir_entry[0].type = FT_REG; lwin.selected_files = 0; /* Select only directories. */ assert_success(exec_commands("select !echo a", &lwin, CIT_COMMAND)); assert_int_equal(1, lwin.selected_files); assert_true(lwin.dir_entry[0].selected); assert_success(remove(SANDBOX_PATH "/link")); }
static void cmd_ctrl_c(key_info_t key_info, keys_info_t *keys_info) { stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if(input_stat.line != NULL) input_stat.line[0] = L'\0'; input_line_changed(); leave_cmdline_mode(); if(prev_mode == VISUAL_MODE) { leave_visual_mode(curr_stats.save_msg, 1, 1); move_to_list_pos(curr_view, check_mark_directory(curr_view, '<')); } if(sub_mode == CMD_SUBMODE) { int save_hist = !keys_info->mapped; curr_stats.save_msg = exec_commands("", curr_view, save_hist, GET_COMMAND); } }
static void prvTimeManageTask( void *pvParameters ) { configASSERT( ( ( unsigned long ) pvParameters ) == TIME_MANAGE_PARAMETER ); minute_count = 0; report_timeout = 60; // Produce a time report once every 60 minutes. /* @non-terminating@ */ for( ;; ) { if (rtc_triggered_a2()) { rtc_get(&time); minute_count++; if(minute_count == report_timeout) report_time(); update_absolute_time(); broadcast_minute(); rtc_reset_a2(); } exec_commands(); } }
static void cmd_ctrl_m(key_info_t key_info, keys_info_t *keys_info) { char* p; int save_hist = !keys_info->mapped; stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if((!input_stat.line || !input_stat.line[0]) && sub_mode == MENU_CMD_SUBMODE) { leave_cmdline_mode(); return; } p = input_stat.line ? to_multibyte(input_stat.line) : NULL; leave_cmdline_mode(); if(prev_mode == VISUAL_MODE && sub_mode != VSEARCH_FORWARD_SUBMODE && sub_mode != VSEARCH_BACKWARD_SUBMODE) leave_visual_mode(curr_stats.save_msg, 1, 0); if(sub_mode == CMD_SUBMODE || sub_mode == MENU_CMD_SUBMODE) { char* s = (p != NULL) ? p : ""; while(*s == ' ' || *s == ':') s++; if(sub_mode == CMD_SUBMODE) curr_stats.save_msg = exec_commands(s, curr_view, save_hist, GET_COMMAND); else curr_stats.save_msg = exec_commands(s, curr_view, save_hist, GET_MENU_COMMAND); } else if(sub_mode == PROMPT_SUBMODE) { prompt_cb cb; if(p != NULL && p[0] != '\0') save_prompt_history(p); modes_post(); modes_pre(); cb = (prompt_cb)sub_mode_ptr; cb(p); } else if(!cfg.inc_search || prev_mode == VIEW_MODE) { if(sub_mode == SEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_FSEARCH_PATTERN); } else if(sub_mode == SEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_BSEARCH_PATTERN); } else if(sub_mode == MENU_SEARCH_FORWARD_SUBMODE || sub_mode == MENU_SEARCH_BACKWARD_SUBMODE) { curr_stats.need_redraw = 1; search_menu_list(p, sub_mode_ptr); } else if(sub_mode == VSEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VFSEARCH_PATTERN); } else if(sub_mode == VSEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VBSEARCH_PATTERN); } else if(sub_mode == VIEW_SEARCH_FORWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VWFSEARCH_PATTERN); } else if(sub_mode == VIEW_SEARCH_BACKWARD_SUBMODE) { curr_stats.save_msg = exec_command(p, curr_view, GET_VWBSEARCH_PATTERN); } } free(p); }
static void cmd_ctrl_m(key_info_t key_info, keys_info_t *keys_info) { /* TODO: refactor this cmd_ctrl_m() function. */ char* p; stop_completion(); werase(status_bar); wnoutrefresh(status_bar); if((!input_stat.line || !input_stat.line[0]) && sub_mode == MENU_CMD_SUBMODE) { leave_cmdline_mode(); return; } p = input_stat.line ? to_multibyte(input_stat.line) : NULL; leave_cmdline_mode(); if(prev_mode == VISUAL_MODE && sub_mode != VSEARCH_FORWARD_SUBMODE && sub_mode != VSEARCH_BACKWARD_SUBMODE) leave_visual_mode(curr_stats.save_msg, 1, 0); save_input_to_history(keys_info, p); if(sub_mode == CMD_SUBMODE || sub_mode == MENU_CMD_SUBMODE) { char* s = (p != NULL) ? p : ""; while(*s == ' ' || *s == ':') s++; if(sub_mode == CMD_SUBMODE) curr_stats.save_msg = exec_commands(s, curr_view, GET_COMMAND); else curr_stats.save_msg = exec_commands(s, curr_view, GET_MENU_COMMAND); } else if(sub_mode == PROMPT_SUBMODE) { finish_prompt_submode(p); } else if(sub_mode == FILTER_SUBMODE) { if(cfg.inc_search) { local_filter_accept(curr_view); } else { local_filter_apply(curr_view, p); load_saving_pos(curr_view, 1); } } else if(!cfg.inc_search || prev_mode == VIEW_MODE) { switch(sub_mode) { case SEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_FSEARCH_PATTERN); break; case SEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_BSEARCH_PATTERN); break; case VSEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VFSEARCH_PATTERN); break; case VSEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VBSEARCH_PATTERN); break; case VIEW_SEARCH_FORWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VWFSEARCH_PATTERN); break; case VIEW_SEARCH_BACKWARD_SUBMODE: curr_stats.save_msg = exec_command(p, curr_view, GET_VWBSEARCH_PATTERN); break; case MENU_SEARCH_FORWARD_SUBMODE: case MENU_SEARCH_BACKWARD_SUBMODE: curr_stats.need_update = UT_FULL; search_menu_list(p, sub_mode_ptr); break; default: assert(0 && "Unknown command line submode."); break; } } else if(cfg.inc_search && input_stat.search_mode) { /* In case of successful search and 'hlsearch' option set, a message like * "n files selected" is printed automatically. */ if(curr_view->matches == 0 || !cfg.hl_search) { print_search_msg(curr_view, is_backward_search(sub_mode)); curr_stats.save_msg = 1; } } free(p); }
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 mod_setup(unsigned int setupfr) { //default key bindings exec_commands("defaults"); //make the mother object fr[setupfr].objs[0] = (object){ mother_type, 0, 0, sizeof(mother), malloc(sizeof(mother)) }; memset( fr[setupfr].objs[0].data, 0, sizeof(mother) ); //make default context object (map) fr[setupfr].objs[1] = (object){ context_type, OBJF_REFC, 0, sizeof(context), malloc(sizeof(context)) }; context *co = fr[setupfr].objs[1].data; co->bsx = co->bsy = co->bsz = 16; co->x = co->y = co->z = 15; co->tileuw = 48; co->tileuh = 24; co->projection = DIMETRIC; int volume = co->x * co->y * co->z; co->map = hack_map = malloc( (sizeof *co->map ) * volume ); //FIXME remove hack co->dmap = hack_dmap = malloc( (sizeof *co->dmap) * volume ); memset( co->map, 0, (sizeof *co->map ) * volume ); memset( co->dmap, 0, (sizeof *co->dmap) * volume ); int i; for( i=0; i<volume; i++ ) { co->map[ i].spr = 0; co->dmap[i].flags = CBF_NULL; } load_context("noise", 1, setupfr); //load a default map //make some dummys #define MAYBE_A_DUMMY(i,x,y,w,h) { \ dummy *du; \ fr[setupfr].objs[i+20].type = dummy_type; \ fr[setupfr].objs[i+20].flags = OBJF_POS|OBJF_VEL|OBJF_HULL|OBJF_VIS|OBJF_PLAT|OBJF_CLIP| \ OBJF_BNDX|OBJF_BNDZ|OBJF_BNDB; \ fr[setupfr].objs[i+20].context = 1; \ fr[setupfr].objs[i+20].size = sizeof *du; \ du = fr[setupfr].objs[i+20].data = malloc(sizeof *du); \ du->pos = (V){x*8,y*8,0}; \ du->vel = (V){0,0,0}; \ du->hull[0] = (V){-w*8,-h*8,-8}; \ du->hull[1] = (V){ w*8, h*8, 8}; \ du->model = 0; } MAYBE_A_DUMMY(20, 3,-25,1,1); MAYBE_A_DUMMY(21, 3,-20,1,1); MAYBE_A_DUMMY(22, 3,-15,1,1); MAYBE_A_DUMMY(23, 3,-10,1,1); MAYBE_A_DUMMY(24, 5,-15,1,1); MAYBE_A_DUMMY(25, 9,-15,1,1); MAYBE_A_DUMMY(26, 43,-20,1,1); MAYBE_A_DUMMY(27, 43,-15,1,1); MAYBE_A_DUMMY(28, 45,-25,1,1); MAYBE_A_DUMMY(29, 45,-20,1,1); MAYBE_A_DUMMY(30, 45,-15,1,1); #undef MAYBE_A_DUMMY fr[setupfr+1].cmds[0].flags |= CMDF_NEW; //server is a client echo("Default controls: \\#F80A, S, Numpad Arrows, F11"); }
TEARDOWN() { assert_success(exec_commands("delbmarks!", &lwin, CIT_COMMAND)); }
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); }
assert_success(exec_commands("set classify=12345678::{*.c}::12345678", &lwin, CIT_COMMAND)); } TEST(classify_pattern_list) { dir_entry_t entry = { .name = "binary-data", .origin = TEST_DATA_PATH "/test-data/read", .name_dec_num = -1, }; const char *prefix, *suffix; assert_success(exec_commands("set classify=<::{*-data}{*-data}::>", &lwin, CIT_COMMAND)); ui_get_decors(&entry, &prefix, &suffix); assert_string_equal("<", prefix); assert_string_equal(">", suffix); } TEST(classify_can_be_set_to_empty_value) { dir_entry_t entry = { .name = "binary-data", .origin = TEST_DATA_PATH "/test-data/read", .name_dec_num = -1, }; const char *prefix, *suffix;
/* Responsible for handling the history shell builtin */ int handle_history(struct commands *cmds, struct command *cmd) { /* just `history` executed? print history */ if (cmd->argc == 1) { int i; for (i = 0; i < history_len ; i++) { // write to a file descriptor - output_fd printf("%d %s\n", i, history[i]); } return 1; } if (cmd->argc > 1) { /* clear history */ if (strcmp(cmd->argv[1], "-c") == 0) { clear(); return 0; } /* exec command from history */ char *end; long loffset; int offset; loffset = strtol(cmd->argv[1], &end, 10); if (end == cmd->argv[1]) { fprintf(stderr, "error: cannot convert to number\n"); return 1; } offset = (int) loffset; if (offset > history_len) { fprintf(stderr, "error: offset > number of items\n"); return 1; } /* parse execute command */ char *line = strdup(history[offset]); if (line == NULL) return 1; struct commands *new_commands = parse_commands_with_pipes(line); /* set pointers so that these can be freed when * child processes die during execution */ parent_cmd = cmd; temp_line = line; parent_cmds = cmds; exec_commands(new_commands); cleanup_commands(new_commands); free(line); /* reset */ parent_cmd = NULL; temp_line = NULL; parent_cmds = NULL; return 0; } return 0; }