diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index a82cdf946..ae58e706f 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -3335,7 +3335,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; } /* --------------------------------------------------------------------------------------------- */ @@ -3438,8 +3438,8 @@ dview_diff_cmd (void) vfs_path_free (file1); vfs_path_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 7273a8ba2..8b0455546 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -942,9 +942,11 @@ 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 @@ -953,7 +955,7 @@ mc_maybe_editor_or_viewer (void) vfs_path_t *param_vpath; param_vpath = vfs_path_from_str (mc_run_param0); - edit_file (param_vpath, mc_args__edit_start_line); + ret = edit_file (param_vpath, mc_args__edit_start_line); vfs_path_free (param_vpath); } break; @@ -965,16 +967,19 @@ mc_maybe_editor_or_viewer (void) vpath = prepend_cwd_on_local (mc_run_param0); view_file (vpath, 0, 1); vfs_path_free (vpath); + 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); } /* --------------------------------------------------------------------------------------------- */ @@ -1651,9 +1656,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_"); @@ -1676,10 +1683,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_vpath, so we have to save a copy :) */ if (mc_args__last_wd_file != NULL && vfs_current_is_local ()) @@ -1704,6 +1712,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 ad6891501..4e13d23a0 100644 --- a/src/main.c +++ b/src/main.c @@ -536,8 +536,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 (); @@ -609,17 +611,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; } /* --------------------------------------------------------------------------------------------- */