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
37 #include <sys/types.h>
55 #include "treestore.h"
56 #include "cons.saver.h"
58 #include "key.h" /* For init_key() and mi_getch() */
59 #include "setup.h" /* save_setup() */
60 #include "../src/mcconfig/mcconfig.h"
61 #include "boxes.h" /* sort_box() */
63 #include "cmd.h" /* Normal commands */
66 #include "learn.h" /* learn_keys() */
69 #include "ext.h" /* For flush_extension_file() */
71 #include <pwd.h> /* for username in xterm title */
73 /* Listbox for the command history feature */
83 #include "../vfs/smbfs.h" /* smbfs_set_debug() */
86 #ifdef USE_INTERNAL_EDIT
87 # include "../edit/edit.h"
92 #endif /* HAVE_CHARSET */
95 #include "../vfs/gc.h"
100 /* When the modes are active, left_panel, right_panel and tree_panel */
101 /* Point to a proper data structure. You should check with the functions */
102 /* get_current_type and get_other_type the types of the panels before using */
103 /* This pointer variables */
105 /* The structures for the panels */
106 WPanel
*left_panel
= NULL
;
107 WPanel
*right_panel
= NULL
;
109 /* The pointer to the tree */
110 WTree
*the_tree
= NULL
;
113 struct WMenu
*the_menubar
= NULL
;
115 /* Pointers to the selected and unselected panel */
116 WPanel
*current_panel
= NULL
;
118 /* Set if the command is being run from the "Right" menu */
121 /* Set when main loop should be terminated */
122 volatile int quit
= 0;
124 /* Set if you want the possible completions dialog for the first time */
125 int show_all_if_ambiguous
= 0;
127 /* Set when cd symlink following is desirable (bash mode) */
130 /* If set then dialogs just clean the screen when refreshing, else */
131 /* they do a complete refresh, refreshing all the parts of the program */
132 int fast_refresh
= 0;
134 /* If true, marking a files moves the cursor down */
135 int mark_moves_down
= 1;
137 /* If true, at startup the user-menu is invoked */
140 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\
141 and M-- and keypad + / - */
142 int alternate_plus_minus
= 0;
144 /* If true, then the +, - and \ keys have their special meaning only if the
145 * command line is emtpy, otherwise they behave like regular letters
147 int only_leading_plus_minus
= 1;
149 int pause_after_run
= pause_on_dumb_terminals
;
151 /* It true saves the setup when quitting */
152 int auto_save_setup
= 1;
155 /* If true, allow characters in the range 160-255 */
156 int eight_bit_clean
= 1;
159 * If true, also allow characters in the range 128-159.
160 * This is reported to break on many terminals (xterm, qansi-m).
162 int full_eight_bits
= 0;
164 #endif /* !HAVE_CHARSET */
167 * If utf-8 terminal utf8_display = 1
168 * Display bits set UTF-8
171 int utf8_display
= 0;
173 /* If true use the internal viewer */
174 int use_internal_view
= 1;
176 /* Have we shown the fast-reload warning in the past? */
177 int fast_reload_w
= 0;
179 /* Move page/item? When clicking on the top or bottom of a panel */
180 int mouse_move_pages
= 1;
182 /* If true: l&r arrows are used to chdir if the input line is empty */
183 int navigate_with_arrows
= 0;
185 /* If true use +, -, | for line drawing */
186 int force_ugly_line_drawing
= 0;
188 /* If true program softkeys (HP terminals only) on startup and after every
189 command ran in the subshell to the description found in the termcap/terminfo
191 int reset_hp_softkeys
= 0;
194 const char *prompt
= NULL
;
196 /* The widget where we draw the prompt */
205 /* For slow terminals */
206 int slow_terminal
= 0;
208 /* Mouse type: GPM, xterm or none */
209 Mouse_Type use_mouse_p
= MOUSE_NONE
;
211 /* If true, assume we are running on an xterm terminal */
212 static int force_xterm
= 0;
214 /* If on, default for "No" in delete operations */
217 /* Controls screen clearing before an exec */
218 int clear_before_exec
= 1;
220 /* Asks for confirmation before deleting a file */
221 int confirm_delete
= 1;
223 /* Asks for confirmation before deleting a hotlist entry */
224 int confirm_directory_hotlist_delete
= 1;
226 /* Asks for confirmation before overwriting a file */
227 int confirm_overwrite
= 1;
229 /* Asks for confirmation before executing a program by pressing enter */
230 int confirm_execute
= 0;
232 /* Asks for confirmation before leaving the program */
233 int confirm_exit
= 1;
235 /* Asks for confirmation when using F3 to view a directory and there
237 int confirm_view_dir
= 0;
239 /* This flag indicates if the pull down menus by default drop down */
242 /* if skip_check_codeset = 1 do not show warning about
243 * system and display codeset is different
245 int skip_check_codeset
= 0;
247 /* The dialog handle for the main program */
248 Dlg_head
*midnight_dlg
;
250 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
251 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
252 int update_prompt
= 0;
254 /* The home directory */
255 const char *home_dir
= NULL
;
257 /* The value of the other directory, only used when loading the setup */
258 char *other_dir
= NULL
;
260 /* Only used at program boot */
261 int boot_current_is_left
= 1;
263 static char *this_dir
= NULL
;
265 /* If this is true, then when browsing the tree the other window will
266 * automatically reload it's directory with the contents of the currently
267 * selected directory.
271 /* If set, then print to the given file the last directory we were at */
272 static char *last_wd_file
= NULL
;
273 static char *last_wd_string
= NULL
;
274 /* Set to 1 to suppress printing the last directory */
275 static int print_last_revert
= 0;
277 /* Force colors, only used by Slang */
278 int force_colors
= 0;
280 /* colors specified on the command line: they override any other setting */
281 char *command_line_colors
= NULL
;
283 /* File name to view if argument was supplied */
284 static const char *view_one_file
= NULL
;
286 /* File name to edit if argument was supplied */
287 const char *edit_one_file
= NULL
;
289 /* Line to start the editor on */
290 static int edit_one_file_start_line
= 0;
292 /* Used so that widgets know if they are being destroyed or
294 int midnight_shutdown
= 0;
296 /* The user's shell */
297 const char *shell
= NULL
;
299 /* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
300 char *mc_home
= NULL
;
302 /* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
303 char *mc_home_alt
= NULL
;
308 reload_panelized (WPanel
*panel
)
311 dir_list
*list
= &panel
->dir
;
313 if (panel
!= current_panel
)
314 mc_chdir (panel
->cwd
);
316 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
317 if (list
->list
[i
].f
.marked
) {
318 /* Unmark the file in advance. In case the following mc_lstat
319 * fails we are done, else we have to mark the file again
320 * (Note: do_file_mark depends on a valid "list->list [i].buf").
321 * IMO that's the best way to update the panel's summary status
324 do_file_mark (panel
, i
, 0);
326 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
327 g_free (list
->list
[i
].fname
);
330 if (list
->list
[i
].f
.marked
)
331 do_file_mark (panel
, i
, 1);
333 list
->list
[j
] = list
->list
[i
];
337 panel
->count
= set_zero_dir (list
);
341 if (panel
!= current_panel
)
342 mc_chdir (current_panel
->cwd
);
346 update_one_panel_widget (WPanel
*panel
, int force_update
,
347 const char *current_file
)
350 char *my_current_file
= NULL
;
352 if (force_update
& UP_RELOAD
) {
353 panel
->is_panelized
= 0;
354 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
355 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
358 /* If current_file == -1 (an invalid pointer) then preserve selection */
359 if (current_file
== UP_KEEPSEL
) {
361 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
362 current_file
= my_current_file
;
366 if (panel
->is_panelized
)
367 reload_panelized (panel
);
369 panel_reload (panel
);
371 try_to_select (panel
, current_file
);
375 g_free (my_current_file
);
379 panel_clean_dir (WPanel
*panel
)
381 int count
= panel
->count
;
387 panel
->dirs_marked
= 0;
389 panel
->searching
= 0;
390 panel
->is_panelized
= 0;
393 clean_dir (&panel
->dir
, count
);
397 update_one_panel (int which
, int force_update
, const char *current_file
)
401 if (get_display_type (which
) != view_listing
)
404 panel
= (WPanel
*) get_panel_widget (which
);
405 update_one_panel_widget (panel
, force_update
, current_file
);
408 /* This routine reloads the directory in both panels. It tries to
409 * select current_file in current_panel and other_file in other_panel.
410 * If current_file == -1 then it automatically sets current_file and
411 * other_file to the currently selected files in the panels.
413 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
414 * will not reload the other panel.
417 update_panels (int force_update
, const char *current_file
)
419 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
422 update_one_panel (get_current_index (), force_update
, current_file
);
424 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
426 if (get_current_type () == view_listing
)
427 panel
= (WPanel
*) get_panel_widget (get_current_index ());
429 panel
= (WPanel
*) get_panel_widget (get_other_index ());
431 mc_chdir (panel
->cwd
);
434 /* Save current stat of directories to avoid reloading the panels */
435 /* when no modifications have taken place */
437 save_cwds_stat (void)
440 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
441 if (get_other_type () == view_listing
)
442 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
446 #ifdef HAVE_SUBSHELL_SUPPORT
448 do_possible_cd (const char *new_dir
)
450 if (!do_cd (new_dir
, cd_exact
))
451 message (D_ERROR
, _("Warning"),
452 _(" The Commander can't change to the directory that \n"
453 " the subshell claims you are in. Perhaps you have \n"
454 " deleted your working directory, or given yourself \n"
455 " extra access permissions with the \"su\" command? "));
459 do_update_prompt (void)
462 printf ("%s", subshell_prompt
);
467 #endif /* HAVE_SUBSHELL_SUPPORT */
472 free_completions (cmdline
);
473 dlg_one_down (midnight_dlg
);
476 /* Stop MC main dialog and the current dialog if it exists.
477 * Needed to provide fast exit from MC viewer or editor on shell exit */
481 midnight_dlg
->running
= 0;
483 current_dlg
->running
= 0;
488 quit_cmd_internal (int quiet
)
492 if (quiet
|| !confirm_exit
) {
496 (_(" The Midnight Commander "),
497 _(" Do you really want to quit the Midnight Commander? "), D_NORMAL
,
498 2, _("&Yes"), _("&No")) == 0)
502 #ifdef HAVE_SUBSHELL_SUPPORT
505 else if ((q
= exit_subshell ()))
517 quit_cmd_internal (0);
521 quiet_quit_cmd (void)
523 print_last_revert
= 1;
524 quit_cmd_internal (1);
528 * Touch window and refresh window functions
531 /* This routine untouches the first line on both panels in order */
532 /* to avoid the refreshing the menu bar */
535 repaint_screen (void)
541 /* Wrapper for do_subshell_chdir, check for availability of subshell */
543 subshell_chdir (const char *directory
)
545 #ifdef HAVE_SUBSHELL_SUPPORT
547 if (vfs_current_is_local ())
548 do_subshell_chdir (directory
, 0, 1);
550 #endif /* HAVE_SUBSHELL_SUPPORT */
554 directory_history_add (struct WPanel
*panel
, const char *dir
)
558 tmp
= g_strdup (dir
);
559 strip_password (tmp
, 1);
561 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
565 * If we moved to the parent directory move the selection pointer to
566 * the old directory name; If we leave VFS dir, remove FS specificator.
568 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
571 get_parent_dir_name (const char *cwd
, const char *lwd
)
574 if (strlen (lwd
) > strlen (cwd
))
575 if ((p
= strrchr (lwd
, PATH_SEP
)) && !strncmp (cwd
, lwd
, p
- lwd
) &&
576 ((gsize
)strlen (cwd
) == (gsize
) p
- (gsize
) lwd
|| (p
== lwd
&& cwd
[0] == PATH_SEP
&&
584 * Changes the current directory of the panel.
585 * Don't record change in the directory history.
588 _do_panel_cd (WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
590 const char *directory
;
592 char temp
[MC_MAXPATHLEN
];
593 char *translated_url
;
595 if (cd_type
== cd_parse_command
) {
596 while (*new_dir
== ' ')
600 olddir
= g_strdup (panel
->cwd
);
601 new_dir
= translated_url
= vfs_translate_url (new_dir
);
603 /* Convert *new_path to a suitable pathname, handle ~user */
605 if (cd_type
== cd_parse_command
) {
606 if (!strcmp (new_dir
, "-")) {
607 strcpy (temp
, panel
->lwd
);
611 directory
= *new_dir
? new_dir
: home_dir
;
613 if (mc_chdir (directory
) == -1) {
614 strcpy (panel
->cwd
, olddir
);
616 g_free (translated_url
);
619 g_free (translated_url
);
621 /* Success: save previous directory, shutdown status of previous dir */
622 strcpy (panel
->lwd
, olddir
);
623 free_completions (cmdline
);
625 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
627 vfs_release_path (olddir
);
629 subshell_chdir (panel
->cwd
);
631 /* Reload current panel */
632 panel_clean_dir (panel
);
634 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
635 panel
->reverse
, panel
->case_sensitive
,
636 panel
->exec_first
, panel
->filter
);
637 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
640 update_xterm_title_path ();
648 * Changes the current directory of the panel.
649 * Record change in the directory history.
652 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
656 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
658 directory_history_add (panel
, panel
->cwd
);
663 do_cd (const char *new_dir
, enum cd_enum exact
)
665 return (do_panel_cd (current_panel
, new_dir
, exact
));
669 directory_history_next (WPanel
*panel
)
673 nextdir
= g_list_next (panel
->dir_history
);
678 if (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
))
679 panel
->dir_history
= nextdir
;
683 directory_history_prev (WPanel
*panel
)
687 prevdir
= g_list_previous (panel
->dir_history
);
692 if (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
))
693 panel
->dir_history
= prevdir
;
697 directory_history_list (WPanel
*panel
)
701 if (!panel
->dir_history
)
704 s
= show_hist (panel
->dir_history
, panel
->widget
.x
, panel
->widget
.y
);
709 if (_do_panel_cd (panel
, s
, cd_exact
))
710 directory_history_add (panel
, panel
->cwd
);
712 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
716 #ifdef HAVE_SUBSHELL_SUPPORT
718 load_prompt (int fd
, void *unused
)
723 if (!read_subshell_prompt ())
726 /* Don't actually change the prompt if it's invisible */
727 if (current_dlg
== midnight_dlg
&& command_prompt
) {
731 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
732 prompt_len
= str_term_width1 (tmp_prompt
);
734 /* Check for prompts too big */
735 if (COLS
> 8 && prompt_len
> COLS
- 8) {
736 tmp_prompt
[COLS
- 8] = '\0';
737 prompt_len
= COLS
- 8;
740 label_set_text (the_prompt
, prompt
);
741 winput_set_origin ((WInput
*) cmdline
, prompt_len
,
744 /* since the prompt has changed, and we are called from one of the
745 * get_event channels, the prompt updating does not take place
746 * automatically: force a cursor update and a screen refresh
748 update_cursor (midnight_dlg
);
754 #endif /* HAVE_SUBSHELL_SUPPORT */
756 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
758 maybe_cd (int move_up_dir
)
760 if (navigate_with_arrows
) {
761 if (!cmdline
->buffer
[0]) {
763 do_cd ("..", cd_exact
);
766 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
767 || link_isdir (selection (current_panel
))) {
768 do_cd (selection (current_panel
)->fname
, cd_exact
);
782 if (!SELECTED_IS_PANEL
)
786 sort_order
= sort_box (p
->sort_type
, &p
->reverse
,
790 panel_set_sort_order (p
, sort_order
);
799 sel_dir
= tree_box (selection (current_panel
)->fname
);
801 do_cd (sel_dir
, cd_exact
);
806 #ifdef LISTMODE_EDITOR
812 if (get_current_type () != view_listing
)
815 newmode
= listmode_edit (current_panel
->user_format
);
819 g_free (current_panel
->user_format
);
820 current_panel
->list_type
= list_user
;
821 current_panel
->user_format
= newmode
;
822 set_panel_formats (current_panel
);
826 #endif /* LISTMODE_EDITOR */
828 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
829 static menu_entry LeftMenu
[] = {
830 {' ', N_("&Listing mode..."), NULL_HOTKEY
, listing_cmd
},
831 {' ', N_("&Quick view C-x q"), NULL_HOTKEY
, quick_view_cmd
},
832 {' ', N_("&Info C-x i"), NULL_HOTKEY
, info_cmd
},
833 {' ', N_("&Tree"), NULL_HOTKEY
, tree_cmd
},
834 {' ', "", NULL_HOTKEY
, 0},
835 {' ', N_("&Sort order..."), NULL_HOTKEY
, sort_cmd
},
836 {' ', "", NULL_HOTKEY
, 0},
837 {' ', N_("&Filter..."), NULL_HOTKEY
, filter_cmd
},
839 {' ', "",NULL_HOTKEY
, 0},
840 {' ', N_("&Encoding... C-t"), NULL_HOTKEY
, encoding_cmd
},
843 {' ', "", NULL_HOTKEY
, 0},
844 #ifdef ENABLE_VFS_MCFS
845 {' ', N_("&Network link..."), NULL_HOTKEY
, netlink_cmd
},
847 {' ', N_("FT&P link..."), NULL_HOTKEY
, ftplink_cmd
},
848 {' ', N_("S&hell link..."), NULL_HOTKEY
, fishlink_cmd
},
850 {' ', N_("SM&B link..."), NULL_HOTKEY
, smblink_cmd
},
853 {' ', "", NULL_HOTKEY
, 0},
854 {' ', N_("&Rescan C-r"), NULL_HOTKEY
, reread_cmd
}
857 static menu_entry RightMenu
[] = {
858 {' ', N_("&Listing mode..."), NULL_HOTKEY
, listing_cmd
},
859 {' ', N_("&Quick view C-x q"), NULL_HOTKEY
, quick_view_cmd
},
860 {' ', N_("&Info C-x i"), NULL_HOTKEY
, info_cmd
},
861 {' ', N_("&Tree"), NULL_HOTKEY
, tree_cmd
},
862 {' ', "", NULL_HOTKEY
, 0},
863 {' ', N_("&Sort order..."), NULL_HOTKEY
, sort_cmd
},
864 {' ', "", NULL_HOTKEY
, 0},
865 {' ', N_("&Filter..."), NULL_HOTKEY
, filter_cmd
},
867 {' ', "",NULL_HOTKEY
, 0},
868 {' ', N_("&Encoding... C-t"), NULL_HOTKEY
, encoding_cmd
},
871 {' ', "", NULL_HOTKEY
, 0},
872 #ifdef ENABLE_VFS_MCFS
873 {' ', N_("&Network link..."), NULL_HOTKEY
, netlink_cmd
},
875 {' ', N_("FT&P link..."), NULL_HOTKEY
, ftplink_cmd
},
876 {' ', N_("S&hell link..."), NULL_HOTKEY
, fishlink_cmd
},
878 {' ', N_("SM&B link..."), NULL_HOTKEY
, smblink_cmd
},
881 {' ', "", NULL_HOTKEY
, 0},
882 {' ', N_("&Rescan C-r"), NULL_HOTKEY
, reread_cmd
}
885 static menu_entry FileMenu
[] = {
886 {' ', N_("&View F3"), NULL_HOTKEY
, view_cmd
},
887 {' ', N_("Vie&w file... "), NULL_HOTKEY
, view_file_cmd
},
888 {' ', N_("&Filtered view M-!"), NULL_HOTKEY
, filtered_view_cmd
},
889 {' ', N_("&Edit F4"), NULL_HOTKEY
, edit_cmd
},
890 {' ', N_("&Copy F5"), NULL_HOTKEY
, copy_cmd
},
891 {' ', N_("c&Hmod C-x c"), NULL_HOTKEY
, chmod_cmd
},
892 {' ', N_("&Link C-x l"), NULL_HOTKEY
, link_cmd
},
893 {' ', N_("&SymLink C-x s"), NULL_HOTKEY
, symlink_cmd
},
894 {' ', N_("edit s&Ymlink C-x C-s"), NULL_HOTKEY
, edit_symlink_cmd
},
895 {' ', N_("ch&Own C-x o"), NULL_HOTKEY
, chown_cmd
},
896 {' ', N_("&Advanced chown "), NULL_HOTKEY
, chown_advanced_cmd
},
897 {' ', N_("&Rename/Move F6"), NULL_HOTKEY
, ren_cmd
},
898 {' ', N_("&Mkdir F7"), NULL_HOTKEY
, mkdir_cmd
},
899 {' ', N_("&Delete F8"), NULL_HOTKEY
, delete_cmd
},
900 {' ', N_("&Quick cd M-c"), NULL_HOTKEY
, quick_cd_cmd
},
901 {' ', "", NULL_HOTKEY
, 0},
902 {' ', N_("select &Group M-+"), NULL_HOTKEY
, select_cmd
},
903 {' ', N_("u&Nselect group M-\\"), NULL_HOTKEY
, unselect_cmd
},
904 {' ', N_("reverse selec&Tion M-*"), NULL_HOTKEY
, reverse_selection_cmd
},
905 {' ', "", NULL_HOTKEY
, 0},
906 {' ', N_("e&Xit F10"), NULL_HOTKEY
, quit_cmd
}
909 static menu_entry CmdMenu
[] = {
910 {' ', N_("&User menu F2"), NULL_HOTKEY
, user_file_menu_cmd
},
911 /* I know, I'm lazy, but the tree widget when it's not running
912 * as a panel still has some problems, I have not yet finished
913 * the WTree widget port, sorry.
915 {' ', N_("&Directory tree"), NULL_HOTKEY
, treebox_cmd
},
916 {' ', N_("&Find file M-?"), NULL_HOTKEY
, find_cmd
},
917 {' ', N_("s&Wap panels C-u"), NULL_HOTKEY
, swap_cmd
},
918 {' ', N_("switch &Panels on/off C-o"), NULL_HOTKEY
, view_other_cmd
},
919 {' ', N_("&Compare directories C-x d"), NULL_HOTKEY
, compare_dirs_cmd
},
920 {' ', N_("e&Xternal panelize C-x !"), NULL_HOTKEY
, external_panelize
},
921 {' ', N_("show directory s&Izes"), NULL_HOTKEY
, dirsizes_cmd
},
922 {' ', "", NULL_HOTKEY
, 0},
923 {' ', N_("command &History"), NULL_HOTKEY
, history_cmd
},
924 {' ', N_("di&Rectory hotlist C-\\"), NULL_HOTKEY
, quick_chdir_cmd
},
926 {' ', N_("&Active VFS list C-x a"), NULL_HOTKEY
, reselect_vfs
},
928 #ifdef WITH_BACKGROUND
929 {' ', N_("&Background jobs C-x j"), NULL_HOTKEY
, jobs_cmd
},
931 {' ', "", NULL_HOTKEY
, 0},
933 {' ', N_("&Undelete files (ext2fs only)"), NULL_HOTKEY
, undelete_cmd
},
935 #ifdef LISTMODE_EDITOR
936 {' ', N_("&Listing format edit"), NULL_HOTKEY
, listmode_cmd
},
938 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
939 {' ', "", NULL_HOTKEY
, 0},
941 {' ', N_("Edit &extension file"), NULL_HOTKEY
, ext_cmd
},
942 {' ', N_("Edit &menu file"), NULL_HOTKEY
, edit_mc_menu_cmd
}
945 /* Must keep in sync with the constants in menu_cmd */
946 static menu_entry OptMenu
[] = {
947 {' ', N_("&Configuration..."), NULL_HOTKEY
, configure_box
},
948 {' ', N_("&Layout..."), NULL_HOTKEY
, layout_cmd
},
949 {' ', N_("c&Onfirmation..."), NULL_HOTKEY
, confirm_box
},
950 {' ', N_("&Display bits..."), NULL_HOTKEY
, display_bits_box
},
951 {' ', N_("learn &Keys..."), NULL_HOTKEY
, learn_keys
},
953 {' ', N_("&Virtual FS..."), NULL_HOTKEY
, configure_vfs
},
954 #endif /* !USE_VFS */
955 {' ', "", NULL_HOTKEY
, 0},
956 {' ', N_("&Save setup"), NULL_HOTKEY
, save_setup_cmd
}
959 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
961 static Menu
*MenuBar
[5];
967 create_menu (horizontal_split
? _(" &Above ") : _(" &Left "),
968 LeftMenu
, menu_entries (LeftMenu
),
969 "[Left and Right Menus]");
971 create_menu (_(" &File "), FileMenu
, menu_entries (FileMenu
),
974 create_menu (_(" &Command "), CmdMenu
, menu_entries (CmdMenu
),
977 create_menu (_(" &Options "), OptMenu
, menu_entries (OptMenu
),
980 create_menu (horizontal_split
? _(" &Below ") : _(" &Right "),
981 RightMenu
, menu_entries (RightMenu
),
982 "[Left and Right Menus]");
990 for (i
= 0; i
< 5; i
++) {
991 destroy_menu (MenuBar
[i
]);
996 menu_last_selected_cmd (void)
998 the_menubar
->active
= 1;
999 the_menubar
->dropped
= drop_menus
;
1000 the_menubar
->previous_widget
= midnight_dlg
->current
->dlg_id
;
1001 dlg_select_widget (the_menubar
);
1007 if (the_menubar
->active
)
1010 if ((get_current_index () == 0) ^ (!current_panel
->active
))
1011 the_menubar
->selected
= 0;
1013 the_menubar
->selected
= 4;
1014 menu_last_selected_cmd ();
1017 /* Flag toggling functions */
1019 toggle_fast_reload (void)
1021 fast_reload
= !fast_reload
;
1022 if (fast_reload_w
== 0 && fast_reload
) {
1023 message (D_NORMAL
, _(" Information "),
1025 (" Using the fast reload option may not reflect the exact \n"
1026 " directory contents. In this case you'll need to do a \n"
1027 " manual reload of the directory. See the man page for \n"
1034 toggle_mix_all_files (void)
1036 mix_all_files
= !mix_all_files
;
1037 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1041 toggle_show_backup (void)
1043 show_backups
= !show_backups
;
1044 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1048 toggle_show_hidden (void)
1050 show_dot_files
= !show_dot_files
;
1051 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1055 * Just a hack for allowing url-like pathnames to be accepted from the
1059 translated_mc_chdir (char *dir
)
1063 newdir
= vfs_translate_url (dir
);
1069 create_panels (void)
1075 char original_dir
[1024];
1077 original_dir
[0] = 0;
1079 if (boot_current_is_left
) {
1082 current_mode
= startup_left_mode
;
1083 other_mode
= startup_right_mode
;
1087 current_mode
= startup_right_mode
;
1088 other_mode
= startup_left_mode
;
1090 /* Creates the left panel */
1093 /* Ok, user has specified two dirs, save the original one,
1094 * since we may not be able to chdir to the proper
1095 * second directory later
1097 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
1099 translated_mc_chdir (this_dir
);
1101 set_display_type (current_index
, current_mode
);
1103 /* The other panel */
1105 if (original_dir
[0])
1106 translated_mc_chdir (original_dir
);
1107 translated_mc_chdir (other_dir
);
1109 set_display_type (other_index
, other_mode
);
1111 if (startup_left_mode
== view_listing
) {
1112 current_panel
= left_panel
;
1115 current_panel
= right_panel
;
1117 current_panel
= left_panel
;
1120 /* Create the nice widgets */
1121 cmdline
= command_new (0, 0, 0);
1122 the_prompt
= label_new (0, 0, prompt
);
1123 the_prompt
->transparent
= 1;
1124 the_bar
= buttonbar_new (keybar_visible
);
1126 the_hint
= label_new (0, 0, 0);
1127 the_hint
->transparent
= 1;
1128 the_hint
->auto_adjust_cols
= 0;
1129 the_hint
->widget
.cols
= COLS
;
1131 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
1135 copy_current_pathname (void)
1138 if (!command_prompt
)
1141 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
1142 command_insert (cmdline
, cwd_path
, 0);
1144 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
1145 command_insert (cmdline
, PATH_SEP_STR
, 0);
1150 copy_other_pathname (void)
1154 if (get_other_type () != view_listing
)
1157 if (!command_prompt
)
1160 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
1161 command_insert (cmdline
, cwd_path
, 0);
1163 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
1164 command_insert (cmdline
, PATH_SEP_STR
, 0);
1169 copy_readlink (WPanel
*panel
)
1171 if (!command_prompt
)
1173 if (S_ISLNK (selection (panel
)->st
.st_mode
)) {
1174 char buffer
[MC_MAXPATHLEN
];
1176 concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1179 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1183 command_insert (cmdline
, buffer
, 1);
1189 copy_current_readlink (void)
1191 copy_readlink (current_panel
);
1195 copy_other_readlink (void)
1197 if (get_other_type () != view_listing
)
1199 copy_readlink (other_panel
);
1202 /* Insert the selected file name into the input line */
1204 copy_prog_name (void)
1207 if (!command_prompt
)
1210 if (get_current_type () == view_tree
) {
1211 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1212 tmp
= tree_selected_name (tree
);
1214 tmp
= selection (current_panel
)->fname
;
1216 command_insert (cmdline
, tmp
, 1);
1220 copy_tagged (WPanel
*panel
)
1224 if (!command_prompt
)
1226 input_disable_update (cmdline
);
1227 if (panel
->marked
) {
1228 for (i
= 0; i
< panel
->count
; i
++) {
1229 if (panel
->dir
.list
[i
].f
.marked
)
1230 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
1233 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
,
1236 input_enable_update (cmdline
);
1240 copy_current_tagged (void)
1242 copy_tagged (current_panel
);
1246 copy_other_tagged (void)
1248 if (get_other_type () != view_listing
)
1250 copy_tagged (other_panel
);
1256 buttonbar_set_label (midnight_dlg
, 1, _("Help"), help_cmd
);
1257 buttonbar_set_label (midnight_dlg
, 2, _("Menu"), user_file_menu_cmd
);
1258 buttonbar_set_label (midnight_dlg
, 9, _("PullDn"), menu_cmd
);
1259 buttonbar_set_label (midnight_dlg
, 10, _("Quit"), quit_cmd
);
1262 static const key_map ctl_x_map
[] = {
1263 {XCTRL ('c'), quit_cmd
},
1264 {'d', compare_dirs_cmd
},
1266 {'a', reselect_vfs
},
1267 #endif /* USE_VFS */
1268 {'p', copy_current_pathname
},
1269 {XCTRL ('p'), copy_other_pathname
},
1270 {'t', copy_current_tagged
},
1271 {XCTRL ('t'), copy_other_tagged
},
1274 {'r', copy_current_readlink
},
1275 {XCTRL ('r'), copy_other_readlink
},
1278 {XCTRL ('s'), edit_symlink_cmd
},
1279 {'i', info_cmd_no_menu
},
1280 {'q', quick_cmd_no_menu
},
1281 {'h', add2hotlist_cmd
},
1282 {'!', external_panelize
},
1283 #ifdef WITH_BACKGROUND
1285 #endif /* WITH_BACKGROUND */
1289 static int ctl_x_map_enabled
= 0;
1294 ctl_x_map_enabled
= 1;
1302 static const key_map default_map
[] = {
1303 {KEY_F (19), menu_last_selected_cmd
},
1304 {KEY_F (20), quiet_quit_cmd
},
1306 {XCTRL ('@'), single_dirsize_cmd
},
1308 /* Copy useful information to the command line */
1309 {ALT ('a'), copy_current_pathname
},
1310 {ALT ('A'), copy_other_pathname
},
1312 {ALT ('c'), quick_cd_cmd
},
1314 /* To access the directory hotlist */
1315 {XCTRL ('\\'), quick_chdir_cmd
},
1318 {XCTRL ('z'), suspend_cmd
},
1320 /* The filtered view command */
1321 {ALT ('!'), filtered_view_cmd
},
1324 {ALT ('?'), find_cmd
},
1327 {XCTRL ('r'), reread_cmd
},
1329 /* Toggle listing between long, user defined and full formats */
1330 {ALT ('t'), toggle_listing_cmd
},
1333 {XCTRL ('u'), swap_cmd
},
1336 {XCTRL ('o'), view_other_cmd
},
1338 /* Control-X keybindings */
1339 {XCTRL ('x'), ctl_x_cmd
},
1341 /* Trap dlg's exit commands */
1342 {ESC_CHAR
, nothing
},
1343 {XCTRL ('c'), nothing
},
1344 {XCTRL ('g'), nothing
},
1349 setup_sigwinch (void)
1351 #if (defined(HAVE_SLANG) || (NCURSES_VERSION_MAJOR >= 4)) && defined(SIGWINCH)
1352 struct sigaction act
, oact
;
1353 act
.sa_handler
= flag_winch
;
1354 sigemptyset (&act
.sa_mask
);
1357 act
.sa_flags
|= SA_RESTART
;
1359 sigaction (SIGWINCH
, &act
, &oact
);
1366 /* Call all the inits */
1369 * Don't restrict the output on the screen manager level,
1370 * the translation tables take care of it.
1372 #define full_eight_bits (1)
1373 #define eight_bit_clean (1)
1374 #endif /* !HAVE_CHARSET */
1377 meta (stdscr
, eight_bit_clean
);
1379 SLsmg_Display_Eight_Bit
= full_eight_bits
? 128 : 160;
1384 init_xterm_support (void)
1386 const char *termvalue
;
1388 termvalue
= getenv ("TERM");
1389 if (!termvalue
|| !(*termvalue
)) {
1390 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1394 /* Check mouse capabilities */
1395 xmouse_seq
= tty_tgetstr ("Km");
1397 if (strcmp (termvalue
, "cygwin") == 0) {
1399 use_mouse_p
= MOUSE_DISABLED
;
1402 if (force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1403 || strncmp (termvalue
, "rxvt", 4) == 0
1404 || strcmp (termvalue
, "Eterm") == 0
1405 || strcmp (termvalue
, "dtterm") == 0) {
1408 /* Default to the standard xterm sequence */
1410 xmouse_seq
= ESC_STR
"[M";
1413 /* Enable mouse unless explicitly disabled by --nomouse */
1414 if (use_mouse_p
!= MOUSE_DISABLED
) {
1415 const char *color_term
= getenv ("COLORTERM");
1416 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
1417 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
1418 strcmp (termvalue
, "Eterm") == 0) {
1419 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
1421 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
1435 #ifdef HAVE_SUBSHELL_SUPPORT
1437 add_select_channel (subshell_pty
, load_prompt
, 0);
1438 #endif /* !HAVE_SUBSHELL_SUPPORT */
1442 if (baudrate () < 9600 || slow_terminal
) {
1451 char d
[MC_MAXPATHLEN
];
1453 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1458 static void check_codeset()
1460 const char *_system_codepage
= NULL
;
1461 const char *_source_codepage
= NULL
;
1462 const char *_display_codepage
= NULL
;
1463 int profile_changed
= 0;
1468 if ( !skip_check_codeset
) {
1470 QuickWidget ecs_widgets
[] = {
1471 { quick_button
, 4, 6, 13, CONFY
, N_("&Skip"),
1472 0, B_EXIT
, 0, 0, NULL
, NULL
, NULL
},
1473 { quick_button
, 1, 11, 13, CONFY
, N_("&Fix it"),
1474 0, B_ENTER
, 0, 0, NULL
, NULL
, NULL
},
1475 { quick_checkbox
, 1, 13, 11, CONFY
, N_("don't ask again"),
1476 11, 0, &skip_check_codeset
, NULL
, NULL
, NULL
, NULL
},
1477 { quick_label
, 2, 30, 3, CONFY
, N_("Chosen display charset (Settings->Display bits)\n"
1478 "or source codeset (in mcedit ctrl-t) \n"
1479 "does not match one set via locale. \n"
1480 "Set correct codeset manually or press <<Fix it>> \n"
1481 "to set locale default.\n\n"
1482 "Or set \'don't ask again\' and press <<Skip>>"),
1483 0, 0, 0, 0, NULL
, NULL
, NULL
},
1489 { CONFX
, CONFY
, -1, -1, N_(" Confirmation "), "[Confirmation]",
1494 _system_codepage
= str_detect_termencoding();
1495 _source_codepage
= get_codepage_id (source_codepage
);
1496 _display_codepage
= get_codepage_id (display_codepage
);
1498 if ( (strcmp (_system_codepage
, _display_codepage
)) ||
1499 (strcmp (_system_codepage
, _source_codepage
)) ) {
1500 if (quick_dialog (&ecs
) == B_ENTER
){
1501 display_codepage
= get_codepage_index (_system_codepage
);
1502 cp_display
= get_codepage_id (display_codepage
);
1503 if ( !strcmp (cp_display
, _system_codepage
)) {
1504 mc_config_set_string(mc_main_config
, "Misc", "display_codepage", cp_display
);
1505 mc_config_set_string(mc_main_config
, "Misc", "source_codepage", cp_display
);
1506 display_codepage
= get_codepage_index ( cp_display
);
1507 utf8_display
= str_isutf8 (_system_codepage
);
1508 source_codepage
= display_codepage
;
1509 profile_changed
= 1;
1512 if ( skip_check_codeset
) {
1513 mc_config_set_int(mc_main_config
, "Midnight-Commander", "skip_check_codeset", 1);
1514 profile_changed
= 1;
1518 if ( profile_changed
)
1532 * We sync the profiles since the hotlist may have changed, while
1533 * we only change the setup data if we have the auto save feature set
1536 if (auto_save_setup
)
1537 save_setup (); /* does also call save_hotlist */
1540 save_panel_types ();
1543 vfs_add_current_stamps ();
1546 /* This should be called after destroy_dlg since panel widgets
1547 * save their state on the profiles
1550 done_mc_profile (void)
1556 midnight_callback (struct Dlg_head
*h
, dlg_msg_t msg
, int parm
)
1563 /* We only need the first idle event */
1564 set_idle_proc (h
, 0);
1566 user_file_menu_cmd ();
1571 if (ctl_x_map_enabled
) {
1572 ctl_x_map_enabled
= 0;
1573 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1574 if (parm
== ctl_x_map
[i
].key_code
) {
1575 (*ctl_x_map
[i
].fn
) ();
1580 /* FIXME: should handle all menu shortcuts before this point */
1581 if (the_menubar
->active
)
1582 return MSG_NOT_HANDLED
;
1584 if (parm
== KEY_F (10)) {
1590 free_completions (cmdline
);
1593 for (i
= 0; cmdline
->buffer
[i
] && (cmdline
->buffer
[i
] == ' ' ||
1594 cmdline
->buffer
[i
] == '\t'); i
++);
1595 if (cmdline
->buffer
[i
]) {
1596 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1599 stuff (cmdline
, "", 0);
1603 /* Ctrl-Enter and Alt-Enter */
1604 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n')
1605 && (parm
& (KEY_M_CTRL
| KEY_M_ALT
))) {
1610 /* Ctrl-Shift-Enter */
1611 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n')) {
1612 copy_current_pathname ();
1617 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1618 && !quote
&& !current_panel
->searching
) {
1619 if (!only_leading_plus_minus
) {
1620 /* Special treatement, since the input line will eat them */
1626 if (parm
== '\\' || parm
== '-') {
1632 reverse_selection_cmd ();
1635 } else if (!command_prompt
|| !cmdline
->buffer
[0]) {
1636 /* Special treatement '+', '-', '\', '*' only when this is
1637 * first char on input line
1645 if (parm
== '\\' || parm
== '-') {
1651 reverse_selection_cmd ();
1656 return MSG_NOT_HANDLED
;
1658 case DLG_HOTKEY_HANDLED
:
1659 if ((get_current_type () == view_listing
) && current_panel
->searching
) {
1660 current_panel
->searching
= 0;
1661 current_panel
->dirty
= 1;
1665 case DLG_UNHANDLED_KEY
:
1666 if (command_prompt
) {
1669 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1673 if (ctl_x_map_enabled
) {
1674 ctl_x_map_enabled
= 0;
1675 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1676 if (parm
== ctl_x_map
[i
].key_code
) {
1677 (*ctl_x_map
[i
].fn
) ();
1681 for (i
= 0; default_map
[i
].key_code
; i
++) {
1682 if (parm
== default_map
[i
].key_code
) {
1683 (*default_map
[i
].fn
) ();
1688 return MSG_NOT_HANDLED
;
1691 /* We handle the special case of the output lines */
1692 if (console_flag
&& output_lines
)
1693 show_console_contents (output_start_y
,
1694 LINES
- output_lines
- keybar_visible
-
1695 1, LINES
- keybar_visible
- 1);
1699 if (!the_menubar
->active
)
1700 update_dirty_panels ();
1704 return default_dlg_callback (h
, msg
, parm
);
1708 /* Show current directory in the xterm title */
1710 update_xterm_title_path (void)
1713 char host
[BUF_TINY
];
1715 struct passwd
*pw
= NULL
;
1718 if (xterm_flag
&& xterm_title
) {
1719 path
= strip_home_and_password (current_panel
->cwd
);
1720 res
= gethostname(host
, sizeof (host
));
1721 if ( res
) { /* On success, res = 0 */
1724 host
[sizeof (host
) - 1] = '\0';
1726 pw
= getpwuid(getuid());
1728 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1730 login
= g_strdup (host
);
1732 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1733 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1736 if (!alternate_plus_minus
)
1737 numeric_keypad_mode ();
1743 * Load new hint and display it.
1744 * IF force is not 0, ignore the timeout.
1747 load_hint (int force
)
1751 if (!the_hint
->widget
.parent
)
1754 if (!message_visible
) {
1755 label_set_text (the_hint
, 0);
1759 if ((hint
= get_random_hint (force
))) {
1764 char text
[BUF_SMALL
];
1766 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"),
1773 setup_panels_and_run_mc (void)
1775 add_widget (midnight_dlg
, the_menubar
);
1776 add_widget (midnight_dlg
, get_panel_widget (0));
1777 add_widget (midnight_dlg
, get_panel_widget (1));
1778 add_widget (midnight_dlg
, the_hint
);
1780 add_widget (midnight_dlg
, cmdline
);
1781 add_widget (midnight_dlg
, the_prompt
);
1782 add_widget (midnight_dlg
, the_bar
);
1785 if (boot_current_is_left
)
1786 dlg_select_widget (get_panel_widget (0));
1788 dlg_select_widget (get_panel_widget (1));
1790 /* Run the Midnight Commander if no file was specified in the command line */
1791 run_dlg (midnight_dlg
);
1794 /* result must be free'd (I think this should go in util.c) */
1796 prepend_cwd_on_local (const char *filename
)
1801 if (vfs_file_is_local (filename
)) {
1802 if (*filename
== PATH_SEP
) /* an absolute pathname */
1803 return g_strdup (filename
);
1804 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1805 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1808 strcpy (d
+ l
, filename
);
1809 canonicalize_pathname (d
);
1812 return g_strdup (filename
);
1816 mc_maybe_editor_or_viewer (void)
1818 if (!(view_one_file
|| edit_one_file
))
1823 /* Invoke the internal view/edit routine with:
1824 * the default processing and forcing the internal viewer/editor
1826 if (view_one_file
) {
1828 path
= prepend_cwd_on_local (view_one_file
);
1829 view_file (path
, 0, 1);
1832 #ifdef USE_INTERNAL_EDIT
1834 edit_file (edit_one_file
, edit_one_file_start_line
);
1836 #endif /* USE_INTERNAL_EDIT */
1837 midnight_shutdown
= 1;
1842 /* Run the main dialog that occupies the whole screen */
1846 int midnight_colors
[4];
1848 midnight_colors
[0] = NORMAL_COLOR
; /* NORMALC */
1849 midnight_colors
[1] = REVERSE_COLOR
; /* FOCUSC */
1850 midnight_colors
[2] = INPUT_COLOR
; /* HOT_NORMALC */
1851 midnight_colors
[3] = NORMAL_COLOR
; /* HOT_FOCUSC */
1854 create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1855 "[main]", NULL
, DLG_WANT_IDLE
);
1857 /* Check if we were invoked as an editor or file viewer */
1858 if (mc_maybe_editor_or_viewer ())
1865 setup_panels_and_run_mc ();
1868 midnight_shutdown
= 1;
1870 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1871 if (last_wd_file
&& vfs_current_is_local ()) {
1872 last_wd_string
= g_strdup (current_panel
->cwd
);
1876 destroy_dlg (midnight_dlg
);
1881 /* POSIX version. The only version we support. */
1885 const char *mc_libdir
;
1886 shell
= getenv ("SHELL");
1887 if (!shell
|| !*shell
) {
1889 pwd
= getpwuid (geteuid ());
1891 shell
= g_strdup (pwd
->pw_shell
);
1893 if (!shell
|| !*shell
)
1896 /* This is the directory, where MC was installed, on Unix this is DATADIR */
1897 /* and can be overriden by the MC_DATADIR environment variable */
1898 if ((mc_libdir
= getenv ("MC_DATADIR")) != NULL
) {
1899 mc_home
= g_strdup (mc_libdir
);
1901 mc_home
= g_strdup (SYSCONFDIR
);
1903 mc_home_alt
= mc_libdir
!= NULL
? g_strdup (SYSCONFDIR
) : g_strdup (DATADIR
);
1907 sigchld_handler_no_subshell (int sig
)
1915 /* COMMENT: if it were true that after the call to handle_console(..INIT)
1916 the value of console_flag never changed, we could simply not install
1917 this handler at all if (!console_flag && !use_subshell). */
1919 /* That comment is no longer true. We need to wait() on a sigchld
1920 handler (that's at least what the tarfs code expects currently). */
1922 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
1924 if (pid
== cons_saver_pid
) {
1926 if (WIFSTOPPED (status
)) {
1927 /* Someone has stopped cons.saver - restart it */
1928 kill (pid
, SIGCONT
);
1930 /* cons.saver has died - disable console saving */
1931 handle_console (CONSOLE_DONE
);
1935 /* If we got here, some other child exited; ignore it */
1936 #endif /* __linux__ */
1944 struct sigaction sigchld_action
;
1946 sigchld_action
.sa_handler
=
1947 #ifdef HAVE_SUBSHELL_SUPPORT
1948 use_subshell
? sigchld_handler
:
1949 #endif /* HAVE_SUBSHELL_SUPPORT */
1950 sigchld_handler_no_subshell
;
1952 sigemptyset (&sigchld_action
.sa_mask
);
1955 sigchld_action
.sa_flags
= SA_RESTART
;
1957 sigchld_action
.sa_flags
= 0;
1958 #endif /* !SA_RESTART */
1960 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1) {
1961 #ifdef HAVE_SUBSHELL_SUPPORT
1963 * This may happen on QNX Neutrino 6, where SA_RESTART
1964 * is defined but not implemented. Fallback to no subshell.
1967 #endif /* HAVE_SUBSHELL_SUPPORT */
1972 print_mc_usage (poptContext ctx
, FILE *stream
)
1976 poptSetOtherOptionHelp (ctx
,
1977 _("[flags] [this_dir] [other_panel_dir]\n"));
1979 /* print help for options */
1980 leftColWidth
= poptPrintHelp (ctx
, stream
, 0);
1981 fprintf (stream
, " %-*s %s\n", leftColWidth
, _("+number"),
1982 _("Set initial line number for the internal editor"));
1985 "Please send any bug reports (including the output of `mc -V')\n"
1986 "to mc-devel@gnome.org\n"), stream
);
1991 print_color_usage (void)
1994 * FIXME: undocumented keywords: viewunderline, editnormal, editbold,
1995 * and editmarked. To preserve translations, lines should be split.
1997 /* TRANSLATORS: don't translate keywords and names of colors */
1999 ("--colors KEYWORD={FORE},{BACK}\n\n"
2000 "{FORE} and {BACK} can be omitted, and the default will be used\n"
2002 " Global: errors, reverse, gauge, input, viewunderline\n"
2003 " File display: normal, selected, marked, markselect\n"
2004 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus, errdhotnormal,\n"
2006 " Menus: menu, menuhot, menusel, menuhotsel\n"
2007 " Editor: editnormal, editbold, editmarked, editwhitespace,\n"
2008 " editlinestate\n"), stdout
);
2011 " Help: helpnormal, helpitalic, helpbold, helplink, helpslink\n"
2012 " File types: directory, executable, link, stalelink, device, special, core\n"
2014 " black, gray, red, brightred, green, brightgreen, brown,\n"
2015 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2016 " brightcyan, lightgray and white\n\n"), stdout
);
2020 process_args (poptContext ctx
, int c
, const char *option_arg
)
2032 #endif /* HAVE_SLANG */
2036 printf ("%s (%s)\n", mc_home
, mc_home_alt
);
2042 mc_setctl ("/#ftp:", VFS_SETCTL_LOGFILE
, (void *) option_arg
);
2044 smbfs_set_debugf (option_arg
);
2045 #endif /* WITH_SMBFS */
2050 smbfs_set_debug (atoi (option_arg
));
2052 #endif /* WITH_SMBFS */
2053 #endif /* USE_NETCODE */
2056 use_mouse_p
= MOUSE_DISABLED
;
2059 #ifdef HAVE_SUBSHELL_SUPPORT
2063 #endif /* HAVE_SUBSHELL_SUPPORT */
2066 print_color_usage ();
2071 print_mc_usage (ctx
, stdout
);
2076 static const struct poptOption argument_table
[] = {
2077 /* generic options */
2078 {"help", 'h', POPT_ARG_NONE
, {NULL
}, 'h',
2079 N_("Displays this help message"), NULL
},
2080 {"version", 'V', POPT_ARG_NONE
, {NULL
}, 'V',
2081 N_("Displays the current version"), NULL
},
2083 /* terminal options */
2084 {"xterm", 'x', POPT_ARG_NONE
, {&force_xterm
}, 0,
2085 N_("Forces xterm features"), NULL
},
2086 {"nomouse", 'd', POPT_ARG_NONE
, {NULL
}, 'd',
2087 N_("Disable mouse support in text version"), NULL
},
2088 #if defined(HAVE_SLANG)
2089 {"termcap", 't', 0, {&SLtt_Try_Termcap
}, 0,
2090 N_("Tries to use termcap instead of terminfo"), NULL
},
2092 {"resetsoft", 'k', POPT_ARG_NONE
, {&reset_hp_softkeys
}, 0,
2093 N_("Resets soft keys on HP terminals"), NULL
},
2094 {"slow", 's', POPT_ARG_NONE
, {&slow_terminal
}, 0,
2095 N_("To run on slow terminals"), NULL
},
2096 {"stickchars", 'a', 0, {&force_ugly_line_drawing
}, 0,
2097 N_("Use stickchars to draw"), NULL
},
2100 {"nocolor", 'b', POPT_ARG_NONE
, {&disable_colors
}, 0,
2101 N_("Requests to run in black and white"), NULL
},
2102 {"color", 'c', POPT_ARG_NONE
, {NULL
}, 'c',
2103 N_("Request to run in color mode"), NULL
},
2104 {"colors", 'C', POPT_ARG_STRING
, {&command_line_colors
}, 0,
2105 N_("Specifies a color configuration"), NULL
},
2106 {"help-colors", 'H', POPT_ARG_NONE
, {NULL
}, 'H',
2107 N_("Displays a help screen on how to change the color scheme"), NULL
},
2111 {"ftplog", 'l', POPT_ARG_STRING
, {NULL
}, 'l',
2112 N_("Log ftp dialog to specified file"), NULL
},
2114 {"debuglevel", 'D', POPT_ARG_STRING
, {NULL
}, 'D',
2115 N_("Set debug level"), NULL
},
2119 /* options for wrappers */
2120 {"datadir", 'f', POPT_ARG_NONE
, {NULL
}, 'f',
2121 N_("Print data directory"), NULL
},
2122 {"printwd", 'P', POPT_ARG_STRING
, {&last_wd_file
}, 0,
2123 N_("Print last working directory to specified file"), NULL
},
2125 /* subshell options */
2126 #ifdef HAVE_SUBSHELL_SUPPORT
2127 {"subshell", 'U', POPT_ARG_NONE
, {&use_subshell
}, 0,
2128 N_("Enables subshell support (default)"), NULL
},
2129 {"nosubshell", 'u', POPT_ARG_NONE
, {NULL
}, 'u',
2130 N_("Disables subshell support"), NULL
},
2133 /* single file operations */
2134 {"view", 'v', POPT_ARG_STRING
, {&view_one_file
}, 0,
2135 N_("Launches the file viewer on a file"), NULL
},
2136 #ifdef USE_INTERNAL_EDIT
2137 {"edit", 'e', POPT_ARG_STRING
, {&edit_one_file
}, 0,
2138 N_("Edits one file"), NULL
},
2141 {NULL
, '\0', 0, {NULL
}, 0, NULL
, NULL
}
2145 handle_args (int argc
, char *argv
[])
2153 poptGetContext ("mc", argc
, argv
, argument_table
,
2154 POPT_CONTEXT_NO_EXEC
);
2156 while ((c
= poptGetNextOpt (ctx
)) > 0) {
2157 process_args (ctx
, c
, poptGetOptArg (ctx
));
2161 print_mc_usage (ctx
, stderr
);
2162 fprintf (stderr
, "%s: %s\n",
2163 poptBadOption (ctx
, POPT_BADOPTION_NOALIAS
),
2168 tmp
= poptGetArg (ctx
);
2171 * Check for special invocation names mcedit and mcview,
2172 * if none apply then set the current directory and the other
2173 * directory from the command line arguments
2175 base
= x_basename (argv
[0]);
2176 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP (base
, "vi")) {
2180 * Check for filename:lineno, followed by an optional colon.
2181 * This format is used by many programs (especially compilers)
2182 * in error messages and warnings. It is supported so that
2183 * users can quickly copy and paste file locations.
2185 char *end
= tmp
+ strlen (tmp
), *p
= end
;
2186 if (p
> tmp
&& p
[-1] == ':')
2188 while (p
> tmp
&& g_ascii_isdigit ((gchar
) p
[-1]))
2190 if (tmp
< p
&& p
< end
&& p
[-1] == ':') {
2192 gchar
*fname
= g_strndup (tmp
, p
- 1 - tmp
);
2194 * Check that the file before the colon actually exists.
2195 * If it doesn't exist, revert to the old behavior.
2197 if (mc_stat (tmp
, &st
) == -1 && mc_stat (fname
, &st
) != -1) {
2198 edit_one_file
= fname
;
2199 edit_one_file_start_line
= atoi (p
);
2202 goto try_plus_filename
;
2206 if (*tmp
== '+' && g_ascii_isdigit ((gchar
) tmp
[1])) {
2207 int start_line
= atoi (tmp
);
2208 if (start_line
> 0) {
2209 char *file
= poptGetArg (ctx
);
2212 edit_one_file_start_line
= start_line
;
2216 edit_one_file
= g_strdup (tmp
);
2219 } else if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP (base
, "view")) {
2221 view_one_file
= g_strdup (tmp
);
2223 fputs ("No arguments given to the viewer\n", stderr
);
2227 /* sets the current dir and the other dir */
2229 this_dir
= g_strdup (tmp
);
2230 if ((tmp
= poptGetArg (ctx
)))
2231 other_dir
= g_strdup (tmp
);
2235 poptFreeContext (ctx
);
2239 main (int argc
, char *argv
[])
2244 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2245 setlocale (LC_ALL
, "");
2246 bindtextdomain ("mc", LOCALEDIR
);
2249 /* Set up temporary directory */
2254 /* This variable is used by the subshell */
2255 home_dir
= getenv ("HOME");
2257 /* mc_home was computed by OS_Setup */
2261 str_init_strings (NULL
);
2265 #ifdef USE_INTERNAL_EDIT
2270 SLtt_Ignore_Beep
= 1;
2273 handle_args (argc
, argv
);
2275 /* NOTE: This has to be called before slang_init or whatever routine
2276 calls any define_sequence */
2279 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
2280 handle_console (CONSOLE_INIT
);
2282 #ifdef HAVE_SUBSHELL_SUPPORT
2283 /* Don't use subshell when invoked as viewer or editor */
2284 if (edit_one_file
|| view_one_file
)
2288 subshell_get_console_attributes ();
2289 #endif /* HAVE_SUBSHELL_SUPPORT */
2291 /* Install the SIGCHLD handler; must be done before init_subshell() */
2294 /* We need this, since ncurses endwin () doesn't restore the signals */
2295 save_stop_handler ();
2297 /* Must be done before init_subshell, to set up the terminal size: */
2298 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2302 /* NOTE: This call has to be after slang_init. It's the small part from
2303 the previous init_key which had to be moved after the call of slang_init */
2304 init_key_input_fd ();
2310 /* create home directory */
2311 /* do it after the screen library initialization to show the error message */
2312 mc_dir
= concat_dir_and_file (home_dir
, MC_BASE
);
2313 canonicalize_pathname (mc_dir
);
2314 if ((stat (mc_dir
, &s
) != 0) && (errno
== ENOENT
)
2315 && mkdir (mc_dir
, 0700) != 0)
2316 message (D_ERROR
, _("Warning"),
2317 _("Cannot create %s directory"), mc_dir
);
2320 init_xterm_support ();
2322 #ifdef HAVE_SUBSHELL_SUPPORT
2324 /* Done here to ensure that the subshell doesn't */
2325 /* inherit the file descriptors opened below, etc */
2329 #endif /* HAVE_SUBSHELL_SUPPORT */
2331 /* Removing this from the X code let's us type C-c */
2334 /* Also done after init_subshell, to save any shell init file messages */
2336 handle_console (CONSOLE_SAVE
);
2338 if (alternate_plus_minus
)
2339 application_keypad_mode ();
2341 #ifdef HAVE_SUBSHELL_SUPPORT
2343 prompt
= strip_ctrl_codes (subshell_prompt
);
2347 #endif /* HAVE_SUBSHELL_SUPPORT */
2348 prompt
= (geteuid () == 0) ? "# " : "$ ";
2350 /* Program main loop */
2351 if (!midnight_shutdown
)
2354 /* Save the tree store */
2357 /* Virtual File System shutdown */
2360 flush_extension_file (); /* does only free memory */
2367 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2368 handle_console (CONSOLE_RESTORE
);
2369 if (alternate_plus_minus
)
2370 numeric_keypad_mode ();
2372 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2375 handle_console (CONSOLE_DONE
);
2376 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2378 if (last_wd_file
&& last_wd_string
&& !print_last_revert
2379 && !edit_one_file
&& !view_one_file
) {
2381 open (last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2384 if (last_wd_fd
!= -1) {
2385 write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2389 g_free (last_wd_string
);
2391 g_free (mc_home_alt
);
2395 free_codepages_list ();
2397 str_uninit_strings ();
2402 #ifdef USE_INTERNAL_EDIT