/* *INDENT-OFF* */ END_PARAMETRIZED_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ /* @Test */ /* *INDENT-OFF* */ START_TEST (the_file_is_remote_but_empty) /* *INDENT-ON* */ { /* given */ vfs_path_t *filename_vpath; filename_vpath = NULL; vfs_file_is_local__return_value = FALSE; /* when */ execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath); /* then */ mctest_assert_str_eq (do_execute__lc_shell__captured, NULL); mctest_assert_str_eq (do_execute__command__captured, NULL); mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 2); mctest_assert_int_eq (vfs_path_equal (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0), vfs_get_raw_current_dir ()), TRUE); fail_unless (g_ptr_array_index (vfs_file_is_local__vpath__captured, 1) == NULL, "\nParameter for second call to vfs_file_is_local() should be NULL!"); fail_unless (mc_getlocalcopy__pathname_vpath__captured == NULL, "\nFunction mc_getlocalcopy() shouldn't be called!"); vfs_path_free (filename_vpath); }
void do_edit_at_line (const char *what, gboolean internal, int start_line) { static const char *editor = NULL; #ifdef USE_INTERNAL_EDIT if (internal) edit_file (what, start_line); else #else (void) start_line; #endif /* USE_INTERNAL_EDIT */ { if (editor == NULL) { editor = getenv ("EDITOR"); if (editor == NULL) editor = get_default_editor (); } execute_with_vfs_arg (editor, what); } if (mc_global.mc_run_mode == MC_RUN_FULL) update_panels (UP_OPTIMIZE, UP_KEEPSEL); #ifdef USE_INTERNAL_EDIT if (use_internal_edit) dialog_switch_process_pending (); else #endif /* USE_INTERNAL_EDIT */ repaint_screen (); }
/* *INDENT-OFF* */ START_PARAMETRIZED_TEST (the_file_is_local, the_file_is_local_ds) /* *INDENT-ON* */ { /* given */ vfs_path_t *filename_vpath; filename_vpath = vfs_path_from_str (data->input_path); vfs_file_is_local__return_value = TRUE; /* when */ execute_with_vfs_arg ("cmd_for_local_file", filename_vpath); /* then */ mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_local_file"); mctest_assert_str_eq (do_execute__command__captured, data->input_path); mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1); { const vfs_path_t *tmp_vpath; tmp_vpath = (data->input_path == NULL) ? vfs_get_raw_current_dir () : filename_vpath; mctest_assert_int_eq (vfs_path_equal (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0), tmp_vpath), TRUE); } mctest_assert_int_eq (do_execute__flags__captured, EXECUTE_INTERNAL); fail_unless (mc_getlocalcopy__pathname_vpath__captured == NULL, "\nFunction mc_getlocalcopy() shouldn't be called!"); vfs_path_free (filename_vpath); }
int view_file_at_line (const char *filename, int plain_view, int internal, int start_line) { static const char *viewer = NULL; int move_dir = 0; if (plain_view) { int changed_hex_mode = 0; int changed_nroff_flag = 0; int changed_magic_flag = 0; altered_hex_mode = 0; altered_nroff_flag = 0; altered_magic_flag = 0; if (default_hex_mode) changed_hex_mode = 1; if (default_nroff_flag) changed_nroff_flag = 1; if (default_magic_flag) changed_magic_flag = 1; default_hex_mode = 0; default_nroff_flag = 0; default_magic_flag = 0; mc_internal_viewer (NULL, filename, &move_dir, start_line); if (changed_hex_mode && !altered_hex_mode) default_hex_mode = 1; if (changed_nroff_flag && !altered_nroff_flag) default_nroff_flag = 1; if (changed_magic_flag && !altered_magic_flag) default_magic_flag = 1; repaint_screen (); return move_dir; } if (internal) { char view_entry[BUF_TINY]; if (start_line != 0) g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line); else strcpy (view_entry, "View"); if (regex_command (filename, view_entry, &move_dir) == 0) { mc_internal_viewer (NULL, filename, &move_dir, start_line); repaint_screen (); } } else { if (!viewer) { viewer = getenv ("VIEWER"); if (!viewer) viewer = getenv ("PAGER"); if (!viewer) viewer = "view"; } execute_with_vfs_arg (viewer, filename); } return move_dir; }
/* *INDENT-OFF* */ END_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ /* @Test */ /* *INDENT-OFF* */ START_TEST (the_file_is_remote) /* *INDENT-ON* */ { /* given */ vfs_path_t *filename_vpath, *local_vpath, *local_vpath_should_be_freeing; filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt"); local_vpath = vfs_path_from_str ("/tmp/blabla-editme.txt"); local_vpath_should_be_freeing = vfs_path_clone (local_vpath); vfs_file_is_local__return_value = FALSE; mc_getlocalcopy__return_value = local_vpath_should_be_freeing; /* when */ execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath); /* then */ mctest_assert_str_eq (do_execute__lc_shell__captured, "cmd_for_remote_file"); mctest_assert_str_eq (do_execute__command__captured, "/tmp/blabla-editme.txt"); mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1); mctest_assert_int_eq (vfs_path_equal (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0), filename_vpath), TRUE); mctest_assert_int_eq (vfs_path_equal (mc_getlocalcopy__pathname_vpath__captured, filename_vpath), TRUE); mctest_assert_int_eq (mc_stat__vpath__captured->len, 2); mctest_assert_int_eq (vfs_path_equal (g_ptr_array_index (mc_stat__vpath__captured, 0), local_vpath), TRUE); mctest_assert_int_eq (vfs_path_equal (g_ptr_array_index (mc_stat__vpath__captured, 0), g_ptr_array_index (mc_stat__vpath__captured, 1)), TRUE); mctest_assert_int_eq (vfs_path_equal (mc_ungetlocalcopy__pathname_vpath__captured, filename_vpath), TRUE); mctest_assert_int_eq (vfs_path_equal (mc_ungetlocalcopy__local_vpath__captured, local_vpath), TRUE); vfs_path_free (filename_vpath); vfs_path_free (local_vpath); }
/* *INDENT-OFF* */ END_TEST /* *INDENT-ON* */ /* --------------------------------------------------------------------------------------------- */ /* @Test */ /* *INDENT-OFF* */ START_TEST (the_file_is_remote_fail_to_create_local_copy) /* *INDENT-ON* */ { /* given */ vfs_path_t *filename_vpath; filename_vpath = vfs_path_from_str ("/ftp://some.host/editme.txt"); vfs_file_is_local__return_value = FALSE; mc_getlocalcopy__return_value = NULL; /* when */ execute_with_vfs_arg ("cmd_for_remote_file", filename_vpath); /* then */ mctest_assert_str_eq (do_execute__lc_shell__captured, NULL); mctest_assert_str_eq (do_execute__command__captured, NULL); mctest_assert_int_eq (vfs_file_is_local__vpath__captured->len, 1); mctest_assert_int_eq (vfs_path_equal (g_ptr_array_index (vfs_file_is_local__vpath__captured, 0), filename_vpath), TRUE); mctest_assert_int_eq (vfs_path_equal (mc_getlocalcopy__pathname_vpath__captured, filename_vpath), TRUE); mctest_assert_str_eq (message_title__captured, _("Error")); mctest_assert_str_eq (message_text__captured, _("Cannot fetch a local copy of /ftp://some.host/editme.txt")); vfs_path_free (filename_vpath); }
void do_edit_at_line (const char *what, int start_line) { static const char *editor = NULL; #ifdef USE_INTERNAL_EDIT if (use_internal_edit){ edit_file (what, start_line); update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); return; } #endif /* USE_INTERNAL_EDIT */ if (!editor){ editor = getenv ("EDITOR"); if (!editor) editor = get_default_editor (); } execute_with_vfs_arg (editor, what); update_panels (UP_OPTIMIZE, UP_KEEPSEL); repaint_screen (); }
int view_file_at_line (const char *filename, int plain_view, int internal, int start_line) { static const char *viewer = NULL; int move_dir = 0; if (plain_view) { int changed_hex_mode = 0; int changed_nroff_flag = 0; int changed_magic_flag = 0; mcview_altered_hex_mode = 0; mcview_altered_nroff_flag = 0; mcview_altered_magic_flag = 0; if (mcview_default_hex_mode) changed_hex_mode = 1; if (mcview_default_nroff_flag) changed_nroff_flag = 1; if (mcview_default_magic_flag) changed_magic_flag = 1; mcview_default_hex_mode = 0; mcview_default_nroff_flag = 0; mcview_default_magic_flag = 0; switch (mcview_viewer (NULL, filename, start_line)) { case MCVIEW_WANT_NEXT: move_dir = 1; break; case MCVIEW_WANT_PREV: move_dir = -1; break; default: move_dir = 0; } if (changed_hex_mode && !mcview_altered_hex_mode) mcview_default_hex_mode = 1; if (changed_nroff_flag && !mcview_altered_nroff_flag) mcview_default_nroff_flag = 1; if (changed_magic_flag && !mcview_altered_magic_flag) mcview_default_magic_flag = 1; dialog_switch_process_pending (); } else if (internal) { char view_entry[BUF_TINY]; if (start_line != 0) g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line); else strcpy (view_entry, "View"); if (regex_command (filename, view_entry, &move_dir) == 0) { switch (mcview_viewer (NULL, filename, start_line)) { case MCVIEW_WANT_NEXT: move_dir = 1; break; case MCVIEW_WANT_PREV: move_dir = -1; break; default: move_dir = 0; } dialog_switch_process_pending (); } } else { if (viewer == NULL) { viewer = getenv ("VIEWER"); if (viewer == NULL) viewer = getenv ("PAGER"); if (viewer == NULL) viewer = "view"; } execute_with_vfs_arg (viewer, filename); } return move_dir; }