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 #endif /* HAVE_CHARSET */
105 #include "keybind.h" /* type global_keymap_t */
107 /* When the modes are active, left_panel, right_panel and tree_panel */
108 /* Point to a proper data structure. You should check with the functions */
109 /* get_current_type and get_other_type the types of the panels before using */
110 /* This pointer variables */
112 /* The structures for the panels */
113 WPanel
*left_panel
= NULL
;
114 WPanel
*right_panel
= NULL
;
116 mc_fhl_t
*mc_filehighlight
;
118 /* The pointer to the tree */
119 WTree
*the_tree
= NULL
;
122 struct WMenuBar
*the_menubar
= NULL
;
124 /* Pointers to the selected and unselected panel */
125 WPanel
*current_panel
= NULL
;
127 /* Set if the command is being run from the "Right" menu */
130 /* Set when main loop should be terminated */
131 volatile int quit
= 0;
133 /* Set if you want the possible completions dialog for the first time */
134 int show_all_if_ambiguous
= 0;
136 /* Set when cd symlink following is desirable (bash mode) */
139 /* If set then dialogs just clean the screen when refreshing, else */
140 /* they do a complete refresh, refreshing all the parts of the program */
141 int fast_refresh
= 0;
143 /* If true, at startup the user-menu is invoked */
146 /* If true, then the +, - and \ keys have their special meaning only if the
147 * command line is emtpy, otherwise they behave like regular letters
149 int only_leading_plus_minus
= 1;
151 int pause_after_run
= pause_on_dumb_terminals
;
153 /* It true saves the setup when quitting */
154 int auto_save_setup
= 1;
158 * Don't restrict the output on the screen manager level,
159 * the translation tables take care of it.
161 #define full_eight_bits (1)
162 #define eight_bit_clean (1)
163 #else /* HAVE_CHARSET */
164 /* If true, allow characters in the range 160-255 */
165 int eight_bit_clean
= 1;
167 * If true, also allow characters in the range 128-159.
168 * This is reported to break on many terminals (xterm, qansi-m).
170 int full_eight_bits
= 0;
171 #endif /* !HAVE_CHARSET */
174 * If utf-8 terminal utf8_display = 1
175 * Display bits set UTF-8
178 int utf8_display
= 0;
180 /* If true use the internal viewer */
181 int use_internal_view
= 1;
184 const char *mc_prompt
= NULL
;
186 /* The widget where we draw the prompt */
195 /* Mouse type: GPM, xterm or none */
196 Mouse_Type use_mouse_p
= MOUSE_NONE
;
198 /* If on, default for "No" in delete operations */
201 /* Controls screen clearing before an exec */
202 int clear_before_exec
= 1;
204 /* Asks for confirmation before deleting a file */
205 int confirm_delete
= 1;
207 /* Asks for confirmation before deleting a hotlist entry */
208 int confirm_directory_hotlist_delete
= 1;
210 /* Asks for confirmation before overwriting a file */
211 int confirm_overwrite
= 1;
213 /* Asks for confirmation before executing a program by pressing enter */
214 int confirm_execute
= 0;
216 /* Asks for confirmation before leaving the program */
217 int confirm_exit
= 1;
219 /* Asks for confirmation before clean up of history */
220 int confirm_history_cleanup
= 1;
222 /* Asks for confirmation when using F3 to view a directory and there
224 int confirm_view_dir
= 0;
226 /* This flag indicates if the pull down menus by default drop down */
229 /* The dialog handle for the main program */
230 Dlg_head
*midnight_dlg
= NULL
;
232 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
233 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
234 int update_prompt
= 0;
236 /* The home directory */
237 const char *home_dir
= NULL
;
239 /* Only used at program boot */
240 int boot_current_is_left
= 1;
242 /* If this is true, then when browsing the tree the other window will
243 * automatically reload it's directory with the contents of the currently
244 * selected directory.
248 /* path to X clipboard utility */
249 char* clipboard_store_path
= NULL
;
250 char* clipboard_paste_path
= NULL
;
252 /* If set, then print to the given file the last directory we were at */
253 static char *last_wd_string
= NULL
;
254 /* Set to 1 to suppress printing the last directory */
255 static int print_last_revert
= 0;
257 mc_run_mode_t mc_run_mode
= MC_RUN_FULL
;
258 char *mc_run_param0
= NULL
;
259 char *mc_run_param1
= NULL
;
261 /* Used so that widgets know if they are being destroyed or
263 int midnight_shutdown
= 0;
265 /* The user's shell */
268 /* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
269 char *mc_home
= NULL
;
271 /* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
272 char *mc_home_alt
= NULL
;
274 /* Define this function for glib-style error handling */
276 mc_main_error_quark (void)
278 return g_quark_from_static_string (PACKAGE
);
281 /* Save current stat of directories to avoid reloading the panels */
282 /* when no modifications have taken place */
284 save_cwds_stat (void)
286 if (panels_options
.fast_reload
)
288 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
289 if (get_other_type () == view_listing
)
290 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
294 #ifdef HAVE_SUBSHELL_SUPPORT
296 do_update_prompt (void)
300 printf ("\r\n%s", subshell_prompt
);
305 #endif /* HAVE_SUBSHELL_SUPPORT */
310 free_completions (cmdline
);
311 dlg_one_down (midnight_dlg
);
314 /* Stop MC main dialog and the current dialog if it exists.
315 * Needed to provide fast exit from MC viewer or editor on shell exit */
319 midnight_dlg
->state
= DLG_CLOSED
;
321 if ((top_dlg
!= NULL
) && (top_dlg
->data
!= NULL
))
322 ((Dlg_head
*) top_dlg
->data
)->state
= DLG_CLOSED
;
326 quit_cmd_internal (int quiet
)
329 size_t n
= dialog_switch_num () - 1;
333 char msg
[BUF_MEDIUM
];
335 g_snprintf (msg
, sizeof (msg
),
336 ngettext ("You have %zd opened screen. Quit anyway?",
337 "You have %zd opened screens. Quit anyway?", n
),
340 if (query_dialog (_("The Midnight Commander"), msg
,
341 D_NORMAL
, 2, _("&Yes"), _("&No")) != 0)
344 } else if (quiet
|| !confirm_exit
)
346 else if (query_dialog (_("The Midnight Commander"),
347 _("Do you really want to quit the Midnight Commander?"),
348 D_NORMAL
, 2, _("&Yes"), _("&No")) == 0)
353 #ifdef HAVE_SUBSHELL_SUPPORT
356 else if ((q
= exit_subshell ()))
369 return quit_cmd_internal (0);
373 quiet_quit_cmd (void)
375 print_last_revert
= 1;
376 return quit_cmd_internal (1);
379 /* Wrapper for do_subshell_chdir, check for availability of subshell */
381 subshell_chdir (const char *directory
)
383 #ifdef HAVE_SUBSHELL_SUPPORT
386 if (vfs_current_is_local ())
387 do_subshell_chdir (directory
, 0, 1);
389 #endif /* HAVE_SUBSHELL_SUPPORT */
393 do_cd (const char *new_dir
, enum cd_enum exact
)
395 return (do_panel_cd (current_panel
, new_dir
, exact
));
398 #ifdef HAVE_SUBSHELL_SUPPORT
400 load_prompt (int fd
, void *unused
)
405 if (!read_subshell_prompt ())
408 /* Don't actually change the prompt if it's invisible */
409 if (((Dlg_head
*) top_dlg
->data
== midnight_dlg
) && command_prompt
)
414 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
415 prompt_len
= str_term_width1 (tmp_prompt
);
417 /* Check for prompts too big */
418 if (COLS
> 8 && prompt_len
> COLS
- 8)
420 prompt_len
= COLS
- 8;
421 tmp_prompt
[prompt_len
] = '\0';
423 mc_prompt
= tmp_prompt
;
424 label_set_text (the_prompt
, mc_prompt
);
425 winput_set_origin ((WInput
*) cmdline
, prompt_len
, COLS
- prompt_len
);
427 /* since the prompt has changed, and we are called from one of the
428 * tty_get_event channels, the prompt updating does not take place
429 * automatically: force a cursor update and a screen refresh
431 update_cursor (midnight_dlg
);
437 #endif /* HAVE_SUBSHELL_SUPPORT */
443 const panel_field_t
*sort_order
;
445 if (!SELECTED_IS_PANEL
)
449 sort_order
= sort_box (p
->current_sort_field
, &p
->reverse
, &p
->case_sensitive
, &p
->exec_first
);
451 panel_set_sort_order (p
, sort_order
);
460 sel_dir
= tree_box (selection (current_panel
)->fname
);
463 do_cd (sel_dir
, cd_exact
);
468 #ifdef LISTMODE_EDITOR
474 if (get_current_type () != view_listing
)
477 newmode
= listmode_edit (current_panel
->user_format
);
481 g_free (current_panel
->user_format
);
482 current_panel
->list_type
= list_user
;
483 current_panel
->user_format
= newmode
;
484 set_panel_formats (current_panel
);
488 #endif /* LISTMODE_EDITOR */
490 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
492 create_panel_menu (void)
494 GList
*entries
= NULL
;
496 entries
= g_list_append (entries
, menu_entry_create (_("File listin&g"), CK_ListingCmd
));
497 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_QuickViewCmd
));
498 entries
= g_list_append (entries
, menu_entry_create (_("&Info"), CK_InfoCmd
));
499 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_TreeCmd
));
500 entries
= g_list_append (entries
, menu_separator_create ());
501 entries
= g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_ChangeListingCmd
));
502 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
503 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_FilterCmd
));
505 entries
= g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding
));
507 #ifdef ENABLE_VFS_NET
508 entries
= g_list_append (entries
, menu_separator_create ());
509 #ifdef ENABLE_VFS_FTP
510 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd
));
512 #ifdef ENABLE_VFS_FISH
513 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd
));
515 #ifdef ENABLE_VFS_SMB
516 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd
));
518 #endif /* ENABLE_VFS_NET */
519 entries
= g_list_append (entries
, menu_separator_create ());
520 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_RereadCmd
));
526 create_file_menu (void)
528 GList
*entries
= NULL
;
530 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_ViewCmd
));
531 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd
));
532 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd
));
533 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_EditCmd
));
534 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_CopyCmd
));
535 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChmodCmd
));
536 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_LinkCmd
));
537 entries
= g_list_append (entries
, menu_entry_create (_("&Symlink"), CK_SymlinkCmd
));
538 entries
= g_list_append (entries
, menu_entry_create (_("Relative symlin&k"), CK_RelativeSymlinkCmd
));
539 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd
));
540 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChownCmd
));
542 g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd
));
543 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_RenameCmd
));
544 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MkdirCmd
));
545 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_DeleteCmd
));
546 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd
));
547 entries
= g_list_append (entries
, menu_separator_create ());
548 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_SelectCmd
));
549 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_UnselectCmd
));
551 g_list_append (entries
,
552 menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd
));
553 entries
= g_list_append (entries
, menu_separator_create ());
554 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_QuitCmd
));
560 create_command_menu (void)
562 /* I know, I'm lazy, but the tree widget when it's not running
563 * as a panel still has some problems, I have not yet finished
564 * the WTree widget port, sorry.
566 GList
*entries
= NULL
;
568 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenuCmd
));
569 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd
));
570 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_FindCmd
));
571 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_SwapCmd
));
573 g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine
));
575 g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd
));
577 entries
= g_list_append (entries
, menu_entry_create (_("&View diff files"), CK_DiffViewCmd
));
580 g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
582 g_list_append (entries
,
583 menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd
));
584 entries
= g_list_append (entries
, menu_separator_create ());
585 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_HistoryCmd
));
587 g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd
));
589 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs
));
591 #ifdef WITH_BACKGROUND
592 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_JobsCmd
));
594 entries
= g_list_append (entries
, menu_entry_create (_("Screen lis&t"), CK_DialogListCmd
));
595 entries
= g_list_append (entries
, menu_separator_create ());
596 #ifdef ENABLE_VFS_UNDELFS
598 g_list_append (entries
,
599 menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd
));
601 #ifdef LISTMODE_EDITOR
603 g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd
));
605 #if defined (ENABLE_VFS_UNDELFS) || defined (LISTMODE_EDITOR)
606 entries
= g_list_append (entries
, menu_separator_create ());
609 g_list_append (entries
, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd
));
610 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd
));
612 g_list_append (entries
,
613 menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd
));
619 create_options_menu (void)
621 GList
*entries
= NULL
;
623 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_ConfigureBox
));
624 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_LayoutBox
));
625 entries
= g_list_append (entries
, menu_entry_create (_("&Panel options..."), CK_PanelOptionsBox
));
626 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox
));
627 entries
= g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox
));
628 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
630 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs
));
632 entries
= g_list_append (entries
, menu_separator_create ());
633 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd
));
641 menubar_add_menu (the_menubar
,
642 create_menu (horizontal_split
? _("&Above") : _("&Left"),
643 create_panel_menu (), "[Left and Right Menus]"));
644 menubar_add_menu (the_menubar
, create_menu (_("&File"), create_file_menu (), "[File Menu]"));
645 menubar_add_menu (the_menubar
,
646 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
647 menubar_add_menu (the_menubar
,
648 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
649 menubar_add_menu (the_menubar
,
650 create_menu (horizontal_split
? _("&Below") : _("&Right"),
651 create_panel_menu (), "[Left and Right Menus]"));
657 menubar_set_menu (the_menubar
, NULL
);
661 menu_last_selected_cmd (void)
663 the_menubar
->is_active
= TRUE
;
664 the_menubar
->is_dropped
= (drop_menus
!= 0);
665 the_menubar
->previous_widget
= dlg_get_current_widget_id (midnight_dlg
);
666 dlg_select_widget (the_menubar
);
672 if (the_menubar
->is_active
)
675 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
676 the_menubar
->selected
= 0;
678 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
679 menu_last_selected_cmd ();
683 midnight_get_shortcut (unsigned long command
)
686 const char *shortcut
= NULL
;
688 shortcut
= lookup_keymap_shortcut (main_map
, command
);
689 if (shortcut
!= NULL
)
690 return g_strdup (shortcut
);
692 shortcut
= lookup_keymap_shortcut (panel_map
, command
);
693 if (shortcut
!= NULL
)
694 return g_strdup (shortcut
);
696 ext_map
= lookup_keymap_shortcut (main_map
, CK_StartExtMap1
);
698 shortcut
= lookup_keymap_shortcut (main_x_map
, command
);
699 if (shortcut
!= NULL
)
700 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
706 midnight_get_title (const Dlg_head
*h
, size_t len
)
708 /* TODO: share code with update_xterm_title_path() */
713 struct passwd
*pw
= NULL
;
719 path
= strip_home_and_password (current_panel
->cwd
);
720 res
= gethostname (host
, sizeof (host
));
724 host
[sizeof (host
) - 1] = '\0';
726 pw
= getpwuid (getuid ());
728 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
730 login
= g_strdup (host
);
732 p
= g_strdup_printf ("%s [%s]:%s", _("Panels:"), login
, path
);
733 path
= str_trunc (p
, len
- 4);
737 return g_strdup (path
);
741 toggle_show_hidden (void)
743 panels_options
.show_dot_files
= !panels_options
.show_dot_files
;
744 update_panels (UP_RELOAD
, UP_KEEPSEL
);
748 toggle_panels_split (void)
750 horizontal_split
= !horizontal_split
;
756 * Just a hack for allowing url-like pathnames to be accepted from the
760 translated_mc_chdir (char *dir
)
765 newdir
= vfs_translate_url (dir
);
766 ret
= mc_chdir (newdir
);
775 panel_view_mode_t current_mode
, other_mode
;
776 char original_dir
[BUF_1K
] = "\0";
778 if (boot_current_is_left
)
782 current_mode
= startup_left_mode
;
783 other_mode
= startup_right_mode
;
789 current_mode
= startup_right_mode
;
790 other_mode
= startup_left_mode
;
792 /* Creates the left panel */
793 if (mc_run_param0
!= NULL
)
795 if (mc_run_param1
!= NULL
)
797 /* Ok, user has specified two dirs, save the original one,
798 * since we may not be able to chdir to the proper
799 * second directory later
801 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
803 translated_mc_chdir (mc_run_param0
);
805 set_display_type (current_index
, current_mode
);
807 /* The other panel */
808 if (mc_run_param1
!= NULL
)
810 if (original_dir
[0] != '\0')
811 translated_mc_chdir (original_dir
);
812 translated_mc_chdir (mc_run_param1
);
814 set_display_type (other_index
, other_mode
);
816 if (startup_left_mode
== view_listing
)
818 current_panel
= left_panel
;
823 current_panel
= right_panel
;
825 current_panel
= left_panel
;
828 /* Create the nice widgets */
829 cmdline
= command_new (0, 0, 0);
830 the_prompt
= label_new (0, 0, mc_prompt
);
831 the_prompt
->transparent
= 1;
832 the_bar
= buttonbar_new (keybar_visible
);
834 the_hint
= label_new (0, 0, 0);
835 the_hint
->transparent
= 1;
836 the_hint
->auto_adjust_cols
= 0;
837 the_hint
->widget
.cols
= COLS
;
839 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
843 copy_current_pathname (void)
849 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
850 command_insert (cmdline
, cwd_path
, 0);
852 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
853 command_insert (cmdline
, PATH_SEP_STR
, 0);
858 copy_other_pathname (void)
862 if (get_other_type () != view_listing
)
868 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
869 command_insert (cmdline
, cwd_path
, 0);
871 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
872 command_insert (cmdline
, PATH_SEP_STR
, 0);
877 copy_readlink (WPanel
* panel
)
881 if (S_ISLNK (selection (panel
)->st
.st_mode
))
883 char buffer
[MC_MAXPATHLEN
];
884 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
887 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
892 command_insert (cmdline
, buffer
, 1);
898 copy_current_readlink (void)
900 copy_readlink (current_panel
);
904 copy_other_readlink (void)
906 if (get_other_type () == view_listing
)
907 copy_readlink (other_panel
);
910 /* Insert the selected file name into the input line */
912 copy_prog_name (void)
918 if (get_current_type () == view_tree
)
920 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
921 tmp
= tree_selected_name (tree
);
924 tmp
= selection (current_panel
)->fname
;
926 command_insert (cmdline
, tmp
, 1);
930 copy_tagged (WPanel
* panel
)
936 input_disable_update (cmdline
);
939 for (i
= 0; i
< panel
->count
; i
++)
941 if (panel
->dir
.list
[i
].f
.marked
)
942 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
947 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
, 1);
949 input_enable_update (cmdline
);
953 copy_current_tagged (void)
955 copy_tagged (current_panel
);
959 copy_other_tagged (void)
961 if (get_other_type () == view_listing
)
962 copy_tagged (other_panel
);
966 midnight_set_buttonbar (WButtonBar
* b
)
968 buttonbar_set_label (b
, 1, Q_ ("ButtonBar|Help"), main_map
, NULL
);
969 buttonbar_set_label (b
, 2, Q_ ("ButtonBar|Menu"), main_map
, NULL
);
970 buttonbar_set_label (b
, 3, Q_ ("ButtonBar|View"), main_map
, NULL
);
971 buttonbar_set_label (b
, 4, Q_ ("ButtonBar|Edit"), main_map
, NULL
);
972 buttonbar_set_label (b
, 5, Q_ ("ButtonBar|Copy"), main_map
, NULL
);
973 buttonbar_set_label (b
, 6, Q_ ("ButtonBar|RenMov"), main_map
, NULL
);
974 buttonbar_set_label (b
, 7, Q_ ("ButtonBar|Mkdir"), main_map
, NULL
);
975 buttonbar_set_label (b
, 8, Q_ ("ButtonBar|Delete"), main_map
, NULL
);
976 buttonbar_set_label (b
, 9, Q_ ("ButtonBar|PullDn"), main_map
, NULL
);
977 buttonbar_set_label (b
, 10, Q_ ("ButtonBar|Quit"), main_map
, NULL
);
980 static gboolean ctl_x_map_enabled
= FALSE
;
985 ctl_x_map_enabled
= TRUE
;
989 midnight_execute_cmd (Widget
* sender
, unsigned long command
)
991 cb_ret_t res
= MSG_HANDLED
;
995 /* stop quick search before executing any command */
996 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1003 case CK_ChangeListingCmd
:
1004 change_listing_cmd ();
1012 case CK_ChownAdvancedCmd
:
1013 chown_advanced_cmd ();
1015 case CK_CompareDirsCmd
:
1016 compare_dirs_cmd ();
1018 case CK_ConfigureBox
:
1022 case CK_ConfigureVfs
:
1032 case CK_CopyCurrentPathname
:
1033 copy_current_pathname ();
1035 case CK_CopyCurrentReadlink
:
1036 copy_current_readlink ();
1038 case CK_CopyCurrentTagged
:
1039 copy_current_tagged ();
1041 case CK_CopyOtherPathname
:
1042 copy_other_pathname ();
1044 case CK_CopyOtherReadlink
:
1045 copy_other_readlink ();
1047 case CK_CopyOtherTagged
:
1048 copy_other_tagged ();
1053 case CK_DialogListCmd
:
1054 dialog_switch_list ();
1056 #ifdef USE_DIFF_VIEW
1057 case CK_DiffViewCmd
:
1061 case CK_DisplayBitsBox
:
1062 display_bits_box ();
1067 #ifdef USE_INTERNAL_EDIT
1068 case CK_EditForceInternalCmd
:
1069 edit_cmd_force_internal ();
1072 case CK_EditExtFileCmd
:
1075 case CK_EditFhlFileCmd
:
1078 case CK_EditMcMenuCmd
:
1079 edit_mc_menu_cmd ();
1081 case CK_EditSymlinkCmd
:
1082 edit_symlink_cmd ();
1084 case CK_ExternalPanelize
:
1085 external_panelize ();
1090 case CK_FilteredViewCmd
:
1091 filtered_view_cmd ();
1096 #ifdef ENABLE_VFS_FISH
1097 case CK_FishlinkCmd
:
1101 #ifdef ENABLE_VFS_FTP
1113 if (sender
== (Widget
*) the_menubar
)
1114 info_cmd (); /* mwnu */
1116 info_cmd_no_menu (); /* shortcut or buttonbar */
1118 #ifdef WITH_BACKGROUND
1130 link_cmd (LINK_HARDLINK
);
1135 #ifdef LISTMODE_EDITOR
1136 case CK_ListmodeCmd
:
1143 case CK_MenuLastSelectedCmd
:
1144 menu_last_selected_cmd ();
1149 case CK_PanelOptionsBox
:
1150 panel_options_box ();
1153 case CK_PanelSetPanelEncoding
:
1160 case CK_QuickChdirCmd
:
1163 case CK_QuickViewCmd
:
1164 if (sender
== (Widget
*) the_menubar
)
1165 quick_view_cmd (); /* menu */
1167 quick_cmd_no_menu (); /* shortcut or buttonabr */
1169 case CK_QuietQuitCmd
:
1175 case CK_RelativeSymlinkCmd
:
1176 link_cmd (LINK_SYMLINK_RELATIVE
);
1185 case CK_ReselectVfs
:
1189 case CK_ReverseSelectionCmd
:
1190 reverse_selection_cmd ();
1192 case CK_SaveSetupCmd
:
1198 case CK_ShowCommandLine
:
1201 case CK_SingleDirsizeCmd
:
1202 smart_dirsize_cmd ();
1204 #ifdef ENABLE_VFS_SMB
1208 #endif /* ENABLE_VFS_SMB */
1212 case CK_StartExtMap1
:
1222 link_cmd (LINK_SYMLINK_ABSOLUTE
);
1224 case CK_ToggleListingCmd
:
1225 toggle_listing_cmd ();
1227 case CK_ToggleShowHidden
:
1228 toggle_show_hidden ();
1230 case CK_TogglePanelsSplit
:
1231 toggle_panels_split ();
1239 #ifdef ENABLE_VFS_UNDELFS
1240 case CK_UndeleteCmd
:
1244 case CK_UnselectCmd
:
1247 case CK_UserMenuCmd
:
1248 user_file_menu_cmd ();
1253 case CK_ViewFileCmd
:
1257 res
= MSG_NOT_HANDLED
;
1264 init_xterm_support (void)
1266 const char *termvalue
;
1268 termvalue
= getenv ("TERM");
1269 if (!termvalue
|| !(*termvalue
))
1271 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1272 exit (EXIT_FAILURE
);
1275 /* Check mouse capabilities */
1276 xmouse_seq
= tty_tgetstr ("Km");
1278 if (strcmp (termvalue
, "cygwin") == 0)
1280 mc_args__force_xterm
= 1;
1281 use_mouse_p
= MOUSE_DISABLED
;
1284 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1285 || strncmp (termvalue
, "konsole", 7) == 0
1286 || strncmp (termvalue
, "rxvt", 4) == 0
1287 || strcmp (termvalue
, "Eterm") == 0 || strcmp (termvalue
, "dtterm") == 0)
1291 /* Default to the standard xterm sequence */
1294 xmouse_seq
= ESC_STR
"[M";
1297 /* Enable mouse unless explicitly disabled by --nomouse */
1298 if (use_mouse_p
!= MOUSE_DISABLED
)
1300 const char *color_term
= getenv ("COLORTERM");
1301 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
1302 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
1303 strcmp (termvalue
, "Eterm") == 0)
1305 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
1309 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
1319 tty_display_8bit (full_eight_bits
!= 0);
1321 tty_display_8bit (eight_bit_clean
!= 0);
1324 #ifdef HAVE_SUBSHELL_SUPPORT
1326 add_select_channel (subshell_pty
, load_prompt
, 0);
1327 #endif /* !HAVE_SUBSHELL_SUPPORT */
1329 tty_setup_sigwinch (sigwinch_handler
);
1331 if ((tty_baudrate () < 9600) || tty_is_slow ())
1334 init_xterm_support ();
1339 setup_dummy_mc (void)
1341 char d
[MC_MAXPATHLEN
];
1344 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1352 const char *current_system_codepage
= NULL
;
1354 current_system_codepage
= str_detect_termencoding ();
1358 const char *_display_codepage
;
1360 _display_codepage
= get_codepage_id (display_codepage
);
1362 if (!strcmp (_display_codepage
, current_system_codepage
))
1364 utf8_display
= str_isutf8 (current_system_codepage
);
1368 display_codepage
= get_codepage_index (current_system_codepage
);
1369 if (display_codepage
== -1)
1371 display_codepage
= 0;
1374 mc_config_set_string (mc_main_config
, "Misc", "display_codepage", cp_display
);
1377 utf8_display
= str_isutf8 (current_system_codepage
);
1383 if (!(quit
& SUBSHELL_EXIT
))
1385 tty_reset_shell_mode ();
1398 * We sync the profiles since the hotlist may have changed, while
1399 * we only change the setup data if we have the auto save feature set
1402 if (auto_save_setup
)
1403 save_setup (); /* does also call save_hotlist */
1407 save_panel_types ();
1412 vfs_stamp_path (vfs_get_current_dir ());
1414 if ((current_panel
!= NULL
)
1415 && (get_current_type () == view_listing
))
1416 vfs_stamp_path (current_panel
->cwd
);
1418 if ((other_panel
!= NULL
)
1419 && (get_other_type () == view_listing
))
1420 vfs_stamp_path (other_panel
->cwd
);
1425 midnight_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
1427 unsigned long command
;
1437 /* We handle the special case of the output lines */
1438 if (console_flag
&& output_lines
)
1439 show_console_contents (output_start_y
,
1440 LINES
- output_lines
- keybar_visible
-
1441 1, LINES
- keybar_visible
- 1);
1446 menubar_arrange (the_menubar
);
1450 /* We only need the first idle event to show user menu after start */
1451 set_idle_proc (h
, 0);
1453 if (boot_current_is_left
)
1454 dlg_select_widget (get_panel_widget (0));
1456 dlg_select_widget (get_panel_widget (1));
1459 midnight_execute_cmd (NULL
, CK_UserMenuCmd
);
1463 if (ctl_x_map_enabled
)
1465 ctl_x_map_enabled
= FALSE
;
1466 command
= lookup_keymap_command (main_x_map
, parm
);
1467 if (command
!= CK_Ignore_Key
)
1468 return midnight_execute_cmd (NULL
, command
);
1471 /* FIXME: should handle all menu shortcuts before this point */
1472 if (the_menubar
->is_active
)
1473 return MSG_NOT_HANDLED
;
1476 free_completions (cmdline
);
1482 for (i
= 0; cmdline
->buffer
[i
] && (cmdline
->buffer
[i
] == ' ' ||
1483 cmdline
->buffer
[i
] == '\t'); i
++)
1485 if (cmdline
->buffer
[i
])
1487 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1490 stuff (cmdline
, "", 0);
1494 /* Ctrl-Enter and Alt-Enter */
1495 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n') && (parm
& (KEY_M_CTRL
| KEY_M_ALT
)))
1501 /* Ctrl-Shift-Enter */
1502 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n'))
1504 copy_current_pathname ();
1509 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1510 && !quote
&& !current_panel
->searching
)
1512 if (!only_leading_plus_minus
)
1514 /* Special treatement, since the input line will eat them */
1521 if (parm
== '\\' || parm
== '-')
1529 reverse_selection_cmd ();
1533 else if (!command_prompt
|| !cmdline
->buffer
[0])
1535 /* Special treatement '+', '-', '\', '*' only when this is
1536 * first char on input line
1545 if (parm
== '\\' || parm
== '-')
1553 reverse_selection_cmd ();
1558 return MSG_NOT_HANDLED
;
1560 case DLG_HOTKEY_HANDLED
:
1561 if ((get_current_type () == view_listing
) && current_panel
->searching
)
1563 current_panel
->dirty
= 1; /* FIXME: unneeded? */
1564 send_message ((Widget
*) current_panel
, WIDGET_COMMAND
, CK_PanelStopSearch
);
1568 case DLG_UNHANDLED_KEY
:
1573 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1574 if (v
== MSG_HANDLED
)
1578 if (ctl_x_map_enabled
)
1580 ctl_x_map_enabled
= FALSE
;
1581 command
= lookup_keymap_command (main_x_map
, parm
);
1584 command
= lookup_keymap_command (main_map
, parm
);
1586 return (command
== CK_Ignore_Key
) ? MSG_NOT_HANDLED
: midnight_execute_cmd (NULL
, command
);
1589 if (!the_menubar
->is_active
)
1590 update_dirty_panels ();
1596 midnight_execute_cmd (NULL
, parm
);
1597 /* message from menu */
1598 else if (sender
== (Widget
*) the_menubar
)
1599 midnight_execute_cmd (sender
, parm
);
1600 /* message from buttonbar */
1601 else if (sender
== (Widget
*) the_bar
)
1604 midnight_execute_cmd (sender
, parm
);
1606 send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1611 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1615 /* Show current directory in the xterm title */
1617 update_xterm_title_path (void)
1619 /* TODO: share code with midnight_get_title () */
1622 char host
[BUF_TINY
];
1624 struct passwd
*pw
= NULL
;
1628 if (xterm_flag
&& xterm_title
)
1630 path
= strip_home_and_password (current_panel
->cwd
);
1631 res
= gethostname (host
, sizeof (host
));
1633 { /* On success, res = 0 */
1638 host
[sizeof (host
) - 1] = '\0';
1640 pw
= getpwuid (getuid ());
1643 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1647 login
= g_strdup (host
);
1649 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1650 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1653 if (!alternate_plus_minus
)
1654 numeric_keypad_mode ();
1660 * Load new hint and display it.
1661 * IF force is not 0, ignore the timeout.
1664 load_hint (int force
)
1668 if (!the_hint
->widget
.owner
)
1671 if (!message_visible
)
1673 label_set_text (the_hint
, NULL
);
1677 hint
= get_random_hint (force
);
1687 char text
[BUF_SMALL
];
1689 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"), VERSION
);
1695 create_panels_and_run_mc (void)
1697 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
1698 midnight_dlg
->get_title
= midnight_get_title
;
1702 add_widget (midnight_dlg
, the_menubar
);
1705 add_widget (midnight_dlg
, get_panel_widget (0));
1706 add_widget (midnight_dlg
, get_panel_widget (1));
1708 add_widget (midnight_dlg
, the_hint
);
1709 add_widget (midnight_dlg
, cmdline
);
1710 add_widget (midnight_dlg
, the_prompt
);
1712 add_widget (midnight_dlg
, the_bar
);
1713 midnight_set_buttonbar (the_bar
);
1715 /* Run the Midnight Commander if no file was specified in the command line */
1716 run_dlg (midnight_dlg
);
1719 /* result must be free'd (I think this should go in util.c) */
1721 prepend_cwd_on_local (const char *filename
)
1726 if (!vfs_file_is_local (filename
) || g_path_is_absolute (filename
))
1727 return g_strdup (filename
);
1729 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1730 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1733 strcpy (d
+ l
, filename
);
1734 canonicalize_pathname (d
);
1738 /* Invoke the internal view/edit routine with:
1739 * the default processing and forcing the internal viewer/editor
1742 mc_maybe_editor_or_viewer (void)
1744 switch (mc_run_mode
)
1746 #ifdef USE_INTERNAL_EDIT
1748 edit_file (mc_run_param0
, mc_args__edit_start_line
);
1750 #endif /* USE_INTERNAL_EDIT */
1754 path
= prepend_cwd_on_local (mc_run_param0
);
1755 view_file (path
, 0, 1);
1759 #ifdef USE_DIFF_VIEW
1760 case MC_RUN_DIFFVIEWER
:
1761 diff_view (mc_run_param0
, mc_run_param1
, mc_run_param0
, mc_run_param1
);
1763 #endif /* USE_DIFF_VIEW */
1767 midnight_shutdown
= 1;
1770 /* Run the main dialog that occupies the whole screen */
1774 int midnight_colors
[DLG_COLOR_NUM
];
1775 midnight_colors
[0] = mc_skin_color_get ("dialog", "_default_");
1776 midnight_colors
[1] = mc_skin_color_get ("dialog", "focus");
1777 midnight_colors
[2] = mc_skin_color_get ("dialog", "hotnormal");
1778 midnight_colors
[3] = mc_skin_color_get ("dialog", "hotfocus");
1782 midnight_dlg
= create_dlg (FALSE
, 0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1783 "[main]", NULL
, DLG_WANT_IDLE
);
1785 if (mc_run_mode
== MC_RUN_FULL
)
1790 /* start check display_codepage and source_codepage */
1793 /* Check if we were invoked as an editor or file viewer */
1794 if (mc_run_mode
!= MC_RUN_FULL
)
1795 mc_maybe_editor_or_viewer ();
1798 create_panels_and_run_mc ();
1801 midnight_shutdown
= 1;
1803 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1804 if (mc_args__last_wd_file
&& vfs_current_is_local ())
1805 last_wd_string
= g_strdup (current_panel
->cwd
);
1809 dialog_switch_shutdown ();
1811 destroy_dlg (midnight_dlg
);
1817 /* POSIX version. The only version we support. */
1821 const char *shell_env
= getenv ("SHELL");
1822 const char *mc_libdir
;
1824 if ((shell_env
== NULL
) || (shell_env
[0] == '\0'))
1827 pwd
= getpwuid (geteuid ());
1829 shell
= g_strdup (pwd
->pw_shell
);
1832 shell
= g_strdup (shell_env
);
1834 if ((shell
== NULL
) || (shell
[0] == '\0'))
1837 shell
= g_strdup ("/bin/sh");
1840 /* This is the directory, where MC was installed, on Unix this is DATADIR */
1841 /* and can be overriden by the MC_DATADIR environment variable */
1842 mc_libdir
= getenv ("MC_DATADIR");
1843 if (mc_libdir
!= NULL
)
1845 mc_home
= g_strdup (mc_libdir
);
1846 mc_home_alt
= g_strdup (SYSCONFDIR
);
1850 mc_home
= g_strdup (SYSCONFDIR
);
1851 mc_home_alt
= g_strdup (DATADIR
);
1854 /* This variable is used by the subshell */
1855 home_dir
= getenv ("HOME");
1862 sigchld_handler_no_subshell (int sig
)
1870 /* COMMENT: if it were true that after the call to handle_console(..INIT)
1871 the value of console_flag never changed, we could simply not install
1872 this handler at all if (!console_flag && !use_subshell). */
1874 /* That comment is no longer true. We need to wait() on a sigchld
1875 handler (that's at least what the tarfs code expects currently). */
1877 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
1879 if (pid
== cons_saver_pid
)
1882 if (WIFSTOPPED (status
))
1884 /* Someone has stopped cons.saver - restart it */
1885 kill (pid
, SIGCONT
);
1889 /* cons.saver has died - disable console saving */
1890 handle_console (CONSOLE_DONE
);
1894 /* If we got here, some other child exited; ignore it */
1895 #endif /* __linux__ */
1903 struct sigaction sigchld_action
;
1905 sigchld_action
.sa_handler
=
1906 #ifdef HAVE_SUBSHELL_SUPPORT
1907 use_subshell
? sigchld_handler
:
1908 #endif /* HAVE_SUBSHELL_SUPPORT */
1909 sigchld_handler_no_subshell
;
1911 sigemptyset (&sigchld_action
.sa_mask
);
1914 sigchld_action
.sa_flags
= SA_RESTART
;
1916 sigchld_action
.sa_flags
= 0;
1917 #endif /* !SA_RESTART */
1919 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1)
1921 #ifdef HAVE_SUBSHELL_SUPPORT
1923 * This may happen on QNX Neutrino 6, where SA_RESTART
1924 * is defined but not implemented. Fallback to no subshell.
1927 #endif /* HAVE_SUBSHELL_SUPPORT */
1932 main (int argc
, char *argv
[])
1936 GError
*error
= NULL
;
1937 gboolean isInitialized
;
1939 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
1940 setlocale (LC_ALL
, "");
1941 bindtextdomain ("mc", LOCALEDIR
);
1944 /* Set up temporary directory */
1949 str_init_strings (NULL
);
1953 #ifdef USE_INTERNAL_EDIT
1958 SLtt_Ignore_Beep
= 1;
1961 if (!mc_args_handle (argc
, argv
, "mc"))
1962 exit (EXIT_FAILURE
);
1964 /* NOTE: This has to be called before tty_init or whatever routine
1965 calls any define_sequence */
1968 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
1969 handle_console (CONSOLE_INIT
);
1971 #ifdef HAVE_SUBSHELL_SUPPORT
1972 /* Don't use subshell when invoked as viewer or editor */
1973 if (mc_run_mode
!= MC_RUN_FULL
)
1977 subshell_get_console_attributes ();
1978 #endif /* HAVE_SUBSHELL_SUPPORT */
1980 /* Install the SIGCHLD handler; must be done before init_subshell() */
1983 /* We need this, since ncurses endwin () doesn't restore the signals */
1984 save_stop_handler ();
1986 /* Must be done before init_subshell, to set up the terminal size: */
1987 /* FIXME: Should be removed and LINES and COLS computed on subshell */
1988 tty_init ((gboolean
) mc_args__slow_terminal
, (gboolean
) mc_args__ugly_line_drawing
);
1992 /* Removing this from the X code let's us type C-c */
1995 load_keymap_defs ();
1997 tty_init_colors (mc_args__disable_colors
, mc_args__force_colors
);
1999 isInitialized
= mc_skin_init (&error
);
2001 mc_filehighlight
= mc_fhl_new (TRUE
);
2003 dlg_set_default_colors ();
2007 message (D_ERROR
, _("Warning"), "%s", error
->message
);
2008 g_error_free (error
);
2012 /* create home directory */
2013 /* do it after the screen library initialization to show the error message */
2014 mc_dir
= concat_dir_and_file (home_dir
, MC_USERCONF_DIR
);
2015 canonicalize_pathname (mc_dir
);
2016 if ((stat (mc_dir
, &s
) != 0) && (errno
== ENOENT
) && mkdir (mc_dir
, 0700) != 0)
2017 message (D_ERROR
, _("Warning"), _("Cannot create %s directory"), mc_dir
);
2020 #ifdef HAVE_SUBSHELL_SUPPORT
2021 /* Done here to ensure that the subshell doesn't */
2022 /* inherit the file descriptors opened below, etc */
2026 #endif /* HAVE_SUBSHELL_SUPPORT */
2028 /* Also done after init_subshell, to save any shell init file messages */
2030 handle_console (CONSOLE_SAVE
);
2032 if (alternate_plus_minus
)
2033 application_keypad_mode ();
2035 #ifdef HAVE_SUBSHELL_SUPPORT
2038 mc_prompt
= strip_ctrl_codes (subshell_prompt
);
2039 if (mc_prompt
== NULL
)
2040 mc_prompt
= (geteuid () == 0) ? "# " : "$ ";
2043 #endif /* HAVE_SUBSHELL_SUPPORT */
2044 mc_prompt
= (geteuid () == 0) ? "# " : "$ ";
2046 /* Program main loop */
2047 if (!midnight_shutdown
)
2050 /* Save the tree store */
2053 free_keymap_defs ();
2055 /* Virtual File System shutdown */
2058 flush_extension_file (); /* does only free memory */
2060 mc_fhl_free (&mc_filehighlight
);
2065 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2066 handle_console (CONSOLE_RESTORE
);
2067 if (alternate_plus_minus
)
2068 numeric_keypad_mode ();
2070 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2073 handle_console (CONSOLE_DONE
);
2074 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2076 if (mc_run_mode
== MC_RUN_FULL
&& mc_args__last_wd_file
&& last_wd_string
&& !print_last_revert
)
2078 int last_wd_fd
= open (mc_args__last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2081 if (last_wd_fd
!= -1)
2085 ret1
= write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2086 ret2
= close (last_wd_fd
);
2089 g_free (last_wd_string
);
2091 g_free (mc_home_alt
);
2097 free_codepages_list ();
2098 g_free (autodetect_codeset
);
2100 g_free (clipboard_store_path
);
2101 g_free (clipboard_paste_path
);
2103 str_uninit_strings ();
2105 g_free (mc_run_param0
);
2106 g_free (mc_run_param1
);
2108 #ifdef USE_INTERNAL_EDIT