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 "../src/tty/tty.h"
45 #include "../src/skin/skin.h"
46 #include "../src/tty/mouse.h"
47 #include "../src/tty/key.h" /* For init_key() */
48 #include "../src/tty/win.h" /* xterm_flag */
50 #include "../src/mcconfig/mcconfig.h"
51 #include "../src/args.h"
52 #include "../src/skin/skin.h"
53 #include "../src/filehighlight/fhl.h"
62 #include "treestore.h"
63 #include "cons.saver.h"
65 #include "setup.h" /* save_setup() */
66 #include "boxes.h" /* sort_box() */
68 #include "cmd.h" /* Normal commands */
71 #include "learn.h" /* learn_keys() */
74 #include "ext.h" /* For flush_extension_file() */
76 /* Listbox for the command history feature */
81 #include "../vfs/vfs.h" /* vfs_translate_url() */
88 #include "../vfs/smbfs.h" /* smbfs_set_debug() */
91 #ifdef USE_INTERNAL_EDIT
92 # include "../edit/edit.h"
97 #endif /* HAVE_CHARSET */
100 #include "../vfs/gc.h"
103 /* When the modes are active, left_panel, right_panel and tree_panel */
104 /* Point to a proper data structure. You should check with the functions */
105 /* get_current_type and get_other_type the types of the panels before using */
106 /* This pointer variables */
108 /* The structures for the panels */
109 WPanel
*left_panel
= NULL
;
110 WPanel
*right_panel
= NULL
;
112 mc_fhl_t
*mc_filehighlight
;
114 /* The pointer to the tree */
115 WTree
*the_tree
= NULL
;
118 struct WMenu
*the_menubar
= NULL
;
120 /* Pointers to the selected and unselected panel */
121 WPanel
*current_panel
= NULL
;
123 /* Set if the command is being run from the "Right" menu */
126 /* Set when main loop should be terminated */
127 volatile int quit
= 0;
129 /* Set if you want the possible completions dialog for the first time */
130 int show_all_if_ambiguous
= 0;
132 /* Set when cd symlink following is desirable (bash mode) */
135 /* If set then dialogs just clean the screen when refreshing, else */
136 /* they do a complete refresh, refreshing all the parts of the program */
137 int fast_refresh
= 0;
139 /* If true, marking a files moves the cursor down */
140 int mark_moves_down
= 1;
142 /* If true, at startup the user-menu is invoked */
145 /* If true, then the +, - and \ keys have their special meaning only if the
146 * command line is emtpy, otherwise they behave like regular letters
148 int only_leading_plus_minus
= 1;
150 int pause_after_run
= pause_on_dumb_terminals
;
152 /* It true saves the setup when quitting */
153 int auto_save_setup
= 1;
157 * Don't restrict the output on the screen manager level,
158 * the translation tables take care of it.
160 #define full_eight_bits (1)
161 #define eight_bit_clean (1)
162 #else /* HAVE_CHARSET */
163 /* If true, allow characters in the range 160-255 */
164 int eight_bit_clean
= 1;
166 * If true, also allow characters in the range 128-159.
167 * This is reported to break on many terminals (xterm, qansi-m).
169 int full_eight_bits
= 0;
170 #endif /* !HAVE_CHARSET */
173 * If utf-8 terminal utf8_display = 1
174 * Display bits set UTF-8
177 int utf8_display
= 0;
179 /* If true use the internal viewer */
180 int use_internal_view
= 1;
182 /* Have we shown the fast-reload warning in the past? */
183 int fast_reload_w
= 0;
185 /* Move page/item? When clicking on the top or bottom of a panel */
186 int mouse_move_pages
= 1;
188 /* If true: l&r arrows are used to chdir if the input line is empty */
189 int navigate_with_arrows
= 0;
191 /* If true program softkeys (HP terminals only) on startup and after every
192 command ran in the subshell to the description found in the termcap/terminfo
194 int reset_hp_softkeys
= 0;
197 const char *prompt
= NULL
;
199 /* The widget where we draw the prompt */
208 /* Mouse type: GPM, xterm or none */
209 Mouse_Type use_mouse_p
= MOUSE_NONE
;
211 /* If on, default for "No" in delete operations */
214 /* Controls screen clearing before an exec */
215 int clear_before_exec
= 1;
217 /* Asks for confirmation before deleting a file */
218 int confirm_delete
= 1;
220 /* Asks for confirmation before deleting a hotlist entry */
221 int confirm_directory_hotlist_delete
= 1;
223 /* Asks for confirmation before overwriting a file */
224 int confirm_overwrite
= 1;
226 /* Asks for confirmation before executing a program by pressing enter */
227 int confirm_execute
= 0;
229 /* Asks for confirmation before leaving the program */
230 int confirm_exit
= 1;
232 /* Asks for confirmation when using F3 to view a directory and there
234 int confirm_view_dir
= 0;
236 /* This flag indicates if the pull down menus by default drop down */
239 /* if skip_check_codeset = 1 do not show warning about
240 * system and display codeset is different
242 int skip_check_codeset
= 0;
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
;
254 /* The value of the other directory, only used when loading the setup */
255 char *other_dir
= NULL
;
257 /* Only used at program boot */
258 int boot_current_is_left
= 1;
260 static char *this_dir
= NULL
;
262 /* If this is true, then when browsing the tree the other window will
263 * automatically reload it's directory with the contents of the currently
264 * selected directory.
268 /* If set, then print to the given file the last directory we were at */
269 static char *last_wd_string
= NULL
;
270 /* Set to 1 to suppress printing the last directory */
271 static int print_last_revert
= 0;
273 /* File name to view if argument was supplied */
274 const char *view_one_file
= NULL
;
276 /* File name to edit if argument was supplied */
277 const char *edit_one_file
= NULL
;
279 /* Line to start the editor on */
280 static int edit_one_file_start_line
= 0;
282 /* Used so that widgets know if they are being destroyed or
284 int midnight_shutdown
= 0;
286 /* The user's shell */
289 /* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
290 char *mc_home
= NULL
;
292 /* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
293 char *mc_home_alt
= NULL
;
297 /* Save current stat of directories to avoid reloading the panels */
298 /* when no modifications have taken place */
300 save_cwds_stat (void)
303 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
304 if (get_other_type () == view_listing
)
305 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
309 #ifdef HAVE_SUBSHELL_SUPPORT
311 do_update_prompt (void)
314 printf ("\r\n%s", subshell_prompt
);
319 #endif /* HAVE_SUBSHELL_SUPPORT */
324 free_completions (cmdline
);
325 dlg_one_down (midnight_dlg
);
328 /* Stop MC main dialog and the current dialog if it exists.
329 * Needed to provide fast exit from MC viewer or editor on shell exit */
333 midnight_dlg
->running
= 0;
335 current_dlg
->running
= 0;
340 quit_cmd_internal (int quiet
)
344 if (quiet
|| !confirm_exit
) {
348 (_(" The Midnight Commander "),
349 _(" Do you really want to quit the Midnight Commander? "), D_NORMAL
,
350 2, _("&Yes"), _("&No")) == 0)
354 #ifdef HAVE_SUBSHELL_SUPPORT
357 else if ((q
= exit_subshell ()))
369 quit_cmd_internal (0);
373 quiet_quit_cmd (void)
375 print_last_revert
= 1;
376 quit_cmd_internal (1);
379 /* Wrapper for do_subshell_chdir, check for availability of subshell */
381 subshell_chdir (const char *directory
)
383 #ifdef HAVE_SUBSHELL_SUPPORT
385 if (vfs_current_is_local ())
386 do_subshell_chdir (directory
, 0, 1);
388 #endif /* HAVE_SUBSHELL_SUPPORT */
392 directory_history_add (struct WPanel
*panel
, const char *dir
)
396 tmp
= g_strdup (dir
);
397 strip_password (tmp
, 1);
399 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
403 * If we moved to the parent directory move the selection pointer to
404 * the old directory name; If we leave VFS dir, remove FS specificator.
406 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
409 get_parent_dir_name (const char *cwd
, const char *lwd
)
412 if (strlen (lwd
) > strlen (cwd
))
413 if ((p
= strrchr (lwd
, PATH_SEP
)) && !strncmp (cwd
, lwd
, p
- lwd
) &&
414 ((gsize
)strlen (cwd
) == (gsize
) p
- (gsize
) lwd
|| (p
== lwd
&& cwd
[0] == PATH_SEP
&&
422 * Changes the current directory of the panel.
423 * Don't record change in the directory history.
426 _do_panel_cd (WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
428 const char *directory
;
430 char temp
[MC_MAXPATHLEN
];
431 char *translated_url
;
433 if (cd_type
== cd_parse_command
) {
434 while (*new_dir
== ' ')
438 olddir
= g_strdup (panel
->cwd
);
439 new_dir
= translated_url
= vfs_translate_url (new_dir
);
441 /* Convert *new_path to a suitable pathname, handle ~user */
443 if (cd_type
== cd_parse_command
) {
444 if (!strcmp (new_dir
, "-")) {
445 strcpy (temp
, panel
->lwd
);
449 directory
= *new_dir
? new_dir
: home_dir
;
451 if (mc_chdir (directory
) == -1) {
452 strcpy (panel
->cwd
, olddir
);
454 g_free (translated_url
);
457 g_free (translated_url
);
459 /* Success: save previous directory, shutdown status of previous dir */
460 strcpy (panel
->lwd
, olddir
);
461 free_completions (cmdline
);
463 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
465 vfs_release_path (olddir
);
467 subshell_chdir (panel
->cwd
);
469 /* Reload current panel */
470 panel_clean_dir (panel
);
472 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
473 panel
->reverse
, panel
->case_sensitive
,
474 panel
->exec_first
, panel
->filter
);
475 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
478 update_xterm_title_path ();
486 * Changes the current directory of the panel.
487 * Record change in the directory history.
490 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
494 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
496 directory_history_add (panel
, panel
->cwd
);
501 do_cd (const char *new_dir
, enum cd_enum exact
)
503 return (do_panel_cd (current_panel
, new_dir
, exact
));
507 directory_history_next (WPanel
*panel
)
511 nextdir
= g_list_next (panel
->dir_history
);
516 if (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
))
517 panel
->dir_history
= nextdir
;
521 directory_history_prev (WPanel
*panel
)
525 prevdir
= g_list_previous (panel
->dir_history
);
530 if (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
))
531 panel
->dir_history
= prevdir
;
535 directory_history_list (WPanel
*panel
)
539 if (!panel
->dir_history
)
542 s
= show_hist (panel
->dir_history
, &panel
->widget
);
547 if (_do_panel_cd (panel
, s
, cd_exact
))
548 directory_history_add (panel
, panel
->cwd
);
550 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
554 #ifdef HAVE_SUBSHELL_SUPPORT
556 load_prompt (int fd
, void *unused
)
561 if (!read_subshell_prompt ())
564 /* Don't actually change the prompt if it's invisible */
565 if (current_dlg
== midnight_dlg
&& command_prompt
) {
569 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
570 prompt_len
= str_term_width1 (tmp_prompt
);
572 /* Check for prompts too big */
573 if (COLS
> 8 && prompt_len
> COLS
- 8) {
574 tmp_prompt
[COLS
- 8] = '\0';
575 prompt_len
= COLS
- 8;
578 label_set_text (the_prompt
, prompt
);
579 winput_set_origin ((WInput
*) cmdline
, prompt_len
,
582 /* since the prompt has changed, and we are called from one of the
583 * tty_get_event channels, the prompt updating does not take place
584 * automatically: force a cursor update and a screen refresh
586 update_cursor (midnight_dlg
);
592 #endif /* HAVE_SUBSHELL_SUPPORT */
600 if (!SELECTED_IS_PANEL
)
604 sort_order
= sort_box (p
->sort_type
, &p
->reverse
,
608 panel_set_sort_order (p
, sort_order
);
617 sel_dir
= tree_box (selection (current_panel
)->fname
);
619 do_cd (sel_dir
, cd_exact
);
624 #ifdef LISTMODE_EDITOR
630 if (get_current_type () != view_listing
)
633 newmode
= listmode_edit (current_panel
->user_format
);
637 g_free (current_panel
->user_format
);
638 current_panel
->list_type
= list_user
;
639 current_panel
->user_format
= newmode
;
640 set_panel_formats (current_panel
);
644 #endif /* LISTMODE_EDITOR */
646 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
647 static menu_entry LeftMenu
[] = {
648 {' ', N_("&Listing mode..."), NULL_HOTKEY
, listing_cmd
},
649 {' ', N_("&Quick view C-x q"), NULL_HOTKEY
, quick_view_cmd
},
650 {' ', N_("&Info C-x i"), NULL_HOTKEY
, info_cmd
},
651 {' ', N_("&Tree"), NULL_HOTKEY
, tree_cmd
},
652 {' ', "", NULL_HOTKEY
, 0},
653 {' ', N_("&Sort order..."), NULL_HOTKEY
, sort_cmd
},
654 {' ', "", NULL_HOTKEY
, 0},
655 {' ', N_("&Filter..."), NULL_HOTKEY
, filter_cmd
},
657 {' ', "",NULL_HOTKEY
, 0},
658 {' ', N_("&Encoding... C-t"), NULL_HOTKEY
, encoding_cmd
},
661 {' ', "", NULL_HOTKEY
, 0},
662 #ifdef ENABLE_VFS_MCFS
663 {' ', N_("&Network link..."), NULL_HOTKEY
, netlink_cmd
},
665 {' ', N_("FT&P link..."), NULL_HOTKEY
, ftplink_cmd
},
666 {' ', N_("S&hell link..."), NULL_HOTKEY
, fishlink_cmd
},
668 {' ', N_("SM&B link..."), NULL_HOTKEY
, smblink_cmd
},
671 {' ', "", NULL_HOTKEY
, 0},
672 {' ', N_("&Rescan C-r"), NULL_HOTKEY
, reread_cmd
}
675 static menu_entry RightMenu
[] = {
676 {' ', N_("&Listing mode..."), NULL_HOTKEY
, listing_cmd
},
677 {' ', N_("&Quick view C-x q"), NULL_HOTKEY
, quick_view_cmd
},
678 {' ', N_("&Info C-x i"), NULL_HOTKEY
, info_cmd
},
679 {' ', N_("&Tree"), NULL_HOTKEY
, tree_cmd
},
680 {' ', "", NULL_HOTKEY
, 0},
681 {' ', N_("&Sort order..."), NULL_HOTKEY
, sort_cmd
},
682 {' ', "", NULL_HOTKEY
, 0},
683 {' ', N_("&Filter..."), NULL_HOTKEY
, filter_cmd
},
685 {' ', "",NULL_HOTKEY
, 0},
686 {' ', N_("&Encoding... C-t"), NULL_HOTKEY
, encoding_cmd
},
689 {' ', "", NULL_HOTKEY
, 0},
690 #ifdef ENABLE_VFS_MCFS
691 {' ', N_("&Network link..."), NULL_HOTKEY
, netlink_cmd
},
693 {' ', N_("FT&P link..."), NULL_HOTKEY
, ftplink_cmd
},
694 {' ', N_("S&hell link..."), NULL_HOTKEY
, fishlink_cmd
},
696 {' ', N_("SM&B link..."), NULL_HOTKEY
, smblink_cmd
},
699 {' ', "", NULL_HOTKEY
, 0},
700 {' ', N_("&Rescan C-r"), NULL_HOTKEY
, reread_cmd
}
703 static menu_entry FileMenu
[] = {
704 {' ', N_("&View F3"), NULL_HOTKEY
, view_cmd
},
705 {' ', N_("Vie&w file... "), NULL_HOTKEY
, view_file_cmd
},
706 {' ', N_("&Filtered view M-!"), NULL_HOTKEY
, filtered_view_cmd
},
707 {' ', N_("&Edit F4"), NULL_HOTKEY
, edit_cmd
},
708 {' ', N_("&Copy F5"), NULL_HOTKEY
, copy_cmd
},
709 {' ', N_("c&Hmod C-x c"), NULL_HOTKEY
, chmod_cmd
},
710 {' ', N_("&Link C-x l"), NULL_HOTKEY
, link_cmd
},
711 {' ', N_("&SymLink C-x s"), NULL_HOTKEY
, symlink_cmd
},
712 {' ', N_("edit s&Ymlink C-x C-s"), NULL_HOTKEY
, edit_symlink_cmd
},
713 {' ', N_("ch&Own C-x o"), NULL_HOTKEY
, chown_cmd
},
714 {' ', N_("&Advanced chown "), NULL_HOTKEY
, chown_advanced_cmd
},
715 {' ', N_("&Rename/Move F6"), NULL_HOTKEY
, ren_cmd
},
716 {' ', N_("&Mkdir F7"), NULL_HOTKEY
, mkdir_cmd
},
717 {' ', N_("&Delete F8"), NULL_HOTKEY
, delete_cmd
},
718 {' ', N_("&Quick cd M-c"), NULL_HOTKEY
, quick_cd_cmd
},
719 {' ', "", NULL_HOTKEY
, 0},
720 {' ', N_("select &Group M-+"), NULL_HOTKEY
, select_cmd
},
721 {' ', N_("u&Nselect group M-\\"), NULL_HOTKEY
, unselect_cmd
},
722 {' ', N_("reverse selec&Tion M-*"), NULL_HOTKEY
, reverse_selection_cmd
},
723 {' ', "", NULL_HOTKEY
, 0},
724 {' ', N_("e&Xit F10"), NULL_HOTKEY
, quit_cmd
}
727 static menu_entry CmdMenu
[] = {
728 {' ', N_("&User menu F2"), NULL_HOTKEY
, user_file_menu_cmd
},
729 /* I know, I'm lazy, but the tree widget when it's not running
730 * as a panel still has some problems, I have not yet finished
731 * the WTree widget port, sorry.
733 {' ', N_("&Directory tree"), NULL_HOTKEY
, treebox_cmd
},
734 {' ', N_("&Find file M-?"), NULL_HOTKEY
, find_cmd
},
735 {' ', N_("s&Wap panels C-u"), NULL_HOTKEY
, swap_cmd
},
736 {' ', N_("switch &Panels on/off C-o"), NULL_HOTKEY
, view_other_cmd
},
737 {' ', N_("&Compare directories C-x d"), NULL_HOTKEY
, compare_dirs_cmd
},
738 {' ', N_("e&Xternal panelize C-x !"), NULL_HOTKEY
, external_panelize
},
739 {' ', N_("show directory s&Izes"), NULL_HOTKEY
, dirsizes_cmd
},
740 {' ', "", NULL_HOTKEY
, 0},
741 {' ', N_("Command &history M-h"), NULL_HOTKEY
, history_cmd
},
742 {' ', N_("di&Rectory hotlist C-\\"), NULL_HOTKEY
, quick_chdir_cmd
},
744 {' ', N_("&Active VFS list C-x a"), NULL_HOTKEY
, reselect_vfs
},
746 #ifdef WITH_BACKGROUND
747 {' ', N_("&Background jobs C-x j"), NULL_HOTKEY
, jobs_cmd
},
749 {' ', "", NULL_HOTKEY
, 0},
751 {' ', N_("&Undelete files (ext2fs only)"), NULL_HOTKEY
, undelete_cmd
},
753 #ifdef LISTMODE_EDITOR
754 {' ', N_("&Listing format edit"), NULL_HOTKEY
, listmode_cmd
},
756 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
757 {' ', "", NULL_HOTKEY
, 0},
759 {' ', N_("Edit &extension file"), NULL_HOTKEY
, ext_cmd
},
760 {' ', N_("Edit &menu file"), NULL_HOTKEY
, edit_mc_menu_cmd
},
761 {' ', N_("Edit &highlighting group file"), NULL_HOTKEY
, edit_fhl_cmd
}
764 /* Must keep in sync with the constants in menu_cmd */
765 static menu_entry OptMenu
[] = {
766 {' ', N_("&Configuration..."), NULL_HOTKEY
, configure_box
},
767 {' ', N_("&Layout..."), NULL_HOTKEY
, layout_cmd
},
768 {' ', N_("c&Onfirmation..."), NULL_HOTKEY
, confirm_box
},
769 {' ', N_("&Display bits..."), NULL_HOTKEY
, display_bits_box
},
770 {' ', N_("learn &Keys..."), NULL_HOTKEY
, learn_keys
},
772 {' ', N_("&Virtual FS..."), NULL_HOTKEY
, configure_vfs
},
773 #endif /* !USE_VFS */
774 {' ', "", NULL_HOTKEY
, 0},
775 {' ', N_("&Save setup"), NULL_HOTKEY
, save_setup_cmd
}
778 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
780 static Menu
*MenuBar
[5];
786 create_menu (horizontal_split
? _(" &Above ") : _(" &Left "),
787 LeftMenu
, menu_entries (LeftMenu
),
788 "[Left and Right Menus]");
790 create_menu (_(" &File "), FileMenu
, menu_entries (FileMenu
),
793 create_menu (_(" &Command "), CmdMenu
, menu_entries (CmdMenu
),
796 create_menu (_(" &Options "), OptMenu
, menu_entries (OptMenu
),
799 create_menu (horizontal_split
? _(" &Below ") : _(" &Right "),
800 RightMenu
, menu_entries (RightMenu
),
801 "[Left and Right Menus]");
809 for (i
= 0; i
< 5; i
++) {
810 destroy_menu (MenuBar
[i
]);
815 menu_last_selected_cmd (void)
817 the_menubar
->active
= 1;
818 the_menubar
->dropped
= drop_menus
;
819 the_menubar
->previous_widget
= midnight_dlg
->current
->dlg_id
;
820 dlg_select_widget (the_menubar
);
826 if (the_menubar
->active
)
829 if ((get_current_index () == 0) ^ (!current_panel
->active
))
830 the_menubar
->selected
= 0;
832 the_menubar
->selected
= 4;
833 menu_last_selected_cmd ();
836 /* Flag toggling functions */
838 toggle_fast_reload (void)
840 fast_reload
= !fast_reload
;
841 if (fast_reload_w
== 0 && fast_reload
) {
842 message (D_NORMAL
, _(" Information "),
844 (" Using the fast reload option may not reflect the exact \n"
845 " directory contents. In this case you'll need to do a \n"
846 " manual reload of the directory. See the man page for \n"
853 toggle_mix_all_files (void)
855 mix_all_files
= !mix_all_files
;
856 update_panels (UP_RELOAD
, UP_KEEPSEL
);
860 toggle_show_backup (void)
862 show_backups
= !show_backups
;
863 update_panels (UP_RELOAD
, UP_KEEPSEL
);
867 toggle_show_hidden (void)
869 show_dot_files
= !show_dot_files
;
870 update_panels (UP_RELOAD
, UP_KEEPSEL
);
874 toggle_kilobyte_si (void)
876 kilobyte_si
= !kilobyte_si
;
877 update_panels (UP_RELOAD
, UP_KEEPSEL
);
881 * Just a hack for allowing url-like pathnames to be accepted from the
885 translated_mc_chdir (char *dir
)
889 newdir
= vfs_translate_url (dir
);
901 char original_dir
[1024];
905 if (boot_current_is_left
) {
908 current_mode
= startup_left_mode
;
909 other_mode
= startup_right_mode
;
913 current_mode
= startup_right_mode
;
914 other_mode
= startup_left_mode
;
916 /* Creates the left panel */
919 /* Ok, user has specified two dirs, save the original one,
920 * since we may not be able to chdir to the proper
921 * second directory later
923 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
925 translated_mc_chdir (this_dir
);
927 set_display_type (current_index
, current_mode
);
929 /* The other panel */
932 translated_mc_chdir (original_dir
);
933 translated_mc_chdir (other_dir
);
935 set_display_type (other_index
, other_mode
);
937 if (startup_left_mode
== view_listing
) {
938 current_panel
= left_panel
;
941 current_panel
= right_panel
;
943 current_panel
= left_panel
;
946 /* Create the nice widgets */
947 cmdline
= command_new (0, 0, 0);
948 the_prompt
= label_new (0, 0, prompt
);
949 the_prompt
->transparent
= 1;
950 the_bar
= buttonbar_new (keybar_visible
);
952 the_hint
= label_new (0, 0, 0);
953 the_hint
->transparent
= 1;
954 the_hint
->auto_adjust_cols
= 0;
955 the_hint
->widget
.cols
= COLS
;
957 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
961 copy_current_pathname (void)
967 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
968 command_insert (cmdline
, cwd_path
, 0);
970 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
971 command_insert (cmdline
, PATH_SEP_STR
, 0);
976 copy_other_pathname (void)
980 if (get_other_type () != view_listing
)
986 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
987 command_insert (cmdline
, cwd_path
, 0);
989 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
990 command_insert (cmdline
, PATH_SEP_STR
, 0);
995 copy_readlink (WPanel
*panel
)
999 if (S_ISLNK (selection (panel
)->st
.st_mode
)) {
1000 char buffer
[MC_MAXPATHLEN
];
1002 concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1005 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1009 command_insert (cmdline
, buffer
, 1);
1015 copy_current_readlink (void)
1017 copy_readlink (current_panel
);
1021 copy_other_readlink (void)
1023 if (get_other_type () != view_listing
)
1025 copy_readlink (other_panel
);
1028 /* Insert the selected file name into the input line */
1030 copy_prog_name (void)
1033 if (!command_prompt
)
1036 if (get_current_type () == view_tree
) {
1037 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1038 tmp
= tree_selected_name (tree
);
1040 tmp
= selection (current_panel
)->fname
;
1042 command_insert (cmdline
, tmp
, 1);
1046 copy_tagged (WPanel
*panel
)
1050 if (!command_prompt
)
1052 input_disable_update (cmdline
);
1053 if (panel
->marked
) {
1054 for (i
= 0; i
< panel
->count
; i
++) {
1055 if (panel
->dir
.list
[i
].f
.marked
)
1056 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
1059 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
,
1062 input_enable_update (cmdline
);
1066 copy_current_tagged (void)
1068 copy_tagged (current_panel
);
1072 copy_other_tagged (void)
1074 if (get_other_type () != view_listing
)
1076 copy_tagged (other_panel
);
1082 buttonbar_set_label (midnight_dlg
, 1, _("Help"), help_cmd
);
1083 buttonbar_set_label (midnight_dlg
, 2, _("Menu"), user_file_menu_cmd
);
1084 buttonbar_set_label (midnight_dlg
, 9, _("PullDn"), menu_cmd
);
1085 buttonbar_set_label (midnight_dlg
, 10, _("Quit"), quit_cmd
);
1088 static const key_map ctl_x_map
[] = {
1089 {XCTRL ('c'), quit_cmd
},
1090 {'d', compare_dirs_cmd
},
1092 {'a', reselect_vfs
},
1093 #endif /* USE_VFS */
1094 {'p', copy_current_pathname
},
1095 {XCTRL ('p'), copy_other_pathname
},
1096 {'t', copy_current_tagged
},
1097 {XCTRL ('t'), copy_other_tagged
},
1100 {'r', copy_current_readlink
},
1101 {XCTRL ('r'), copy_other_readlink
},
1104 {XCTRL ('s'), edit_symlink_cmd
},
1105 {'i', info_cmd_no_menu
},
1106 {'q', quick_cmd_no_menu
},
1107 {'h', add2hotlist_cmd
},
1108 {'!', external_panelize
},
1109 #ifdef WITH_BACKGROUND
1111 #endif /* WITH_BACKGROUND */
1115 static int ctl_x_map_enabled
= 0;
1120 ctl_x_map_enabled
= 1;
1128 static const key_map default_map
[] = {
1129 {KEY_F (19), menu_last_selected_cmd
},
1130 {KEY_F (20), quiet_quit_cmd
},
1132 {XCTRL ('@'), smart_dirsize_cmd
},
1134 /* Copy useful information to the command line */
1135 {ALT ('a'), copy_current_pathname
},
1136 {ALT ('A'), copy_other_pathname
},
1138 {ALT ('c'), quick_cd_cmd
},
1140 /* To access the directory hotlist */
1141 {XCTRL ('\\'), quick_chdir_cmd
},
1144 {XCTRL ('z'), suspend_cmd
},
1146 /* The filtered view command */
1147 {ALT ('!'), filtered_view_cmd
},
1150 {ALT ('?'), find_cmd
},
1153 {XCTRL ('r'), reread_cmd
},
1155 /* Toggle listing between long, user defined and full formats */
1156 {ALT ('t'), toggle_listing_cmd
},
1159 {XCTRL ('u'), swap_cmd
},
1162 {XCTRL ('o'), view_other_cmd
},
1164 /* Control-X keybindings */
1165 {XCTRL ('x'), ctl_x_cmd
},
1167 /* Show/hide hidden files */
1168 {ALT ('.'), toggle_show_hidden
},
1170 /* Trap dlg's exit commands */
1171 {ESC_CHAR
, nothing
},
1172 {XCTRL ('c'), nothing
},
1173 {XCTRL ('g'), nothing
},
1180 /* Call all the inits */
1183 tty_display_8bit (full_eight_bits
!= 0);
1185 tty_display_8bit (eight_bit_clean
!= 0);
1190 init_xterm_support (void)
1192 const char *termvalue
;
1194 termvalue
= getenv ("TERM");
1195 if (!termvalue
|| !(*termvalue
)) {
1196 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1200 /* Check mouse capabilities */
1201 xmouse_seq
= tty_tgetstr ("Km");
1203 if (strcmp (termvalue
, "cygwin") == 0) {
1204 mc_args__force_xterm
= 1;
1205 use_mouse_p
= MOUSE_DISABLED
;
1208 if (mc_args__force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1209 || strncmp (termvalue
, "konsole", 7) == 0
1210 || strncmp (termvalue
, "rxvt", 4) == 0
1211 || strcmp (termvalue
, "Eterm") == 0
1212 || strcmp (termvalue
, "dtterm") == 0) {
1215 /* Default to the standard xterm sequence */
1217 xmouse_seq
= ESC_STR
"[M";
1220 /* Enable mouse unless explicitly disabled by --nomouse */
1221 if (use_mouse_p
!= MOUSE_DISABLED
) {
1222 const char *color_term
= getenv ("COLORTERM");
1223 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
1224 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
1225 strcmp (termvalue
, "Eterm") == 0) {
1226 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
1228 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
1242 #ifdef HAVE_SUBSHELL_SUPPORT
1244 add_select_channel (subshell_pty
, load_prompt
, 0);
1245 #endif /* !HAVE_SUBSHELL_SUPPORT */
1247 tty_setup_sigwinch (sigwinch_handler
);
1249 verbose
= !((tty_baudrate () < 9600) || tty_is_slow ());
1251 init_xterm_support ();
1256 setup_dummy_mc (void)
1258 char d
[MC_MAXPATHLEN
];
1260 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1265 static void check_codeset()
1267 const char *_system_codepage
= NULL
;
1269 const char *_source_codepage
= NULL
;
1270 const char *_display_codepage
= NULL
;
1271 int profile_changed
= 0;
1276 if ( !skip_check_codeset
) {
1278 QuickWidget ecs_widgets
[] = {
1279 QUICK_BUTTON (4, 6, 13, CONFY
, N_("&Skip"), B_EXIT
, NULL
),
1280 QUICK_BUTTON (1, 11, 13, CONFY
, N_("&Fix it"), B_ENTER
, NULL
),
1281 QUICK_CHECKBOX (1, 13, 11, CONFY
, N_("don't ask again"), &skip_check_codeset
),
1282 QUICK_LABEL (2, 30, 3, CONFY
, N_("Chosen display charset (Settings->Display bits)\n"
1283 "or source codeset (in mcedit ctrl-t) \n"
1284 "does not match one set via locale. \n"
1285 "Set correct codeset manually or press <<Fix it>> \n"
1286 "to set locale default.\n\n"
1287 "Or set \'don't ask again\' and press <<Skip>>")),
1293 CONFX
, CONFY
, -1, -1, N_(" Confirmation "),
1294 "[Confirmation]", ecs_widgets
, FALSE
1298 _system_codepage
= str_detect_termencoding();
1299 _source_codepage
= get_codepage_id (source_codepage
);
1300 _display_codepage
= get_codepage_id (display_codepage
);
1301 if ( (strcmp (_system_codepage
, _display_codepage
)) ||
1302 (strcmp (_system_codepage
, _source_codepage
)) ) {
1303 if (quick_dialog (&ecs
) == B_ENTER
){
1304 display_codepage
= get_codepage_index (_system_codepage
);
1305 cp_display
= get_codepage_id (display_codepage
);
1306 if ( !strcmp (cp_display
, _system_codepage
)) {
1307 mc_config_set_string(mc_main_config
, "Misc", "display_codepage", cp_display
);
1308 mc_config_set_string(mc_main_config
, "Misc", "source_codepage", cp_display
);
1309 display_codepage
= get_codepage_index ( cp_display
);
1310 utf8_display
= str_isutf8 (_system_codepage
);
1311 source_codepage
= display_codepage
;
1312 cp_source
= cp_display
;
1313 profile_changed
= 1;
1315 utf8_display
= str_isutf8 (_system_codepage
);
1316 cp_source
= cp_display
= _system_codepage
;
1319 if ( skip_check_codeset
) {
1320 mc_config_set_int(mc_main_config
, "Midnight-Commander", "skip_check_codeset", 1);
1321 profile_changed
= 1;
1325 if ( profile_changed
)
1328 #else /* HAVE_CHARSET */
1329 _system_codepage
= str_detect_termencoding();
1330 utf8_display
= str_isutf8 (_system_codepage
);
1331 #endif /* HAVE_CHARSET */
1337 if (!(quit
& SUBSHELL_EXIT
))
1339 tty_reset_shell_mode ();
1354 * We sync the profiles since the hotlist may have changed, while
1355 * we only change the setup data if we have the auto save feature set
1358 if (auto_save_setup
)
1359 save_setup (); /* does also call save_hotlist */
1362 save_panel_types ();
1365 vfs_add_current_stamps ();
1368 /* This should be called after destroy_dlg since panel widgets
1369 * save their state on the profiles
1372 done_mc_profile (void)
1378 midnight_callback (struct Dlg_head
*h
, dlg_msg_t msg
, int parm
)
1385 /* We only need the first idle event */
1386 set_idle_proc (h
, 0);
1388 user_file_menu_cmd ();
1393 if (ctl_x_map_enabled
) {
1394 ctl_x_map_enabled
= 0;
1395 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1396 if (parm
== ctl_x_map
[i
].key_code
) {
1397 (*ctl_x_map
[i
].fn
) ();
1402 /* FIXME: should handle all menu shortcuts before this point */
1403 if (the_menubar
->active
)
1404 return MSG_NOT_HANDLED
;
1406 if (parm
== KEY_F (10)) {
1412 free_completions (cmdline
);
1415 for (i
= 0; cmdline
->buffer
[i
] && (cmdline
->buffer
[i
] == ' ' ||
1416 cmdline
->buffer
[i
] == '\t'); i
++);
1417 if (cmdline
->buffer
[i
]) {
1418 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1421 stuff (cmdline
, "", 0);
1425 /* Ctrl-Enter and Alt-Enter */
1426 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n')
1427 && (parm
& (KEY_M_CTRL
| KEY_M_ALT
))) {
1432 /* Ctrl-Shift-Enter */
1433 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n')) {
1434 copy_current_pathname ();
1439 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1440 && !quote
&& !current_panel
->searching
) {
1441 if (!only_leading_plus_minus
) {
1442 /* Special treatement, since the input line will eat them */
1448 if (parm
== '\\' || parm
== '-') {
1454 reverse_selection_cmd ();
1457 } else if (!command_prompt
|| !cmdline
->buffer
[0]) {
1458 /* Special treatement '+', '-', '\', '*' only when this is
1459 * first char on input line
1467 if (parm
== '\\' || parm
== '-') {
1473 reverse_selection_cmd ();
1478 return MSG_NOT_HANDLED
;
1480 case DLG_HOTKEY_HANDLED
:
1481 if ((get_current_type () == view_listing
) && current_panel
->searching
) {
1482 current_panel
->searching
= 0;
1483 current_panel
->dirty
= 1;
1487 case DLG_UNHANDLED_KEY
:
1488 if (command_prompt
) {
1491 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1495 if (ctl_x_map_enabled
) {
1496 ctl_x_map_enabled
= 0;
1497 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1498 if (parm
== ctl_x_map
[i
].key_code
) {
1499 (*ctl_x_map
[i
].fn
) ();
1503 for (i
= 0; default_map
[i
].key_code
; i
++) {
1504 if (parm
== default_map
[i
].key_code
) {
1505 (*default_map
[i
].fn
) ();
1510 return MSG_NOT_HANDLED
;
1514 /* We handle the special case of the output lines */
1515 if (console_flag
&& output_lines
)
1516 show_console_contents (output_start_y
,
1517 LINES
- output_lines
- keybar_visible
-
1518 1, LINES
- keybar_visible
- 1);
1522 if (!the_menubar
->active
)
1523 update_dirty_panels ();
1527 return default_dlg_callback (h
, msg
, parm
);
1531 /* Show current directory in the xterm title */
1533 update_xterm_title_path (void)
1536 char host
[BUF_TINY
];
1538 struct passwd
*pw
= NULL
;
1541 if (xterm_flag
&& xterm_title
) {
1542 path
= strip_home_and_password (current_panel
->cwd
);
1543 res
= gethostname(host
, sizeof (host
));
1544 if ( res
) { /* On success, res = 0 */
1547 host
[sizeof (host
) - 1] = '\0';
1549 pw
= getpwuid(getuid());
1551 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1553 login
= g_strdup (host
);
1555 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1556 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1559 if (!alternate_plus_minus
)
1560 numeric_keypad_mode ();
1566 * Load new hint and display it.
1567 * IF force is not 0, ignore the timeout.
1570 load_hint (int force
)
1574 if (!the_hint
->widget
.parent
)
1577 if (!message_visible
) {
1578 label_set_text (the_hint
, NULL
);
1582 hint
= get_random_hint (force
);
1589 char text
[BUF_SMALL
];
1591 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"),
1598 setup_panels_and_run_mc (void)
1600 add_widget (midnight_dlg
, the_menubar
);
1601 add_widget (midnight_dlg
, get_panel_widget (0));
1602 add_widget (midnight_dlg
, get_panel_widget (1));
1603 add_widget (midnight_dlg
, the_hint
);
1604 add_widget (midnight_dlg
, cmdline
);
1605 add_widget (midnight_dlg
, the_prompt
);
1606 add_widget (midnight_dlg
, the_bar
);
1609 if (boot_current_is_left
)
1610 dlg_select_widget (get_panel_widget (0));
1612 dlg_select_widget (get_panel_widget (1));
1614 /* Run the Midnight Commander if no file was specified in the command line */
1615 run_dlg (midnight_dlg
);
1618 /* result must be free'd (I think this should go in util.c) */
1620 prepend_cwd_on_local (const char *filename
)
1625 if (vfs_file_is_local (filename
)) {
1626 if (*filename
== PATH_SEP
) /* an absolute pathname */
1627 return g_strdup (filename
);
1628 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1629 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1632 strcpy (d
+ l
, filename
);
1633 canonicalize_pathname (d
);
1636 return g_strdup (filename
);
1640 mc_maybe_editor_or_viewer (void)
1642 if (!(view_one_file
|| edit_one_file
))
1645 /* Invoke the internal view/edit routine with:
1646 * the default processing and forcing the internal viewer/editor
1648 if (view_one_file
) {
1650 path
= prepend_cwd_on_local (view_one_file
);
1651 view_file (path
, 0, 1);
1654 #ifdef USE_INTERNAL_EDIT
1656 edit_file (edit_one_file
, edit_one_file_start_line
);
1658 #endif /* USE_INTERNAL_EDIT */
1659 midnight_shutdown
= 1;
1664 /* Run the main dialog that occupies the whole screen */
1668 int midnight_colors
[DLG_COLOR_NUM
];
1669 midnight_colors
[0] = mc_skin_color_get("dialog", "_default_");
1670 midnight_colors
[1] = mc_skin_color_get("dialog", "focus");
1671 midnight_colors
[2] = mc_skin_color_get("dialog", "hotnormal");
1672 midnight_colors
[3] = mc_skin_color_get("dialog", "hotfocus");
1674 midnight_dlg
= create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1675 "[main]", NULL
, DLG_WANT_IDLE
);
1677 if (view_one_file
|| edit_one_file
)
1682 /* start check display_codepage and source_codepage */
1685 /* Check if we were invoked as an editor or file viewer */
1686 if (!mc_maybe_editor_or_viewer ()) {
1687 setup_panels_and_run_mc ();
1690 midnight_shutdown
= 1;
1692 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1693 if (mc_args__last_wd_file
&& vfs_current_is_local ()) {
1694 last_wd_string
= g_strdup (current_panel
->cwd
);
1698 destroy_dlg (midnight_dlg
);
1703 /* POSIX version. The only version we support. */
1707 const char *shell_env
= getenv ("SHELL");
1708 const char *mc_libdir
;
1710 if ((shell_env
== NULL
) || (shell_env
[0] == '\0')) {
1712 pwd
= getpwuid (geteuid ());
1714 shell
= g_strdup (pwd
->pw_shell
);
1716 shell
= g_strdup (shell_env
);
1718 if ((shell
== NULL
) || (shell
[0] == '\0')) {
1720 shell
= g_strdup ("/bin/sh");
1723 /* This is the directory, where MC was installed, on Unix this is DATADIR */
1724 /* and can be overriden by the MC_DATADIR environment variable */
1725 mc_libdir
= getenv ("MC_DATADIR");
1726 if (mc_libdir
!= NULL
) {
1727 mc_home
= g_strdup (mc_libdir
);
1728 mc_home_alt
= g_strdup (SYSCONFDIR
);
1730 mc_home
= g_strdup (SYSCONFDIR
);
1731 mc_home_alt
= g_strdup (DATADIR
);
1734 /* This variable is used by the subshell */
1735 home_dir
= getenv ("HOME");
1743 sigchld_handler_no_subshell (int sig
)
1751 /* COMMENT: if it were true that after the call to handle_console(..INIT)
1752 the value of console_flag never changed, we could simply not install
1753 this handler at all if (!console_flag && !use_subshell). */
1755 /* That comment is no longer true. We need to wait() on a sigchld
1756 handler (that's at least what the tarfs code expects currently). */
1758 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
1760 if (pid
== cons_saver_pid
) {
1762 if (WIFSTOPPED (status
)) {
1763 /* Someone has stopped cons.saver - restart it */
1764 kill (pid
, SIGCONT
);
1766 /* cons.saver has died - disable console saving */
1767 handle_console (CONSOLE_DONE
);
1771 /* If we got here, some other child exited; ignore it */
1772 #endif /* __linux__ */
1780 struct sigaction sigchld_action
;
1782 sigchld_action
.sa_handler
=
1783 #ifdef HAVE_SUBSHELL_SUPPORT
1784 use_subshell
? sigchld_handler
:
1785 #endif /* HAVE_SUBSHELL_SUPPORT */
1786 sigchld_handler_no_subshell
;
1788 sigemptyset (&sigchld_action
.sa_mask
);
1791 sigchld_action
.sa_flags
= SA_RESTART
;
1793 sigchld_action
.sa_flags
= 0;
1794 #endif /* !SA_RESTART */
1796 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1) {
1797 #ifdef HAVE_SUBSHELL_SUPPORT
1799 * This may happen on QNX Neutrino 6, where SA_RESTART
1800 * is defined but not implemented. Fallback to no subshell.
1803 #endif /* HAVE_SUBSHELL_SUPPORT */
1808 mc_main__setup_by_args(int argc
, char *argv
[])
1813 if (mc_args__nomouse
)
1814 use_mouse_p
= MOUSE_DISABLED
;
1817 if (mc_args__netfs_logfile
!= NULL
)
1819 mc_setctl ("/#ftp:", VFS_SETCTL_LOGFILE
, (void *) mc_args__netfs_logfile
);
1821 smbfs_set_debugf (mc_args__netfs_logfile
);
1822 #endif /* WITH_SMBFS */
1826 if (mc_args__debug_level
!= 0)
1828 smbfs_set_debug (mc_args__debug_level
);
1830 #endif /* WITH_SMBFS */
1831 #endif /* USE_NETCODE */
1834 base
= x_basename (argv
[0]);
1835 tmp
= (argc
> 0)? argv
[1] : NULL
;
1838 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP (base
, "vi")) {
1842 * Check for filename:lineno, followed by an optional colon.
1843 * This format is used by many programs (especially compilers)
1844 * in error messages and warnings. It is supported so that
1845 * users can quickly copy and paste file locations.
1847 char *end
= tmp
+ strlen (tmp
), *p
= end
;
1848 if (p
> tmp
&& p
[-1] == ':')
1850 while (p
> tmp
&& g_ascii_isdigit ((gchar
) p
[-1]))
1852 if (tmp
< p
&& p
< end
&& p
[-1] == ':') {
1854 gchar
*fname
= g_strndup (tmp
, p
- 1 - tmp
);
1856 * Check that the file before the colon actually exists.
1857 * If it doesn't exist, revert to the old behavior.
1859 if (mc_stat (tmp
, &st
) == -1 && mc_stat (fname
, &st
) != -1) {
1860 edit_one_file
= fname
;
1861 edit_one_file_start_line
= atoi (p
);
1864 goto try_plus_filename
;
1868 if (*tmp
== '+' && g_ascii_isdigit ((gchar
) tmp
[1])) {
1869 int start_line
= atoi (tmp
);
1870 if (start_line
> 0) {
1871 char *file
= (argc
> 1) ? argv
[2] : NULL
;
1874 edit_one_file_start_line
= start_line
;
1878 edit_one_file
= g_strdup (tmp
);
1881 } else if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP (base
, "view")) {
1883 view_one_file
= g_strdup (tmp
);
1885 fputs ("No arguments given to the viewer\n", stderr
);
1889 /* sets the current dir and the other dir */
1891 this_dir
= g_strdup (tmp
);
1892 tmp
= (argc
> 1) ? argv
[2] : NULL
;
1894 other_dir
= g_strdup (tmp
);
1902 main (int argc
, char *argv
[])
1907 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
1908 setlocale (LC_ALL
, "");
1909 bindtextdomain ("mc", LOCALEDIR
);
1912 /* Set up temporary directory */
1917 str_init_strings (NULL
);
1921 #ifdef USE_INTERNAL_EDIT
1926 SLtt_Ignore_Beep
= 1;
1929 if ( !mc_args_handle (&argc
, &argv
, "mc"))
1931 mc_main__setup_by_args(argc
,argv
);
1934 /* NOTE: This has to be called before tty_init or whatever routine
1935 calls any define_sequence */
1938 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
1939 handle_console (CONSOLE_INIT
);
1941 #ifdef HAVE_SUBSHELL_SUPPORT
1942 /* Don't use subshell when invoked as viewer or editor */
1943 if (edit_one_file
|| view_one_file
)
1947 subshell_get_console_attributes ();
1948 #endif /* HAVE_SUBSHELL_SUPPORT */
1950 /* Install the SIGCHLD handler; must be done before init_subshell() */
1953 /* We need this, since ncurses endwin () doesn't restore the signals */
1954 save_stop_handler ();
1956 /* Must be done before init_subshell, to set up the terminal size: */
1957 /* FIXME: Should be removed and LINES and COLS computed on subshell */
1958 tty_init ((gboolean
) mc_args__slow_terminal
, (gboolean
) mc_args__ugly_line_drawing
);
1962 tty_init_colors (mc_args__disable_colors
, mc_args__force_colors
);
1965 mc_filehighlight
= mc_fhl_new (TRUE
);
1967 dlg_set_default_colors ();
1969 /* create home directory */
1970 /* do it after the screen library initialization to show the error message */
1971 mc_dir
= concat_dir_and_file (home_dir
, MC_BASE
);
1972 canonicalize_pathname (mc_dir
);
1973 if ((stat (mc_dir
, &s
) != 0) && (errno
== ENOENT
)
1974 && mkdir (mc_dir
, 0700) != 0)
1975 message (D_ERROR
, _("Warning"),
1976 _("Cannot create %s directory"), mc_dir
);
1979 #ifdef HAVE_SUBSHELL_SUPPORT
1980 /* Done here to ensure that the subshell doesn't */
1981 /* inherit the file descriptors opened below, etc */
1985 #endif /* HAVE_SUBSHELL_SUPPORT */
1987 /* Removing this from the X code let's us type C-c */
1990 /* Also done after init_subshell, to save any shell init file messages */
1992 handle_console (CONSOLE_SAVE
);
1994 if (alternate_plus_minus
)
1995 application_keypad_mode ();
1997 #ifdef HAVE_SUBSHELL_SUPPORT
1999 prompt
= strip_ctrl_codes (subshell_prompt
);
2003 #endif /* HAVE_SUBSHELL_SUPPORT */
2004 prompt
= (geteuid () == 0) ? "# " : "$ ";
2007 /* Program main loop */
2008 if (!midnight_shutdown
)
2011 /* Save the tree store */
2014 /* Virtual File System shutdown */
2017 flush_extension_file (); /* does only free memory */
2019 mc_fhl_free (&mc_filehighlight
);
2024 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2025 handle_console (CONSOLE_RESTORE
);
2026 if (alternate_plus_minus
)
2027 numeric_keypad_mode ();
2029 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2032 handle_console (CONSOLE_DONE
);
2033 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2035 if (mc_args__last_wd_file
&& last_wd_string
&& !print_last_revert
2036 && !edit_one_file
&& !view_one_file
) {
2038 open (mc_args__last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2041 if (last_wd_fd
!= -1) {
2042 write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2046 g_free (last_wd_string
);
2048 g_free (mc_home_alt
);
2054 free_codepages_list ();
2056 str_uninit_strings ();
2061 #ifdef USE_INTERNAL_EDIT