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 */
51 #include "lib/mcconfig.h"
52 #include "lib/filehighlight.h"
53 #include "lib/fileloc.h" /* MC_USERCONF_DIR */
55 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_translate_url() */
58 #include "lib/vfs/mc-vfs/smbfs.h" /* smbfs_set_debug() */
59 #endif /* ENABLE_VFS_SMB */
62 #include "lib/vfs/mc-vfs/gc.h"
65 #include "lib/strutil.h"
75 #include "treestore.h"
76 #include "consaver/cons.saver.h"
78 #include "setup.h" /* save_setup() */
79 #include "boxes.h" /* sort_box() */
81 #include "cmd.h" /* Normal commands */
84 #include "learn.h" /* learn_keys() */
87 #include "ext.h" /* For flush_extension_file() */
91 #include "cmddef.h" /* CK_ cmd name const */
92 #include "user.h" /* user_file_menu_cmd() */
102 #ifdef USE_INTERNAL_EDIT
103 # include "src/editor/edit.h"
107 #include "charsets.h"
108 #endif /* HAVE_CHARSET */
111 #include "keybind.h" /* type global_keymap_t */
113 /* When the modes are active, left_panel, right_panel and tree_panel */
114 /* Point to a proper data structure. You should check with the functions */
115 /* get_current_type and get_other_type the types of the panels before using */
116 /* This pointer variables */
118 /* The structures for the panels */
119 WPanel
*left_panel
= NULL
;
120 WPanel
*right_panel
= NULL
;
122 mc_fhl_t
*mc_filehighlight
;
124 /* The pointer to the tree */
125 WTree
*the_tree
= NULL
;
128 struct WMenuBar
*the_menubar
= NULL
;
130 /* Pointers to the selected and unselected panel */
131 WPanel
*current_panel
= NULL
;
133 /* Set if the command is being run from the "Right" menu */
136 /* Set when main loop should be terminated */
137 volatile int quit
= 0;
139 /* Set if you want the possible completions dialog for the first time */
140 int show_all_if_ambiguous
= 0;
142 /* Set when cd symlink following is desirable (bash mode) */
145 /* If set then dialogs just clean the screen when refreshing, else */
146 /* they do a complete refresh, refreshing all the parts of the program */
147 int fast_refresh
= 0;
149 /* If true, marking a files moves the cursor down */
150 int mark_moves_down
= 1;
152 /* If true, at startup the user-menu is invoked */
155 /* If true, then the +, - and \ keys have their special meaning only if the
156 * command line is emtpy, otherwise they behave like regular letters
158 int only_leading_plus_minus
= 1;
160 int pause_after_run
= pause_on_dumb_terminals
;
162 /* It true saves the setup when quitting */
163 int auto_save_setup
= 1;
167 * Don't restrict the output on the screen manager level,
168 * the translation tables take care of it.
170 #define full_eight_bits (1)
171 #define eight_bit_clean (1)
172 #else /* HAVE_CHARSET */
173 /* If true, allow characters in the range 160-255 */
174 int eight_bit_clean
= 1;
176 * If true, also allow characters in the range 128-159.
177 * This is reported to break on many terminals (xterm, qansi-m).
179 int full_eight_bits
= 0;
180 #endif /* !HAVE_CHARSET */
183 * If utf-8 terminal utf8_display = 1
184 * Display bits set UTF-8
187 int utf8_display
= 0;
189 /* If true use the internal viewer */
190 int use_internal_view
= 1;
192 /* Have we shown the fast-reload warning in the past? */
193 int fast_reload_w
= 0;
195 /* Move page/item? When clicking on the top or bottom of a panel */
196 int mouse_move_pages
= 1;
198 /* If true: l&r arrows are used to chdir if the input line is empty */
199 int navigate_with_arrows
= 0;
202 const char *mc_prompt
= NULL
;
204 /* The widget where we draw the prompt */
213 /* Mouse type: GPM, xterm or none */
214 Mouse_Type use_mouse_p
= MOUSE_NONE
;
216 /* If on, default for "No" in delete operations */
219 /* Controls screen clearing before an exec */
220 int clear_before_exec
= 1;
222 /* Asks for confirmation before deleting a file */
223 int confirm_delete
= 1;
225 /* Asks for confirmation before deleting a hotlist entry */
226 int confirm_directory_hotlist_delete
= 1;
228 /* Asks for confirmation before overwriting a file */
229 int confirm_overwrite
= 1;
231 /* Asks for confirmation before executing a program by pressing enter */
232 int confirm_execute
= 0;
234 /* Asks for confirmation before leaving the program */
235 int confirm_exit
= 1;
237 /* Asks for confirmation when using F3 to view a directory and there
239 int confirm_view_dir
= 0;
241 /* This flag indicates if the pull down menus by default drop down */
244 /* The dialog handle for the main program */
245 Dlg_head
*midnight_dlg
= NULL
;
247 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
248 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
249 int update_prompt
= 0;
251 /* The home directory */
252 const char *home_dir
= NULL
;
255 int option_tab_spacing
= 8;
257 /* The value of the other directory, only used when loading the setup */
258 char *other_dir
= NULL
;
260 /* Only used at program boot */
261 int boot_current_is_left
= 1;
263 static char *this_dir
= NULL
;
265 /* If this is true, then when browsing the tree the other window will
266 * automatically reload it's directory with the contents of the currently
267 * selected directory.
271 /* If set, then print to the given file the last directory we were at */
272 static char *last_wd_string
= NULL
;
273 /* Set to 1 to suppress printing the last directory */
274 static int print_last_revert
= 0;
276 /* File name to view if argument was supplied */
277 const char *view_one_file
= NULL
;
279 /* File name to edit if argument was supplied */
280 const char *edit_one_file
= NULL
;
282 /* Line to start the editor on */
283 static int edit_one_file_start_line
= 0;
285 /* Used so that widgets know if they are being destroyed or
287 int midnight_shutdown
= 0;
289 /* The user's shell */
292 /* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
293 char *mc_home
= NULL
;
295 /* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
296 char *mc_home_alt
= NULL
;
298 /* Define this function for glib-style error handling */
300 mc_main_error_quark (void)
302 return g_quark_from_static_string (PACKAGE
);
305 #ifdef USE_INTERNAL_EDIT
306 GArray
*editor_keymap
= NULL
;
307 GArray
*editor_x_keymap
= NULL
;
309 GArray
*viewer_keymap
= NULL
;
310 GArray
*viewer_hex_keymap
= NULL
;
311 GArray
*main_keymap
= NULL
;
312 GArray
*main_x_keymap
= NULL
;
313 GArray
*panel_keymap
= NULL
;
314 GArray
*input_keymap
= NULL
;
315 GArray
*tree_keymap
= NULL
;
316 GArray
*help_keymap
= NULL
;
318 const global_keymap_t
*main_map
;
319 const global_keymap_t
*main_x_map
;
321 /* Save current stat of directories to avoid reloading the panels */
322 /* when no modifications have taken place */
324 save_cwds_stat (void)
327 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
328 if (get_other_type () == view_listing
)
329 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
333 #ifdef HAVE_SUBSHELL_SUPPORT
335 do_update_prompt (void)
338 printf ("\r\n%s", subshell_prompt
);
343 #endif /* HAVE_SUBSHELL_SUPPORT */
348 free_completions (cmdline
);
349 dlg_one_down (midnight_dlg
);
352 /* Stop MC main dialog and the current dialog if it exists.
353 * Needed to provide fast exit from MC viewer or editor on shell exit */
357 midnight_dlg
->running
= 0;
359 current_dlg
->running
= 0;
364 quit_cmd_internal (int quiet
)
368 if (quiet
|| !confirm_exit
) {
372 (_(" The Midnight Commander "),
373 _(" Do you really want to quit the Midnight Commander? "), D_NORMAL
,
374 2, _("&Yes"), _("&No")) == 0)
378 #ifdef HAVE_SUBSHELL_SUPPORT
381 else if ((q
= exit_subshell ()))
393 quit_cmd_internal (0);
397 quiet_quit_cmd (void)
399 print_last_revert
= 1;
400 quit_cmd_internal (1);
403 /* Wrapper for do_subshell_chdir, check for availability of subshell */
405 subshell_chdir (const char *directory
)
407 #ifdef HAVE_SUBSHELL_SUPPORT
409 if (vfs_current_is_local ())
410 do_subshell_chdir (directory
, 0, 1);
412 #endif /* HAVE_SUBSHELL_SUPPORT */
416 directory_history_add (struct WPanel
*panel
, const char *dir
)
420 tmp
= g_strdup (dir
);
421 strip_password (tmp
, 1);
423 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
427 * If we moved to the parent directory move the selection pointer to
428 * the old directory name; If we leave VFS dir, remove FS specificator.
430 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
433 get_parent_dir_name (const char *cwd
, const char *lwd
)
436 if (strlen (lwd
) > strlen (cwd
))
437 if ((p
= strrchr (lwd
, PATH_SEP
)) && !strncmp (cwd
, lwd
, p
- lwd
) &&
438 ((gsize
)strlen (cwd
) == (gsize
) p
- (gsize
) lwd
|| (p
== lwd
&& cwd
[0] == PATH_SEP
&&
446 * Changes the current directory of the panel.
447 * Don't record change in the directory history.
450 _do_panel_cd (WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
452 const char *directory
;
454 char temp
[MC_MAXPATHLEN
];
455 char *translated_url
;
457 if (cd_type
== cd_parse_command
) {
458 while (*new_dir
== ' ')
462 olddir
= g_strdup (panel
->cwd
);
463 new_dir
= translated_url
= vfs_translate_url (new_dir
);
465 /* Convert *new_path to a suitable pathname, handle ~user */
467 if (cd_type
== cd_parse_command
) {
468 if (!strcmp (new_dir
, "-")) {
469 strcpy (temp
, panel
->lwd
);
473 directory
= *new_dir
? new_dir
: home_dir
;
475 if (mc_chdir (directory
) == -1) {
476 strcpy (panel
->cwd
, olddir
);
478 g_free (translated_url
);
481 g_free (translated_url
);
483 /* Success: save previous directory, shutdown status of previous dir */
484 strcpy (panel
->lwd
, olddir
);
485 free_completions (cmdline
);
487 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
489 vfs_release_path (olddir
);
491 subshell_chdir (panel
->cwd
);
493 /* Reload current panel */
494 panel_clean_dir (panel
);
496 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
497 panel
->reverse
, panel
->case_sensitive
,
498 panel
->exec_first
, panel
->filter
);
499 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
502 update_xterm_title_path ();
510 * Changes the current directory of the panel.
511 * Record change in the directory history.
514 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
518 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
520 directory_history_add (panel
, panel
->cwd
);
525 do_cd (const char *new_dir
, enum cd_enum exact
)
527 return (do_panel_cd (current_panel
, new_dir
, exact
));
531 directory_history_next (WPanel
*panel
)
535 nextdir
= g_list_next (panel
->dir_history
);
540 if (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
))
541 panel
->dir_history
= nextdir
;
545 directory_history_prev (WPanel
*panel
)
549 prevdir
= g_list_previous (panel
->dir_history
);
554 if (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
))
555 panel
->dir_history
= prevdir
;
559 directory_history_list (WPanel
*panel
)
563 if (!panel
->dir_history
)
566 s
= show_hist (panel
->dir_history
, &panel
->widget
);
571 if (_do_panel_cd (panel
, s
, cd_exact
))
572 directory_history_add (panel
, panel
->cwd
);
574 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
578 #ifdef HAVE_SUBSHELL_SUPPORT
580 load_prompt (int fd
, void *unused
)
585 if (!read_subshell_prompt ())
588 /* Don't actually change the prompt if it's invisible */
589 if (current_dlg
== midnight_dlg
&& command_prompt
) {
593 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
594 prompt_len
= str_term_width1 (tmp_prompt
);
596 /* Check for prompts too big */
597 if (COLS
> 8 && prompt_len
> COLS
- 8) {
598 tmp_prompt
[COLS
- 8] = '\0';
599 prompt_len
= COLS
- 8;
601 mc_prompt
= tmp_prompt
;
602 label_set_text (the_prompt
, mc_prompt
);
603 winput_set_origin ((WInput
*) cmdline
, prompt_len
,
606 /* since the prompt has changed, and we are called from one of the
607 * tty_get_event channels, the prompt updating does not take place
608 * automatically: force a cursor update and a screen refresh
610 update_cursor (midnight_dlg
);
616 #endif /* HAVE_SUBSHELL_SUPPORT */
622 const panel_field_t
*sort_order
;
624 if (!SELECTED_IS_PANEL
)
628 sort_order
= sort_box (p
->current_sort_field
, &p
->reverse
,
632 panel_set_sort_order (p
, sort_order
);
641 sel_dir
= tree_box (selection (current_panel
)->fname
);
643 do_cd (sel_dir
, cd_exact
);
648 #ifdef LISTMODE_EDITOR
654 if (get_current_type () != view_listing
)
657 newmode
= listmode_edit (current_panel
->user_format
);
661 g_free (current_panel
->user_format
);
662 current_panel
->list_type
= list_user
;
663 current_panel
->user_format
= newmode
;
664 set_panel_formats (current_panel
);
668 #endif /* LISTMODE_EDITOR */
670 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
672 create_panel_menu (void)
674 GList
*entries
= NULL
;
676 entries
= g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_ListingCmd
));
677 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_QuickViewCmd
));
678 entries
= g_list_append (entries
, menu_entry_create (_("&Info" ), CK_InfoCmd
));
679 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_TreeCmd
));
680 entries
= g_list_append (entries
, menu_separator_create ());
681 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
682 entries
= g_list_append (entries
, menu_separator_create ());
683 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_FilterCmd
));
685 entries
= g_list_append (entries
, menu_separator_create ());
686 entries
= g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding
));
689 entries
= g_list_append (entries
, menu_separator_create ());
690 #ifdef ENABLE_VFS_MCFS
691 entries
= g_list_append (entries
, menu_entry_create (_("&Network link..."), CK_NetlinkCmd
));
693 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd
));
694 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd
));
695 #ifdef ENABLE_VFS_SMB
696 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd
));
697 #endif /* ENABLE_VFS_SMB */
699 entries
= g_list_append (entries
, menu_separator_create ());
700 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_RereadCmd
));
706 create_file_menu (void)
708 GList
*entries
= NULL
;
710 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_ViewCmd
));
711 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd
));
712 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd
));
713 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_EditCmd
));
714 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_CopyCmd
));
715 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChmodCmd
));
716 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_LinkCmd
));
717 entries
= g_list_append (entries
, menu_entry_create (_("&SymLink"), CK_SymlinkCmd
));
718 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd
));
719 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChownCmd
));
720 entries
= g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd
));
721 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_RenameCmd
));
722 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MkdirCmd
));
723 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_DeleteCmd
));
724 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd
));
725 entries
= g_list_append (entries
, menu_separator_create ());
726 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_SelectCmd
));
727 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_UnselectCmd
));
728 entries
= g_list_append (entries
, menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd
));
729 entries
= g_list_append (entries
, menu_separator_create ());
730 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_QuitCmd
));
736 create_command_menu (void)
738 /* I know, I'm lazy, but the tree widget when it's not running
739 * as a panel still has some problems, I have not yet finished
740 * the WTree widget port, sorry.
742 GList
*entries
= NULL
;
744 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenuCmd
));
745 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd
));
746 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_FindCmd
));
747 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_SwapCmd
));
748 entries
= g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine
));
749 entries
= g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd
));
750 entries
= g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
751 entries
= g_list_append (entries
, menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd
));
752 entries
= g_list_append (entries
, menu_separator_create ());
753 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_HistoryCmd
));
754 entries
= g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd
));
756 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs
));
758 #ifdef WITH_BACKGROUND
759 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_JobsCmd
));
761 entries
= g_list_append (entries
, menu_separator_create ());
763 entries
= g_list_append (entries
, menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd
));
765 #ifdef LISTMODE_EDITOR
766 entries
= g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd
));
768 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
769 entries
= g_list_append (entries
, menu_separator_create ());
771 entries
= g_list_append (entries
, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd
));
772 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd
));
773 entries
= g_list_append (entries
, menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd
));
779 create_options_menu (void)
781 GList
*entries
= NULL
;
783 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_ConfigureBox
));
784 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_LayoutCmd
));
785 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox
));
786 entries
= g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox
));
787 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
789 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs
));
791 entries
= g_list_append (entries
, menu_separator_create ());
792 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd
));
800 menubar_add_menu (the_menubar
,
801 create_menu (horizontal_split
? _("&Above") : _("&Left"),
802 create_panel_menu (), "[Left and Right Menus]"));
803 menubar_add_menu (the_menubar
,
804 create_menu (_("&File"), create_file_menu (), "[File Menu]"));
805 menubar_add_menu (the_menubar
,
806 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
807 menubar_add_menu (the_menubar
,
808 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
809 menubar_add_menu (the_menubar
,
810 create_menu (horizontal_split
? _("&Below") : _("&Right"),
811 create_panel_menu (), "[Left and Right Menus]"));
817 menubar_set_menu (the_menubar
, NULL
);
821 menu_last_selected_cmd (void)
823 the_menubar
->is_active
= TRUE
;
824 the_menubar
->is_dropped
= (drop_menus
!= 0);
825 the_menubar
->previous_widget
= midnight_dlg
->current
->dlg_id
;
826 dlg_select_widget (the_menubar
);
832 if (the_menubar
->is_active
)
835 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
836 the_menubar
->selected
= 0;
838 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
839 menu_last_selected_cmd ();
843 midnight_get_shortcut (unsigned long command
)
846 const char *shortcut
= NULL
;
848 shortcut
= lookup_keymap_shortcut (main_map
, command
);
849 if (shortcut
!= NULL
)
850 return g_strdup (shortcut
);
852 shortcut
= lookup_keymap_shortcut (panel_map
, command
);
853 if (shortcut
!= NULL
)
854 return g_strdup (shortcut
);
856 ext_map
= lookup_keymap_shortcut (main_map
, CK_StartExtMap1
);
858 shortcut
= lookup_keymap_shortcut (main_x_map
, command
);
859 if (shortcut
!= NULL
)
860 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
865 /* Flag toggling functions */
867 toggle_fast_reload (void)
869 fast_reload
= !fast_reload
;
870 if (fast_reload_w
== 0 && fast_reload
) {
871 message (D_NORMAL
, _(" Information "),
873 (" Using the fast reload option may not reflect the exact \n"
874 " directory contents. In this case you'll need to do a \n"
875 " manual reload of the directory. See the man page for \n"
882 toggle_mix_all_files (void)
884 mix_all_files
= !mix_all_files
;
885 update_panels (UP_RELOAD
, UP_KEEPSEL
);
889 toggle_show_backup (void)
891 show_backups
= !show_backups
;
892 update_panels (UP_RELOAD
, UP_KEEPSEL
);
896 toggle_show_hidden (void)
898 show_dot_files
= !show_dot_files
;
899 update_panels (UP_RELOAD
, UP_KEEPSEL
);
903 toggle_kilobyte_si (void)
905 kilobyte_si
= !kilobyte_si
;
906 update_panels (UP_RELOAD
, UP_KEEPSEL
);
910 * Just a hack for allowing url-like pathnames to be accepted from the
914 translated_mc_chdir (char *dir
)
918 newdir
= vfs_translate_url (dir
);
928 panel_view_mode_t current_mode
, other_mode
;
929 char original_dir
[BUF_1K
] = "\0";
931 if (boot_current_is_left
) {
934 current_mode
= startup_left_mode
;
935 other_mode
= startup_right_mode
;
939 current_mode
= startup_right_mode
;
940 other_mode
= startup_left_mode
;
942 /* Creates the left panel */
945 /* Ok, user has specified two dirs, save the original one,
946 * since we may not be able to chdir to the proper
947 * second directory later
949 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
951 translated_mc_chdir (this_dir
);
953 set_display_type (current_index
, current_mode
);
955 /* The other panel */
957 if (original_dir
[0] != '\0')
958 translated_mc_chdir (original_dir
);
959 translated_mc_chdir (other_dir
);
961 set_display_type (other_index
, other_mode
);
963 if (startup_left_mode
== view_listing
) {
964 current_panel
= left_panel
;
967 current_panel
= right_panel
;
969 current_panel
= left_panel
;
972 /* Create the nice widgets */
973 cmdline
= command_new (0, 0, 0);
974 the_prompt
= label_new (0, 0, mc_prompt
);
975 the_prompt
->transparent
= 1;
976 the_bar
= buttonbar_new (keybar_visible
);
978 the_hint
= label_new (0, 0, 0);
979 the_hint
->transparent
= 1;
980 the_hint
->auto_adjust_cols
= 0;
981 the_hint
->widget
.cols
= COLS
;
983 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
987 copy_current_pathname (void)
993 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
994 command_insert (cmdline
, cwd_path
, 0);
996 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
997 command_insert (cmdline
, PATH_SEP_STR
, 0);
1002 copy_other_pathname (void)
1006 if (get_other_type () != view_listing
)
1009 if (!command_prompt
)
1012 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
1013 command_insert (cmdline
, cwd_path
, 0);
1015 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
1016 command_insert (cmdline
, PATH_SEP_STR
, 0);
1021 copy_readlink (WPanel
*panel
)
1023 if (!command_prompt
)
1025 if (S_ISLNK (selection (panel
)->st
.st_mode
)) {
1026 char buffer
[MC_MAXPATHLEN
];
1028 concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1031 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1035 command_insert (cmdline
, buffer
, 1);
1041 copy_current_readlink (void)
1043 copy_readlink (current_panel
);
1047 copy_other_readlink (void)
1049 if (get_other_type () == view_listing
)
1050 copy_readlink (other_panel
);
1053 /* Insert the selected file name into the input line */
1055 copy_prog_name (void)
1058 if (!command_prompt
)
1061 if (get_current_type () == view_tree
) {
1062 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1063 tmp
= tree_selected_name (tree
);
1065 tmp
= selection (current_panel
)->fname
;
1067 command_insert (cmdline
, tmp
, 1);
1071 copy_tagged (WPanel
*panel
)
1075 if (!command_prompt
)
1077 input_disable_update (cmdline
);
1078 if (panel
->marked
) {
1079 for (i
= 0; i
< panel
->count
; i
++) {
1080 if (panel
->dir
.list
[i
].f
.marked
)
1081 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
1084 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
,
1087 input_enable_update (cmdline
);
1091 copy_current_tagged (void)
1093 copy_tagged (current_panel
);
1097 copy_other_tagged (void)
1099 if (get_other_type () == view_listing
)
1100 copy_tagged (other_panel
);
1104 midnight_set_buttonbar (WButtonBar
*b
)
1106 buttonbar_set_label (b
, 1, Q_("ButtonBar|Help"), main_map
, NULL
);
1107 buttonbar_set_label (b
, 2, Q_("ButtonBar|Menu"), main_map
, NULL
);
1108 buttonbar_set_label (b
, 3, Q_("ButtonBar|View"), main_map
, NULL
);
1109 buttonbar_set_label (b
, 4, Q_("ButtonBar|Edit"), main_map
, NULL
);
1110 buttonbar_set_label (b
, 5, Q_("ButtonBar|Copy"), main_map
, NULL
);
1111 buttonbar_set_label (b
, 6, Q_("ButtonBar|RenMov"), main_map
, NULL
);
1112 buttonbar_set_label (b
, 7, Q_("ButtonBar|Mkdir"), main_map
, NULL
);
1113 buttonbar_set_label (b
, 8, Q_("ButtonBar|Delete"), main_map
, NULL
);
1114 buttonbar_set_label (b
, 9, Q_("ButtonBar|PullDn"), main_map
, NULL
);
1115 buttonbar_set_label (b
, 10, Q_("ButtonBar|Quit"), main_map
, NULL
);
1118 static gboolean ctl_x_map_enabled
= FALSE
;
1123 ctl_x_map_enabled
= TRUE
;
1127 midnight_execute_cmd (Widget
*sender
, unsigned long command
)
1129 cb_ret_t res
= MSG_HANDLED
;
1143 case CK_ChownAdvancedCmd
:
1144 chown_advanced_cmd ();
1146 case CK_CompareDirsCmd
:
1147 compare_dirs_cmd ();
1149 case CK_ConfigureBox
:
1153 case CK_ConfigureVfs
:
1163 case CK_CopyCurrentPathname
:
1164 copy_current_pathname ();
1166 case CK_CopyCurrentReadlink
:
1167 copy_current_readlink ();
1169 case CK_CopyCurrentTagged
:
1170 copy_current_tagged ();
1172 case CK_CopyOtherPathname
:
1173 copy_other_pathname ();
1175 case CK_CopyOtherReadlink
:
1176 copy_other_readlink ();
1178 case CK_CopyOtherTagged
:
1179 copy_other_tagged ();
1184 case CK_DisplayBitsBox
:
1185 display_bits_box ();
1190 case CK_EditExtFileCmd
:
1193 case CK_EditFhlFileCmd
:
1196 case CK_EditMcMenuCmd
:
1197 edit_mc_menu_cmd ();
1199 case CK_EditSymlinkCmd
:
1200 edit_symlink_cmd ();
1202 case CK_ExternalPanelize
:
1203 external_panelize ();
1208 case CK_FilteredViewCmd
:
1209 filtered_view_cmd ();
1214 #if defined (USE_NETCODE)
1215 case CK_FishlinkCmd
:
1229 if (sender
== (Widget
*) the_menubar
)
1230 info_cmd (); /* mwnu */
1232 info_cmd_no_menu (); /* shortcut or buttonbar */
1234 #ifdef WITH_BACKGROUND
1251 #ifdef LISTMODE_EDITOR
1252 case CK_ListmodeCmd
:
1259 case CK_MenuLastSelectedCmd
:
1260 menu_last_selected_cmd ();
1265 #if defined (USE_NETCODE) && defined (ENABLE_VFS_MCFS)
1271 case CK_PanelSetPanelEncoding
:
1278 case CK_QuickChdirCmd
:
1281 case CK_QuickViewCmd
:
1282 if (sender
== (Widget
*) the_menubar
)
1283 quick_view_cmd (); /* menu */
1285 quick_cmd_no_menu (); /* shortcut or buttonabr */
1287 case CK_QuietQuitCmd
:
1300 case CK_ReselectVfs
:
1304 case CK_ReverseSelectionCmd
:
1305 reverse_selection_cmd ();
1307 case CK_SaveSetupCmd
:
1313 case CK_ShowCommandLine
:
1316 case CK_SingleDirsizeCmd
:
1317 smart_dirsize_cmd ();
1319 #if defined (USE_NETCODE) && defined (ENABLE_VFS_SMB)
1323 #endif /* USE_NETCODE && ENABLE_VFS_SMB */
1327 case CK_StartExtMap1
:
1339 case CK_ToggleListingCmd
:
1340 toggle_listing_cmd ();
1342 case CK_ToggleShowHidden
:
1343 toggle_show_hidden ();
1351 #ifdef USE_EXT2FSLIB
1352 case CK_UndeleteCmd
:
1356 case CK_UnselectCmd
:
1359 case CK_UserMenuCmd
:
1360 user_file_menu_cmd ();
1365 case CK_ViewFileCmd
:
1369 res
= MSG_NOT_HANDLED
;
1376 init_xterm_support (void)
1378 const char *termvalue
;
1380 termvalue
= getenv ("TERM");
1381 if (!termvalue
|| !(*termvalue
)) {
1382 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1386 /* Check mouse capabilities */
1387 xmouse_seq
= tty_tgetstr ("Km");
1389 if (strcmp (termvalue
, "cygwin") == 0) {
1390 mc_args__force_xterm
= 1;
1391 use_mouse_p
= MOUSE_DISABLED
;
1394 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1395 || strncmp (termvalue
, "konsole", 7) == 0
1396 || strncmp (termvalue
, "rxvt", 4) == 0
1397 || strcmp (termvalue
, "Eterm") == 0
1398 || strcmp (termvalue
, "dtterm") == 0) {
1401 /* Default to the standard xterm sequence */
1403 xmouse_seq
= ESC_STR
"[M";
1406 /* Enable mouse unless explicitly disabled by --nomouse */
1407 if (use_mouse_p
!= MOUSE_DISABLED
) {
1408 const char *color_term
= getenv ("COLORTERM");
1409 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
1410 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
1411 strcmp (termvalue
, "Eterm") == 0) {
1412 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
1414 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
1424 tty_display_8bit (full_eight_bits
!= 0);
1426 tty_display_8bit (eight_bit_clean
!= 0);
1429 #ifdef HAVE_SUBSHELL_SUPPORT
1431 add_select_channel (subshell_pty
, load_prompt
, 0);
1432 #endif /* !HAVE_SUBSHELL_SUPPORT */
1434 tty_setup_sigwinch (sigwinch_handler
);
1436 if ((tty_baudrate () < 9600) || tty_is_slow ())
1439 init_xterm_support ();
1444 setup_dummy_mc (void)
1446 char d
[MC_MAXPATHLEN
];
1448 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1453 static void check_codeset()
1455 const char *current_system_codepage
= NULL
;
1457 current_system_codepage
= str_detect_termencoding();
1461 const char *_display_codepage
;
1463 _display_codepage
= get_codepage_id (display_codepage
);
1465 if (! strcmp(_display_codepage
, current_system_codepage
)) {
1466 utf8_display
= str_isutf8 (current_system_codepage
);
1470 display_codepage
= get_codepage_index (current_system_codepage
);
1471 if (display_codepage
== -1) {
1472 display_codepage
= 0;
1475 mc_config_set_string(mc_main_config
, "Misc", "display_codepage", cp_display
);
1478 utf8_display
= str_isutf8 (current_system_codepage
);
1484 if (!(quit
& SUBSHELL_EXIT
))
1486 tty_reset_shell_mode ();
1499 * We sync the profiles since the hotlist may have changed, while
1500 * we only change the setup data if we have the auto save feature set
1503 if (auto_save_setup
)
1504 save_setup (); /* does also call save_hotlist */
1507 save_panel_types ();
1510 vfs_add_current_stamps ();
1513 /* This should be called after destroy_dlg since panel widgets
1514 * save their state on the profiles
1517 done_mc_profile (void)
1523 midnight_callback (Dlg_head
*h
, Widget
*sender
,
1524 dlg_msg_t msg
, int parm
, void *data
)
1526 unsigned long command
;
1535 /* We handle the special case of the output lines */
1536 if (console_flag
&& output_lines
)
1537 show_console_contents (output_start_y
,
1538 LINES
- output_lines
- keybar_visible
-
1539 1, LINES
- keybar_visible
- 1);
1544 menubar_arrange (the_menubar
);
1548 /* We only need the first idle event to show user menu after start */
1549 set_idle_proc (h
, 0);
1551 if (boot_current_is_left
)
1552 dlg_select_widget (get_panel_widget (0));
1554 dlg_select_widget (get_panel_widget (1));
1557 midnight_execute_cmd (NULL
, CK_UserMenuCmd
);
1561 if (ctl_x_map_enabled
) {
1562 ctl_x_map_enabled
= FALSE
;
1563 command
= lookup_keymap_command (main_x_map
, parm
);
1564 if (command
!= CK_Ignore_Key
)
1565 return midnight_execute_cmd (NULL
, command
);
1568 /* FIXME: should handle all menu shortcuts before this point */
1569 if (the_menubar
->is_active
)
1570 return MSG_NOT_HANDLED
;
1573 free_completions (cmdline
);
1578 for (i
= 0; cmdline
->buffer
[i
] && (cmdline
->buffer
[i
] == ' ' ||
1579 cmdline
->buffer
[i
] == '\t'); i
++)
1581 if (cmdline
->buffer
[i
]) {
1582 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1585 stuff (cmdline
, "", 0);
1589 /* Ctrl-Enter and Alt-Enter */
1590 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n')
1591 && (parm
& (KEY_M_CTRL
| KEY_M_ALT
))) {
1596 /* Ctrl-Shift-Enter */
1597 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n')) {
1598 copy_current_pathname ();
1603 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1604 && !quote
&& !current_panel
->searching
) {
1605 if (!only_leading_plus_minus
) {
1606 /* Special treatement, since the input line will eat them */
1612 if (parm
== '\\' || parm
== '-') {
1618 reverse_selection_cmd ();
1621 } else if (!command_prompt
|| !cmdline
->buffer
[0]) {
1622 /* Special treatement '+', '-', '\', '*' only when this is
1623 * first char on input line
1631 if (parm
== '\\' || parm
== '-') {
1637 reverse_selection_cmd ();
1642 return MSG_NOT_HANDLED
;
1644 case DLG_HOTKEY_HANDLED
:
1645 if ((get_current_type () == view_listing
) && current_panel
->searching
) {
1646 current_panel
->searching
= 0;
1647 current_panel
->dirty
= 1;
1651 case DLG_UNHANDLED_KEY
:
1652 if (command_prompt
) {
1655 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1656 if (v
== MSG_HANDLED
)
1660 if (ctl_x_map_enabled
) {
1661 ctl_x_map_enabled
= FALSE
;
1662 command
= lookup_keymap_command (main_x_map
, parm
);
1664 command
= lookup_keymap_command (main_map
, parm
);
1666 return (command
== CK_Ignore_Key
)
1668 : midnight_execute_cmd (NULL
, command
);
1671 if (!the_menubar
->is_active
)
1672 update_dirty_panels ();
1678 midnight_execute_cmd (NULL
, parm
);
1679 /* message from menu */
1680 else if (sender
== (Widget
*) the_menubar
)
1681 midnight_execute_cmd (sender
, parm
);
1682 /* message from buttonbar */
1683 else if (sender
== (Widget
*) the_bar
) {
1685 midnight_execute_cmd (sender
, parm
);
1687 send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1692 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1696 /* Show current directory in the xterm title */
1698 update_xterm_title_path (void)
1701 char host
[BUF_TINY
];
1703 struct passwd
*pw
= NULL
;
1706 if (xterm_flag
&& xterm_title
) {
1707 path
= strip_home_and_password (current_panel
->cwd
);
1708 res
= gethostname(host
, sizeof (host
));
1709 if ( res
) { /* On success, res = 0 */
1712 host
[sizeof (host
) - 1] = '\0';
1714 pw
= getpwuid(getuid());
1716 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1718 login
= g_strdup (host
);
1720 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1721 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1724 if (!alternate_plus_minus
)
1725 numeric_keypad_mode ();
1731 * Load new hint and display it.
1732 * IF force is not 0, ignore the timeout.
1735 load_hint (int force
)
1739 if (!the_hint
->widget
.parent
)
1742 if (!message_visible
) {
1743 label_set_text (the_hint
, NULL
);
1747 hint
= get_random_hint (force
);
1754 char text
[BUF_SMALL
];
1756 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"),
1763 create_panels_and_run_mc (void)
1765 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
1769 add_widget (midnight_dlg
, the_menubar
);
1772 add_widget (midnight_dlg
, get_panel_widget (0));
1773 add_widget (midnight_dlg
, get_panel_widget (1));
1775 add_widget (midnight_dlg
, the_hint
);
1776 add_widget (midnight_dlg
, cmdline
);
1777 add_widget (midnight_dlg
, the_prompt
);
1779 add_widget (midnight_dlg
, the_bar
);
1780 midnight_set_buttonbar (the_bar
);
1782 /* Run the Midnight Commander if no file was specified in the command line */
1783 run_dlg (midnight_dlg
);
1786 /* result must be free'd (I think this should go in util.c) */
1788 prepend_cwd_on_local (const char *filename
)
1793 if (!vfs_file_is_local (filename
)
1794 || g_path_is_absolute (filename
))
1795 return g_strdup (filename
);
1797 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1798 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1801 strcpy (d
+ l
, filename
);
1802 canonicalize_pathname (d
);
1806 /* Invoke the internal view/edit routine with:
1807 * the default processing and forcing the internal viewer/editor
1810 mc_maybe_editor_or_viewer (void)
1812 if (view_one_file
!= NULL
) {
1814 path
= prepend_cwd_on_local (view_one_file
);
1815 view_file (path
, 0, 1);
1818 #ifdef USE_INTERNAL_EDIT
1820 edit_file (edit_one_file
, edit_one_file_start_line
);
1821 #endif /* USE_INTERNAL_EDIT */
1822 midnight_shutdown
= 1;
1826 /* Run the main dialog that occupies the whole screen */
1830 int midnight_colors
[DLG_COLOR_NUM
];
1831 midnight_colors
[0] = mc_skin_color_get("dialog", "_default_");
1832 midnight_colors
[1] = mc_skin_color_get("dialog", "focus");
1833 midnight_colors
[2] = mc_skin_color_get("dialog", "hotnormal");
1834 midnight_colors
[3] = mc_skin_color_get("dialog", "hotfocus");
1838 midnight_dlg
= create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1839 "[main]", NULL
, DLG_WANT_IDLE
);
1841 if ((view_one_file
!= NULL
) || (edit_one_file
!= NULL
))
1846 /* start check display_codepage and source_codepage */
1849 main_map
= default_main_map
;
1850 if (main_keymap
&& main_keymap
->len
> 0)
1851 main_map
= (global_keymap_t
*) main_keymap
->data
;
1853 main_x_map
= default_main_x_map
;
1854 if (main_x_keymap
&& main_x_keymap
->len
> 0)
1855 main_x_map
= (global_keymap_t
*) main_x_keymap
->data
;
1857 panel_map
= default_panel_keymap
;
1858 if (panel_keymap
&& panel_keymap
->len
> 0)
1859 panel_map
= (global_keymap_t
*) panel_keymap
->data
;
1861 input_map
= default_input_keymap
;
1862 if (input_keymap
&& input_keymap
->len
> 0)
1863 input_map
= (global_keymap_t
*) input_keymap
->data
;
1865 tree_map
= default_tree_keymap
;
1866 if (tree_keymap
&& tree_keymap
->len
> 0)
1867 tree_map
= (global_keymap_t
*) tree_keymap
->data
;
1869 help_map
= default_help_keymap
;
1870 if (help_keymap
&& help_keymap
->len
> 0)
1871 help_map
= (global_keymap_t
*) help_keymap
->data
;
1873 /* Check if we were invoked as an editor or file viewer */
1874 if ((view_one_file
!= NULL
) || (edit_one_file
!= NULL
))
1875 mc_maybe_editor_or_viewer ();
1877 create_panels_and_run_mc ();
1880 midnight_shutdown
= 1;
1882 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1883 if (mc_args__last_wd_file
&& vfs_current_is_local ())
1884 last_wd_string
= g_strdup (current_panel
->cwd
);
1889 destroy_dlg (midnight_dlg
);
1895 /* POSIX version. The only version we support. */
1899 const char *shell_env
= getenv ("SHELL");
1900 const char *mc_libdir
;
1902 if ((shell_env
== NULL
) || (shell_env
[0] == '\0')) {
1904 pwd
= getpwuid (geteuid ());
1906 shell
= g_strdup (pwd
->pw_shell
);
1908 shell
= g_strdup (shell_env
);
1910 if ((shell
== NULL
) || (shell
[0] == '\0')) {
1912 shell
= g_strdup ("/bin/sh");
1915 /* This is the directory, where MC was installed, on Unix this is DATADIR */
1916 /* and can be overriden by the MC_DATADIR environment variable */
1917 mc_libdir
= getenv ("MC_DATADIR");
1918 if (mc_libdir
!= NULL
) {
1919 mc_home
= g_strdup (mc_libdir
);
1920 mc_home_alt
= g_strdup (SYSCONFDIR
);
1922 mc_home
= g_strdup (SYSCONFDIR
);
1923 mc_home_alt
= g_strdup (DATADIR
);
1926 /* This variable is used by the subshell */
1927 home_dir
= getenv ("HOME");
1934 sigchld_handler_no_subshell (int sig
)
1942 /* COMMENT: if it were true that after the call to handle_console(..INIT)
1943 the value of console_flag never changed, we could simply not install
1944 this handler at all if (!console_flag && !use_subshell). */
1946 /* That comment is no longer true. We need to wait() on a sigchld
1947 handler (that's at least what the tarfs code expects currently). */
1949 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
1951 if (pid
== cons_saver_pid
) {
1953 if (WIFSTOPPED (status
)) {
1954 /* Someone has stopped cons.saver - restart it */
1955 kill (pid
, SIGCONT
);
1957 /* cons.saver has died - disable console saving */
1958 handle_console (CONSOLE_DONE
);
1962 /* If we got here, some other child exited; ignore it */
1963 #endif /* __linux__ */
1971 struct sigaction sigchld_action
;
1973 sigchld_action
.sa_handler
=
1974 #ifdef HAVE_SUBSHELL_SUPPORT
1975 use_subshell
? sigchld_handler
:
1976 #endif /* HAVE_SUBSHELL_SUPPORT */
1977 sigchld_handler_no_subshell
;
1979 sigemptyset (&sigchld_action
.sa_mask
);
1982 sigchld_action
.sa_flags
= SA_RESTART
;
1984 sigchld_action
.sa_flags
= 0;
1985 #endif /* !SA_RESTART */
1987 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1) {
1988 #ifdef HAVE_SUBSHELL_SUPPORT
1990 * This may happen on QNX Neutrino 6, where SA_RESTART
1991 * is defined but not implemented. Fallback to no subshell.
1994 #endif /* HAVE_SUBSHELL_SUPPORT */
1999 mc_main__setup_by_args (int argc
, char *argv
[])
2004 if (mc_args__nomouse
)
2005 use_mouse_p
= MOUSE_DISABLED
;
2008 if (mc_args__netfs_logfile
!= NULL
) {
2009 mc_setctl ("/#ftp:", VFS_SETCTL_LOGFILE
, (void *) mc_args__netfs_logfile
);
2010 #ifdef ENABLE_VFS_SMB
2011 smbfs_set_debugf (mc_args__netfs_logfile
);
2012 #endif /* ENABLE_VFS_SMB */
2015 #ifdef ENABLE_VFS_SMB
2016 if (mc_args__debug_level
!= 0)
2017 smbfs_set_debug (mc_args__debug_level
);
2018 #endif /* ENABLE_VFS_SMB */
2019 #endif /* USE_NETCODE */
2021 base
= x_basename (argv
[0]);
2022 tmp
= (argc
> 0) ? argv
[1] : NULL
;
2024 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP (base
, "vi")) {
2028 * Check for filename:lineno, followed by an optional colon.
2029 * This format is used by many programs (especially compilers)
2030 * in error messages and warnings. It is supported so that
2031 * users can quickly copy and paste file locations.
2033 char *end
= tmp
+ strlen (tmp
), *p
= end
;
2034 if (p
> tmp
&& p
[-1] == ':')
2036 while (p
> tmp
&& g_ascii_isdigit ((gchar
) p
[-1]))
2038 if (tmp
< p
&& p
< end
&& p
[-1] == ':') {
2040 gchar
*fname
= g_strndup (tmp
, p
- 1 - tmp
);
2042 * Check that the file before the colon actually exists.
2043 * If it doesn't exist, revert to the old behavior.
2045 if (mc_stat (tmp
, &st
) == -1 && mc_stat (fname
, &st
) != -1) {
2046 edit_one_file
= fname
;
2047 edit_one_file_start_line
= atoi (p
);
2050 goto try_plus_filename
;
2054 if (*tmp
== '+' && g_ascii_isdigit ((gchar
) tmp
[1])) {
2055 int start_line
= atoi (tmp
);
2056 if (start_line
> 0) {
2057 char *file
= (argc
> 1) ? argv
[2] : NULL
;
2060 edit_one_file_start_line
= start_line
;
2064 edit_one_file
= g_strdup (tmp
);
2067 } else if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP (base
, "view")) {
2069 view_one_file
= g_strdup (tmp
);
2071 fputs ("No arguments given to the viewer\n", stderr
);
2075 /* sets the current dir and the other dir */
2077 this_dir
= g_strdup (tmp
);
2078 tmp
= (argc
> 1) ? argv
[2] : NULL
;
2080 other_dir
= g_strdup (tmp
);
2086 main (int argc
, char *argv
[])
2090 GError
*error
= NULL
;
2091 gboolean isInitialized
;
2093 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2094 setlocale (LC_ALL
, "");
2095 bindtextdomain ("mc", LOCALEDIR
);
2098 /* Set up temporary directory */
2103 str_init_strings (NULL
);
2107 #ifdef USE_INTERNAL_EDIT
2112 SLtt_Ignore_Beep
= 1;
2115 if ( !mc_args_handle (&argc
, &argv
, "mc"))
2118 mc_main__setup_by_args (argc
,argv
);
2120 /* NOTE: This has to be called before tty_init or whatever routine
2121 calls any define_sequence */
2124 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
2125 handle_console (CONSOLE_INIT
);
2127 #ifdef HAVE_SUBSHELL_SUPPORT
2128 /* Don't use subshell when invoked as viewer or editor */
2129 if ((view_one_file
!= NULL
) || (edit_one_file
!= NULL
))
2133 subshell_get_console_attributes ();
2134 #endif /* HAVE_SUBSHELL_SUPPORT */
2136 /* Install the SIGCHLD handler; must be done before init_subshell() */
2139 /* We need this, since ncurses endwin () doesn't restore the signals */
2140 save_stop_handler ();
2142 /* Must be done before init_subshell, to set up the terminal size: */
2143 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2144 tty_init ((gboolean
) mc_args__slow_terminal
, (gboolean
) mc_args__ugly_line_drawing
);
2148 tty_init_colors (mc_args__disable_colors
, mc_args__force_colors
);
2150 isInitialized
= mc_skin_init(&error
);
2152 mc_filehighlight
= mc_fhl_new (TRUE
);
2154 dlg_set_default_colors ();
2156 if ( ! isInitialized
) {
2157 message (D_ERROR
, _("Warning"), "%s", error
->message
);
2158 g_error_free(error
);
2162 /* create home directory */
2163 /* do it after the screen library initialization to show the error message */
2164 mc_dir
= concat_dir_and_file (home_dir
, MC_USERCONF_DIR
);
2165 canonicalize_pathname (mc_dir
);
2166 if ((stat (mc_dir
, &s
) != 0) && (errno
== ENOENT
)
2167 && mkdir (mc_dir
, 0700) != 0)
2168 message (D_ERROR
, _("Warning"),
2169 _("Cannot create %s directory"), mc_dir
);
2172 #ifdef HAVE_SUBSHELL_SUPPORT
2173 /* Done here to ensure that the subshell doesn't */
2174 /* inherit the file descriptors opened below, etc */
2178 #endif /* HAVE_SUBSHELL_SUPPORT */
2180 /* Removing this from the X code let's us type C-c */
2183 load_keymap_defs ();
2185 /* Also done after init_subshell, to save any shell init file messages */
2187 handle_console (CONSOLE_SAVE
);
2189 if (alternate_plus_minus
)
2190 application_keypad_mode ();
2192 #ifdef HAVE_SUBSHELL_SUPPORT
2194 mc_prompt
= strip_ctrl_codes (subshell_prompt
);
2195 if (mc_prompt
== NULL
)
2196 mc_prompt
= (geteuid () == 0) ? "# " : "$ ";
2198 #endif /* HAVE_SUBSHELL_SUPPORT */
2199 mc_prompt
= (geteuid () == 0) ? "# " : "$ ";
2201 /* Program main loop */
2202 if (!midnight_shutdown
)
2205 /* Save the tree store */
2208 free_keymap_defs ();
2210 /* Virtual File System shutdown */
2213 flush_extension_file (); /* does only free memory */
2215 mc_fhl_free (&mc_filehighlight
);
2220 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2221 handle_console (CONSOLE_RESTORE
);
2222 if (alternate_plus_minus
)
2223 numeric_keypad_mode ();
2225 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2228 handle_console (CONSOLE_DONE
);
2229 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2231 if (mc_args__last_wd_file
&& last_wd_string
&& !print_last_revert
2232 && !edit_one_file
&& !view_one_file
) {
2234 open (mc_args__last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2237 if (last_wd_fd
!= -1) {
2238 write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2242 g_free (last_wd_string
);
2244 g_free (mc_home_alt
);
2250 free_codepages_list ();
2252 str_uninit_strings ();
2257 #ifdef USE_INTERNAL_EDIT