From 80248891265aaf1144fca982168fcfb4b9e1e4b8 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 1 May 2010 16:37:06 +0400 Subject: [PATCH] Added type for MC viewer exit codes. Changed MC viewer run interface. Signed-off-by: Andrew Borodin --- src/cmd.c | 52 +++++++++++++++++++++++++++++++------------ src/ext.c | 25 ++++++++++++++++----- src/screen.c | 2 +- src/user.c | 5 +---- src/viewer/mcviewer.c | 16 +++++++------ src/viewer/mcviewer.h | 14 ++++++++---- 6 files changed, 78 insertions(+), 36 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index 17548303d..014249fee 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -121,7 +121,6 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start static const char *viewer = NULL; int move_dir = 0; - if (plain_view) { int changed_hex_mode = 0; @@ -140,17 +139,29 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start mcview_default_hex_mode = 0; mcview_default_nroff_flag = 0; mcview_default_magic_flag = 0; - mcview_viewer (NULL, filename, &move_dir, start_line); + + 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; + repaint_screen (); - return move_dir; } - if (internal) + else if (internal) { char view_entry[BUF_TINY]; @@ -161,22 +172,35 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start if (regex_command (filename, view_entry, &move_dir) == 0) { - mcview_viewer (NULL, filename, &move_dir, start_line); + 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; + } + repaint_screen (); } } else { - if (!viewer) + if (viewer == NULL) { viewer = getenv ("VIEWER"); - if (!viewer) + if (viewer == NULL) viewer = getenv ("PAGER"); - if (!viewer) + if (viewer == NULL) viewer = "view"; } + execute_with_vfs_arg (viewer, filename); } + return move_dir; } @@ -300,12 +324,12 @@ filtered_view_cmd (void) input_dialog (_("Filtered view"), _("Filter command and arguments:"), MC_HISTORY_FM_FILTERED_VIEW, selection (current_panel)->fname); - if (!command) - return; - mcview_viewer (command, "", NULL, 0); - - g_free (command); + if (command != NULL) + { + mcview_viewer (command, "", 0); + g_free (command); + } } void @@ -345,7 +369,7 @@ do_edit (const char *what) void edit_cmd (void) { - if (regex_command (selection (current_panel)->fname, "Edit", 0) == 0) + if (regex_command (selection (current_panel)->fname, "Edit", NULL) == 0) do_edit (selection (current_panel)->fname); } diff --git a/src/ext.c b/src/ext.c index 8bcf21e80..9d78a2ba4 100644 --- a/src/ext.c +++ b/src/ext.c @@ -283,6 +283,8 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st if (run_view) { + mcview_ret_t ret; + mcview_altered_hex_mode = 0; mcview_altered_nroff_flag = 0; if (def_hex_mode != mcview_default_hex_mode) @@ -295,17 +297,30 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st */ if (written_nonspace) { - mcview_viewer (cmd, filename, move_dir, start_line); + ret = mcview_viewer (cmd, filename, start_line); unlink (file_name); } else - { - mcview_viewer (NULL, filename, move_dir, start_line); - } + ret = mcview_viewer (NULL, filename, start_line); + + if (move_dir != NULL) + switch (ret) + { + 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 = def_hex_mode; if (changed_nroff_flag && !mcview_altered_nroff_flag) mcview_default_nroff_flag = def_nroff_flag; + repaint_screen (); } else if (is_cd) @@ -331,11 +346,9 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st { handle_console (CONSOLE_SAVE); if (output_lines && keybar_visible) - { show_console_contents (output_start_y, LINES - keybar_visible - output_lines - 1, LINES - keybar_visible - 1); - } } } diff --git a/src/screen.c b/src/screen.c index e2de51f71..ae9f2476a 100644 --- a/src/screen.c +++ b/src/screen.c @@ -2509,7 +2509,7 @@ do_enter_on_file_entry (file_entry * fe) } /* Try associated command */ - if (regex_command (fe->fname, "Open", 0) != 0) + if (regex_command (fe->fname, "Open", NULL) != 0) return 1; /* Check if the file is executable */ diff --git a/src/user.c b/src/user.c index 6d1aa51e9..c7d306026 100644 --- a/src/user.c +++ b/src/user.c @@ -775,10 +775,7 @@ execute_menu_command (WEdit * edit_widget, const char *commands) fclose (cmd_file); chmod (file_name, S_IRWXU); if (run_view) - { - run_view = 0; - mcview_viewer (file_name, NULL, &run_view, 0); - } + mcview_viewer (file_name, NULL, 0); else { /* execute the command indirectly to allow execution even diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index 2b899a319..51c51ac70 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -237,12 +237,13 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel) /* --------------------------------------------------------------------------------------------- */ /* Real view only */ -int -mcview_viewer (const char *command, const char *file, int *move_dir_p, int start_line) +mcview_ret_t +mcview_viewer (const char *command, const char *file, int start_line) { gboolean succeeded; mcview_t *lc_mcview; Dlg_head *view_dlg; + mcview_ret_t ret; /* Create dialog and widgets, put them on the dialog */ view_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, NULL, mcview_dialog_callback, @@ -259,17 +260,18 @@ mcview_viewer (const char *command, const char *file, int *move_dir_p, int start if (succeeded) { run_dlg (view_dlg); - if (move_dir_p) - *move_dir_p = lc_mcview->move_dir; + + ret = lc_mcview->move_dir == 0 ? MCVIEW_EXIT_OK : + lc_mcview->move_dir > 0 ? MCVIEW_WANT_NEXT : MCVIEW_WANT_PREV; } else { - if (move_dir_p) - *move_dir_p = 0; + view_dlg->state = DLG_CLOSED; + ret = MCVIEW_EXIT_FAILURE; } destroy_dlg (view_dlg); - return succeeded; + return ret; } /* {{{ Miscellaneous functions }}} */ diff --git a/src/viewer/mcviewer.h b/src/viewer/mcviewer.h index c9fa0202b..135efb28c 100644 --- a/src/viewer/mcviewer.h +++ b/src/viewer/mcviewer.h @@ -11,6 +11,14 @@ struct mcview_struct; +typedef enum +{ + MCVIEW_EXIT_FAILURE = -1, + MCVIEW_EXIT_OK = 0, + MCVIEW_WANT_NEXT, + MCVIEW_WANT_PREV +} mcview_ret_t; + /*** enums *************************************************************/ /*** structures declarations (and typedefs of structures)***************/ @@ -41,11 +49,9 @@ extern struct mcview_struct *mcview_new (int y, int x, int lines, int cols, gboo /* Shows {file} or the output of {command} in the internal viewer, - * starting in line {start_line}. {move_dir_p} may be NULL or - * point to a variable that will receive the direction in which the user - * wants to move (-1 = previous file, 1 = next file, 0 = do nothing). + * starting in line {start_line}. */ -extern int mcview_viewer (const char *command, const char *file, int *move_dir_p, int start_line); +extern mcview_ret_t mcview_viewer (const char *command, const char *file, int start_line); extern gboolean mcview_load (struct mcview_struct *, const char *, const char *, int);