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 */
44 #include "lib/tty/tty.h"
45 #include "lib/skin/skin.h"
46 #include "lib/tty/mouse.h"
47 #include "lib/tty/key.h" /* For init_key() */
48 #include "lib/tty/win.h" /* xterm_flag */
50 #include "lib/mcconfig/mcconfig.h"
52 #include "lib/filehighlight/fhl.h"
60 #include "treestore.h"
61 #include "cons.saver.h"
63 #include "setup.h" /* save_setup() */
64 #include "boxes.h" /* sort_box() */
66 #include "cmd.h" /* Normal commands */
69 #include "learn.h" /* learn_keys() */
72 #include "ext.h" /* For flush_extension_file() */
77 #include "cmddef.h" /* CK_ cmd name const */
78 #include "fileloc.h" /* MC_USERCONF_DIR */
79 #include "user.h" /* user_file_menu_cmd() */
81 #include "lib/vfs/mc-vfs/vfs.h" /* vfs_translate_url() */
90 #include "lib/vfs/mc-vfs/smbfs.h" /* smbfs_set_debug() */
91 #endif /* ENABLE_VFS_SMB */
93 #ifdef USE_INTERNAL_EDIT
94 # include "src/editor/edit.h"
99 #endif /* HAVE_CHARSET */
102 #include "lib/vfs/mc-vfs/gc.h"
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, marking a files moves the cursor down */
144 int mark_moves_down
= 1;
146 /* If true, at startup the user-menu is invoked */
149 /* If true, then the +, - and \ keys have their special meaning only if the
150 * command line is emtpy, otherwise they behave like regular letters
152 int only_leading_plus_minus
= 1;
154 int pause_after_run
= pause_on_dumb_terminals
;
156 /* It true saves the setup when quitting */
157 int auto_save_setup
= 1;
161 * Don't restrict the output on the screen manager level,
162 * the translation tables take care of it.
164 #define full_eight_bits (1)
165 #define eight_bit_clean (1)
166 #else /* HAVE_CHARSET */
167 /* If true, allow characters in the range 160-255 */
168 int eight_bit_clean
= 1;
170 * If true, also allow characters in the range 128-159.
171 * This is reported to break on many terminals (xterm, qansi-m).
173 int full_eight_bits
= 0;
174 #endif /* !HAVE_CHARSET */
177 * If utf-8 terminal utf8_display = 1
178 * Display bits set UTF-8
181 int utf8_display
= 0;
183 /* If true use the internal viewer */
184 int use_internal_view
= 1;
186 /* Have we shown the fast-reload warning in the past? */
187 int fast_reload_w
= 0;
189 /* Move page/item? When clicking on the top or bottom of a panel */
190 int mouse_move_pages
= 1;
192 /* If true: l&r arrows are used to chdir if the input line is empty */
193 int navigate_with_arrows
= 0;
195 /* If true program softkeys (HP terminals only) on startup and after every
196 command ran in the subshell to the description found in the termcap/terminfo
198 int reset_hp_softkeys
= 0;
201 const char *prompt
= NULL
;
203 /* The widget where we draw the prompt */
212 /* Mouse type: GPM, xterm or none */
213 Mouse_Type use_mouse_p
= MOUSE_NONE
;
215 /* If on, default for "No" in delete operations */
218 /* Controls screen clearing before an exec */
219 int clear_before_exec
= 1;
221 /* Asks for confirmation before deleting a file */
222 int confirm_delete
= 1;
224 /* Asks for confirmation before deleting a hotlist entry */
225 int confirm_directory_hotlist_delete
= 1;
227 /* Asks for confirmation before overwriting a file */
228 int confirm_overwrite
= 1;
230 /* Asks for confirmation before executing a program by pressing enter */
231 int confirm_execute
= 0;
233 /* Asks for confirmation before leaving the program */
234 int confirm_exit
= 1;
236 /* Asks for confirmation when using F3 to view a directory and there
238 int confirm_view_dir
= 0;
240 /* This flag indicates if the pull down menus by default drop down */
243 /* The dialog handle for the main program */
244 Dlg_head
*midnight_dlg
= NULL
;
246 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
247 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
248 int update_prompt
= 0;
250 /* The home directory */
251 const char *home_dir
= NULL
;
254 int option_tab_spacing
= 8;
256 /* The value of the other directory, only used when loading the setup */
257 char *other_dir
= NULL
;
259 /* Only used at program boot */
260 int boot_current_is_left
= 1;
262 static char *this_dir
= NULL
;
264 /* If this is true, then when browsing the tree the other window will
265 * automatically reload it's directory with the contents of the currently
266 * selected directory.
270 /* If set, then print to the given file the last directory we were at */
271 static char *last_wd_string
= NULL
;
272 /* Set to 1 to suppress printing the last directory */
273 static int print_last_revert
= 0;
275 /* File name to view if argument was supplied */
276 const char *view_one_file
= NULL
;
278 /* File name to edit if argument was supplied */
279 const char *edit_one_file
= NULL
;
281 /* Line to start the editor on */
282 static int edit_one_file_start_line
= 0;
284 /* Used so that widgets know if they are being destroyed or
286 int midnight_shutdown
= 0;
288 /* The user's shell */
291 /* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
292 char *mc_home
= NULL
;
294 /* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
295 char *mc_home_alt
= NULL
;
297 /* Define this function for glib-style error handling */
299 mc_main_error_quark (void)
301 return g_quark_from_static_string (PACKAGE
);
304 #ifdef USE_INTERNAL_EDIT
305 GArray
*editor_keymap
= NULL
;
306 GArray
*editor_x_keymap
= NULL
;
308 GArray
*viewer_keymap
= NULL
;
309 GArray
*viewer_hex_keymap
= NULL
;
310 GArray
*main_keymap
= NULL
;
311 GArray
*main_x_keymap
= NULL
;
312 GArray
*panel_keymap
= NULL
;
313 GArray
*input_keymap
= NULL
;
314 GArray
*tree_keymap
= NULL
;
315 GArray
*help_keymap
= NULL
;
317 const global_keymap_t
*main_map
;
318 const global_keymap_t
*main_x_map
;
320 /* Save current stat of directories to avoid reloading the panels */
321 /* when no modifications have taken place */
323 save_cwds_stat (void)
326 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
327 if (get_other_type () == view_listing
)
328 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
332 #ifdef HAVE_SUBSHELL_SUPPORT
334 do_update_prompt (void)
337 printf ("\r\n%s", subshell_prompt
);
342 #endif /* HAVE_SUBSHELL_SUPPORT */
347 free_completions (cmdline
);
348 dlg_one_down (midnight_dlg
);
351 /* Stop MC main dialog and the current dialog if it exists.
352 * Needed to provide fast exit from MC viewer or editor on shell exit */
356 midnight_dlg
->running
= 0;
358 current_dlg
->running
= 0;
363 quit_cmd_internal (int quiet
)
367 if (quiet
|| !confirm_exit
) {
371 (_(" The Midnight Commander "),
372 _(" Do you really want to quit the Midnight Commander? "), D_NORMAL
,
373 2, _("&Yes"), _("&No")) == 0)
377 #ifdef HAVE_SUBSHELL_SUPPORT
380 else if ((q
= exit_subshell ()))
392 quit_cmd_internal (0);
396 quiet_quit_cmd (void)
398 print_last_revert
= 1;
399 quit_cmd_internal (1);
402 /* Wrapper for do_subshell_chdir, check for availability of subshell */
404 subshell_chdir (const char *directory
)
406 #ifdef HAVE_SUBSHELL_SUPPORT
408 if (vfs_current_is_local ())
409 do_subshell_chdir (directory
, 0, 1);
411 #endif /* HAVE_SUBSHELL_SUPPORT */
415 directory_history_add (struct WPanel
*panel
, const char *dir
)
419 tmp
= g_strdup (dir
);
420 strip_password (tmp
, 1);
422 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
426 * If we moved to the parent directory move the selection pointer to
427 * the old directory name; If we leave VFS dir, remove FS specificator.
429 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
432 get_parent_dir_name (const char *cwd
, const char *lwd
)
435 if (strlen (lwd
) > strlen (cwd
))
436 if ((p
= strrchr (lwd
, PATH_SEP
)) && !strncmp (cwd
, lwd
, p
- lwd
) &&
437 ((gsize
)strlen (cwd
) == (gsize
) p
- (gsize
) lwd
|| (p
== lwd
&& cwd
[0] == PATH_SEP
&&
445 * Changes the current directory of the panel.
446 * Don't record change in the directory history.
449 _do_panel_cd (WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
451 const char *directory
;
453 char temp
[MC_MAXPATHLEN
];
454 char *translated_url
;
456 if (cd_type
== cd_parse_command
) {
457 while (*new_dir
== ' ')
461 olddir
= g_strdup (panel
->cwd
);
462 new_dir
= translated_url
= vfs_translate_url (new_dir
);
464 /* Convert *new_path to a suitable pathname, handle ~user */
466 if (cd_type
== cd_parse_command
) {
467 if (!strcmp (new_dir
, "-")) {
468 strcpy (temp
, panel
->lwd
);
472 directory
= *new_dir
? new_dir
: home_dir
;
474 if (mc_chdir (directory
) == -1) {
475 strcpy (panel
->cwd
, olddir
);
477 g_free (translated_url
);
480 g_free (translated_url
);
482 /* Success: save previous directory, shutdown status of previous dir */
483 strcpy (panel
->lwd
, olddir
);
484 free_completions (cmdline
);
486 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
488 vfs_release_path (olddir
);
490 subshell_chdir (panel
->cwd
);
492 /* Reload current panel */
493 panel_clean_dir (panel
);
495 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->current_sort_field
->sort_routine
,
496 panel
->reverse
, panel
->case_sensitive
,
497 panel
->exec_first
, panel
->filter
);
498 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
501 update_xterm_title_path ();
509 * Changes the current directory of the panel.
510 * Record change in the directory history.
513 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
517 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
519 directory_history_add (panel
, panel
->cwd
);
524 do_cd (const char *new_dir
, enum cd_enum exact
)
526 return (do_panel_cd (current_panel
, new_dir
, exact
));
530 directory_history_next (WPanel
*panel
)
534 nextdir
= g_list_next (panel
->dir_history
);
539 if (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
))
540 panel
->dir_history
= nextdir
;
544 directory_history_prev (WPanel
*panel
)
548 prevdir
= g_list_previous (panel
->dir_history
);
553 if (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
))
554 panel
->dir_history
= prevdir
;
558 directory_history_list (WPanel
*panel
)
562 if (!panel
->dir_history
)
565 s
= show_hist (panel
->dir_history
, &panel
->widget
);
570 if (_do_panel_cd (panel
, s
, cd_exact
))
571 directory_history_add (panel
, panel
->cwd
);
573 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
577 #ifdef HAVE_SUBSHELL_SUPPORT
579 load_prompt (int fd
, void *unused
)
584 if (!read_subshell_prompt ())
587 /* Don't actually change the prompt if it's invisible */
588 if (current_dlg
== midnight_dlg
&& command_prompt
) {
592 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
593 prompt_len
= str_term_width1 (tmp_prompt
);
595 /* Check for prompts too big */
596 if (COLS
> 8 && prompt_len
> COLS
- 8) {
597 tmp_prompt
[COLS
- 8] = '\0';
598 prompt_len
= COLS
- 8;
601 label_set_text (the_prompt
, prompt
);
602 winput_set_origin ((WInput
*) cmdline
, prompt_len
,
605 /* since the prompt has changed, and we are called from one of the
606 * tty_get_event channels, the prompt updating does not take place
607 * automatically: force a cursor update and a screen refresh
609 update_cursor (midnight_dlg
);
615 #endif /* HAVE_SUBSHELL_SUPPORT */
621 const panel_field_t
*sort_order
;
623 if (!SELECTED_IS_PANEL
)
627 sort_order
= sort_box (p
->current_sort_field
, &p
->reverse
,
631 panel_set_sort_order (p
, sort_order
);
640 sel_dir
= tree_box (selection (current_panel
)->fname
);
642 do_cd (sel_dir
, cd_exact
);
647 #ifdef LISTMODE_EDITOR
653 if (get_current_type () != view_listing
)
656 newmode
= listmode_edit (current_panel
->user_format
);
660 g_free (current_panel
->user_format
);
661 current_panel
->list_type
= list_user
;
662 current_panel
->user_format
= newmode
;
663 set_panel_formats (current_panel
);
667 #endif /* LISTMODE_EDITOR */
669 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
671 create_panel_menu (void)
673 GList
*entries
= NULL
;
675 entries
= g_list_append (entries
, menu_entry_create (_("&Listing mode..."), CK_ListingCmd
));
676 entries
= g_list_append (entries
, menu_entry_create (_("&Quick view"), CK_QuickViewCmd
));
677 entries
= g_list_append (entries
, menu_entry_create (_("&Info" ), CK_InfoCmd
));
678 entries
= g_list_append (entries
, menu_entry_create (_("&Tree"), CK_TreeCmd
));
679 entries
= g_list_append (entries
, menu_separator_create ());
680 entries
= g_list_append (entries
, menu_entry_create (_("&Sort order..."), CK_Sort
));
681 entries
= g_list_append (entries
, menu_separator_create ());
682 entries
= g_list_append (entries
, menu_entry_create (_("&Filter..."), CK_FilterCmd
));
684 entries
= g_list_append (entries
, menu_separator_create ());
685 entries
= g_list_append (entries
, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding
));
688 entries
= g_list_append (entries
, menu_separator_create ());
689 #ifdef ENABLE_VFS_MCFS
690 entries
= g_list_append (entries
, menu_entry_create (_("&Network link..."), CK_NetlinkCmd
));
692 entries
= g_list_append (entries
, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd
));
693 entries
= g_list_append (entries
, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd
));
694 #ifdef ENABLE_VFS_SMB
695 entries
= g_list_append (entries
, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd
));
696 #endif /* ENABLE_VFS_SMB */
698 entries
= g_list_append (entries
, menu_separator_create ());
699 entries
= g_list_append (entries
, menu_entry_create (_("&Rescan"), CK_RereadCmd
));
705 create_file_menu (void)
707 GList
*entries
= NULL
;
709 entries
= g_list_append (entries
, menu_entry_create (_("&View"), CK_ViewCmd
));
710 entries
= g_list_append (entries
, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd
));
711 entries
= g_list_append (entries
, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd
));
712 entries
= g_list_append (entries
, menu_entry_create (_("&Edit"), CK_EditCmd
));
713 entries
= g_list_append (entries
, menu_entry_create (_("&Copy"), CK_CopyCmd
));
714 entries
= g_list_append (entries
, menu_entry_create (_("C&hmod"), CK_ChmodCmd
));
715 entries
= g_list_append (entries
, menu_entry_create (_("&Link"), CK_LinkCmd
));
716 entries
= g_list_append (entries
, menu_entry_create (_("&SymLink"), CK_SymlinkCmd
));
717 entries
= g_list_append (entries
, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd
));
718 entries
= g_list_append (entries
, menu_entry_create (_("Ch&own"), CK_ChownCmd
));
719 entries
= g_list_append (entries
, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd
));
720 entries
= g_list_append (entries
, menu_entry_create (_("&Rename/Move"), CK_RenameCmd
));
721 entries
= g_list_append (entries
, menu_entry_create (_("&Mkdir"), CK_MkdirCmd
));
722 entries
= g_list_append (entries
, menu_entry_create (_("&Delete"), CK_DeleteCmd
));
723 entries
= g_list_append (entries
, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd
));
724 entries
= g_list_append (entries
, menu_separator_create ());
725 entries
= g_list_append (entries
, menu_entry_create (_("Select &group"), CK_SelectCmd
));
726 entries
= g_list_append (entries
, menu_entry_create (_("U&nselect group"), CK_UnselectCmd
));
727 entries
= g_list_append (entries
, menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd
));
728 entries
= g_list_append (entries
, menu_separator_create ());
729 entries
= g_list_append (entries
, menu_entry_create (_("E&xit"), CK_QuitCmd
));
735 create_command_menu (void)
737 /* I know, I'm lazy, but the tree widget when it's not running
738 * as a panel still has some problems, I have not yet finished
739 * the WTree widget port, sorry.
741 GList
*entries
= NULL
;
743 entries
= g_list_append (entries
, menu_entry_create (_("&User menu"), CK_UserMenuCmd
));
744 entries
= g_list_append (entries
, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd
));
745 entries
= g_list_append (entries
, menu_entry_create (_("&Find file"), CK_FindCmd
));
746 entries
= g_list_append (entries
, menu_entry_create (_("S&wap panels"), CK_SwapCmd
));
747 entries
= g_list_append (entries
, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine
));
748 entries
= g_list_append (entries
, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd
));
749 entries
= g_list_append (entries
, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize
));
750 entries
= g_list_append (entries
, menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd
));
751 entries
= g_list_append (entries
, menu_separator_create ());
752 entries
= g_list_append (entries
, menu_entry_create (_("Command &history"), CK_HistoryCmd
));
753 entries
= g_list_append (entries
, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd
));
755 entries
= g_list_append (entries
, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs
));
757 #ifdef WITH_BACKGROUND
758 entries
= g_list_append (entries
, menu_entry_create (_("&Background jobs"), CK_JobsCmd
));
760 entries
= g_list_append (entries
, menu_separator_create ());
762 entries
= g_list_append (entries
, menu_entry_create (_("&Undelete files (ext2fs only)"), CK_UndeleteCmd
));
764 #ifdef LISTMODE_EDITOR
765 entries
= g_list_append (entries
, menu_entry_create (_("&Listing format edit"), CK_ListmodeCmd
));
767 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
768 entries
= g_list_append (entries
, menu_separator_create ());
770 entries
= g_list_append (entries
, menu_entry_create (_("Edit &extension file"), CK_EditExtFileCmd
));
771 entries
= g_list_append (entries
, menu_entry_create (_("Edit &menu file"), CK_EditMcMenuCmd
));
772 entries
= g_list_append (entries
, menu_entry_create (_("Edit hi&ghlighting group file"), CK_EditFhlFileCmd
));
778 create_options_menu (void)
780 GList
*entries
= NULL
;
782 entries
= g_list_append (entries
, menu_entry_create (_("&Configuration..."), CK_ConfigureBox
));
783 entries
= g_list_append (entries
, menu_entry_create (_("&Layout..."), CK_LayoutCmd
));
784 entries
= g_list_append (entries
, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox
));
785 entries
= g_list_append (entries
, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox
));
786 entries
= g_list_append (entries
, menu_entry_create (_("Learn &keys..."), CK_LearnKeys
));
788 entries
= g_list_append (entries
, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs
));
790 entries
= g_list_append (entries
, menu_separator_create ());
791 entries
= g_list_append (entries
, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd
));
799 menubar_add_menu (the_menubar
,
800 create_menu (horizontal_split
? _("&Above") : _("&Left"),
801 create_panel_menu (), "[Left and Right Menus]"));
802 menubar_add_menu (the_menubar
,
803 create_menu (_("&File"), create_file_menu (), "[File Menu]"));
804 menubar_add_menu (the_menubar
,
805 create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
806 menubar_add_menu (the_menubar
,
807 create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
808 menubar_add_menu (the_menubar
,
809 create_menu (horizontal_split
? _("&Below") : _("&Right"),
810 create_panel_menu (), "[Left and Right Menus]"));
816 menubar_set_menu (the_menubar
, NULL
);
820 menu_last_selected_cmd (void)
822 the_menubar
->is_active
= TRUE
;
823 the_menubar
->is_dropped
= (drop_menus
!= 0);
824 the_menubar
->previous_widget
= midnight_dlg
->current
->dlg_id
;
825 dlg_select_widget (the_menubar
);
831 if (the_menubar
->is_active
)
834 if ((get_current_index () == 0) == (current_panel
->active
!= 0))
835 the_menubar
->selected
= 0;
837 the_menubar
->selected
= g_list_length (the_menubar
->menu
) - 1;
838 menu_last_selected_cmd ();
842 midnight_get_shortcut (unsigned long command
)
845 const char *shortcut
= NULL
;
847 shortcut
= lookup_keymap_shortcut (main_map
, command
);
848 if (shortcut
!= NULL
)
849 return g_strdup (shortcut
);
851 shortcut
= lookup_keymap_shortcut (panel_map
, command
);
852 if (shortcut
!= NULL
)
853 return g_strdup (shortcut
);
855 ext_map
= lookup_keymap_shortcut (main_map
, CK_StartExtMap1
);
857 shortcut
= lookup_keymap_shortcut (main_x_map
, command
);
858 if (shortcut
!= NULL
)
859 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
864 /* Flag toggling functions */
866 toggle_fast_reload (void)
868 fast_reload
= !fast_reload
;
869 if (fast_reload_w
== 0 && fast_reload
) {
870 message (D_NORMAL
, _(" Information "),
872 (" Using the fast reload option may not reflect the exact \n"
873 " directory contents. In this case you'll need to do a \n"
874 " manual reload of the directory. See the man page for \n"
881 toggle_mix_all_files (void)
883 mix_all_files
= !mix_all_files
;
884 update_panels (UP_RELOAD
, UP_KEEPSEL
);
888 toggle_show_backup (void)
890 show_backups
= !show_backups
;
891 update_panels (UP_RELOAD
, UP_KEEPSEL
);
895 toggle_show_hidden (void)
897 show_dot_files
= !show_dot_files
;
898 update_panels (UP_RELOAD
, UP_KEEPSEL
);
902 toggle_kilobyte_si (void)
904 kilobyte_si
= !kilobyte_si
;
905 update_panels (UP_RELOAD
, UP_KEEPSEL
);
909 * Just a hack for allowing url-like pathnames to be accepted from the
913 translated_mc_chdir (char *dir
)
917 newdir
= vfs_translate_url (dir
);
927 panel_view_mode_t current_mode
, other_mode
;
928 char original_dir
[1024];
932 if (boot_current_is_left
) {
935 current_mode
= startup_left_mode
;
936 other_mode
= startup_right_mode
;
940 current_mode
= startup_right_mode
;
941 other_mode
= startup_left_mode
;
943 /* Creates the left panel */
946 /* Ok, user has specified two dirs, save the original one,
947 * since we may not be able to chdir to the proper
948 * second directory later
950 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
952 translated_mc_chdir (this_dir
);
954 set_display_type (current_index
, current_mode
);
956 /* The other panel */
959 translated_mc_chdir (original_dir
);
960 translated_mc_chdir (other_dir
);
962 set_display_type (other_index
, other_mode
);
964 if (startup_left_mode
== view_listing
) {
965 current_panel
= left_panel
;
968 current_panel
= right_panel
;
970 current_panel
= left_panel
;
973 /* Create the nice widgets */
974 cmdline
= command_new (0, 0, 0);
975 the_prompt
= label_new (0, 0, prompt
);
976 the_prompt
->transparent
= 1;
977 the_bar
= buttonbar_new (keybar_visible
);
979 the_hint
= label_new (0, 0, 0);
980 the_hint
->transparent
= 1;
981 the_hint
->auto_adjust_cols
= 0;
982 the_hint
->widget
.cols
= COLS
;
984 the_menubar
= menubar_new (0, 0, COLS
, NULL
);
988 copy_current_pathname (void)
994 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
995 command_insert (cmdline
, cwd_path
, 0);
997 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
998 command_insert (cmdline
, PATH_SEP_STR
, 0);
1003 copy_other_pathname (void)
1007 if (get_other_type () != view_listing
)
1010 if (!command_prompt
)
1013 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
1014 command_insert (cmdline
, cwd_path
, 0);
1016 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
1017 command_insert (cmdline
, PATH_SEP_STR
, 0);
1022 copy_readlink (WPanel
*panel
)
1024 if (!command_prompt
)
1026 if (S_ISLNK (selection (panel
)->st
.st_mode
)) {
1027 char buffer
[MC_MAXPATHLEN
];
1029 concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1032 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1036 command_insert (cmdline
, buffer
, 1);
1042 copy_current_readlink (void)
1044 copy_readlink (current_panel
);
1048 copy_other_readlink (void)
1050 if (get_other_type () == view_listing
)
1051 copy_readlink (other_panel
);
1054 /* Insert the selected file name into the input line */
1056 copy_prog_name (void)
1059 if (!command_prompt
)
1062 if (get_current_type () == view_tree
) {
1063 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1064 tmp
= tree_selected_name (tree
);
1066 tmp
= selection (current_panel
)->fname
;
1068 command_insert (cmdline
, tmp
, 1);
1072 copy_tagged (WPanel
*panel
)
1076 if (!command_prompt
)
1078 input_disable_update (cmdline
);
1079 if (panel
->marked
) {
1080 for (i
= 0; i
< panel
->count
; i
++) {
1081 if (panel
->dir
.list
[i
].f
.marked
)
1082 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
1085 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
,
1088 input_enable_update (cmdline
);
1092 copy_current_tagged (void)
1094 copy_tagged (current_panel
);
1098 copy_other_tagged (void)
1100 if (get_other_type () == view_listing
)
1101 copy_tagged (other_panel
);
1105 midnight_set_buttonbar (WButtonBar
*b
)
1107 buttonbar_set_label (b
, 1, Q_("ButtonBar|Help"), main_map
, NULL
);
1108 buttonbar_set_label (b
, 2, Q_("ButtonBar|Menu"), main_map
, NULL
);
1109 buttonbar_set_label (b
, 3, Q_("ButtonBar|View"), main_map
, NULL
);
1110 buttonbar_set_label (b
, 4, Q_("ButtonBar|Edit"), main_map
, NULL
);
1111 buttonbar_set_label (b
, 5, Q_("ButtonBar|Copy"), main_map
, NULL
);
1112 buttonbar_set_label (b
, 6, Q_("ButtonBar|RenMov"), main_map
, NULL
);
1113 buttonbar_set_label (b
, 7, Q_("ButtonBar|Mkdir"), main_map
, NULL
);
1114 buttonbar_set_label (b
, 8, Q_("ButtonBar|Delete"), main_map
, NULL
);
1115 buttonbar_set_label (b
, 9, Q_("ButtonBar|PullDn"), main_map
, NULL
);
1116 buttonbar_set_label (b
, 10, Q_("ButtonBar|Quit"), main_map
, NULL
);
1119 static gboolean ctl_x_map_enabled
= FALSE
;
1124 ctl_x_map_enabled
= TRUE
;
1128 midnight_execute_cmd (Widget
*sender
, unsigned long command
)
1130 cb_ret_t res
= MSG_HANDLED
;
1144 case CK_ChownAdvancedCmd
:
1145 chown_advanced_cmd ();
1147 case CK_CompareDirsCmd
:
1148 compare_dirs_cmd ();
1150 case CK_ConfigureBox
:
1154 case CK_ConfigureVfs
:
1164 case CK_CopyCurrentPathname
:
1165 copy_current_pathname ();
1167 case CK_CopyCurrentReadlink
:
1168 copy_current_readlink ();
1170 case CK_CopyCurrentTagged
:
1171 copy_current_tagged ();
1173 case CK_CopyOtherPathname
:
1174 copy_other_pathname ();
1176 case CK_CopyOtherReadlink
:
1177 copy_other_readlink ();
1179 case CK_CopyOtherTagged
:
1180 copy_other_tagged ();
1185 case CK_DisplayBitsBox
:
1186 display_bits_box ();
1191 case CK_EditExtFileCmd
:
1194 case CK_EditFhlFileCmd
:
1197 case CK_EditMcMenuCmd
:
1198 edit_mc_menu_cmd ();
1200 case CK_EditSymlinkCmd
:
1201 edit_symlink_cmd ();
1203 case CK_ExternalPanelize
:
1204 external_panelize ();
1209 case CK_FilteredViewCmd
:
1210 filtered_view_cmd ();
1215 #if defined (USE_NETCODE)
1216 case CK_FishlinkCmd
:
1230 if (sender
== (Widget
*) the_menubar
)
1231 info_cmd (); /* mwnu */
1233 info_cmd_no_menu (); /* shortcut or buttonbar */
1235 #ifdef WITH_BACKGROUND
1252 #ifdef LISTMODE_EDITOR
1253 case CK_ListmodeCmd
:
1260 case CK_MenuLastSelectedCmd
:
1261 menu_last_selected_cmd ();
1266 #if defined (USE_NETCODE) && defined (ENABLE_VFS_MCFS)
1272 case CK_PanelSetPanelEncoding
:
1279 case CK_QuickChdirCmd
:
1282 case CK_QuickViewCmd
:
1283 if (sender
== (Widget
*) the_menubar
)
1284 quick_view_cmd (); /* menu */
1286 quick_cmd_no_menu (); /* shortcut or buttonabr */
1288 case CK_QuietQuitCmd
:
1301 case CK_ReselectVfs
:
1305 case CK_ReverseSelectionCmd
:
1306 reverse_selection_cmd ();
1308 case CK_SaveSetupCmd
:
1314 case CK_ShowCommandLine
:
1317 case CK_SingleDirsizeCmd
:
1318 smart_dirsize_cmd ();
1320 #if defined (USE_NETCODE) && defined (ENABLE_VFS_SMB)
1324 #endif /* USE_NETCODE && ENABLE_VFS_SMB */
1328 case CK_StartExtMap1
:
1340 case CK_ToggleListingCmd
:
1341 toggle_listing_cmd ();
1343 case CK_ToggleShowHidden
:
1344 toggle_show_hidden ();
1352 #ifdef USE_EXT2FSLIB
1353 case CK_UndeleteCmd
:
1357 case CK_UnselectCmd
:
1360 case CK_UserMenuCmd
:
1361 user_file_menu_cmd ();
1366 case CK_ViewFileCmd
:
1370 res
= MSG_NOT_HANDLED
;
1379 /* Call all the inits */
1382 tty_display_8bit (full_eight_bits
!= 0);
1384 tty_display_8bit (eight_bit_clean
!= 0);
1389 init_xterm_support (void)
1391 const char *termvalue
;
1393 termvalue
= getenv ("TERM");
1394 if (!termvalue
|| !(*termvalue
)) {
1395 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1399 /* Check mouse capabilities */
1400 xmouse_seq
= tty_tgetstr ("Km");
1402 if (strcmp (termvalue
, "cygwin") == 0) {
1403 mc_args__force_xterm
= 1;
1404 use_mouse_p
= MOUSE_DISABLED
;
1407 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1408 || strncmp (termvalue
, "konsole", 7) == 0
1409 || strncmp (termvalue
, "rxvt", 4) == 0
1410 || strcmp (termvalue
, "Eterm") == 0
1411 || strcmp (termvalue
, "dtterm") == 0) {
1414 /* Default to the standard xterm sequence */
1416 xmouse_seq
= ESC_STR
"[M";
1419 /* Enable mouse unless explicitly disabled by --nomouse */
1420 if (use_mouse_p
!= MOUSE_DISABLED
) {
1421 const char *color_term
= getenv ("COLORTERM");
1422 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
1423 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
1424 strcmp (termvalue
, "Eterm") == 0) {
1425 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
1427 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
1440 #ifdef HAVE_SUBSHELL_SUPPORT
1442 add_select_channel (subshell_pty
, load_prompt
, 0);
1443 #endif /* !HAVE_SUBSHELL_SUPPORT */
1445 tty_setup_sigwinch (sigwinch_handler
);
1447 verbose
= !((tty_baudrate () < 9600) || tty_is_slow ());
1449 init_xterm_support ();
1454 setup_dummy_mc (void)
1456 char d
[MC_MAXPATHLEN
];
1458 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1463 static void check_codeset()
1465 const char *current_system_codepage
= NULL
;
1467 current_system_codepage
= str_detect_termencoding();
1471 const char *_display_codepage
;
1473 _display_codepage
= get_codepage_id (display_codepage
);
1475 if (! strcmp(_display_codepage
, current_system_codepage
)) {
1476 utf8_display
= str_isutf8 (current_system_codepage
);
1480 display_codepage
= get_codepage_index (current_system_codepage
);
1481 if (display_codepage
== -1) {
1482 display_codepage
= 0;
1485 mc_config_set_string(mc_main_config
, "Misc", "display_codepage", cp_display
);
1488 utf8_display
= str_isutf8 (current_system_codepage
);
1494 if (!(quit
& SUBSHELL_EXIT
))
1496 tty_reset_shell_mode ();
1509 * We sync the profiles since the hotlist may have changed, while
1510 * we only change the setup data if we have the auto save feature set
1513 if (auto_save_setup
)
1514 save_setup (); /* does also call save_hotlist */
1517 save_panel_types ();
1520 vfs_add_current_stamps ();
1523 /* This should be called after destroy_dlg since panel widgets
1524 * save their state on the profiles
1527 done_mc_profile (void)
1533 midnight_callback (Dlg_head
*h
, Widget
*sender
,
1534 dlg_msg_t msg
, int parm
, void *data
)
1536 unsigned long command
;
1542 /* We handle the special case of the output lines */
1543 if (console_flag
&& output_lines
)
1544 show_console_contents (output_start_y
,
1545 LINES
- output_lines
- keybar_visible
-
1546 1, LINES
- keybar_visible
- 1);
1551 menubar_arrange (the_menubar
);
1555 /* We only need the first idle event to show user menu after start */
1556 set_idle_proc (h
, 0);
1558 midnight_execute_cmd (NULL
, CK_UserMenuCmd
);
1562 if (ctl_x_map_enabled
) {
1563 ctl_x_map_enabled
= FALSE
;
1564 command
= lookup_keymap_command (main_x_map
, parm
);
1565 if (command
!= CK_Ignore_Key
)
1566 return midnight_execute_cmd (NULL
, command
);
1569 /* FIXME: should handle all menu shortcuts before this point */
1570 if (the_menubar
->is_active
)
1571 return MSG_NOT_HANDLED
;
1574 free_completions (cmdline
);
1579 for (i
= 0; cmdline
->buffer
[i
] && (cmdline
->buffer
[i
] == ' ' ||
1580 cmdline
->buffer
[i
] == '\t'); i
++)
1582 if (cmdline
->buffer
[i
]) {
1583 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1586 stuff (cmdline
, "", 0);
1590 /* Ctrl-Enter and Alt-Enter */
1591 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n')
1592 && (parm
& (KEY_M_CTRL
| KEY_M_ALT
))) {
1597 /* Ctrl-Shift-Enter */
1598 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n')) {
1599 copy_current_pathname ();
1604 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1605 && !quote
&& !current_panel
->searching
) {
1606 if (!only_leading_plus_minus
) {
1607 /* Special treatement, since the input line will eat them */
1613 if (parm
== '\\' || parm
== '-') {
1619 reverse_selection_cmd ();
1622 } else if (!command_prompt
|| !cmdline
->buffer
[0]) {
1623 /* Special treatement '+', '-', '\', '*' only when this is
1624 * first char on input line
1632 if (parm
== '\\' || parm
== '-') {
1638 reverse_selection_cmd ();
1643 return MSG_NOT_HANDLED
;
1645 case DLG_HOTKEY_HANDLED
:
1646 if ((get_current_type () == view_listing
) && current_panel
->searching
) {
1647 current_panel
->searching
= 0;
1648 current_panel
->dirty
= 1;
1652 case DLG_UNHANDLED_KEY
:
1653 if (command_prompt
) {
1656 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1657 if (v
== MSG_HANDLED
)
1661 if (ctl_x_map_enabled
) {
1662 ctl_x_map_enabled
= FALSE
;
1663 command
= lookup_keymap_command (main_x_map
, parm
);
1665 command
= lookup_keymap_command (main_map
, parm
);
1667 return (command
== CK_Ignore_Key
)
1669 : midnight_execute_cmd (NULL
, command
);
1672 if (!the_menubar
->is_active
)
1673 update_dirty_panels ();
1679 midnight_execute_cmd (NULL
, parm
);
1680 /* message from menu */
1681 else if (sender
== (Widget
*) the_menubar
)
1682 midnight_execute_cmd (sender
, parm
);
1683 /* message from buttonbar */
1684 else if (sender
== (Widget
*) the_bar
) {
1686 midnight_execute_cmd (sender
, parm
);
1688 send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
1693 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
1697 /* Show current directory in the xterm title */
1699 update_xterm_title_path (void)
1702 char host
[BUF_TINY
];
1704 struct passwd
*pw
= NULL
;
1707 if (xterm_flag
&& xterm_title
) {
1708 path
= strip_home_and_password (current_panel
->cwd
);
1709 res
= gethostname(host
, sizeof (host
));
1710 if ( res
) { /* On success, res = 0 */
1713 host
[sizeof (host
) - 1] = '\0';
1715 pw
= getpwuid(getuid());
1717 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1719 login
= g_strdup (host
);
1721 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1722 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1725 if (!alternate_plus_minus
)
1726 numeric_keypad_mode ();
1732 * Load new hint and display it.
1733 * IF force is not 0, ignore the timeout.
1736 load_hint (int force
)
1740 if (!the_hint
->widget
.parent
)
1743 if (!message_visible
) {
1744 label_set_text (the_hint
, NULL
);
1748 hint
= get_random_hint (force
);
1755 char text
[BUF_SMALL
];
1757 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"),
1764 setup_panels_and_run_mc (void)
1766 midnight_dlg
->get_shortcut
= midnight_get_shortcut
;
1768 add_widget (midnight_dlg
, the_menubar
);
1771 add_widget (midnight_dlg
, get_panel_widget (0));
1772 add_widget (midnight_dlg
, get_panel_widget (1));
1773 add_widget (midnight_dlg
, the_hint
);
1774 add_widget (midnight_dlg
, cmdline
);
1775 add_widget (midnight_dlg
, the_prompt
);
1777 add_widget (midnight_dlg
, the_bar
);
1778 midnight_set_buttonbar (the_bar
);
1780 if (boot_current_is_left
)
1781 dlg_select_widget (get_panel_widget (0));
1783 dlg_select_widget (get_panel_widget (1));
1785 /* Run the Midnight Commander if no file was specified in the command line */
1786 run_dlg (midnight_dlg
);
1789 /* result must be free'd (I think this should go in util.c) */
1791 prepend_cwd_on_local (const char *filename
)
1796 if (vfs_file_is_local (filename
)) {
1797 if (*filename
== PATH_SEP
) /* an absolute pathname */
1798 return g_strdup (filename
);
1799 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1800 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1803 strcpy (d
+ l
, filename
);
1804 canonicalize_pathname (d
);
1807 return g_strdup (filename
);
1811 mc_maybe_editor_or_viewer (void)
1813 if (!(view_one_file
|| edit_one_file
))
1816 /* Invoke the internal view/edit routine with:
1817 * the default processing and forcing the internal viewer/editor
1819 if (view_one_file
) {
1821 path
= prepend_cwd_on_local (view_one_file
);
1822 view_file (path
, 0, 1);
1825 #ifdef USE_INTERNAL_EDIT
1827 edit_file (edit_one_file
, edit_one_file_start_line
);
1829 #endif /* USE_INTERNAL_EDIT */
1830 midnight_shutdown
= 1;
1835 /* Run the main dialog that occupies the whole screen */
1839 int midnight_colors
[DLG_COLOR_NUM
];
1840 midnight_colors
[0] = mc_skin_color_get("dialog", "_default_");
1841 midnight_colors
[1] = mc_skin_color_get("dialog", "focus");
1842 midnight_colors
[2] = mc_skin_color_get("dialog", "hotnormal");
1843 midnight_colors
[3] = mc_skin_color_get("dialog", "hotfocus");
1847 midnight_dlg
= create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1848 "[main]", NULL
, DLG_WANT_IDLE
);
1850 if (view_one_file
|| edit_one_file
)
1855 /* start check display_codepage and source_codepage */
1858 main_map
= default_main_map
;
1859 if (main_keymap
&& main_keymap
->len
> 0)
1860 main_map
= (global_keymap_t
*) main_keymap
->data
;
1862 main_x_map
= default_main_x_map
;
1863 if (main_x_keymap
&& main_x_keymap
->len
> 0)
1864 main_x_map
= (global_keymap_t
*) main_x_keymap
->data
;
1866 panel_map
= default_panel_keymap
;
1867 if (panel_keymap
&& panel_keymap
->len
> 0)
1868 panel_map
= (global_keymap_t
*) panel_keymap
->data
;
1870 input_map
= default_input_keymap
;
1871 if (input_keymap
&& input_keymap
->len
> 0)
1872 input_map
= (global_keymap_t
*) input_keymap
->data
;
1874 tree_map
= default_tree_keymap
;
1875 if (tree_keymap
&& tree_keymap
->len
> 0)
1876 tree_map
= (global_keymap_t
*) tree_keymap
->data
;
1878 help_map
= default_help_keymap
;
1879 if (help_keymap
&& help_keymap
->len
> 0)
1880 help_map
= (global_keymap_t
*) help_keymap
->data
;
1882 /* Check if we were invoked as an editor or file viewer */
1883 if (!mc_maybe_editor_or_viewer ()) {
1884 setup_panels_and_run_mc ();
1887 midnight_shutdown
= 1;
1889 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1890 if (mc_args__last_wd_file
&& vfs_current_is_local ())
1891 last_wd_string
= g_strdup (current_panel
->cwd
);
1896 destroy_dlg (midnight_dlg
);
1902 /* POSIX version. The only version we support. */
1906 const char *shell_env
= getenv ("SHELL");
1907 const char *mc_libdir
;
1909 if ((shell_env
== NULL
) || (shell_env
[0] == '\0')) {
1911 pwd
= getpwuid (geteuid ());
1913 shell
= g_strdup (pwd
->pw_shell
);
1915 shell
= g_strdup (shell_env
);
1917 if ((shell
== NULL
) || (shell
[0] == '\0')) {
1919 shell
= g_strdup ("/bin/sh");
1922 /* This is the directory, where MC was installed, on Unix this is DATADIR */
1923 /* and can be overriden by the MC_DATADIR environment variable */
1924 mc_libdir
= getenv ("MC_DATADIR");
1925 if (mc_libdir
!= NULL
) {
1926 mc_home
= g_strdup (mc_libdir
);
1927 mc_home_alt
= g_strdup (SYSCONFDIR
);
1929 mc_home
= g_strdup (SYSCONFDIR
);
1930 mc_home_alt
= g_strdup (DATADIR
);
1933 /* This variable is used by the subshell */
1934 home_dir
= getenv ("HOME");
1941 sigchld_handler_no_subshell (int sig
)
1949 /* COMMENT: if it were true that after the call to handle_console(..INIT)
1950 the value of console_flag never changed, we could simply not install
1951 this handler at all if (!console_flag && !use_subshell). */
1953 /* That comment is no longer true. We need to wait() on a sigchld
1954 handler (that's at least what the tarfs code expects currently). */
1956 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
1958 if (pid
== cons_saver_pid
) {
1960 if (WIFSTOPPED (status
)) {
1961 /* Someone has stopped cons.saver - restart it */
1962 kill (pid
, SIGCONT
);
1964 /* cons.saver has died - disable console saving */
1965 handle_console (CONSOLE_DONE
);
1969 /* If we got here, some other child exited; ignore it */
1970 #endif /* __linux__ */
1978 struct sigaction sigchld_action
;
1980 sigchld_action
.sa_handler
=
1981 #ifdef HAVE_SUBSHELL_SUPPORT
1982 use_subshell
? sigchld_handler
:
1983 #endif /* HAVE_SUBSHELL_SUPPORT */
1984 sigchld_handler_no_subshell
;
1986 sigemptyset (&sigchld_action
.sa_mask
);
1989 sigchld_action
.sa_flags
= SA_RESTART
;
1991 sigchld_action
.sa_flags
= 0;
1992 #endif /* !SA_RESTART */
1994 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1) {
1995 #ifdef HAVE_SUBSHELL_SUPPORT
1997 * This may happen on QNX Neutrino 6, where SA_RESTART
1998 * is defined but not implemented. Fallback to no subshell.
2001 #endif /* HAVE_SUBSHELL_SUPPORT */
2006 mc_main__setup_by_args (int argc
, char *argv
[])
2011 if (mc_args__nomouse
)
2012 use_mouse_p
= MOUSE_DISABLED
;
2015 if (mc_args__netfs_logfile
!= NULL
) {
2016 mc_setctl ("/#ftp:", VFS_SETCTL_LOGFILE
, (void *) mc_args__netfs_logfile
);
2017 #ifdef ENABLE_VFS_SMB
2018 smbfs_set_debugf (mc_args__netfs_logfile
);
2019 #endif /* ENABLE_VFS_SMB */
2022 #ifdef ENABLE_VFS_SMB
2023 if (mc_args__debug_level
!= 0)
2024 smbfs_set_debug (mc_args__debug_level
);
2025 #endif /* ENABLE_VFS_SMB */
2026 #endif /* USE_NETCODE */
2028 base
= x_basename (argv
[0]);
2029 tmp
= (argc
> 0) ? argv
[1] : NULL
;
2031 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP (base
, "vi")) {
2035 * Check for filename:lineno, followed by an optional colon.
2036 * This format is used by many programs (especially compilers)
2037 * in error messages and warnings. It is supported so that
2038 * users can quickly copy and paste file locations.
2040 char *end
= tmp
+ strlen (tmp
), *p
= end
;
2041 if (p
> tmp
&& p
[-1] == ':')
2043 while (p
> tmp
&& g_ascii_isdigit ((gchar
) p
[-1]))
2045 if (tmp
< p
&& p
< end
&& p
[-1] == ':') {
2047 gchar
*fname
= g_strndup (tmp
, p
- 1 - tmp
);
2049 * Check that the file before the colon actually exists.
2050 * If it doesn't exist, revert to the old behavior.
2052 if (mc_stat (tmp
, &st
) == -1 && mc_stat (fname
, &st
) != -1) {
2053 edit_one_file
= fname
;
2054 edit_one_file_start_line
= atoi (p
);
2057 goto try_plus_filename
;
2061 if (*tmp
== '+' && g_ascii_isdigit ((gchar
) tmp
[1])) {
2062 int start_line
= atoi (tmp
);
2063 if (start_line
> 0) {
2064 char *file
= (argc
> 1) ? argv
[2] : NULL
;
2067 edit_one_file_start_line
= start_line
;
2071 edit_one_file
= g_strdup (tmp
);
2074 } else if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP (base
, "view")) {
2076 view_one_file
= g_strdup (tmp
);
2078 fputs ("No arguments given to the viewer\n", stderr
);
2082 /* sets the current dir and the other dir */
2084 this_dir
= g_strdup (tmp
);
2085 tmp
= (argc
> 1) ? argv
[2] : NULL
;
2087 other_dir
= g_strdup (tmp
);
2093 main (int argc
, char *argv
[])
2097 GError
*error
= NULL
;
2098 gboolean isInitialized
;
2100 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2101 setlocale (LC_ALL
, "");
2102 bindtextdomain ("mc", LOCALEDIR
);
2105 /* Set up temporary directory */
2110 str_init_strings (NULL
);
2114 #ifdef USE_INTERNAL_EDIT
2119 SLtt_Ignore_Beep
= 1;
2122 if ( !mc_args_handle (&argc
, &argv
, "mc"))
2125 mc_main__setup_by_args (argc
,argv
);
2127 /* NOTE: This has to be called before tty_init or whatever routine
2128 calls any define_sequence */
2131 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
2132 handle_console (CONSOLE_INIT
);
2134 #ifdef HAVE_SUBSHELL_SUPPORT
2135 /* Don't use subshell when invoked as viewer or editor */
2136 if (edit_one_file
|| view_one_file
)
2140 subshell_get_console_attributes ();
2141 #endif /* HAVE_SUBSHELL_SUPPORT */
2143 /* Install the SIGCHLD handler; must be done before init_subshell() */
2146 /* We need this, since ncurses endwin () doesn't restore the signals */
2147 save_stop_handler ();
2149 /* Must be done before init_subshell, to set up the terminal size: */
2150 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2151 tty_init ((gboolean
) mc_args__slow_terminal
, (gboolean
) mc_args__ugly_line_drawing
);
2155 tty_init_colors (mc_args__disable_colors
, mc_args__force_colors
);
2157 isInitialized
= mc_skin_init(&error
);
2159 mc_filehighlight
= mc_fhl_new (TRUE
);
2161 dlg_set_default_colors ();
2163 if ( ! isInitialized
) {
2164 message (D_ERROR
, _("Warning"), "%s", error
->message
);
2165 g_error_free(error
);
2169 /* create home directory */
2170 /* do it after the screen library initialization to show the error message */
2171 mc_dir
= concat_dir_and_file (home_dir
, MC_USERCONF_DIR
);
2172 canonicalize_pathname (mc_dir
);
2173 if ((stat (mc_dir
, &s
) != 0) && (errno
== ENOENT
)
2174 && mkdir (mc_dir
, 0700) != 0)
2175 message (D_ERROR
, _("Warning"),
2176 _("Cannot create %s directory"), mc_dir
);
2179 #ifdef HAVE_SUBSHELL_SUPPORT
2180 /* Done here to ensure that the subshell doesn't */
2181 /* inherit the file descriptors opened below, etc */
2185 #endif /* HAVE_SUBSHELL_SUPPORT */
2187 /* Removing this from the X code let's us type C-c */
2190 load_keymap_defs ();
2192 /* Also done after init_subshell, to save any shell init file messages */
2194 handle_console (CONSOLE_SAVE
);
2196 if (alternate_plus_minus
)
2197 application_keypad_mode ();
2199 #ifdef HAVE_SUBSHELL_SUPPORT
2201 prompt
= strip_ctrl_codes (subshell_prompt
);
2205 #endif /* HAVE_SUBSHELL_SUPPORT */
2206 prompt
= (geteuid () == 0) ? "# " : "$ ";
2209 /* Program main loop */
2210 if (!midnight_shutdown
)
2213 /* Save the tree store */
2216 free_keymap_defs ();
2218 /* Virtual File System shutdown */
2221 flush_extension_file (); /* does only free memory */
2223 mc_fhl_free (&mc_filehighlight
);
2228 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2229 handle_console (CONSOLE_RESTORE
);
2230 if (alternate_plus_minus
)
2231 numeric_keypad_mode ();
2233 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2236 handle_console (CONSOLE_DONE
);
2237 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2239 if (mc_args__last_wd_file
&& last_wd_string
&& !print_last_revert
2240 && !edit_one_file
&& !view_one_file
) {
2242 open (mc_args__last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2245 if (last_wd_fd
!= -1) {
2246 write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2250 g_free (last_wd_string
);
2252 g_free (mc_home_alt
);
2258 free_codepages_list ();
2260 str_uninit_strings ();
2265 #ifdef USE_INTERNAL_EDIT