1 /* Main program for the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
5 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
6 1994, 1995 Janne Kukonlehto
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 * \brief Source: this is a main module
36 #include <sys/types.h>
40 #include <pwd.h> /* for username in xterm title */
42 #include "lib/global.h"
44 #include "lib/tty/tty.h"
45 #include "lib/tty/mouse.h"
46 #include "lib/tty/key.h" /* For init_key() */
47 #include "lib/tty/win.h" /* xterm_flag */
49 #include "lib/mcconfig.h"
50 #include "lib/filehighlight.h"
51 #include "lib/fileloc.h" /* MC_USERCONF_DIR */
52 #include "lib/strutil.h"
54 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_translate_url() */
56 #include "lib/vfs/mc-vfs/smbfs.h" /* smbfs_set_debug() */
57 #endif /* ENABLE_VFS_SMB */
66 #include "treestore.h"
67 #include "consaver/cons.saver.h"
69 #include "setup.h" /* save_setup() */
70 #include "boxes.h" /* sort_box() */
72 #include "cmd.h" /* Normal commands */
75 #include "learn.h" /* learn_keys() */
78 #include "ext.h" /* For flush_extension_file() */
82 #include "cmddef.h" /* CK_ cmd name const */
83 #include "user.h" /* user_file_menu_cmd() */
84 #include "dialog-switch.h"
92 #ifdef USE_INTERNAL_EDIT
93 #include "src/editor/edit.h"
97 #include "src/diffviewer/ydiff.h"
101 #include "charsets.h"
102 #include "selcodepage.h"
103 #endif /* HAVE_CHARSET */
106 #include "keybind.h" /* type global_keymap_t */
108 /* When the modes are active, left_panel, right_panel and tree_panel */
109 /* Point to a proper data structure. You should check with the functions */
110 /* get_current_type and get_other_type the types of the panels before using */
111 /* This pointer variables */
113 /* The structures for the panels */
114 WPanel
*left_panel
= NULL
;
115 WPanel
*right_panel
= NULL
;
117 mc_fhl_t
*mc_filehighlight
;
119 /* The pointer to the tree */
120 WTree
*the_tree
= NULL
;
123 struct WMenuBar
*the_menubar
= NULL
;
125 /* Pointers to the selected and unselected panel */
126 WPanel
*current_panel
= NULL
;
128 /* Set if the command is being run from the "Right" menu */
131 /* Set when main loop should be terminated */
132 volatile int quit
= 0;
134 /* Set if you want the possible completions dialog for the first time */
135 int show_all_if_ambiguous
= 0;
137 /* Set when cd symlink following is desirable (bash mode) */
140 /* If set then dialogs just clean the screen when refreshing, else */
141 /* they do a complete refresh, refreshing all the parts of the program */
142 int fast_refresh
= 0;
144 /* If true, at startup the user-menu is invoked */
147 /* If true, then the +, - and \ keys have their special meaning only if the
148 * command line is emtpy, otherwise they behave like regular letters
150 int only_leading_plus_minus
= 1;
152 int pause_after_run
= pause_on_dumb_terminals
;
154 /* It true saves the setup when quitting */
155 int auto_save_setup
= 1;
159 * Don't restrict the output on the screen manager level,
160 * the translation tables take care of it.
162 #define full_eight_bits (1)
163 #define eight_bit_clean (1)
164 #else /* HAVE_CHARSET */
165 /* If true, allow characters in the range 160-255 */
166 int eight_bit_clean
= 1;
168 * If true, also allow characters in the range 128-159.
169 * This is reported to break on many terminals (xterm, qansi-m).
171 int full_eight_bits
= 0;
172 #endif /* !HAVE_CHARSET */
175 * If utf-8 terminal utf8_display = 1
176 * Display bits set UTF-8
179 int utf8_display
= 0;
181 /* If true use the internal viewer */
182 int use_internal_view
= 1;
185 const char *mc_prompt
= NULL
;
187 /* The widget where we draw the prompt */
196 /* Mouse type: GPM, xterm or none */
197 Mouse_Type use_mouse_p
= MOUSE_NONE
;
199 /* If on, default for "No" in delete operations */
202 /* Controls screen clearing before an exec */
203 int clear_before_exec
= 1;
205 /* Asks for confirmation before deleting a file */
206 int confirm_delete
= 1;
208 /* Asks for confirmation before deleting a hotlist entry */
209 int confirm_directory_hotlist_delete
= 1;
211 /* Asks for confirmation before overwriting a file */
212 int confirm_overwrite
= 1;
214 /* Asks for confirmation before executing a program by pressing enter */
215 int confirm_execute
= 0;
217 /* Asks for confirmation before leaving the program */
218 int confirm_exit
= 1;
220 /* Asks for confirmation before clean up of history */
221 int confirm_history_cleanup
= 1;
223 /* Asks for confirmation when using F3 to view a directory and there
225 int confirm_view_dir
= 0;
227 /* This flag indicates if the pull down menus by default drop down */
230 /* The dialog handle for the main program */
231 Dlg_head
*midnight_dlg
= NULL
;
233 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
234 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
235 int update_prompt
= 0;
237 /* The home directory */
238 const char *home_dir
= NULL
;
240 /* Only used at program boot */
241 int boot_current_is_left
= 1;
243 /* If this is true, then when browsing the tree the other window will
244 * automatically reload it's directory with the contents of the currently
245 * selected directory.
249 /* path to X clipboard utility */
250 char* clipboard_store_path
= NULL
;
251 char* clipboard_paste_path
= NULL
;
253 /* If set, then print to the given file the last directory we were at */
254 static char *last_wd_string
= NULL
;
255 /* Set to 1 to suppress printing the last directory */
256 static int print_last_revert
= 0;
258 mc_run_mode_t mc_run_mode
= MC_RUN_FULL
;
259 char *mc_run_param0
= NULL
;
260 char *mc_run_param1
= NULL
;
262 /* Used so that widgets know if they are being destroyed or
264 int midnight_shutdown
= 0;
266 /* The user's shell */
269 /* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
270 char *mc_home
= NULL
;
272 /* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
273 char *mc_home_alt
= NULL
;
275 /* Define this function for glib-style error handling */
277 mc_main_error_quark (void)
279 return g_quark_from_static_string (PACKAGE
);
282 /* Save current stat of directories to avoid reloading the panels */
283 /* when no modifications have taken place */
285 save_cwds_stat (void)
287 if (panels_options
.fast_reload
)
289 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
290 if (get_other_type () == view_listing
)
291 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
295 #ifdef HAVE_SUBSHELL_SUPPORT
297 do_update_prompt (void)
301 printf ("\r\n%s", subshell_prompt
);
306 #endif /* HAVE_SUBSHELL_SUPPORT */
311 free_completions (cmdline
);
312 dlg_one_down (midnight_dlg
);
315 /* Stop MC main dialog and the current dialog if it exists.
316 * Needed to provide fast exit from MC viewer or editor on shell exit */
320 midnight_dlg
->state
= DLG_CLOSED
;
322 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
323 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
327 quit_cmd_internal (int quiet
)
330 size_t n
= dialog_switch_num () - 1;
334 char msg
[BUF_MEDIUM
];
336 g_snprintf (msg
, sizeof (msg
),
337 ngettext ("You have %zd opened screen. Quit anyway?",
338 "You have %zd opened screens. Quit anyway?", n
),
341 if (query_dialog (_("The Midnight Commander"), msg
,
342 D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
345 } else if (quiet
|| !confirm_exit
)
347 else if (query_dialog (_("The Midnight Commander"),
348 _("Do you really want to quit the Midnight Commander?"),
349 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
354 #ifdef HAVE_SUBSHELL_SUPPORT
357 else if ((q
= exit_subshell ()))
370 return quit_cmd_internal (0);
374 quiet_quit_cmd (void)
376 print_last_revert
= 1;
377 return quit_cmd_internal (1);
380 /* Wrapper for do_subshell_chdir, check for availability of subshell */
382 subshell_chdir (const char *directory
)
384 #ifdef HAVE_SUBSHELL_SUPPORT
387 if (vfs_current_is_local ())
388 do_subshell_chdir (directory
, 0, 1);
390 #endif /* HAVE_SUBSHELL_SUPPORT */
394 do_cd (const char *new_dir
, enum cd_enum exact
)
398 res
= do_panel_cd (current_panel
, new_dir
, exact
);
403 const char *enc_name
;
405 enc_name
= vfs_get_encoding (current_panel
->cwd
);
406 if (enc_name
!= NULL
)
407 current_panel
->codepage
= get_codepage_index (enc_name
);
409 current_panel
->codepage
= SELECT_CHARSET_NO_TRANSLATE
;
411 #endif /* HAVE_CHARSET */
416 #ifdef HAVE_SUBSHELL_SUPPORT
418 load_prompt (int fd
, void *unused
)
423 if (!read_subshell_prompt ())
426 /* Don't actually change the prompt if it's invisible */
427 if (((Dlg_head
*) top_dlg
->data
== midnight_dlg
) && command_prompt
)
432 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
433 prompt_len
= str_term_width1 (tmp_prompt
);
435 /* Check for prompts too big */
436 if (COLS
> 8 && prompt_len
> COLS
- 8)
438 prompt_len
= COLS
- 8;
439 tmp_prompt
[prompt_len
] = '\0';
441 mc_prompt
= tmp_prompt
;
442 label_set_text (the_prompt
, mc_prompt
);
443 winput_set_origin ((WInput
*) cmdline
, prompt_len
, COLS
- prompt_len
);
445 /* since the prompt has changed, and we are called from one of the
446 * tty_get_event channels, the prompt updating does not take place
447 * automatically: force a cursor update and a screen refresh
449 update_cursor (midnight_dlg
);
455 #endif /* HAVE_SUBSHELL_SUPPORT */
461 const panel_field_t
*sort_order
;
463 if (!SELECTED_IS_PANEL
)
467 sort_order
= sort_box (p
->current_sort_field
, &p
->reverse
, &p
->case_sensitive
, &p
->exec_first
);
469 panel_set_sort_order (p
, sort_order
);
478 sel_dir
= tree_box (selection (current_panel
)->fname
);
481 do_cd (sel_dir
, cd_exact
);
486 #ifdef LISTMODE_EDITOR
492 if (get_current_type () != view_listing
)
495 newmode
= listmode_edit (current_panel
->user_format
);
499 g_free (current_panel
->user_format
);
500 current_panel
->list_type
= list_user
;
501 current_panel
->user_format
= newmode
;
502 set_panel_formats (current_panel
);
506 #endif /* LISTMODE_EDITOR */
508 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
510 create_panel_menu (void)
512 GList
*entries
= NULL
;
514 entries
= g_list_append (entries
, menu_entry_create (_("File listin&g"), CK_ListingCmd
));
515 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_QuickViewCmd
));
516 entries
= g_list_append (entries
, menu_entry_create (_("&Info"), CK_InfoCmd
));
517 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_TreeCmd
));
518 entries
= g_list_append (entries
, menu_separator_create ());
519 entries
= g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_ChangeListingCmd
));
520 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
521 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_FilterCmd
));
523 entries
= g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding
));
525 #ifdef ENABLE_VFS_NET
526 entries
= g_list_append (entries
, menu_separator_create ());
527 #ifdef ENABLE_VFS_FTP
528 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd
));
530 #ifdef ENABLE_VFS_FISH
531 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd
));
533 #ifdef ENABLE_VFS_SMB
534 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd
));
536 #endif /* ENABLE_VFS_NET */
537 entries
= g_list_append (entries
, menu_separator_create ());
538 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_RereadCmd
));
544 create_file_menu (void)
546 GList
*entries
= NULL
;
548 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_ViewCmd
));
549 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd
));
550 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd
));
551 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_EditCmd
));
552 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_CopyCmd
));
553 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChmodCmd
));
554 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_LinkCmd
));
555 entries
= g_list_append (entries
, menu_entry_create (_("&Symlink"), CK_SymlinkCmd
));
556 entries
= g_list_append (entries
, menu_entry_create (_("Relative symlin&k"), CK_RelativeSymlinkCmd
));
557 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd
));
558 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChownCmd
));
560 g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd
));
561 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_RenameCmd
));
562 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MkdirCmd
));
563 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_DeleteCmd
));
564 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd
));
565 entries
= g_list_append (entries
, menu_separator_create ());
566 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_SelectCmd
));
567 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_UnselectCmd
));
569 g_list_append (entries
,
570 menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd
));
571 entries
= g_list_append (entries
, menu_separator_create ());
572 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_QuitCmd
));
578 create_command_menu (void)
580 /* I know, I'm lazy, but the tree widget when it's not running
581 * as a panel still has some problems, I have not yet finished
582 * the WTree widget port, sorry.
584 GList
*entries
= NULL
;
586 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenuCmd
));
587 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd
));
588 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_FindCmd
));
589 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_SwapCmd
));
591 g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine
));
593 g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd
));
595 entries
= g_list_append (entries
, menu_entry_create (_("&View diff files"), CK_DiffViewCmd
));
598 g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
600 g_list_append (entries
,
601 menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd
));
602 entries
= g_list_append (entries
, menu_separator_create ());
603 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_HistoryCmd
));
605 g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd
));
607 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs
));
609 #ifdef WITH_BACKGROUND
610 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_JobsCmd
));
612 entries
= g_list_append (entries
, menu_entry_create (_("Screen lis&t"), CK_DialogListCmd
));
613 entries
= g_list_append (entries
, menu_separator_create ());
614 #ifdef ENABLE_VFS_UNDELFS
616 g_list_append (entries
,
617 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd
));
619 #ifdef LISTMODE_EDITOR
621 g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd
));
623 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
624 entries
= g_list_append (entries
, menu_separator_create ());
627 g_list_append (entries
, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd
));
628 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd
));
630 g_list_append (entries
,
631 menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd
));
637 create_options_menu (void)
639 GList
*entries
= NULL
;
641 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_ConfigureBox
));
642 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_LayoutBox
));
643 entries
= g_list_append (entries
, menu_entry_create (_("&Panel options..."), CK_PanelOptionsBox
));
644 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox
));
645 entries
= g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox
));
646 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
648 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs
));
650 entries
= g_list_append (entries
, menu_separator_create ());
651 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd
));
659 menubar_add_menu (the_menubar
,
660 create_menu (horizontal_split
? _("&Above") : _("&Left"),
661 create_panel_menu (), "[Left and Right Menus]"));
662 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
663 menubar_add_menu (the_menubar
,
664 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
665 menubar_add_menu (the_menubar
,
666 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
667 menubar_add_menu (the_menubar
,
668 create_menu (horizontal_split
? _("&Below") : _("&Right"),
669 create_panel_menu (), "[Left and Right Menus]"));
675 menubar_set_menu (the_menubar
, NULL
);
679 menu_last_selected_cmd (void)
681 the_menubar
->is_active
= TRUE
;
682 the_menubar
->is_dropped
= (drop_menus
!= 0);
683 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
684 dlg_select_widget (the_menubar
);
690 if (the_menubar
->is_active
)
693 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
694 the_menubar
->selected
= 0;
696 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
697 menu_last_selected_cmd ();
701 midnight_get_shortcut (unsigned long command
)
704 const char *shortcut
= NULL
;
706 shortcut
= lookup_keymap_shortcut (main_map
, command
);
707 if (shortcut
!= NULL
)
708 return g_strdup (shortcut
);
710 shortcut
= lookup_keymap_shortcut (panel_map
, command
);
711 if (shortcut
!= NULL
)
712 return g_strdup (shortcut
);
714 ext_map
= lookup_keymap_shortcut (main_map
, CK_StartExtMap1
);
716 shortcut
= lookup_keymap_shortcut (main_x_map
, command
);
717 if (shortcut
!= NULL
)
718 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
724 midnight_get_title (const Dlg_head
*h
, size_t len
)
726 /* TODO: share code with update_xterm_title_path() */
731 struct passwd
*pw
= NULL
;
737 path
= strip_home_and_password (current_panel
->cwd
);
738 res
= gethostname (host
, sizeof (host
));
742 host
[sizeof (host
) - 1] = '\0';
744 pw
= getpwuid (getuid ());
746 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
748 login
= g_strdup (host
);
750 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
751 path
= str_trunc (p
, len
- 4);
755 return g_strdup (path
);
759 toggle_show_hidden (void)
761 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
762 update_panels (UP_RELOAD
, UP_KEEPSEL
);
766 toggle_panels_split (void)
768 horizontal_split
= !horizontal_split
;
774 * Just a hack for allowing url-like pathnames to be accepted from the
778 translated_mc_chdir (char *dir
)
783 newdir
= vfs_translate_url (dir
);
784 ret
= mc_chdir (newdir
);
793 panel_view_mode_t current_mode
, other_mode
;
794 char original_dir
[BUF_1K
] = "\0";
796 if (boot_current_is_left
)
800 current_mode
= startup_left_mode
;
801 other_mode
= startup_right_mode
;
807 current_mode
= startup_right_mode
;
808 other_mode
= startup_left_mode
;
810 /* Creates the left panel */
811 if (mc_run_param0
!= NULL
)
813 if (mc_run_param1
!= NULL
)
815 /* Ok, user has specified two dirs, save the original one,
816 * since we may not be able to chdir to the proper
817 * second directory later
819 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
821 translated_mc_chdir (mc_run_param0
);
823 set_display_type (current_index
, current_mode
);
825 /* The other panel */
826 if (mc_run_param1
!= NULL
)
828 if (original_dir
[0] != '\0')
829 translated_mc_chdir (original_dir
);
830 translated_mc_chdir (mc_run_param1
);
832 set_display_type (other_index
, other_mode
);
834 if (startup_left_mode
== view_listing
)
836 current_panel
= left_panel
;
841 current_panel
= right_panel
;
843 current_panel
= left_panel
;
846 /* Create the nice widgets */
847 cmdline
= command_new (0, 0, 0);
848 the_prompt
= label_new (0, 0, mc_prompt
);
849 the_prompt
->transparent
= 1;
850 the_bar
= buttonbar_new (keybar_visible
);
852 the_hint
= label_new (0, 0, 0);
853 the_hint
->transparent
= 1;
854 the_hint
->auto_adjust_cols
= 0;
855 the_hint
->widget
.cols
= COLS
;
857 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
861 copy_current_pathname (void)
867 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
868 command_insert (cmdline
, cwd_path
, 0);
870 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
871 command_insert (cmdline
, PATH_SEP_STR
, 0);
876 copy_other_pathname (void)
880 if (get_other_type () != view_listing
)
886 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
887 command_insert (cmdline
, cwd_path
, 0);
889 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
890 command_insert (cmdline
, PATH_SEP_STR
, 0);
895 copy_readlink (WPanel
* panel
)
899 if (S_ISLNK (selection (panel
)->st
.st_mode
))
901 char buffer
[MC_MAXPATHLEN
];
902 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
905 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
910 command_insert (cmdline
, buffer
, 1);
916 copy_current_readlink (void)
918 copy_readlink (current_panel
);
922 copy_other_readlink (void)
924 if (get_other_type () == view_listing
)
925 copy_readlink (other_panel
);
928 /* Insert the selected file name into the input line */
930 copy_prog_name (void)
936 if (get_current_type () == view_tree
)
938 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
939 tmp
= tree_selected_name (tree
);
942 tmp
= selection (current_panel
)->fname
;
944 command_insert (cmdline
, tmp
, 1);
948 copy_tagged (WPanel
* panel
)
954 input_disable_update (cmdline
);
957 for (i
= 0; i
< panel
->count
; i
++)
959 if (panel
->dir
.list
[i
].f
.marked
)
960 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
965 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, 1);
967 input_enable_update (cmdline
);
971 copy_current_tagged (void)
973 copy_tagged (current_panel
);
977 copy_other_tagged (void)
979 if (get_other_type () == view_listing
)
980 copy_tagged (other_panel
);
984 midnight_set_buttonbar (WButtonBar
* b
)
986 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
987 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
988 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
989 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
990 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
991 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
992 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
993 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
994 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
995 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
998 static gboolean ctl_x_map_enabled
= FALSE
;
1003 ctl_x_map_enabled
= TRUE
;
1007 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
1009 cb_ret_t res
= MSG_HANDLED
;
1013 /* stop quick search before executing any command */
1014 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1021 case CK_ChangeListingCmd
:
1022 change_listing_cmd ();
1030 case CK_ChownAdvancedCmd
:
1031 chown_advanced_cmd ();
1033 case CK_CompareDirsCmd
:
1034 compare_dirs_cmd ();
1036 case CK_ConfigureBox
:
1040 case CK_ConfigureVfs
:
1050 case CK_CopyCurrentPathname
:
1051 copy_current_pathname ();
1053 case CK_CopyCurrentReadlink
:
1054 copy_current_readlink ();
1056 case CK_CopyCurrentTagged
:
1057 copy_current_tagged ();
1059 case CK_CopyOtherPathname
:
1060 copy_other_pathname ();
1062 case CK_CopyOtherReadlink
:
1063 copy_other_readlink ();
1065 case CK_CopyOtherTagged
:
1066 copy_other_tagged ();
1071 case CK_DialogListCmd
:
1072 dialog_switch_list ();
1074 #ifdef USE_DIFF_VIEW
1075 case CK_DiffViewCmd
:
1079 case CK_DisplayBitsBox
:
1080 display_bits_box ();
1085 #ifdef USE_INTERNAL_EDIT
1086 case CK_EditForceInternalCmd
:
1087 edit_cmd_force_internal ();
1090 case CK_EditExtFileCmd
:
1093 case CK_EditFhlFileCmd
:
1096 case CK_EditMcMenuCmd
:
1097 edit_mc_menu_cmd ();
1099 case CK_EditSymlinkCmd
:
1100 edit_symlink_cmd ();
1102 case CK_ExternalPanelize
:
1103 external_panelize ();
1108 case CK_FilteredViewCmd
:
1109 filtered_view_cmd ();
1114 #ifdef ENABLE_VFS_FISH
1115 case CK_FishlinkCmd
:
1119 #ifdef ENABLE_VFS_FTP
1131 if (sender
== (Widget
*) the_menubar
)
1132 info_cmd (); /* mwnu */
1134 info_cmd_no_menu (); /* shortcut or buttonbar */
1136 #ifdef WITH_BACKGROUND
1148 link_cmd (LINK_HARDLINK
);
1153 #ifdef LISTMODE_EDITOR
1154 case CK_ListmodeCmd
:
1161 case CK_MenuLastSelectedCmd
:
1162 menu_last_selected_cmd ();
1167 case CK_PanelOptionsBox
:
1168 panel_options_box ();
1171 case CK_PanelSetPanelEncoding
:
1178 case CK_QuickChdirCmd
:
1181 case CK_QuickViewCmd
:
1182 if (sender
== (Widget
*) the_menubar
)
1183 quick_view_cmd (); /* menu */
1185 quick_cmd_no_menu (); /* shortcut or buttonabr */
1187 case CK_QuietQuitCmd
:
1193 case CK_RelativeSymlinkCmd
:
1194 link_cmd (LINK_SYMLINK_RELATIVE
);
1203 case CK_ReselectVfs
:
1207 case CK_ReverseSelectionCmd
:
1208 reverse_selection_cmd ();
1210 case CK_SaveSetupCmd
:
1216 case CK_ShowCommandLine
:
1219 case CK_SingleDirsizeCmd
:
1220 smart_dirsize_cmd ();
1222 #ifdef ENABLE_VFS_SMB
1226 #endif /* ENABLE_VFS_SMB */
1230 case CK_StartExtMap1
:
1240 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1242 case CK_ToggleListingCmd
:
1243 toggle_listing_cmd ();
1245 case CK_ToggleShowHidden
:
1246 toggle_show_hidden ();
1248 case CK_TogglePanelsSplit
:
1249 toggle_panels_split ();
1257 #ifdef ENABLE_VFS_UNDELFS
1258 case CK_UndeleteCmd
:
1262 case CK_UnselectCmd
:
1265 case CK_UserMenuCmd
:
1266 user_file_menu_cmd ();
1271 case CK_ViewFileCmd
:
1275 res
= MSG_NOT_HANDLED
;
1282 init_xterm_support (void)
1284 const char *termvalue
;
1286 termvalue
= getenv ("TERM");
1287 if (!termvalue
|| !(*termvalue
))
1289 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1290 exit (EXIT_FAILURE
);
1293 /* Check mouse capabilities */
1294 xmouse_seq
= tty_tgetstr ("Km");
1296 if (strcmp (termvalue
, "cygwin") == 0)
1298 mc_args__force_xterm
= 1;
1299 use_mouse_p
= MOUSE_DISABLED
;
1302 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1303 || strncmp (termvalue
, "konsole", 7) == 0
1304 || strncmp (termvalue
, "rxvt", 4) == 0
1305 || strcmp (termvalue
, "Eterm") == 0 || strcmp (termvalue
, "dtterm") == 0)
1309 /* Default to the standard xterm sequence */
1312 xmouse_seq
= ESC_STR
"[M";
1315 /* Enable mouse unless explicitly disabled by --nomouse */
1316 if (use_mouse_p
!= MOUSE_DISABLED
)
1318 const char *color_term
= getenv ("COLORTERM");
1319 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
1320 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
1321 strcmp (termvalue
, "Eterm") == 0)
1323 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
1327 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
1337 tty_display_8bit (full_eight_bits
!= 0);
1339 tty_display_8bit (eight_bit_clean
!= 0);
1342 #ifdef HAVE_SUBSHELL_SUPPORT
1344 add_select_channel (subshell_pty
, load_prompt
, 0);
1345 #endif /* !HAVE_SUBSHELL_SUPPORT */
1347 tty_setup_sigwinch (sigwinch_handler
);
1349 if ((tty_baudrate () < 9600) || tty_is_slow ())
1352 init_xterm_support ();
1357 setup_dummy_mc (void)
1359 char d
[MC_MAXPATHLEN
];
1362 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1370 const char *current_system_codepage
= NULL
;
1372 current_system_codepage
= str_detect_termencoding ();
1376 const char *_display_codepage
;
1378 _display_codepage
= get_codepage_id (display_codepage
);
1380 if (!strcmp (_display_codepage
, current_system_codepage
))
1382 utf8_display
= str_isutf8 (current_system_codepage
);
1386 display_codepage
= get_codepage_index (current_system_codepage
);
1387 if (display_codepage
== -1)
1389 display_codepage
= 0;
1392 mc_config_set_string (mc_main_config
, "Misc", "display_codepage", cp_display
);
1395 utf8_display
= str_isutf8 (current_system_codepage
);
1401 if (!(quit
& SUBSHELL_EXIT
))
1403 tty_reset_shell_mode ();
1416 * We sync the profiles since the hotlist may have changed, while
1417 * we only change the setup data if we have the auto save feature set
1420 if (auto_save_setup
)
1421 save_setup (); /* does also call save_hotlist */
1425 save_panel_types ();
1429 vfs_stamp_path (vfs_get_current_dir ());
1431 if ((current_panel
!= NULL
) && (get_current_type () == view_listing
))
1432 vfs_stamp_path (current_panel
->cwd
);
1434 if ((other_panel
!= NULL
) && (get_other_type () == view_listing
))
1435 vfs_stamp_path (other_panel
->cwd
);
1439 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1441 unsigned long command
;
1451 /* We handle the special case of the output lines */
1452 if (console_flag
&& output_lines
)
1453 show_console_contents (output_start_y
,
1454 LINES
- output_lines
- keybar_visible
-
1455 1, LINES
- keybar_visible
- 1);
1460 menubar_arrange (the_menubar
);
1464 /* We only need the first idle event to show user menu after start */
1465 set_idle_proc (h
, 0);
1467 if (boot_current_is_left
)
1468 dlg_select_widget (get_panel_widget (0));
1470 dlg_select_widget (get_panel_widget (1));
1473 midnight_execute_cmd (NULL
, CK_UserMenuCmd
);
1477 if (ctl_x_map_enabled
)
1479 ctl_x_map_enabled
= FALSE
;
1480 command
= lookup_keymap_command (main_x_map
, parm
);
1481 if (command
!= CK_Ignore_Key
)
1482 return midnight_execute_cmd (NULL
, command
);
1485 /* FIXME: should handle all menu shortcuts before this point */
1486 if (the_menubar
->is_active
)
1487 return MSG_NOT_HANDLED
;
1490 free_completions (cmdline
);
1496 for (i
= 0; cmdline
->buffer
[i
] && (cmdline
->buffer
[i
] == ' ' ||
1497 cmdline
->buffer
[i
] == '\t'); i
++)
1499 if (cmdline
->buffer
[i
])
1501 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1504 stuff (cmdline
, "", 0);
1508 /* Ctrl-Enter and Alt-Enter */
1509 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1515 /* Ctrl-Shift-Enter */
1516 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1518 copy_current_pathname ();
1523 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1524 && !quote
&& !current_panel
->searching
)
1526 if (!only_leading_plus_minus
)
1528 /* Special treatement, since the input line will eat them */
1535 if (parm
== '\\' || parm
== '-')
1543 reverse_selection_cmd ();
1547 else if (!command_prompt
|| !cmdline
->buffer
[0])
1549 /* Special treatement '+', '-', '\', '*' only when this is
1550 * first char on input line
1559 if (parm
== '\\' || parm
== '-')
1567 reverse_selection_cmd ();
1572 return MSG_NOT_HANDLED
;
1574 case DLG_HOTKEY_HANDLED
:
1575 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1577 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1578 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1582 case DLG_UNHANDLED_KEY
:
1587 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1588 if (v
== MSG_HANDLED
)
1592 if (ctl_x_map_enabled
)
1594 ctl_x_map_enabled
= FALSE
;
1595 command
= lookup_keymap_command (main_x_map
, parm
);
1598 command
= lookup_keymap_command (main_map
, parm
);
1600 return (command
== CK_Ignore_Key
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1603 if (!the_menubar
->is_active
)
1604 update_dirty_panels ();
1610 midnight_execute_cmd (NULL
, parm
);
1611 /* message from menu */
1612 else if (sender
== (Widget
*) the_menubar
)
1613 midnight_execute_cmd (sender
, parm
);
1614 /* message from buttonbar */
1615 else if (sender
== (Widget
*) the_bar
)
1618 midnight_execute_cmd (sender
, parm
);
1620 send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1625 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1629 /* Show current directory in the xterm title */
1631 update_xterm_title_path (void)
1633 /* TODO: share code with midnight_get_title () */
1636 char host
[BUF_TINY
];
1638 struct passwd
*pw
= NULL
;
1642 if (xterm_flag
&& xterm_title
)
1644 path
= strip_home_and_password (current_panel
->cwd
);
1645 res
= gethostname (host
, sizeof (host
));
1647 { /* On success, res = 0 */
1652 host
[sizeof (host
) - 1] = '\0';
1654 pw
= getpwuid (getuid ());
1657 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1661 login
= g_strdup (host
);
1663 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1664 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1667 if (!alternate_plus_minus
)
1668 numeric_keypad_mode ();
1674 * Load new hint and display it.
1675 * IF force is not 0, ignore the timeout.
1678 load_hint (int force
)
1682 if (!the_hint
->widget
.owner
)
1685 if (!message_visible
)
1687 label_set_text (the_hint
, NULL
);
1691 hint
= get_random_hint (force
);
1701 char text
[BUF_SMALL
];
1703 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1709 create_panels_and_run_mc (void)
1711 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
1712 midnight_dlg
->get_title
= midnight_get_title
;
1716 add_widget (midnight_dlg
, the_menubar
);
1719 add_widget (midnight_dlg
, get_panel_widget (0));
1720 add_widget (midnight_dlg
, get_panel_widget (1));
1722 add_widget (midnight_dlg
, the_hint
);
1723 add_widget (midnight_dlg
, cmdline
);
1724 add_widget (midnight_dlg
, the_prompt
);
1726 add_widget (midnight_dlg
, the_bar
);
1727 midnight_set_buttonbar (the_bar
);
1729 /* Run the Midnight Commander if no file was specified in the command line */
1730 run_dlg (midnight_dlg
);
1733 /* result must be free'd (I think this should go in util.c) */
1735 prepend_cwd_on_local (const char *filename
)
1740 if (!vfs_file_is_local (filename
) || g_path_is_absolute (filename
))
1741 return g_strdup (filename
);
1743 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1744 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1747 strcpy (d
+ l
, filename
);
1748 canonicalize_pathname (d
);
1752 /* Invoke the internal view/edit routine with:
1753 * the default processing and forcing the internal viewer/editor
1756 mc_maybe_editor_or_viewer (void)
1758 switch (mc_run_mode
)
1760 #ifdef USE_INTERNAL_EDIT
1762 edit_file (mc_run_param0
, mc_args__edit_start_line
);
1764 #endif /* USE_INTERNAL_EDIT */
1768 path
= prepend_cwd_on_local (mc_run_param0
);
1769 view_file (path
, 0, 1);
1773 #ifdef USE_DIFF_VIEW
1774 case MC_RUN_DIFFVIEWER
:
1775 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
1777 #endif /* USE_DIFF_VIEW */
1781 midnight_shutdown
= 1;
1784 /* Run the main dialog that occupies the whole screen */
1788 dlg_colors_t midnight_colors
;
1789 midnight_colors
[DLG_COLOR_NORMAL
] = mc_skin_color_get ("dialog", "_default_");
1790 midnight_colors
[DLG_COLOR_FOCUS
] = mc_skin_color_get ("dialog", "focus");
1791 midnight_colors
[DLG_COLOR_HOT_NORMAL
] = mc_skin_color_get ("dialog", "hotnormal");
1792 midnight_colors
[DLG_COLOR_HOT_FOCUS
] = mc_skin_color_get ("dialog", "hotfocus");
1793 midnight_colors
[DLG_COLOR_TITLE
] = mc_skin_color_get ("dialog", "title");
1797 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1798 "[main]", NULL
, DLG_WANT_IDLE
);
1800 if (mc_run_mode
== MC_RUN_FULL
)
1805 /* start check display_codepage and source_codepage */
1808 /* Check if we were invoked as an editor or file viewer */
1809 if (mc_run_mode
!= MC_RUN_FULL
)
1810 mc_maybe_editor_or_viewer ();
1813 create_panels_and_run_mc ();
1816 midnight_shutdown
= 1;
1818 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1819 if (mc_args__last_wd_file
&& vfs_current_is_local ())
1820 last_wd_string
= g_strdup (current_panel
->cwd
);
1824 dialog_switch_shutdown ();
1826 destroy_dlg (midnight_dlg
);
1832 /* POSIX version. The only version we support. */
1836 const char *shell_env
= getenv ("SHELL");
1837 const char *mc_libdir
;
1839 if ((shell_env
== NULL
) || (shell_env
[0] == '\0'))
1842 pwd
= getpwuid (geteuid ());
1844 shell
= g_strdup (pwd
->pw_shell
);
1847 shell
= g_strdup (shell_env
);
1849 if ((shell
== NULL
) || (shell
[0] == '\0'))
1852 shell
= g_strdup ("/bin/sh");
1855 /* This is the directory, where MC was installed, on Unix this is DATADIR */
1856 /* and can be overriden by the MC_DATADIR environment variable */
1857 mc_libdir
= getenv ("MC_DATADIR");
1858 if (mc_libdir
!= NULL
)
1860 mc_home
= g_strdup (mc_libdir
);
1861 mc_home_alt
= g_strdup (SYSCONFDIR
);
1865 mc_home
= g_strdup (SYSCONFDIR
);
1866 mc_home_alt
= g_strdup (DATADIR
);
1869 /* This variable is used by the subshell */
1870 home_dir
= getenv ("HOME");
1877 sigchld_handler_no_subshell (int sig
)
1885 /* COMMENT: if it were true that after the call to handle_console(..INIT)
1886 the value of console_flag never changed, we could simply not install
1887 this handler at all if (!console_flag && !use_subshell). */
1889 /* That comment is no longer true. We need to wait() on a sigchld
1890 handler (that's at least what the tarfs code expects currently). */
1892 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
1894 if (pid
== cons_saver_pid
)
1897 if (WIFSTOPPED (status
))
1899 /* Someone has stopped cons.saver - restart it */
1900 kill (pid
, SIGCONT
);
1904 /* cons.saver has died - disable console saving */
1905 handle_console (CONSOLE_DONE
);
1909 /* If we got here, some other child exited; ignore it */
1910 #endif /* __linux__ */
1918 struct sigaction sigchld_action
;
1920 sigchld_action
.sa_handler
=
1921 #ifdef HAVE_SUBSHELL_SUPPORT
1922 use_subshell
? sigchld_handler
:
1923 #endif /* HAVE_SUBSHELL_SUPPORT */
1924 sigchld_handler_no_subshell
;
1926 sigemptyset (&sigchld_action
.sa_mask
);
1929 sigchld_action
.sa_flags
= SA_RESTART
;
1931 sigchld_action
.sa_flags
= 0;
1932 #endif /* !SA_RESTART */
1934 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1)
1936 #ifdef HAVE_SUBSHELL_SUPPORT
1938 * This may happen on QNX Neutrino 6, where SA_RESTART
1939 * is defined but not implemented. Fallback to no subshell.
1942 #endif /* HAVE_SUBSHELL_SUPPORT */
1947 main (int argc
, char *argv
[])
1951 GError
*error
= NULL
;
1952 gboolean isInitialized
;
1954 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
1955 setlocale (LC_ALL
, "");
1956 bindtextdomain ("mc", LOCALEDIR
);
1959 /* Set up temporary directory */
1964 str_init_strings (NULL
);
1968 #ifdef USE_INTERNAL_EDIT
1973 SLtt_Ignore_Beep
= 1;
1976 if (!mc_args_handle (argc
, argv
, "mc"))
1977 exit (EXIT_FAILURE
);
1979 /* NOTE: This has to be called before tty_init or whatever routine
1980 calls any define_sequence */
1983 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
1984 handle_console (CONSOLE_INIT
);
1986 #ifdef HAVE_SUBSHELL_SUPPORT
1987 /* Don't use subshell when invoked as viewer or editor */
1988 if (mc_run_mode
!= MC_RUN_FULL
)
1992 subshell_get_console_attributes ();
1993 #endif /* HAVE_SUBSHELL_SUPPORT */
1995 /* Install the SIGCHLD handler; must be done before init_subshell() */
1998 /* We need this, since ncurses endwin () doesn't restore the signals */
1999 save_stop_handler ();
2001 /* Must be done before init_subshell, to set up the terminal size: */
2002 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2003 tty_init ((gboolean
) mc_args__slow_terminal
, (gboolean
) mc_args__ugly_line_drawing
);
2007 /* Removing this from the X code let's us type C-c */
2010 load_keymap_defs ();
2012 tty_init_colors (mc_args__disable_colors
, mc_args__force_colors
);
2014 isInitialized
= mc_skin_init (&error
);
2016 mc_filehighlight
= mc_fhl_new (TRUE
);
2018 dlg_set_default_colors ();
2022 message (D_ERROR
, _("Warning"), "%s", error
->message
);
2023 g_error_free (error
);
2027 /* create home directory */
2028 /* do it after the screen library initialization to show the error message */
2029 mc_dir
= concat_dir_and_file (home_dir
, MC_USERCONF_DIR
);
2030 canonicalize_pathname (mc_dir
);
2031 if ((stat (mc_dir
, &s
) != 0) && (errno
== ENOENT
) && mkdir (mc_dir
, 0700) != 0)
2032 message (D_ERROR
, _("Warning"), _("Cannot create %s directory"), mc_dir
);
2035 #ifdef HAVE_SUBSHELL_SUPPORT
2036 /* Done here to ensure that the subshell doesn't */
2037 /* inherit the file descriptors opened below, etc */
2041 #endif /* HAVE_SUBSHELL_SUPPORT */
2043 /* Also done after init_subshell, to save any shell init file messages */
2045 handle_console (CONSOLE_SAVE
);
2047 if (alternate_plus_minus
)
2048 application_keypad_mode ();
2050 #ifdef HAVE_SUBSHELL_SUPPORT
2053 mc_prompt
= strip_ctrl_codes (subshell_prompt
);
2054 if (mc_prompt
== NULL
)
2055 mc_prompt
= (geteuid () == 0) ? "# " : "$ ";
2058 #endif /* HAVE_SUBSHELL_SUPPORT */
2059 mc_prompt
= (geteuid () == 0) ? "# " : "$ ";
2061 /* Program main loop */
2062 if (!midnight_shutdown
)
2065 /* Save the tree store */
2068 free_keymap_defs ();
2070 /* Virtual File System shutdown */
2073 flush_extension_file (); /* does only free memory */
2075 mc_fhl_free (&mc_filehighlight
);
2080 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2081 handle_console (CONSOLE_RESTORE
);
2082 if (alternate_plus_minus
)
2083 numeric_keypad_mode ();
2085 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2088 handle_console (CONSOLE_DONE
);
2089 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2091 if (mc_run_mode
== MC_RUN_FULL
&& mc_args__last_wd_file
&& last_wd_string
&& !print_last_revert
)
2093 int last_wd_fd
= open (mc_args__last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2096 if (last_wd_fd
!= -1)
2100 ret1
= write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2101 ret2
= close (last_wd_fd
);
2104 g_free (last_wd_string
);
2106 g_free (mc_home_alt
);
2112 free_codepages_list ();
2113 g_free (autodetect_codeset
);
2115 g_free (clipboard_store_path
);
2116 g_free (clipboard_paste_path
);
2118 str_uninit_strings ();
2120 g_free (mc_run_param0
);
2121 g_free (mc_run_param1
);
2123 #ifdef USE_INTERNAL_EDIT