From 176ae14711b02c89775c33cc65d5da5ffff82e79 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 4 Mar 2012 17:11:55 +0300 Subject: [PATCH] Handle error of mc main loop. Signed-off-by: Andrew Borodin --- src/diffviewer/ydiff.c | 6 +++--- src/filemanager/midnight.c | 23 +++++++++++++++++------ src/filemanager/midnight.h | 2 +- src/main.c | 11 ++++++----- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 4b7893b2e..1cb1dc951 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -3319,7 +3319,7 @@ diff_view (const char *file1, const char *file2, const char *label1, const char if ((error != 0) || (dview_dlg->state == DLG_CLOSED)) destroy_dlg (dview_dlg); - return error; + return error == 0 ? 1 : 0; } /* --------------------------------------------------------------------------------------------- */ @@ -3412,8 +3412,8 @@ dview_diff_cmd (void) g_free (file1); g_free (file0); - if (rv != 0) - message (1, MSG_ERROR, _("Two files are needed to compare")); + if (rv == 0) + message (D_ERROR, MSG_ERROR, _("Two files are needed to compare")); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 3734e73af..466b14638 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -936,32 +936,38 @@ prepend_cwd_on_local (const char *filename) /** Invoke the internal view/edit routine with: * the default processing and forcing the internal viewer/editor */ -static void +static gboolean mc_maybe_editor_or_viewer (void) { + int ret; + switch (mc_global.mc_run_mode) { #ifdef USE_INTERNAL_EDIT case MC_RUN_EDITOR: - edit_file (mc_run_param0, mc_args__edit_start_line); + ret = edit_file (mc_run_param0, mc_args__edit_start_line); break; #endif /* USE_INTERNAL_EDIT */ case MC_RUN_VIEWER: { char *path; + path = prepend_cwd_on_local (mc_run_param0); view_file (path, 0, 1); g_free (path); + ret = 1; break; } #ifdef USE_DIFF_VIEW case MC_RUN_DIFFVIEWER: - diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1); + ret = diff_view (mc_run_param0, mc_run_param1, mc_run_param0, mc_run_param1); break; #endif /* USE_DIFF_VIEW */ default: - break; + ret = 0; } + + return (ret != 0); } /* --------------------------------------------------------------------------------------------- */ @@ -1629,9 +1635,11 @@ quiet_quit_cmd (void) /* --------------------------------------------------------------------------------------------- */ /** Run the main dialog that occupies the whole screen */ -void +gboolean do_nc (void) { + gboolean ret; + dlg_colors_t midnight_colors; midnight_colors[DLG_COLOR_NORMAL] = mc_skin_color_get ("dialog", "_default_"); @@ -1654,10 +1662,11 @@ do_nc (void) /* Check if we were invoked as an editor or file viewer */ if (mc_global.mc_run_mode != MC_RUN_FULL) - mc_maybe_editor_or_viewer (); + ret = mc_maybe_editor_or_viewer (); else { create_panels_and_run_mc (); + ret = TRUE; /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */ if (mc_args__last_wd_file != NULL && vfs_current_is_local ()) @@ -1682,6 +1691,8 @@ do_nc (void) if ((quit & SUBSHELL_EXIT) == 0) clr_scr (); + + return ret; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/midnight.h b/src/filemanager/midnight.h index 7072887f6..12be488fc 100644 --- a/src/filemanager/midnight.h +++ b/src/filemanager/midnight.h @@ -45,7 +45,7 @@ void load_hint (gboolean force); void change_panel (void); void save_cwds_stat (void); gboolean quiet_quit_cmd (void); -void do_nc (void); +gboolean do_nc (void); /*** inline functions ****************************************************************************/ diff --git a/src/main.c b/src/main.c index 3bdc817b0..610790ccf 100644 --- a/src/main.c +++ b/src/main.c @@ -518,8 +518,10 @@ main (int argc, char *argv[]) mc_prompt = (geteuid () == 0) ? "# " : "$ "; /* Program main loop */ - if (!mc_global.widget.midnight_shutdown) - do_nc (); + if (mc_global.widget.midnight_shutdown) + exit_code = EXIT_SUCCESS; + else + exit_code = do_nc () ? EXIT_SUCCESS : EXIT_FAILURE; /* Save the tree store */ (void) tree_store_save (); @@ -591,17 +593,16 @@ main (int argc, char *argv[]) mc_config_deinit_config_paths (); (void) mc_event_deinit (&error); - if (error != NULL) { fprintf (stderr, _("\nFailed while close:\n%s\n"), error->message); g_error_free (error); - exit (EXIT_FAILURE); + exit_code = EXIT_FAILURE; } (void) putchar ('\n'); /* Hack to make shell's prompt start at left of screen */ - return 0; + return exit_code; } /* --------------------------------------------------------------------------------------------- */ -- 2.11.4.GIT