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>
45 #include "../src/tty/tty.h"
46 #include "../src/tty/color.h"
47 #include "../src/tty/mouse.h"
48 #include "../src/tty/key.h" /* For init_key() */
49 #include "../src/tty/win.h" /* xterm_flag */
58 #include "treestore.h"
59 #include "cons.saver.h"
61 #include "setup.h" /* save_setup() */
62 #include "../src/mcconfig/mcconfig.h"
63 #include "boxes.h" /* sort_box() */
65 #include "cmd.h" /* Normal commands */
68 #include "learn.h" /* learn_keys() */
71 #include "ext.h" /* For flush_extension_file() */
73 #include <pwd.h> /* for username in xterm title */
75 /* Listbox for the command history feature */
85 #include "../vfs/smbfs.h" /* smbfs_set_debug() */
88 #ifdef USE_INTERNAL_EDIT
89 # include "../edit/edit.h"
94 #endif /* HAVE_CHARSET */
97 #include "../vfs/gc.h"
102 /* When the modes are active, left_panel, right_panel and tree_panel */
103 /* Point to a proper data structure. You should check with the functions */
104 /* get_current_type and get_other_type the types of the panels before using */
105 /* This pointer variables */
107 /* The structures for the panels */
108 WPanel
*left_panel
= NULL
;
109 WPanel
*right_panel
= NULL
;
111 /* The pointer to the tree */
112 WTree
*the_tree
= NULL
;
115 struct WMenu
*the_menubar
= NULL
;
117 /* Pointers to the selected and unselected panel */
118 WPanel
*current_panel
= NULL
;
120 /* Set if the command is being run from the "Right" menu */
123 /* Set when main loop should be terminated */
124 volatile int quit
= 0;
126 /* Set if you want the possible completions dialog for the first time */
127 int show_all_if_ambiguous
= 0;
129 /* Set when cd symlink following is desirable (bash mode) */
132 /* If set then dialogs just clean the screen when refreshing, else */
133 /* they do a complete refresh, refreshing all the parts of the program */
134 int fast_refresh
= 0;
136 /* If true, marking a files moves the cursor down */
137 int mark_moves_down
= 1;
139 /* If true, at startup the user-menu is invoked */
142 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\
143 and M-- and keypad + / - */
144 int alternate_plus_minus
= 0;
146 /* If true, then the +, - and \ keys have their special meaning only if the
147 * command line is emtpy, otherwise they behave like regular letters
149 int only_leading_plus_minus
= 1;
151 int pause_after_run
= pause_on_dumb_terminals
;
153 /* It true saves the setup when quitting */
154 int auto_save_setup
= 1;
157 /* If true, allow characters in the range 160-255 */
158 int eight_bit_clean
= 1;
161 * If true, also allow characters in the range 128-159.
162 * This is reported to break on many terminals (xterm, qansi-m).
164 int full_eight_bits
= 0;
166 #endif /* !HAVE_CHARSET */
169 * If utf-8 terminal utf8_display = 1
170 * Display bits set UTF-8
173 int utf8_display
= 0;
175 /* If true use the internal viewer */
176 int use_internal_view
= 1;
178 /* Have we shown the fast-reload warning in the past? */
179 int fast_reload_w
= 0;
181 /* Move page/item? When clicking on the top or bottom of a panel */
182 int mouse_move_pages
= 1;
184 /* If true: l&r arrows are used to chdir if the input line is empty */
185 int navigate_with_arrows
= 0;
187 /* If true program softkeys (HP terminals only) on startup and after every
188 command ran in the subshell to the description found in the termcap/terminfo
190 int reset_hp_softkeys
= 0;
193 const char *prompt
= NULL
;
195 /* The widget where we draw the prompt */
204 /* For slow terminals */
205 static int slow_terminal
= 0;
207 /* If true use +, -, | for line drawing */
208 static int ugly_line_drawing
= 0;
210 /* Mouse type: GPM, xterm or none */
211 Mouse_Type use_mouse_p
= MOUSE_NONE
;
213 /* If true, assume we are running on an xterm terminal */
214 static int force_xterm
= 0;
216 /* If on, default for "No" in delete operations */
219 /* Controls screen clearing before an exec */
220 int clear_before_exec
= 1;
222 /* Asks for confirmation before deleting a file */
223 int confirm_delete
= 1;
225 /* Asks for confirmation before deleting a hotlist entry */
226 int confirm_directory_hotlist_delete
= 1;
228 /* Asks for confirmation before overwriting a file */
229 int confirm_overwrite
= 1;
231 /* Asks for confirmation before executing a program by pressing enter */
232 int confirm_execute
= 0;
234 /* Asks for confirmation before leaving the program */
235 int confirm_exit
= 1;
237 /* Asks for confirmation when using F3 to view a directory and there
239 int confirm_view_dir
= 0;
241 /* This flag indicates if the pull down menus by default drop down */
244 /* if skip_check_codeset = 1 do not show warning about
245 * system and display codeset is different
247 int skip_check_codeset
= 0;
249 /* The dialog handle for the main program */
250 Dlg_head
*midnight_dlg
= NULL
;
252 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
253 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
254 int update_prompt
= 0;
256 /* The home directory */
257 const char *home_dir
= NULL
;
259 /* The value of the other directory, only used when loading the setup */
260 char *other_dir
= NULL
;
262 /* Only used at program boot */
263 int boot_current_is_left
= 1;
265 static char *this_dir
= NULL
;
267 /* If this is true, then when browsing the tree the other window will
268 * automatically reload it's directory with the contents of the currently
269 * selected directory.
273 /* If set, then print to the given file the last directory we were at */
274 static char *last_wd_file
= NULL
;
275 static char *last_wd_string
= NULL
;
276 /* Set to 1 to suppress printing the last directory */
277 static int print_last_revert
= 0;
279 /* Set to force black and white display at program startup */
280 static gboolean disable_colors
= FALSE
;
281 /* Force colors, only used by Slang */
282 static gboolean force_colors
= FALSE
;
284 /* colors specified on the command line: they override any other setting */
285 char *command_line_colors
= NULL
;
287 /* File name to view if argument was supplied */
288 static const char *view_one_file
= NULL
;
290 /* File name to edit if argument was supplied */
291 const char *edit_one_file
= NULL
;
293 /* Line to start the editor on */
294 static int edit_one_file_start_line
= 0;
296 /* Used so that widgets know if they are being destroyed or
298 int midnight_shutdown
= 0;
300 /* The user's shell */
303 /* mc_home: The home of MC - /etc/mc or defined by MC_DATADIR */
304 char *mc_home
= NULL
;
306 /* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
307 char *mc_home_alt
= NULL
;
312 reload_panelized (WPanel
*panel
)
315 dir_list
*list
= &panel
->dir
;
317 if (panel
!= current_panel
)
318 mc_chdir (panel
->cwd
);
320 for (i
= 0, j
= 0; i
< panel
->count
; i
++) {
321 if (list
->list
[i
].f
.marked
) {
322 /* Unmark the file in advance. In case the following mc_lstat
323 * fails we are done, else we have to mark the file again
324 * (Note: do_file_mark depends on a valid "list->list [i].buf").
325 * IMO that's the best way to update the panel's summary status
328 do_file_mark (panel
, i
, 0);
330 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].st
)) {
331 g_free (list
->list
[i
].fname
);
334 if (list
->list
[i
].f
.marked
)
335 do_file_mark (panel
, i
, 1);
337 list
->list
[j
] = list
->list
[i
];
341 panel
->count
= set_zero_dir (list
);
345 if (panel
!= current_panel
)
346 mc_chdir (current_panel
->cwd
);
350 update_one_panel_widget (WPanel
*panel
, int force_update
,
351 const char *current_file
)
354 char *my_current_file
= NULL
;
356 if (force_update
& UP_RELOAD
) {
357 panel
->is_panelized
= 0;
358 mc_setctl (panel
->cwd
, VFS_SETCTL_FLUSH
, 0);
359 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
362 /* If current_file == -1 (an invalid pointer) then preserve selection */
363 if (current_file
== UP_KEEPSEL
) {
365 my_current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
366 current_file
= my_current_file
;
370 if (panel
->is_panelized
)
371 reload_panelized (panel
);
373 panel_reload (panel
);
375 try_to_select (panel
, current_file
);
379 g_free (my_current_file
);
383 panel_clean_dir (WPanel
*panel
)
385 int count
= panel
->count
;
391 panel
->dirs_marked
= 0;
393 panel
->searching
= 0;
394 panel
->is_panelized
= 0;
397 clean_dir (&panel
->dir
, count
);
401 update_one_panel (int which
, int force_update
, const char *current_file
)
405 if (get_display_type (which
) != view_listing
)
408 panel
= (WPanel
*) get_panel_widget (which
);
409 update_one_panel_widget (panel
, force_update
, current_file
);
412 /* This routine reloads the directory in both panels. It tries to
413 * select current_file in current_panel and other_file in other_panel.
414 * If current_file == -1 then it automatically sets current_file and
415 * other_file to the currently selected files in the panels.
417 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
418 * will not reload the other panel.
421 update_panels (int force_update
, const char *current_file
)
423 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
426 update_one_panel (get_current_index (), force_update
, current_file
);
428 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
430 if (get_current_type () == view_listing
)
431 panel
= (WPanel
*) get_panel_widget (get_current_index ());
433 panel
= (WPanel
*) get_panel_widget (get_other_index ());
435 mc_chdir (panel
->cwd
);
438 /* Save current stat of directories to avoid reloading the panels */
439 /* when no modifications have taken place */
441 save_cwds_stat (void)
444 mc_stat (current_panel
->cwd
, &(current_panel
->dir_stat
));
445 if (get_other_type () == view_listing
)
446 mc_stat (other_panel
->cwd
, &(other_panel
->dir_stat
));
450 #ifdef HAVE_SUBSHELL_SUPPORT
452 do_possible_cd (const char *new_dir
)
454 if (!do_cd (new_dir
, cd_exact
))
455 message (D_ERROR
, _("Warning"),
456 _(" The Commander can't change to the directory that \n"
457 " the subshell claims you are in. Perhaps you have \n"
458 " deleted your working directory, or given yourself \n"
459 " extra access permissions with the \"su\" command? "));
463 do_update_prompt (void)
466 printf ("%s", subshell_prompt
);
471 #endif /* HAVE_SUBSHELL_SUPPORT */
476 free_completions (cmdline
);
477 dlg_one_down (midnight_dlg
);
480 /* Stop MC main dialog and the current dialog if it exists.
481 * Needed to provide fast exit from MC viewer or editor on shell exit */
485 midnight_dlg
->running
= 0;
487 current_dlg
->running
= 0;
492 quit_cmd_internal (int quiet
)
496 if (quiet
|| !confirm_exit
) {
500 (_(" The Midnight Commander "),
501 _(" Do you really want to quit the Midnight Commander? "), D_NORMAL
,
502 2, _("&Yes"), _("&No")) == 0)
506 #ifdef HAVE_SUBSHELL_SUPPORT
509 else if ((q
= exit_subshell ()))
521 quit_cmd_internal (0);
525 quiet_quit_cmd (void)
527 print_last_revert
= 1;
528 quit_cmd_internal (1);
531 /* Wrapper for do_subshell_chdir, check for availability of subshell */
533 subshell_chdir (const char *directory
)
535 #ifdef HAVE_SUBSHELL_SUPPORT
537 if (vfs_current_is_local ())
538 do_subshell_chdir (directory
, 0, 1);
540 #endif /* HAVE_SUBSHELL_SUPPORT */
544 directory_history_add (struct WPanel
*panel
, const char *dir
)
548 tmp
= g_strdup (dir
);
549 strip_password (tmp
, 1);
551 panel
->dir_history
= list_append_unique (panel
->dir_history
, tmp
);
555 * If we moved to the parent directory move the selection pointer to
556 * the old directory name; If we leave VFS dir, remove FS specificator.
558 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
561 get_parent_dir_name (const char *cwd
, const char *lwd
)
564 if (strlen (lwd
) > strlen (cwd
))
565 if ((p
= strrchr (lwd
, PATH_SEP
)) && !strncmp (cwd
, lwd
, p
- lwd
) &&
566 ((gsize
)strlen (cwd
) == (gsize
) p
- (gsize
) lwd
|| (p
== lwd
&& cwd
[0] == PATH_SEP
&&
574 * Changes the current directory of the panel.
575 * Don't record change in the directory history.
578 _do_panel_cd (WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
580 const char *directory
;
582 char temp
[MC_MAXPATHLEN
];
583 char *translated_url
;
585 if (cd_type
== cd_parse_command
) {
586 while (*new_dir
== ' ')
590 olddir
= g_strdup (panel
->cwd
);
591 new_dir
= translated_url
= vfs_translate_url (new_dir
);
593 /* Convert *new_path to a suitable pathname, handle ~user */
595 if (cd_type
== cd_parse_command
) {
596 if (!strcmp (new_dir
, "-")) {
597 strcpy (temp
, panel
->lwd
);
601 directory
= *new_dir
? new_dir
: home_dir
;
603 if (mc_chdir (directory
) == -1) {
604 strcpy (panel
->cwd
, olddir
);
606 g_free (translated_url
);
609 g_free (translated_url
);
611 /* Success: save previous directory, shutdown status of previous dir */
612 strcpy (panel
->lwd
, olddir
);
613 free_completions (cmdline
);
615 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
617 vfs_release_path (olddir
);
619 subshell_chdir (panel
->cwd
);
621 /* Reload current panel */
622 panel_clean_dir (panel
);
624 do_load_dir (panel
->cwd
, &panel
->dir
, panel
->sort_type
,
625 panel
->reverse
, panel
->case_sensitive
,
626 panel
->exec_first
, panel
->filter
);
627 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
630 update_xterm_title_path ();
638 * Changes the current directory of the panel.
639 * Record change in the directory history.
642 do_panel_cd (struct WPanel
*panel
, const char *new_dir
, enum cd_enum cd_type
)
646 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
648 directory_history_add (panel
, panel
->cwd
);
653 do_cd (const char *new_dir
, enum cd_enum exact
)
655 return (do_panel_cd (current_panel
, new_dir
, exact
));
659 directory_history_next (WPanel
*panel
)
663 nextdir
= g_list_next (panel
->dir_history
);
668 if (_do_panel_cd (panel
, (char *) nextdir
->data
, cd_exact
))
669 panel
->dir_history
= nextdir
;
673 directory_history_prev (WPanel
*panel
)
677 prevdir
= g_list_previous (panel
->dir_history
);
682 if (_do_panel_cd (panel
, (char *) prevdir
->data
, cd_exact
))
683 panel
->dir_history
= prevdir
;
687 directory_history_list (WPanel
*panel
)
691 if (!panel
->dir_history
)
694 s
= show_hist (panel
->dir_history
, panel
->widget
.x
, panel
->widget
.y
);
699 if (_do_panel_cd (panel
, s
, cd_exact
))
700 directory_history_add (panel
, panel
->cwd
);
702 message (D_ERROR
, MSG_ERROR
, _("Cannot change directory"));
706 #ifdef HAVE_SUBSHELL_SUPPORT
708 load_prompt (int fd
, void *unused
)
713 if (!read_subshell_prompt ())
716 /* Don't actually change the prompt if it's invisible */
717 if (current_dlg
== midnight_dlg
&& command_prompt
) {
721 tmp_prompt
= strip_ctrl_codes (subshell_prompt
);
722 prompt_len
= str_term_width1 (tmp_prompt
);
724 /* Check for prompts too big */
725 if (COLS
> 8 && prompt_len
> COLS
- 8) {
726 tmp_prompt
[COLS
- 8] = '\0';
727 prompt_len
= COLS
- 8;
730 label_set_text (the_prompt
, prompt
);
731 winput_set_origin ((WInput
*) cmdline
, prompt_len
,
734 /* since the prompt has changed, and we are called from one of the
735 * tty_get_event channels, the prompt updating does not take place
736 * automatically: force a cursor update and a screen refresh
738 update_cursor (midnight_dlg
);
744 #endif /* HAVE_SUBSHELL_SUPPORT */
746 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
748 maybe_cd (int move_up_dir
)
750 if (navigate_with_arrows
) {
751 if (!cmdline
->buffer
[0]) {
753 do_cd ("..", cd_exact
);
756 if (S_ISDIR (selection (current_panel
)->st
.st_mode
)
757 || link_isdir (selection (current_panel
))) {
758 do_cd (selection (current_panel
)->fname
, cd_exact
);
772 if (!SELECTED_IS_PANEL
)
776 sort_order
= sort_box (p
->sort_type
, &p
->reverse
,
780 panel_set_sort_order (p
, sort_order
);
789 sel_dir
= tree_box (selection (current_panel
)->fname
);
791 do_cd (sel_dir
, cd_exact
);
796 #ifdef LISTMODE_EDITOR
802 if (get_current_type () != view_listing
)
805 newmode
= listmode_edit (current_panel
->user_format
);
809 g_free (current_panel
->user_format
);
810 current_panel
->list_type
= list_user
;
811 current_panel
->user_format
= newmode
;
812 set_panel_formats (current_panel
);
816 #endif /* LISTMODE_EDITOR */
818 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
819 static menu_entry LeftMenu
[] = {
820 {' ', N_("&Listing mode..."), NULL_HOTKEY
, listing_cmd
},
821 {' ', N_("&Quick view C-x q"), NULL_HOTKEY
, quick_view_cmd
},
822 {' ', N_("&Info C-x i"), NULL_HOTKEY
, info_cmd
},
823 {' ', N_("&Tree"), NULL_HOTKEY
, tree_cmd
},
824 {' ', "", NULL_HOTKEY
, 0},
825 {' ', N_("&Sort order..."), NULL_HOTKEY
, sort_cmd
},
826 {' ', "", NULL_HOTKEY
, 0},
827 {' ', N_("&Filter..."), NULL_HOTKEY
, filter_cmd
},
829 {' ', "",NULL_HOTKEY
, 0},
830 {' ', N_("&Encoding... C-t"), NULL_HOTKEY
, encoding_cmd
},
833 {' ', "", NULL_HOTKEY
, 0},
834 #ifdef ENABLE_VFS_MCFS
835 {' ', N_("&Network link..."), NULL_HOTKEY
, netlink_cmd
},
837 {' ', N_("FT&P link..."), NULL_HOTKEY
, ftplink_cmd
},
838 {' ', N_("S&hell link..."), NULL_HOTKEY
, fishlink_cmd
},
840 {' ', N_("SM&B link..."), NULL_HOTKEY
, smblink_cmd
},
843 {' ', "", NULL_HOTKEY
, 0},
844 {' ', N_("&Rescan C-r"), NULL_HOTKEY
, reread_cmd
}
847 static menu_entry RightMenu
[] = {
848 {' ', N_("&Listing mode..."), NULL_HOTKEY
, listing_cmd
},
849 {' ', N_("&Quick view C-x q"), NULL_HOTKEY
, quick_view_cmd
},
850 {' ', N_("&Info C-x i"), NULL_HOTKEY
, info_cmd
},
851 {' ', N_("&Tree"), NULL_HOTKEY
, tree_cmd
},
852 {' ', "", NULL_HOTKEY
, 0},
853 {' ', N_("&Sort order..."), NULL_HOTKEY
, sort_cmd
},
854 {' ', "", NULL_HOTKEY
, 0},
855 {' ', N_("&Filter..."), NULL_HOTKEY
, filter_cmd
},
857 {' ', "",NULL_HOTKEY
, 0},
858 {' ', N_("&Encoding... C-t"), NULL_HOTKEY
, encoding_cmd
},
861 {' ', "", NULL_HOTKEY
, 0},
862 #ifdef ENABLE_VFS_MCFS
863 {' ', N_("&Network link..."), NULL_HOTKEY
, netlink_cmd
},
865 {' ', N_("FT&P link..."), NULL_HOTKEY
, ftplink_cmd
},
866 {' ', N_("S&hell link..."), NULL_HOTKEY
, fishlink_cmd
},
868 {' ', N_("SM&B link..."), NULL_HOTKEY
, smblink_cmd
},
871 {' ', "", NULL_HOTKEY
, 0},
872 {' ', N_("&Rescan C-r"), NULL_HOTKEY
, reread_cmd
}
875 static menu_entry FileMenu
[] = {
876 {' ', N_("&View F3"), NULL_HOTKEY
, view_cmd
},
877 {' ', N_("Vie&w file... "), NULL_HOTKEY
, view_file_cmd
},
878 {' ', N_("&Filtered view M-!"), NULL_HOTKEY
, filtered_view_cmd
},
879 {' ', N_("&Edit F4"), NULL_HOTKEY
, edit_cmd
},
880 {' ', N_("&Copy F5"), NULL_HOTKEY
, copy_cmd
},
881 {' ', N_("c&Hmod C-x c"), NULL_HOTKEY
, chmod_cmd
},
882 {' ', N_("&Link C-x l"), NULL_HOTKEY
, link_cmd
},
883 {' ', N_("&SymLink C-x s"), NULL_HOTKEY
, symlink_cmd
},
884 {' ', N_("edit s&Ymlink C-x C-s"), NULL_HOTKEY
, edit_symlink_cmd
},
885 {' ', N_("ch&Own C-x o"), NULL_HOTKEY
, chown_cmd
},
886 {' ', N_("&Advanced chown "), NULL_HOTKEY
, chown_advanced_cmd
},
887 {' ', N_("&Rename/Move F6"), NULL_HOTKEY
, ren_cmd
},
888 {' ', N_("&Mkdir F7"), NULL_HOTKEY
, mkdir_cmd
},
889 {' ', N_("&Delete F8"), NULL_HOTKEY
, delete_cmd
},
890 {' ', N_("&Quick cd M-c"), NULL_HOTKEY
, quick_cd_cmd
},
891 {' ', "", NULL_HOTKEY
, 0},
892 {' ', N_("select &Group M-+"), NULL_HOTKEY
, select_cmd
},
893 {' ', N_("u&Nselect group M-\\"), NULL_HOTKEY
, unselect_cmd
},
894 {' ', N_("reverse selec&Tion M-*"), NULL_HOTKEY
, reverse_selection_cmd
},
895 {' ', "", NULL_HOTKEY
, 0},
896 {' ', N_("e&Xit F10"), NULL_HOTKEY
, quit_cmd
}
899 static menu_entry CmdMenu
[] = {
900 {' ', N_("&User menu F2"), NULL_HOTKEY
, user_file_menu_cmd
},
901 /* I know, I'm lazy, but the tree widget when it's not running
902 * as a panel still has some problems, I have not yet finished
903 * the WTree widget port, sorry.
905 {' ', N_("&Directory tree"), NULL_HOTKEY
, treebox_cmd
},
906 {' ', N_("&Find file M-?"), NULL_HOTKEY
, find_cmd
},
907 {' ', N_("s&Wap panels C-u"), NULL_HOTKEY
, swap_cmd
},
908 {' ', N_("switch &Panels on/off C-o"), NULL_HOTKEY
, view_other_cmd
},
909 {' ', N_("&Compare directories C-x d"), NULL_HOTKEY
, compare_dirs_cmd
},
910 {' ', N_("e&Xternal panelize C-x !"), NULL_HOTKEY
, external_panelize
},
911 {' ', N_("show directory s&Izes"), NULL_HOTKEY
, dirsizes_cmd
},
912 {' ', "", NULL_HOTKEY
, 0},
913 {' ', N_("Command &history M-h"), NULL_HOTKEY
, history_cmd
},
914 {' ', N_("di&Rectory hotlist C-\\"), NULL_HOTKEY
, quick_chdir_cmd
},
916 {' ', N_("&Active VFS list C-x a"), NULL_HOTKEY
, reselect_vfs
},
918 #ifdef WITH_BACKGROUND
919 {' ', N_("&Background jobs C-x j"), NULL_HOTKEY
, jobs_cmd
},
921 {' ', "", NULL_HOTKEY
, 0},
923 {' ', N_("&Undelete files (ext2fs only)"), NULL_HOTKEY
, undelete_cmd
},
925 #ifdef LISTMODE_EDITOR
926 {' ', N_("&Listing format edit"), NULL_HOTKEY
, listmode_cmd
},
928 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
929 {' ', "", NULL_HOTKEY
, 0},
931 {' ', N_("Edit &extension file"), NULL_HOTKEY
, ext_cmd
},
932 {' ', N_("Edit &menu file"), NULL_HOTKEY
, edit_mc_menu_cmd
}
935 /* Must keep in sync with the constants in menu_cmd */
936 static menu_entry OptMenu
[] = {
937 {' ', N_("&Configuration..."), NULL_HOTKEY
, configure_box
},
938 {' ', N_("&Layout..."), NULL_HOTKEY
, layout_cmd
},
939 {' ', N_("c&Onfirmation..."), NULL_HOTKEY
, confirm_box
},
940 {' ', N_("&Display bits..."), NULL_HOTKEY
, display_bits_box
},
941 {' ', N_("learn &Keys..."), NULL_HOTKEY
, learn_keys
},
943 {' ', N_("&Virtual FS..."), NULL_HOTKEY
, configure_vfs
},
944 #endif /* !USE_VFS */
945 {' ', "", NULL_HOTKEY
, 0},
946 {' ', N_("&Save setup"), NULL_HOTKEY
, save_setup_cmd
}
949 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
951 static Menu
*MenuBar
[5];
957 create_menu (horizontal_split
? _(" &Above ") : _(" &Left "),
958 LeftMenu
, menu_entries (LeftMenu
),
959 "[Left and Right Menus]");
961 create_menu (_(" &File "), FileMenu
, menu_entries (FileMenu
),
964 create_menu (_(" &Command "), CmdMenu
, menu_entries (CmdMenu
),
967 create_menu (_(" &Options "), OptMenu
, menu_entries (OptMenu
),
970 create_menu (horizontal_split
? _(" &Below ") : _(" &Right "),
971 RightMenu
, menu_entries (RightMenu
),
972 "[Left and Right Menus]");
980 for (i
= 0; i
< 5; i
++) {
981 destroy_menu (MenuBar
[i
]);
986 menu_last_selected_cmd (void)
988 the_menubar
->active
= 1;
989 the_menubar
->dropped
= drop_menus
;
990 the_menubar
->previous_widget
= midnight_dlg
->current
->dlg_id
;
991 dlg_select_widget (the_menubar
);
997 if (the_menubar
->active
)
1000 if ((get_current_index () == 0) ^ (!current_panel
->active
))
1001 the_menubar
->selected
= 0;
1003 the_menubar
->selected
= 4;
1004 menu_last_selected_cmd ();
1007 /* Flag toggling functions */
1009 toggle_fast_reload (void)
1011 fast_reload
= !fast_reload
;
1012 if (fast_reload_w
== 0 && fast_reload
) {
1013 message (D_NORMAL
, _(" Information "),
1015 (" Using the fast reload option may not reflect the exact \n"
1016 " directory contents. In this case you'll need to do a \n"
1017 " manual reload of the directory. See the man page for \n"
1024 toggle_mix_all_files (void)
1026 mix_all_files
= !mix_all_files
;
1027 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1031 toggle_show_backup (void)
1033 show_backups
= !show_backups
;
1034 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1038 toggle_show_hidden (void)
1040 show_dot_files
= !show_dot_files
;
1041 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1045 * Just a hack for allowing url-like pathnames to be accepted from the
1049 translated_mc_chdir (char *dir
)
1053 newdir
= vfs_translate_url (dir
);
1059 create_panels (void)
1065 char original_dir
[1024];
1067 original_dir
[0] = 0;
1069 if (boot_current_is_left
) {
1072 current_mode
= startup_left_mode
;
1073 other_mode
= startup_right_mode
;
1077 current_mode
= startup_right_mode
;
1078 other_mode
= startup_left_mode
;
1080 /* Creates the left panel */
1083 /* Ok, user has specified two dirs, save the original one,
1084 * since we may not be able to chdir to the proper
1085 * second directory later
1087 mc_get_current_wd (original_dir
, sizeof (original_dir
) - 2);
1089 translated_mc_chdir (this_dir
);
1091 set_display_type (current_index
, current_mode
);
1093 /* The other panel */
1095 if (original_dir
[0])
1096 translated_mc_chdir (original_dir
);
1097 translated_mc_chdir (other_dir
);
1099 set_display_type (other_index
, other_mode
);
1101 if (startup_left_mode
== view_listing
) {
1102 current_panel
= left_panel
;
1105 current_panel
= right_panel
;
1107 current_panel
= left_panel
;
1110 /* Create the nice widgets */
1111 cmdline
= command_new (0, 0, 0);
1112 the_prompt
= label_new (0, 0, prompt
);
1113 the_prompt
->transparent
= 1;
1114 the_bar
= buttonbar_new (keybar_visible
);
1116 the_hint
= label_new (0, 0, 0);
1117 the_hint
->transparent
= 1;
1118 the_hint
->auto_adjust_cols
= 0;
1119 the_hint
->widget
.cols
= COLS
;
1121 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
1125 copy_current_pathname (void)
1128 if (!command_prompt
)
1131 cwd_path
= remove_encoding_from_path (current_panel
->cwd
);
1132 command_insert (cmdline
, cwd_path
, 0);
1134 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
1135 command_insert (cmdline
, PATH_SEP_STR
, 0);
1140 copy_other_pathname (void)
1144 if (get_other_type () != view_listing
)
1147 if (!command_prompt
)
1150 cwd_path
= remove_encoding_from_path (other_panel
->cwd
);
1151 command_insert (cmdline
, cwd_path
, 0);
1153 if (cwd_path
[strlen (cwd_path
) - 1] != PATH_SEP
)
1154 command_insert (cmdline
, PATH_SEP_STR
, 0);
1159 copy_readlink (WPanel
*panel
)
1161 if (!command_prompt
)
1163 if (S_ISLNK (selection (panel
)->st
.st_mode
)) {
1164 char buffer
[MC_MAXPATHLEN
];
1166 concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1169 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
- 1);
1173 command_insert (cmdline
, buffer
, 1);
1179 copy_current_readlink (void)
1181 copy_readlink (current_panel
);
1185 copy_other_readlink (void)
1187 if (get_other_type () != view_listing
)
1189 copy_readlink (other_panel
);
1192 /* Insert the selected file name into the input line */
1194 copy_prog_name (void)
1197 if (!command_prompt
)
1200 if (get_current_type () == view_tree
) {
1201 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1202 tmp
= tree_selected_name (tree
);
1204 tmp
= selection (current_panel
)->fname
;
1206 command_insert (cmdline
, tmp
, 1);
1210 copy_tagged (WPanel
*panel
)
1214 if (!command_prompt
)
1216 input_disable_update (cmdline
);
1217 if (panel
->marked
) {
1218 for (i
= 0; i
< panel
->count
; i
++) {
1219 if (panel
->dir
.list
[i
].f
.marked
)
1220 command_insert (cmdline
, panel
->dir
.list
[i
].fname
, 1);
1223 command_insert (cmdline
, panel
->dir
.list
[panel
->selected
].fname
,
1226 input_enable_update (cmdline
);
1230 copy_current_tagged (void)
1232 copy_tagged (current_panel
);
1236 copy_other_tagged (void)
1238 if (get_other_type () != view_listing
)
1240 copy_tagged (other_panel
);
1246 buttonbar_set_label (midnight_dlg
, 1, _("Help"), help_cmd
);
1247 buttonbar_set_label (midnight_dlg
, 2, _("Menu"), user_file_menu_cmd
);
1248 buttonbar_set_label (midnight_dlg
, 9, _("PullDn"), menu_cmd
);
1249 buttonbar_set_label (midnight_dlg
, 10, _("Quit"), quit_cmd
);
1252 static const key_map ctl_x_map
[] = {
1253 {XCTRL ('c'), quit_cmd
},
1254 {'d', compare_dirs_cmd
},
1256 {'a', reselect_vfs
},
1257 #endif /* USE_VFS */
1258 {'p', copy_current_pathname
},
1259 {XCTRL ('p'), copy_other_pathname
},
1260 {'t', copy_current_tagged
},
1261 {XCTRL ('t'), copy_other_tagged
},
1264 {'r', copy_current_readlink
},
1265 {XCTRL ('r'), copy_other_readlink
},
1268 {XCTRL ('s'), edit_symlink_cmd
},
1269 {'i', info_cmd_no_menu
},
1270 {'q', quick_cmd_no_menu
},
1271 {'h', add2hotlist_cmd
},
1272 {'!', external_panelize
},
1273 #ifdef WITH_BACKGROUND
1275 #endif /* WITH_BACKGROUND */
1279 static int ctl_x_map_enabled
= 0;
1284 ctl_x_map_enabled
= 1;
1292 static const key_map default_map
[] = {
1293 {KEY_F (19), menu_last_selected_cmd
},
1294 {KEY_F (20), quiet_quit_cmd
},
1296 {XCTRL ('@'), smart_dirsize_cmd
},
1298 /* Copy useful information to the command line */
1299 {ALT ('a'), copy_current_pathname
},
1300 {ALT ('A'), copy_other_pathname
},
1302 {ALT ('c'), quick_cd_cmd
},
1304 /* To access the directory hotlist */
1305 {XCTRL ('\\'), quick_chdir_cmd
},
1308 {XCTRL ('z'), suspend_cmd
},
1310 /* The filtered view command */
1311 {ALT ('!'), filtered_view_cmd
},
1314 {ALT ('?'), find_cmd
},
1317 {XCTRL ('r'), reread_cmd
},
1319 /* Toggle listing between long, user defined and full formats */
1320 {ALT ('t'), toggle_listing_cmd
},
1323 {XCTRL ('u'), swap_cmd
},
1326 {XCTRL ('o'), view_other_cmd
},
1328 /* Control-X keybindings */
1329 {XCTRL ('x'), ctl_x_cmd
},
1331 /* Show/hide hidden files */
1332 {ALT ('.'), toggle_show_hidden
},
1334 /* Trap dlg's exit commands */
1335 {ESC_CHAR
, nothing
},
1336 {XCTRL ('c'), nothing
},
1337 {XCTRL ('g'), nothing
},
1342 setup_sigwinch (void)
1344 #if (defined(HAVE_SLANG) || (NCURSES_VERSION_MAJOR >= 4)) && defined(SIGWINCH)
1345 struct sigaction act
, oact
;
1346 act
.sa_handler
= flag_winch
;
1347 sigemptyset (&act
.sa_mask
);
1350 act
.sa_flags
|= SA_RESTART
;
1352 sigaction (SIGWINCH
, &act
, &oact
);
1359 /* Call all the inits */
1362 * Don't restrict the output on the screen manager level,
1363 * the translation tables take care of it.
1365 #define full_eight_bits (1)
1366 #define eight_bit_clean (1)
1367 #endif /* !HAVE_CHARSET */
1370 tty_display_8bit (full_eight_bits
!= 0);
1372 tty_display_8bit (eight_bit_clean
!= 0);
1377 init_xterm_support (void)
1379 const char *termvalue
;
1381 termvalue
= getenv ("TERM");
1382 if (!termvalue
|| !(*termvalue
)) {
1383 fputs (_("The TERM environment variable is unset!\n"), stderr
);
1387 /* Check mouse capabilities */
1388 xmouse_seq
= tty_tgetstr ("Km");
1390 if (strcmp (termvalue
, "cygwin") == 0) {
1392 use_mouse_p
= MOUSE_DISABLED
;
1395 if (force_xterm
|| strncmp (termvalue
, "xterm", 5) == 0
1396 || strncmp (termvalue
, "rxvt", 4) == 0
1397 || strcmp (termvalue
, "Eterm") == 0
1398 || strcmp (termvalue
, "dtterm") == 0) {
1401 /* Default to the standard xterm sequence */
1403 xmouse_seq
= ESC_STR
"[M";
1406 /* Enable mouse unless explicitly disabled by --nomouse */
1407 if (use_mouse_p
!= MOUSE_DISABLED
) {
1408 const char *color_term
= getenv ("COLORTERM");
1409 if (strncmp (termvalue
, "rxvt", 4) == 0 ||
1410 (color_term
!= NULL
&& strncmp (color_term
, "rxvt", 4) == 0) ||
1411 strcmp (termvalue
, "Eterm") == 0) {
1412 use_mouse_p
= MOUSE_XTERM_NORMAL_TRACKING
;
1414 use_mouse_p
= MOUSE_XTERM_BUTTON_EVENT_TRACKING
;
1428 #ifdef HAVE_SUBSHELL_SUPPORT
1430 add_select_channel (subshell_pty
, load_prompt
, 0);
1431 #endif /* !HAVE_SUBSHELL_SUPPORT */
1435 verbose
= !((tty_baudrate () < 9600) || tty_is_slow ());
1443 char d
[MC_MAXPATHLEN
];
1445 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1450 static void check_codeset()
1452 const char *_system_codepage
= NULL
;
1454 const char *_source_codepage
= NULL
;
1455 const char *_display_codepage
= NULL
;
1456 int profile_changed
= 0;
1461 if ( !skip_check_codeset
) {
1463 QuickWidget ecs_widgets
[] = {
1464 { quick_button
, 4, 6, 13, CONFY
, N_("&Skip"),
1465 0, B_EXIT
, 0, 0, NULL
, NULL
, NULL
},
1466 { quick_button
, 1, 11, 13, CONFY
, N_("&Fix it"),
1467 0, B_ENTER
, 0, 0, NULL
, NULL
, NULL
},
1468 { quick_checkbox
, 1, 13, 11, CONFY
, N_("don't ask again"),
1469 11, 0, &skip_check_codeset
, NULL
, NULL
, NULL
, NULL
},
1470 { quick_label
, 2, 30, 3, CONFY
, N_("Chosen display charset (Settings->Display bits)\n"
1471 "or source codeset (in mcedit ctrl-t) \n"
1472 "does not match one set via locale. \n"
1473 "Set correct codeset manually or press <<Fix it>> \n"
1474 "to set locale default.\n\n"
1475 "Or set \'don't ask again\' and press <<Skip>>"),
1476 0, 0, 0, 0, NULL
, NULL
, NULL
},
1482 { CONFX
, CONFY
, -1, -1, N_(" Confirmation "), "[Confirmation]",
1487 _system_codepage
= str_detect_termencoding();
1488 _source_codepage
= get_codepage_id (source_codepage
);
1489 _display_codepage
= get_codepage_id (display_codepage
);
1491 if ( (strcmp (_system_codepage
, _display_codepage
)) ||
1492 (strcmp (_system_codepage
, _source_codepage
)) ) {
1493 if (quick_dialog (&ecs
) == B_ENTER
){
1494 display_codepage
= get_codepage_index (_system_codepage
);
1495 cp_display
= get_codepage_id (display_codepage
);
1496 if ( !strcmp (cp_display
, _system_codepage
)) {
1497 mc_config_set_string(mc_main_config
, "Misc", "display_codepage", cp_display
);
1498 mc_config_set_string(mc_main_config
, "Misc", "source_codepage", cp_display
);
1499 display_codepage
= get_codepage_index ( cp_display
);
1500 utf8_display
= str_isutf8 (_system_codepage
);
1501 source_codepage
= display_codepage
;
1502 cp_source
= cp_display
;
1503 profile_changed
= 1;
1506 if ( skip_check_codeset
) {
1507 mc_config_set_int(mc_main_config
, "Midnight-Commander", "skip_check_codeset", 1);
1508 profile_changed
= 1;
1512 if ( profile_changed
)
1515 #else /* HAVE_CHARSET */
1516 _system_codepage
= str_detect_termencoding();
1517 utf8_display
= str_isutf8 (_system_codepage
);
1518 #endif /* HAVE_CHARSET */
1524 if (!(quit
& SUBSHELL_EXIT
))
1526 tty_reset_shell_mode ();
1541 * We sync the profiles since the hotlist may have changed, while
1542 * we only change the setup data if we have the auto save feature set
1545 if (auto_save_setup
)
1546 save_setup (); /* does also call save_hotlist */
1549 save_panel_types ();
1552 vfs_add_current_stamps ();
1555 /* This should be called after destroy_dlg since panel widgets
1556 * save their state on the profiles
1559 done_mc_profile (void)
1565 midnight_callback (struct Dlg_head
*h
, dlg_msg_t msg
, int parm
)
1572 /* We only need the first idle event */
1573 set_idle_proc (h
, 0);
1575 user_file_menu_cmd ();
1580 if (ctl_x_map_enabled
) {
1581 ctl_x_map_enabled
= 0;
1582 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1583 if (parm
== ctl_x_map
[i
].key_code
) {
1584 (*ctl_x_map
[i
].fn
) ();
1589 /* FIXME: should handle all menu shortcuts before this point */
1590 if (the_menubar
->active
)
1591 return MSG_NOT_HANDLED
;
1593 if (parm
== KEY_F (10)) {
1599 free_completions (cmdline
);
1602 for (i
= 0; cmdline
->buffer
[i
] && (cmdline
->buffer
[i
] == ' ' ||
1603 cmdline
->buffer
[i
] == '\t'); i
++);
1604 if (cmdline
->buffer
[i
]) {
1605 send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1608 stuff (cmdline
, "", 0);
1612 /* Ctrl-Enter and Alt-Enter */
1613 if (((parm
& ~(KEY_M_CTRL
| KEY_M_ALT
)) == '\n')
1614 && (parm
& (KEY_M_CTRL
| KEY_M_ALT
))) {
1619 /* Ctrl-Shift-Enter */
1620 if (parm
== (KEY_M_CTRL
| KEY_M_SHIFT
| '\n')) {
1621 copy_current_pathname ();
1626 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
))
1627 && !quote
&& !current_panel
->searching
) {
1628 if (!only_leading_plus_minus
) {
1629 /* Special treatement, since the input line will eat them */
1635 if (parm
== '\\' || parm
== '-') {
1641 reverse_selection_cmd ();
1644 } else if (!command_prompt
|| !cmdline
->buffer
[0]) {
1645 /* Special treatement '+', '-', '\', '*' only when this is
1646 * first char on input line
1654 if (parm
== '\\' || parm
== '-') {
1660 reverse_selection_cmd ();
1665 return MSG_NOT_HANDLED
;
1667 case DLG_HOTKEY_HANDLED
:
1668 if ((get_current_type () == view_listing
) && current_panel
->searching
) {
1669 current_panel
->searching
= 0;
1670 current_panel
->dirty
= 1;
1674 case DLG_UNHANDLED_KEY
:
1675 if (command_prompt
) {
1678 v
= send_message ((Widget
*) cmdline
, WIDGET_KEY
, parm
);
1682 if (ctl_x_map_enabled
) {
1683 ctl_x_map_enabled
= 0;
1684 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1685 if (parm
== ctl_x_map
[i
].key_code
) {
1686 (*ctl_x_map
[i
].fn
) ();
1690 for (i
= 0; default_map
[i
].key_code
; i
++) {
1691 if (parm
== default_map
[i
].key_code
) {
1692 (*default_map
[i
].fn
) ();
1697 return MSG_NOT_HANDLED
;
1700 /* We handle the special case of the output lines */
1701 if (console_flag
&& output_lines
)
1702 show_console_contents (output_start_y
,
1703 LINES
- output_lines
- keybar_visible
-
1704 1, LINES
- keybar_visible
- 1);
1708 if (!the_menubar
->active
)
1709 update_dirty_panels ();
1713 return default_dlg_callback (h
, msg
, parm
);
1717 /* Show current directory in the xterm title */
1719 update_xterm_title_path (void)
1722 char host
[BUF_TINY
];
1724 struct passwd
*pw
= NULL
;
1727 if (xterm_flag
&& xterm_title
) {
1728 path
= strip_home_and_password (current_panel
->cwd
);
1729 res
= gethostname(host
, sizeof (host
));
1730 if ( res
) { /* On success, res = 0 */
1733 host
[sizeof (host
) - 1] = '\0';
1735 pw
= getpwuid(getuid());
1737 login
= g_strdup_printf ("%s@%s", pw
->pw_name
, host
);
1739 login
= g_strdup (host
);
1741 p
= g_strdup_printf ("mc [%s]:%s", login
, path
);
1742 fprintf (stdout
, "\33]0;%s\7", str_term_form (p
));
1745 if (!alternate_plus_minus
)
1746 numeric_keypad_mode ();
1752 * Load new hint and display it.
1753 * IF force is not 0, ignore the timeout.
1756 load_hint (int force
)
1760 if (!the_hint
->widget
.parent
)
1763 if (!message_visible
) {
1764 label_set_text (the_hint
, 0);
1768 if ((hint
= get_random_hint (force
))) {
1773 char text
[BUF_SMALL
];
1775 g_snprintf (text
, sizeof (text
), _("GNU Midnight Commander %s\n"),
1782 setup_panels_and_run_mc (void)
1784 add_widget (midnight_dlg
, the_menubar
);
1785 add_widget (midnight_dlg
, get_panel_widget (0));
1786 add_widget (midnight_dlg
, get_panel_widget (1));
1787 add_widget (midnight_dlg
, the_hint
);
1789 add_widget (midnight_dlg
, cmdline
);
1790 add_widget (midnight_dlg
, the_prompt
);
1791 add_widget (midnight_dlg
, the_bar
);
1794 if (boot_current_is_left
)
1795 dlg_select_widget (get_panel_widget (0));
1797 dlg_select_widget (get_panel_widget (1));
1799 /* Run the Midnight Commander if no file was specified in the command line */
1800 run_dlg (midnight_dlg
);
1803 /* result must be free'd (I think this should go in util.c) */
1805 prepend_cwd_on_local (const char *filename
)
1810 if (vfs_file_is_local (filename
)) {
1811 if (*filename
== PATH_SEP
) /* an absolute pathname */
1812 return g_strdup (filename
);
1813 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
1814 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1817 strcpy (d
+ l
, filename
);
1818 canonicalize_pathname (d
);
1821 return g_strdup (filename
);
1825 mc_maybe_editor_or_viewer (void)
1827 if (!(view_one_file
|| edit_one_file
))
1832 /* Invoke the internal view/edit routine with:
1833 * the default processing and forcing the internal viewer/editor
1835 if (view_one_file
) {
1837 path
= prepend_cwd_on_local (view_one_file
);
1838 view_file (path
, 0, 1);
1841 #ifdef USE_INTERNAL_EDIT
1843 edit_file (edit_one_file
, edit_one_file_start_line
);
1845 #endif /* USE_INTERNAL_EDIT */
1846 midnight_shutdown
= 1;
1851 /* Run the main dialog that occupies the whole screen */
1855 const int midnight_colors
[4] =
1857 NORMAL_COLOR
, /* NORMALC */
1858 REVERSE_COLOR
, /* FOCUSC */
1859 INPUT_COLOR
, /* HOT_NORMALC */
1860 NORMAL_COLOR
/* HOT_FOCUSC */
1863 midnight_dlg
= create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
,
1864 "[main]", NULL
, DLG_WANT_IDLE
);
1866 /* start check display_codepage and source_codepage */
1869 /* Check if we were invoked as an editor or file viewer */
1870 if (!mc_maybe_editor_or_viewer ()) {
1872 setup_panels_and_run_mc ();
1875 midnight_shutdown
= 1;
1877 /* destroy_dlg destroys even current_panel->cwd, so we have to save a copy :) */
1878 if (last_wd_file
&& vfs_current_is_local ()) {
1879 last_wd_string
= g_strdup (current_panel
->cwd
);
1883 destroy_dlg (midnight_dlg
);
1888 /* POSIX version. The only version we support. */
1892 const char *shell_env
= getenv ("SHELL");
1893 const char *mc_libdir
;
1895 if ((shell_env
== NULL
) || (shell_env
[0] == '\0')) {
1897 pwd
= getpwuid (geteuid ());
1899 shell
= g_strdup (pwd
->pw_shell
);
1901 shell
= g_strdup (shell_env
);
1903 if ((shell
== NULL
) || (shell
[0] == '\0')) {
1905 shell
= g_strdup ("/bin/sh");
1908 /* This is the directory, where MC was installed, on Unix this is DATADIR */
1909 /* and can be overriden by the MC_DATADIR environment variable */
1910 mc_libdir
= getenv ("MC_DATADIR");
1911 if (mc_libdir
!= NULL
) {
1912 mc_home
= g_strdup (mc_libdir
);
1913 mc_home_alt
= g_strdup (SYSCONFDIR
);
1915 mc_home
= g_strdup (SYSCONFDIR
);
1916 mc_home_alt
= g_strdup (DATADIR
);
1919 /* This variable is used by the subshell */
1920 home_dir
= getenv ("HOME");
1928 sigchld_handler_no_subshell (int sig
)
1936 /* COMMENT: if it were true that after the call to handle_console(..INIT)
1937 the value of console_flag never changed, we could simply not install
1938 this handler at all if (!console_flag && !use_subshell). */
1940 /* That comment is no longer true. We need to wait() on a sigchld
1941 handler (that's at least what the tarfs code expects currently). */
1943 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
1945 if (pid
== cons_saver_pid
) {
1947 if (WIFSTOPPED (status
)) {
1948 /* Someone has stopped cons.saver - restart it */
1949 kill (pid
, SIGCONT
);
1951 /* cons.saver has died - disable console saving */
1952 handle_console (CONSOLE_DONE
);
1956 /* If we got here, some other child exited; ignore it */
1957 #endif /* __linux__ */
1965 struct sigaction sigchld_action
;
1967 sigchld_action
.sa_handler
=
1968 #ifdef HAVE_SUBSHELL_SUPPORT
1969 use_subshell
? sigchld_handler
:
1970 #endif /* HAVE_SUBSHELL_SUPPORT */
1971 sigchld_handler_no_subshell
;
1973 sigemptyset (&sigchld_action
.sa_mask
);
1976 sigchld_action
.sa_flags
= SA_RESTART
;
1978 sigchld_action
.sa_flags
= 0;
1979 #endif /* !SA_RESTART */
1981 if (sigaction (SIGCHLD
, &sigchld_action
, NULL
) == -1) {
1982 #ifdef HAVE_SUBSHELL_SUPPORT
1984 * This may happen on QNX Neutrino 6, where SA_RESTART
1985 * is defined but not implemented. Fallback to no subshell.
1988 #endif /* HAVE_SUBSHELL_SUPPORT */
1993 print_mc_usage (poptContext ctx
, FILE *stream
)
1997 poptSetOtherOptionHelp (ctx
,
1998 _("[flags] [this_dir] [other_panel_dir]\n"));
2000 /* print help for options */
2001 leftColWidth
= poptPrintHelp (ctx
, stream
, 0);
2002 fprintf (stream
, " %-*s %s\n", leftColWidth
, _("+number"),
2003 _("Set initial line number for the internal editor"));
2006 "Please send any bug reports (including the output of `mc -V')\n"
2007 "to mc-devel@gnome.org\n"), stream
);
2012 print_color_usage (void)
2015 * FIXME: undocumented keywords: viewunderline, editnormal, editbold,
2016 * and editmarked. To preserve translations, lines should be split.
2018 /* TRANSLATORS: don't translate keywords and names of colors */
2020 ("--colors KEYWORD={FORE},{BACK}\n\n"
2021 "{FORE} and {BACK} can be omitted, and the default will be used\n"
2023 " Global: errors, reverse, gauge, input, viewunderline\n"
2024 " File display: normal, selected, marked, markselect\n"
2025 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus, errdhotnormal,\n"
2027 " Menus: menu, menuhot, menusel, menuhotsel\n"
2028 " Editor: editnormal, editbold, editmarked, editwhitespace,\n"
2029 " editlinestate\n"), stdout
);
2032 " Help: helpnormal, helpitalic, helpbold, helplink, helpslink\n"
2033 " File types: directory, executable, link, stalelink, device, special, core\n"
2035 " black, gray, red, brightred, green, brightgreen, brown,\n"
2036 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2037 " brightcyan, lightgray and white\n\n"), stdout
);
2041 process_args (poptContext ctx
, int c
, const char *option_arg
)
2050 disable_colors
= FALSE
;
2051 force_colors
= TRUE
; /* for S-Lang only */
2055 printf ("%s (%s)\n", mc_home
, mc_home_alt
);
2061 mc_setctl ("/#ftp:", VFS_SETCTL_LOGFILE
, (void *) option_arg
);
2063 smbfs_set_debugf (option_arg
);
2064 #endif /* WITH_SMBFS */
2069 smbfs_set_debug (atoi (option_arg
));
2071 #endif /* WITH_SMBFS */
2072 #endif /* USE_NETCODE */
2075 use_mouse_p
= MOUSE_DISABLED
;
2078 #ifdef HAVE_SUBSHELL_SUPPORT
2082 #endif /* HAVE_SUBSHELL_SUPPORT */
2085 print_color_usage ();
2090 print_mc_usage (ctx
, stdout
);
2095 static const struct poptOption argument_table
[] = {
2096 /* generic options */
2097 {"help", 'h', POPT_ARG_NONE
, {NULL
}, 'h',
2098 N_("Displays this help message"), NULL
},
2099 {"version", 'V', POPT_ARG_NONE
, {NULL
}, 'V',
2100 N_("Displays the current version"), NULL
},
2102 /* terminal options */
2103 {"xterm", 'x', POPT_ARG_NONE
, {&force_xterm
}, 0,
2104 N_("Forces xterm features"), NULL
},
2105 {"nomouse", 'd', POPT_ARG_NONE
, {NULL
}, 'd',
2106 N_("Disable mouse support in text version"), NULL
},
2107 #if defined(HAVE_SLANG)
2108 {"termcap", 't', 0, {&SLtt_Try_Termcap
}, 0,
2109 N_("Tries to use termcap instead of terminfo"), NULL
},
2111 {"resetsoft", 'k', POPT_ARG_NONE
, {&reset_hp_softkeys
}, 0,
2112 N_("Resets soft keys on HP terminals"), NULL
},
2113 {"slow", 's', POPT_ARG_NONE
, {&slow_terminal
}, 0,
2114 N_("To run on slow terminals"), NULL
},
2115 {"stickchars", 'a', POPT_ARG_NONE
, {&ugly_line_drawing
}, 0,
2116 N_("Use stickchars to draw"), NULL
},
2119 {"nocolor", 'b', POPT_ARG_NONE
, {&disable_colors
}, 0,
2120 N_("Requests to run in black and white"), NULL
},
2121 {"color", 'c', POPT_ARG_NONE
, {NULL
}, 'c',
2122 N_("Request to run in color mode"), NULL
},
2123 {"colors", 'C', POPT_ARG_STRING
, {&command_line_colors
}, 0,
2124 N_("Specifies a color configuration"), NULL
},
2125 {"help-colors", 'H', POPT_ARG_NONE
, {NULL
}, 'H',
2126 N_("Displays a help screen on how to change the color scheme"), NULL
},
2130 {"ftplog", 'l', POPT_ARG_STRING
, {NULL
}, 'l',
2131 N_("Log ftp dialog to specified file"), NULL
},
2133 {"debuglevel", 'D', POPT_ARG_STRING
, {NULL
}, 'D',
2134 N_("Set debug level"), NULL
},
2138 /* options for wrappers */
2139 {"datadir", 'f', POPT_ARG_NONE
, {NULL
}, 'f',
2140 N_("Print data directory"), NULL
},
2141 {"printwd", 'P', POPT_ARG_STRING
, {&last_wd_file
}, 0,
2142 N_("Print last working directory to specified file"), NULL
},
2144 /* subshell options */
2145 #ifdef HAVE_SUBSHELL_SUPPORT
2146 {"subshell", 'U', POPT_ARG_NONE
, {&use_subshell
}, 0,
2147 N_("Enables subshell support (default)"), NULL
},
2148 {"nosubshell", 'u', POPT_ARG_NONE
, {NULL
}, 'u',
2149 N_("Disables subshell support"), NULL
},
2152 /* single file operations */
2153 {"view", 'v', POPT_ARG_STRING
, {&view_one_file
}, 0,
2154 N_("Launches the file viewer on a file"), NULL
},
2155 #ifdef USE_INTERNAL_EDIT
2156 {"edit", 'e', POPT_ARG_STRING
, {&edit_one_file
}, 0,
2157 N_("Edits one file"), NULL
},
2160 {NULL
, '\0', 0, {NULL
}, 0, NULL
, NULL
}
2164 handle_args (int argc
, char *argv
[])
2172 poptGetContext ("mc", argc
, argv
, argument_table
,
2173 POPT_CONTEXT_NO_EXEC
);
2175 while ((c
= poptGetNextOpt (ctx
)) > 0) {
2176 process_args (ctx
, c
, poptGetOptArg (ctx
));
2180 print_mc_usage (ctx
, stderr
);
2181 fprintf (stderr
, "%s: %s\n",
2182 poptBadOption (ctx
, POPT_BADOPTION_NOALIAS
),
2187 tmp
= poptGetArg (ctx
);
2190 * Check for special invocation names mcedit and mcview,
2191 * if none apply then set the current directory and the other
2192 * directory from the command line arguments
2194 base
= x_basename (argv
[0]);
2195 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP (base
, "vi")) {
2199 * Check for filename:lineno, followed by an optional colon.
2200 * This format is used by many programs (especially compilers)
2201 * in error messages and warnings. It is supported so that
2202 * users can quickly copy and paste file locations.
2204 char *end
= tmp
+ strlen (tmp
), *p
= end
;
2205 if (p
> tmp
&& p
[-1] == ':')
2207 while (p
> tmp
&& g_ascii_isdigit ((gchar
) p
[-1]))
2209 if (tmp
< p
&& p
< end
&& p
[-1] == ':') {
2211 gchar
*fname
= g_strndup (tmp
, p
- 1 - tmp
);
2213 * Check that the file before the colon actually exists.
2214 * If it doesn't exist, revert to the old behavior.
2216 if (mc_stat (tmp
, &st
) == -1 && mc_stat (fname
, &st
) != -1) {
2217 edit_one_file
= fname
;
2218 edit_one_file_start_line
= atoi (p
);
2221 goto try_plus_filename
;
2225 if (*tmp
== '+' && g_ascii_isdigit ((gchar
) tmp
[1])) {
2226 int start_line
= atoi (tmp
);
2227 if (start_line
> 0) {
2228 char *file
= poptGetArg (ctx
);
2231 edit_one_file_start_line
= start_line
;
2235 edit_one_file
= g_strdup (tmp
);
2238 } else if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP (base
, "view")) {
2240 view_one_file
= g_strdup (tmp
);
2242 fputs ("No arguments given to the viewer\n", stderr
);
2246 /* sets the current dir and the other dir */
2248 this_dir
= g_strdup (tmp
);
2249 if ((tmp
= poptGetArg (ctx
)))
2250 other_dir
= g_strdup (tmp
);
2254 poptFreeContext (ctx
);
2258 main (int argc
, char *argv
[])
2263 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2264 setlocale (LC_ALL
, "");
2265 bindtextdomain ("mc", LOCALEDIR
);
2268 /* Set up temporary directory */
2273 str_init_strings (NULL
);
2277 #ifdef USE_INTERNAL_EDIT
2282 SLtt_Ignore_Beep
= 1;
2285 handle_args (argc
, argv
);
2287 /* NOTE: This has to be called before tty_init or whatever routine
2288 calls any define_sequence */
2291 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
2292 handle_console (CONSOLE_INIT
);
2294 #ifdef HAVE_SUBSHELL_SUPPORT
2295 /* Don't use subshell when invoked as viewer or editor */
2296 if (edit_one_file
|| view_one_file
)
2300 subshell_get_console_attributes ();
2301 #endif /* HAVE_SUBSHELL_SUPPORT */
2303 /* Install the SIGCHLD handler; must be done before init_subshell() */
2306 /* We need this, since ncurses endwin () doesn't restore the signals */
2307 save_stop_handler ();
2309 /* Must be done before init_subshell, to set up the terminal size: */
2310 /* FIXME: Should be removed and LINES and COLS computed on subshell */
2311 tty_init ((gboolean
) slow_terminal
, (gboolean
) ugly_line_drawing
);
2315 tty_init_colors (disable_colors
, force_colors
);
2316 dlg_set_default_colors ();
2318 /* create home directory */
2319 /* do it after the screen library initialization to show the error message */
2320 mc_dir
= concat_dir_and_file (home_dir
, MC_BASE
);
2321 canonicalize_pathname (mc_dir
);
2322 if ((stat (mc_dir
, &s
) != 0) && (errno
== ENOENT
)
2323 && mkdir (mc_dir
, 0700) != 0)
2324 message (D_ERROR
, _("Warning"),
2325 _("Cannot create %s directory"), mc_dir
);
2328 init_xterm_support ();
2330 #ifdef HAVE_SUBSHELL_SUPPORT
2331 /* Done here to ensure that the subshell doesn't */
2332 /* inherit the file descriptors opened below, etc */
2336 #endif /* HAVE_SUBSHELL_SUPPORT */
2338 /* Removing this from the X code let's us type C-c */
2341 /* Also done after init_subshell, to save any shell init file messages */
2343 handle_console (CONSOLE_SAVE
);
2345 if (alternate_plus_minus
)
2346 application_keypad_mode ();
2348 #ifdef HAVE_SUBSHELL_SUPPORT
2350 prompt
= strip_ctrl_codes (subshell_prompt
);
2354 #endif /* HAVE_SUBSHELL_SUPPORT */
2355 prompt
= (geteuid () == 0) ? "# " : "$ ";
2357 /* Program main loop */
2358 if (!midnight_shutdown
)
2361 /* Save the tree store */
2364 /* Virtual File System shutdown */
2367 flush_extension_file (); /* does only free memory */
2371 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
2372 handle_console (CONSOLE_RESTORE
);
2373 if (alternate_plus_minus
)
2374 numeric_keypad_mode ();
2376 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
2379 handle_console (CONSOLE_DONE
);
2380 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
2382 if (last_wd_file
&& last_wd_string
&& !print_last_revert
2383 && !edit_one_file
&& !view_one_file
) {
2385 open (last_wd_file
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_EXCL
,
2388 if (last_wd_fd
!= -1) {
2389 write (last_wd_fd
, last_wd_string
, strlen (last_wd_string
));
2393 g_free (last_wd_string
);
2395 g_free (mc_home_alt
);
2401 free_codepages_list ();
2403 str_uninit_strings ();
2408 #ifdef USE_INTERNAL_EDIT