1 /* Main program for the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997 The Free Software Foundation
4 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
5 1994, 1995 Janne Kukonlehto
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 # define INCL_DOSFILEMGR
32 # define INCL_DOSERRORS
40 #include <sys/types.h>
41 #include <sys/param.h>
49 /* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
50 #if defined(HAVE_DIRENT_H) || defined(_POSIX_VERSION)
52 # define NLENGTH(dirent) (strlen ((dirent)->d_name))
54 # define dirent direct
55 # define NLENGTH(dirent) ((dirent)->d_namlen)
57 # ifdef HAVE_SYS_NDIR_H
58 # include <sys/ndir.h>
59 # endif /* HAVE_SYS_NDIR_H */
61 # ifdef HAVE_SYS_DIR_H
63 # endif /* HAVE_SYS_DIR_H */
67 # endif /* HAVE_NDIR_H */
68 #endif /* not (HAVE_DIRENT_H or _POSIX_VERSION) */
71 # include <sys/wait.h> /* For waitpid() */
75 #ifndef HAS_NO_GRP_PWD_H
79 #include <fcntl.h> /* For O_RDWR */
83 # include <libgnorba/gnorba.h>
88 /* Program include files */
103 #include "cons.saver.h"
104 #include "subshell.h"
105 #include "key.h" /* For init_key() and mi_getch() */
106 #include "setup.h" /* save_setup() */
107 #include "profile.h" /* free_profiles() */
110 #include "cmd.h" /* Normal commands */
112 #include "panelize.h"
116 #include "listmode.h"
117 #include "background.h"
118 #include "ext.h" /* For flush_extension_file() */
120 /* Listbox for the command history feature */
124 #include "complete.h" /* For the free_completion */
126 #include "textconf.h"
139 #include "../vfs/vfs.h"
140 #include "../vfs/extfs.h"
147 #include "gsession.h"
148 #ifdef HAVE_GNOME_WINDOW_ICON
149 # include <libgnomeui/gnome-window-icon.h>
155 /* When the modes are active, left_panel, right_panel and tree_panel */
156 /* Point to a proper data structure. You should check with the functions */
157 /* get_current_type and get_other_type the types of the panels before using */
158 /* This pointer variables */
160 /* The structures for the panels */
164 /* The pointer to the tree */
172 /* Pointers to the selected and unselected panel */
173 WPanel
*current_panel
= NULL
;
175 /* Set when we want use advanced chmod command instead of chmod and/or chown */
176 int advanced_chfns
= 0;
178 /* Set when main loop should be terminated */
179 volatile int quit
= 0;
181 /* Set if you want the possible completions dialog for the first time */
182 int show_all_if_ambiguous
= 0;
184 /* Set when cd symlink following is desirable (bash mode) */
191 /* If set then dialogs just clean the screen when refreshing, else */
192 /* they do a complete refresh, refreshing all the parts of the program */
193 int fast_refresh
= 0;
195 /* If true, marking a files moves the cursor down */
196 int mark_moves_down
= 1;
198 /* If true, at startup the user-menu is invoked */
201 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\
202 and M-- and keypad + / - */
203 int alternate_plus_minus
= 0;
205 /* If true, then the +, - and \ keys have their special meaning only if the
206 * command line is emtpy, otherwise they behave like regular letters
208 int only_leading_plus_minus
= 1;
210 /* If true, after executing a command, wait for a keystroke */
211 enum { pause_never
, pause_on_dumb_terminals
, pause_always
};
213 int pause_after_run
= pause_on_dumb_terminals
;
215 /* It true saves the setup when quitting */
216 int auto_save_setup
= 1;
219 /* If true, be eight bit clean */
220 int eight_bit_clean
= 1;
222 /* If true, then display chars 0-255, else iso-8859-1,
223 requires eight_bit_clean */
224 int full_eight_bits
= 1;
227 /* If true use the internal viewer */
228 int use_internal_view
= 1;
230 /* Have we shown the fast-reload warning in the past? */
231 int fast_reload_w
= 0;
233 /* Move page/item? When clicking on the top or bottom of a panel */
234 int mouse_move_pages
= 1;
236 /* If true: l&r arrows are used to chdir if the input line is empty */
237 int navigate_with_arrows
= 0;
239 /* If it is set, the commander will iconify itself when executing a program */
240 int iconify_on_exec
= 1;
242 /* If true use +, -, | for line drawing */
243 int force_ugly_line_drawing
= 0;
245 /* If true message "The shell is already running a command" never */
246 int force_subshell_execution
= 0;
248 /* If true program softkeys (HP terminals only) on startup and after every
249 command ran in the subshell to the description found in the termcap/terminfo
251 int reset_hp_softkeys
= 0;
256 /* The widget where we draw the prompt */
265 /* For slow terminals */
266 int slow_terminal
= 0;
269 int use_mouse_p
= GPM_MOUSE
;
271 /* If true, assume we are running on an xterm terminal */
272 static int force_xterm
= 0;
274 /* Controls screen clearing before an exec */
275 int clear_before_exec
= 1;
277 /* Asks for confirmation before deleting a file */
278 int confirm_delete
= 1;
280 /* Asks for confirmation before overwriting a file */
281 int confirm_overwrite
= 1;
283 /* Asks for confirmation before executing a program by pressing enter */
284 int confirm_execute
= 0;
286 /* Asks for confirmation before leaving the program */
287 int confirm_exit
= 1;
289 /* Asks for confirmation when using F3 to view a directory and there
291 int confirm_view_dir
= 0;
293 /* This flag indicates if the pull down menus by default drop down */
296 /* The dialog handle for the main program */
297 Dlg_head
*midnight_dlg
;
299 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
300 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
301 int update_prompt
= 0;
303 /* The name which was used to invoke mc */
306 /* The home directory */
309 /* The value of the other directory, only used when loading the setup */
313 /* If this is true, then when browsing the tree the other window will
314 * automatically reload it's directory with the contents of the currently
315 * selected directory.
319 /* If true, then print on stdout the last directory we were at */
320 static int print_last_wd
= 0;
321 static char *last_wd_string
;
322 static int print_last_revert
= 0;
324 /* On OS/2 and on Windows NT, we need a batch file to do the -P magic */
326 static char *batch_file_name
= 0;
329 /* widget colors for the midnight commander */
330 int midnight_colors
[4];
332 /* Force colors, only used by Slang */
333 int force_colors
= 0;
335 /* colors specified on the command line: they override any other setting */
336 char *command_line_colors
;
338 /* File name to view if argument was supplied */
339 char *view_one_file
= 0;
341 /* File name to edit if argument was supplied */
342 char *edit_one_file
= 0;
343 static int edit_one_file_start_line
= 1;
345 /* Used so that widgets know if they are being destroyed or
347 int midnight_shutdown
= 0;
349 /* to show nice prompts */
350 static int last_paused
= 0;
352 /* Only used at program boot */
353 int boot_current_is_left
= 1;
355 /* Used for keeping track of the original stdout */
358 /* The user's shell */
361 /* mc_home: The home of MC */
364 /* if on, it displays the information that files have been moved to ~/.mc */
365 int show_change_notice
= 0;
369 /* Used during argument processing */
370 int finish_program
= 0;
372 /* If set, then no windows are displayed in the GNOME edition */
373 int nowindows
= 0, nodesktop
= 0, twopanel
;
375 /* If set it displays the directory that holds the gnome .links files */
376 int display_linksdir
= 0;
378 /* Forward declarations */
379 char *get_mc_lib_dir ();
380 int panel_event (Gpm_Event
*event
, WPanel
*panel
);
381 int menu_bar_event (Gpm_Event
*event
, void *);
384 static void menu_cmd (void);
389 return current_panel
;
395 return (WPanel
*) get_panel_widget (get_other_index ());
400 try_to_select (WPanel
*panel
, char *name
)
402 Xtry_to_select (panel
, name
);
406 display_mini_info (panel
);
410 reload_panelized (WPanel
*panel
)
413 dir_list
*list
= &panel
->dir
;
416 mc_chdir (panel
->cwd
);
418 for (i
= 0, j
= 0; i
< panel
->count
; i
++){
419 if (list
->list
[i
].f
.marked
) {
420 /* Unmark the file in advance. In case the following mc_lstat
421 * fails we are done, else we have to mark the file again
422 * (Note: do_file_mark depends on a valid "list->list [i].buf").
423 * IMO that's the best way to update the panel's summary status
426 do_file_mark (panel
, i
, 0);
428 if (mc_lstat (list
->list
[i
].fname
, &list
->list
[i
].buf
)){
429 g_free (list
->list
[i
].fname
);
432 if (list
->list
[i
].f
.marked
)
433 do_file_mark (panel
, i
, 1);
435 list
->list
[j
] = list
->list
[i
];
439 panel
->count
= set_zero_dir (list
);
444 mc_chdir (cpanel
->cwd
);
448 update_one_panel_widget (WPanel
*panel
, int force_update
, char *current_file
)
452 if (force_update
& UP_RELOAD
){
453 panel
->is_panelized
= 0;
458 /* FIXME: Should supply flushdir method */
459 memset (&(panel
->dir_stat
), 0, sizeof (panel
->dir_stat
));
462 /* If current_file == -1 (an invalid pointer) then preserve selection */
463 if (current_file
== UP_KEEPSEL
){
465 current_file
= g_strdup (panel
->dir
.list
[panel
->selected
].fname
);
469 if (panel
->is_panelized
)
470 reload_panelized (panel
);
472 panel_reload (panel
);
474 try_to_select (panel
, current_file
);
478 g_free (current_file
);
487 panel_clean_dir (WPanel
*panel
)
489 int count
= panel
->count
;
495 panel
->dirs_marked
= 0;
497 panel
->searching
= 0;
498 panel
->is_panelized
= 0;
500 clean_dir (&panel
->dir
, count
);
503 #ifndef PORT_HAS_UPDATE_PANELS
505 update_one_panel (int which
, int force_update
, char *current_file
)
509 if (get_display_type (which
) != view_listing
)
512 panel
= (WPanel
*) get_panel_widget (which
);
513 update_one_panel_widget (panel
, force_update
, current_file
);
516 /* This routine reloads the directory in both panels. It tries to
517 * select current_file in current_panel and other_file in other_panel.
518 * If current_file == -1 then it automatically sets current_file and
519 * other_file to the currently selected files in the panels.
521 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
522 * will not reload the other panel.
525 update_panels (int force_update
, char *current_file
)
527 int reload_other
= !(force_update
& UP_ONLY_CURRENT
);
530 update_one_panel (get_current_index (), force_update
, current_file
);
532 update_one_panel (get_other_index (), force_update
, UP_KEEPSEL
);
534 if (get_current_type () == view_listing
)
535 panel
= (WPanel
*) get_panel_widget (get_current_index ());
537 panel
= (WPanel
*) get_panel_widget (get_other_index ());
539 mc_chdir (panel
->cwd
);
544 static void select_by_index (WPanel
*panel
, int i
);
546 /* Called by parse_control_file */
547 static int index_by_name (file_entry
*list
, int count
)
552 name
= strtok (NULL
, " \t\n");
555 for (i
= 0; i
< count
; i
++){
556 if (strcmp (name
, list
[i
].fname
) == 0)
562 /* Called by parse_control_file */
563 static void select_by_index (WPanel
*panel
, int i
)
565 if (i
>= panel
->count
)
568 unselect_item (panel
);
572 while (panel
->selected
- panel
->top_file
>= ITEMS (panel
)){
573 /* Scroll window half screen */
574 panel
->top_file
+= ITEMS (panel
)/2;
578 while (panel
->selected
< panel
->top_file
){
579 /* Scroll window half screen */
580 panel
->top_file
-= ITEMS (panel
)/2;
581 if (panel
->top_file
< 0) panel
->top_file
= 0;
588 /* Called by my_system
589 No error reporting, just exits on the first sign of trouble */
590 static void parse_control_file (void)
592 char *data
, *current
;
599 if ((file
= fopen (control_file
, "r")) == NULL
){
602 /* Use of fstat prevents race conditions */
603 if (fstat (fileno (file
), &s
) != 0){
608 /* Security: Check that the user owns the control file and this file
609 is not group/world writable to prevent other users from playing tricks
611 if (s
.st_uid
!= getuid () || ((s
.st_mode
) & (S_IWGRP
|S_IWOTH
))) {
616 data
= (char *) g_malloc (s
.st_size
+1);
621 if (s
.st_size
!= fread (data
, 1, s
.st_size
, file
)){
626 data
[s
.st_size
] = 0;
629 /* The Control file has now been loaded to memory -> start parsing. */
630 current
= strtok (data
, " \t\n");
631 while (current
&& *current
){
632 if (isupper (*current
)){
633 if (get_other_type () != view_listing
)
640 list
= panel
->dir
.list
;
641 *current
= tolower (*current
);
643 if (strcmp (current
, "clear_tags") == 0){
644 unmark_files (panel
);
645 } else if (strcmp (current
, "tag") == 0){
646 i
= index_by_name (list
, panel
->count
);
648 do_file_mark (panel
, i
, 1);
650 } else if (strcmp (current
, "untag") == 0){
651 i
= index_by_name (list
, panel
->count
);
653 do_file_mark (panel
, i
, 0);
655 } else if (strcmp (current
, "select") == 0){
656 i
= index_by_name (list
, panel
->count
);
658 select_by_index (panel
, i
);
660 } else if (strcmp (current
, "change_panel") == 0){
662 } else if (strcmp (current
, "cd") == 0){
664 current
= strtok (NULL
, " \t\n");
666 if (cpanel
!= panel
){
670 do_cd (current
, cd_parse_command
);
674 /* Unknown command -> let's give up */
677 current
= strtok (NULL
, " \t\n");
681 paint_panel (cpanel
);
682 paint_panel (opanel
);
685 #define parse_control_file()
686 #endif /* WANT_PARSE */
688 /* Sets up the terminal before executing a program */
696 /* Save current stat of directories to avoid reloading the panels */
697 /* when no modifications have taken place */
699 save_cwds_stat (void)
702 mc_stat (cpanel
->cwd
, &(cpanel
->dir_stat
));
703 if (get_other_type () == view_listing
)
704 mc_stat (opanel
->cwd
, &(opanel
->dir_stat
));
708 #ifdef HAVE_SUBSHELL_SUPPORT
710 do_possible_cd (char *new_dir
)
712 if (!do_cd (new_dir
, cd_exact
))
713 message (1, _(" Warning "),
714 _(" The Commander can't change to the directory that \n"
715 " the subshell claims you are in. Perhaps you have \n"
716 " deleted your working directory, or given yourself \n"
717 " extra access permissions with the \"su\" command? "));
724 printf ("%s", subshell_prompt
);
732 restore_console (void)
734 handle_console (CONSOLE_RESTORE
);
740 do_execute (shell
, 0, 0);
744 do_execute (const char *shell
, const char *command
, int flags
)
746 #ifdef HAVE_SUBSHELL_SUPPORT
747 char *new_dir
= NULL
;
751 char *old_vfs_dir
= 0;
753 if (!vfs_current_is_local ())
754 old_vfs_dir
= g_strdup (vfs_get_current_dir ());
763 unlink (control_file
);
765 if (!use_subshell
&& !(flags
& EXECUTE_INTERNAL
)){
766 printf ("%s%s%s\n", last_paused
? "\r\n":"", prompt
, command
);
770 #ifdef HAVE_SUBSHELL_SUPPORT
771 if (use_subshell
&& !(flags
& EXECUTE_INTERNAL
)){
774 /* We don't care if it died, higher level takes care of this */
776 invoke_subshell (command
, VISIBLY
, old_vfs_dir
? 0 : &new_dir
);
778 invoke_subshell (command
, VISIBLY
, &new_dir
);
782 my_system (flags
, shell
, command
);
785 if (!(flags
& EXECUTE_INTERNAL
)){
786 if ((pause_after_run
== pause_always
||
787 (pause_after_run
== pause_on_dumb_terminals
&&
788 !xterm_flag
&& !console_flag
)) && !quit
){
789 printf (_("Press any key to continue..."));
796 if (output_lines
&& keybar_visible
) {
805 handle_console (CONSOLE_SAVE
);
806 edition_post_exec ();
808 #ifdef HAVE_SUBSHELL_SUPPORT
810 do_possible_cd (new_dir
);
815 mc_chdir (old_vfs_dir
);
816 g_free (old_vfs_dir
);
820 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
822 parse_control_file ();
824 unlink (control_file
);
830 /* Executes a command */
832 shell_execute (char *command
, int flags
)
834 #ifdef HAVE_SUBSHELL_SUPPORT
836 if (subshell_state
== INACTIVE
|| force_subshell_execution
)
837 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
839 message (1, MSG_ERROR
, _(" The shell is already running a command "));
842 do_execute (shell
, command
, flags
| EXECUTE_AS_SHELL
);
846 execute (char *command
)
848 shell_execute (command
, 0);
854 free_completions (input_w (cmdline
));
855 dlg_one_down (midnight_dlg
);
859 quit_cmd_internal (int quiet
)
863 if (quiet
|| !confirm_exit
){
866 if (query_dialog (_(" The Midnight Commander "),
867 _(" Do you really want to quit the Midnight Commander? "),
868 0, 2, _("&Yes"), _("&No")) == 0)
872 #ifdef HAVE_SUBSHELL_SUPPORT
874 midnight_dlg
->running
= 0;
876 if ((q
= exit_subshell ()))
878 midnight_dlg
->running
= 0;
887 quit_cmd_internal (0);
891 int quiet_quit_cmd (void)
893 print_last_revert
= 1;
894 quit_cmd_internal (1);
899 * Touch window and refresh window functions
902 /* This routine untouches the first line on both panels in order */
903 /* to avoid the refreshing the menu bar */
912 repaint_screen (void)
925 repaint_screen (void)
932 /* Wrapper for do_subshell_chdir, check for availability of subshell */
934 subshell_chdir (char *directory
)
936 #ifdef HAVE_SUBSHELL_SUPPORT
938 if (vfs_current_is_local ())
939 do_subshell_chdir (directory
, 0, 1);
945 directory_history_add (WPanel
* panel
, char *s
)
947 if (!panel
->dir_history
) {
948 panel
->dir_history
= g_new0 (Hist
, 1);
949 panel
->dir_history
->text
= g_strdup (s
);
950 strip_password (panel
->dir_history
->text
, 1);
953 if (!strcmp (panel
->dir_history
->text
, s
))
955 if (panel
->dir_history
->next
) {
956 if (panel
->dir_history
->next
->text
) {
957 g_free (panel
->dir_history
->next
->text
);
958 panel
->dir_history
->next
->text
= 0;
961 panel
->dir_history
->next
= g_new0 (Hist
, 1);
962 panel
->dir_history
->next
->prev
= panel
->dir_history
;
964 panel
->dir_history
= panel
->dir_history
->next
;
965 panel
->dir_history
->text
= g_strdup (s
);
966 strip_password (panel
->dir_history
->text
, 1);
968 panel_update_marks (panel
);
972 * If we moved to the parent directory move the selection pointer to
973 * the old directory name; If we leave VFS dir, remove FS specificator.
974 * Warn: This code spoils lwd string.
976 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
979 get_parent_dir_name (char *cwd
, char *lwd
)
982 if (strlen (lwd
) > strlen (cwd
))
983 if((p
=strrchr(lwd
, PATH_SEP
)) && !strncmp(cwd
, lwd
, p
-lwd
)){
989 /* Changes the current panel directory */
991 _do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
993 char *directory
, *olddir
;
994 char temp
[MC_MAXPATHLEN
];
995 char *translated_url
;
999 struct vfs_stamping
*parent
;
1001 olddir
= g_strdup (panel
->cwd
);
1002 translated_url
= new_dir
= vfs_translate_url (new_dir
);
1004 /* Convert *new_path to a suitable pathname, handle ~user */
1006 if (cd_type
== cd_parse_command
){
1007 while (*new_dir
== ' ')
1010 if (!strcmp (new_dir
, "-")){
1011 strcpy (temp
, panel
->lwd
);
1015 directory
= *new_dir
? new_dir
: home_dir
;
1018 if (is_a_desktop_panel (panel
)) {
1019 new_panel_at (directory
);
1021 g_free (translated_url
);
1022 return 0; /* Don't add to history */
1026 if (mc_chdir (directory
) == -1){
1027 strcpy (panel
->cwd
, olddir
);
1029 g_free (translated_url
);
1032 g_free (translated_url
);
1034 /* Success: save previous directory, shutdown status of previous dir */
1035 strcpy (panel
->lwd
, olddir
);
1036 free_completions (input_w (cmdline
));
1038 mc_get_current_wd (panel
->cwd
, sizeof (panel
->cwd
) - 2);
1041 oldvfs
= vfs_type (olddir
);
1042 oldvfsid
= vfs_ncs_getid (oldvfs
, olddir
, &parent
);
1043 vfs_add_noncurrent_stamps (oldvfs
, oldvfsid
, parent
);
1044 vfs_rm_parents (parent
);
1047 subshell_chdir (panel
->cwd
);
1049 /* Reload current panel */
1050 panel_clean_dir (panel
);
1051 panel
->count
= do_load_dir (&panel
->dir
, panel
->sort_type
,
1052 panel
->reverse
, panel
->case_sensitive
, panel
->filter
);
1053 try_to_select (panel
, get_parent_dir_name (panel
->cwd
, olddir
));
1055 panel_update_contents (panel
);
1063 do_panel_cd (WPanel
*panel
, char *new_dir
, enum cd_enum cd_type
)
1067 r
= _do_panel_cd (panel
, new_dir
, cd_type
);
1069 directory_history_add (cpanel
, cpanel
->cwd
);
1074 do_cd (char *new_dir
, enum cd_enum exact
)
1076 return (do_panel_cd (cpanel
, new_dir
, exact
));
1080 directory_history_next (WPanel
* panel
)
1082 if (!panel
->dir_history
->next
)
1084 if (_do_panel_cd (panel
, panel
->dir_history
->next
->text
, cd_exact
))
1085 panel
->dir_history
= panel
->dir_history
->next
;
1086 panel_update_marks (panel
);
1090 directory_history_prev (WPanel
* panel
)
1092 if (!panel
->dir_history
->prev
)
1094 if (_do_panel_cd (panel
, panel
->dir_history
->prev
->text
, cd_exact
))
1095 panel
->dir_history
= panel
->dir_history
->prev
;
1096 panel_update_marks (panel
);
1100 directory_history_list (WPanel
* panel
)
1103 /* must be at least two to show a history */
1104 if (panel
->dir_history
) {
1105 if (panel
->dir_history
->prev
|| panel
->dir_history
->next
) {
1106 s
= show_hist (panel
->dir_history
, panel
->widget
.x
, panel
->widget
.y
);
1109 r
= _do_panel_cd (panel
, s
, cd_exact
);
1111 directory_history_add (panel
, panel
->cwd
);
1118 #ifdef HAVE_SUBSHELL_SUPPORT
1120 load_prompt (int fd
, void *unused
)
1122 if (!read_subshell_prompt (QUIETLY
))
1125 if (command_prompt
){
1128 prompt
= strip_ctrl_codes (subshell_prompt
);
1129 prompt_len
= strlen (prompt
);
1131 /* Check for prompts too big */
1132 if (prompt_len
> COLS
- 8) {
1133 prompt
[COLS
- 8 ] = 0;
1134 prompt_len
= COLS
- 8;
1136 label_set_text (the_prompt
, prompt
);
1137 winput_set_origin ((WInput
*)cmdline
, prompt_len
, COLS
-prompt_len
);
1139 /* since the prompt has changed, and we are called from one of the
1140 * get_event channels, the prompt updating does not take place
1141 * automatically: force a cursor update and a screen refresh
1143 if (current_dlg
== midnight_dlg
){
1144 update_cursor (midnight_dlg
);
1153 /* The user pressed the enter key */
1155 menu_bar_event (Gpm_Event
*event
, void *x
)
1157 if (event
->type
!= GPM_DOWN
)
1163 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1165 maybe_cd (int char_code
, int move_up_dir
)
1167 if (navigate_with_arrows
){
1168 if (!input_w (cmdline
)->buffer
[0]){
1170 do_cd ("..", cd_exact
);
1173 if (S_ISDIR (selection (cpanel
)->buf
.st_mode
)
1174 || link_isdir (selection (cpanel
))){
1175 do_cd (selection (cpanel
)->fname
, cd_exact
);
1184 set_sort_to (WPanel
*p
, sortfn
*sort_order
)
1186 p
->sort_type
= sort_order
;
1188 /* The directory is already sorted, we have to load the unsorted stuff */
1189 if (sort_order
== (sortfn
*) unsorted
){
1192 current_file
= g_strdup (cpanel
->dir
.list
[cpanel
->selected
].fname
);
1193 panel_reload (cpanel
);
1194 try_to_select (cpanel
, current_file
);
1195 g_free (current_file
);
1207 if (!SELECTED_IS_PANEL
)
1211 sort_order
= sort_box (p
->sort_type
, &p
->reverse
, &p
->case_sensitive
);
1213 panel_set_sort_order (p
, sort_order
);
1222 sel_dir
= tree (selection (cpanel
)->fname
);
1224 do_cd(sel_dir
, cd_exact
);
1229 #ifdef LISTMODE_EDITOR
1234 newmode
= listmode_edit ("half <type,>name,|,size:8,|,perm:4+");
1235 message (0, _(" Listing format edit "), _(" New mode is \"%s\" "), newmode
);
1238 #endif /* LISTMODE_EDITOR */
1239 #endif /* !HAVE_GNOME */
1242 void init_menu (void) {};
1243 void done_menu (void) {};
1245 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
1246 static menu_entry PanelMenu
[] = {
1247 { ' ', N_("&Listing mode..."), 'L', listing_cmd
},
1248 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
1249 { ' ', N_("&Info C-x i"), 'I', info_cmd
},
1250 { ' ', N_("&Tree"), 'T', tree_cmd
},
1251 { ' ', "", ' ', 0 },
1252 { ' ', N_("&Sort order..."), 'S', sort_cmd
},
1253 { ' ', "", ' ', 0 },
1254 { ' ', N_("&Filter..."), 'F', filter_cmd
},
1256 { ' ', "", ' ', 0 },
1257 { ' ', N_("&Network link..."), 'N', netlink_cmd
},
1258 { ' ', N_("FT&P link..."), 'P', ftplink_cmd
},
1260 { ' ', N_("SM&B link..."), 'B', smblink_cmd
},
1263 { ' ', "", ' ', 0 },
1265 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_a
},
1267 { ' ', N_("&Rescan C-r"), 'R', reread_cmd
}
1270 static menu_entry RightMenu
[] = {
1271 { ' ', N_("&Listing mode..."), 'L', listing_cmd
},
1272 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd
},
1273 { ' ', N_("&Info C-x i"), 'I', info_cmd
},
1274 { ' ', N_("&Tree"), 'T', tree_cmd
},
1275 { ' ', "", ' ', 0 },
1276 { ' ', N_("&Sort order..."), 'S', sort_cmd
},
1277 { ' ', "", ' ', 0 },
1278 { ' ', N_("&Filter..."), 'F', filter_cmd
},
1280 { ' ', "", ' ', 0 },
1281 { ' ', N_("&Network link..."), 'N', netlink_cmd
},
1282 { ' ', N_("FT&P link..."), 'P', ftplink_cmd
},
1284 { ' ', N_("SM&B link..."), 'B', smblink_cmd
},
1287 { ' ', "", ' ', 0 },
1289 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_b
},
1291 { ' ', N_("&Rescan C-r"), 'R', reread_cmd
}
1294 static menu_entry FileMenu
[] = {
1295 { ' ', N_("&User menu F2"), 'U', user_file_menu_cmd
},
1296 { ' ', N_("&View F3"), 'V', view_cmd
},
1297 { ' ', N_("Vie&w file... "), 'W', view_file_cmd
},
1298 { ' ', N_("&Filtered view M-!"), 'F', filtered_view_cmd
},
1299 { ' ', N_("&Edit F4"), 'E', edit_cmd
},
1300 { ' ', N_("&Copy F5"), 'C', copy_cmd
},
1301 { ' ', N_("c&Hmod C-x c"), 'H', chmod_cmd
},
1303 { ' ', N_("&Link C-x l"), 'L', link_cmd
},
1304 { ' ', N_("&SymLink C-x s"), 'S', symlink_cmd
},
1305 { ' ', N_("edit s&Ymlink C-x C-s"), 'Y', edit_symlink_cmd
},
1306 { ' ', N_("ch&Own C-x o"), 'O', chown_cmd
},
1307 { ' ', N_("&Advanced chown "), 'A', chown_advanced_cmd
},
1309 { ' ', N_("&Rename/Move F6"), 'R', ren_cmd
},
1310 { ' ', N_("&Mkdir F7"), 'M', mkdir_cmd
},
1311 { ' ', N_("&Delete F8"), 'D', delete_cmd
},
1312 { ' ', N_("&Quick cd M-c"), 'Q', quick_cd_cmd
},
1313 { ' ', "", ' ', 0 },
1314 { ' ', N_("select &Group M-+"), 'G', select_cmd
},
1315 { ' ', N_("u&Nselect group M-\\"),'N', unselect_cmd
},
1316 { ' ', N_("reverse selec&Tion M-*"), 'T', reverse_selection_cmd
},
1317 { ' ', "", ' ', 0 },
1318 { ' ', N_("e&Xit F10"), 'X', (callfn
) quit_cmd
}
1321 void external_panelize (void);
1322 static menu_entry CmdMenu
[] = {
1323 /* I know, I'm lazy, but the tree widget when it's not running
1324 * as a panel still has some problems, I have not yet finished
1325 * the WTree widget port, sorry.
1327 { ' ', N_("&Directory tree"), 'D', tree_box
},
1328 { ' ', N_("&Find file M-?"), 'F', find_cmd
},
1329 { ' ', N_("s&Wap panels C-u"), 'W', swap_cmd
},
1330 { ' ', N_("switch &Panels on/off C-o"), 'P', view_other_cmd
},
1331 { ' ', N_("&Compare directories C-x d"), 'C', compare_dirs_cmd
},
1332 { ' ', N_("e&Xternal panelize C-x !"), 'X', external_panelize
},
1333 { ' ', N_("show directory s&Izes"), 'I', dirsizes_cmd
},
1334 { ' ', "", ' ', 0 },
1335 { ' ', N_("command &History"), 'H', history_cmd
},
1336 { ' ', N_("di&Rectory hotlist C-\\"), 'R', quick_chdir_cmd
},
1338 { ' ', N_("&Active VFS list C-x a"), 'A', reselect_vfs
},
1339 { ' ', N_("Fr&ee VFSs now"), 'E', free_vfs_now
},
1341 #ifdef WITH_BACKGROUND
1342 { ' ', N_("&Background jobs C-x j"), 'B', jobs_cmd
},
1344 { ' ', "", ' ', 0 },
1345 #ifdef USE_EXT2FSLIB
1346 { ' ', N_("&Undelete files (ext2fs only)"), 'U', undelete_cmd
},
1348 #ifdef LISTMODE_EDITOR
1349 { ' ', N_("&Listing format edit"), 'L', listmode_cmd
},
1351 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
1352 { ' ', "", ' ', 0 },
1354 { ' ', N_("&Extension file edit"), 'E', ext_cmd
},
1355 { ' ', N_("&Menu file edit"), 'M', menu_edit_cmd
},
1356 #ifdef USE_INTERNAL_EDIT
1357 {' ', N_("Menu edi&Tor edit"), 'T', edit_user_menu_cmd
}
1358 #endif /* USE_INTERNAL_EDIT */
1361 /* Must keep in sync with the constants in menu_cmd */
1362 static menu_entry OptMenu
[] = {
1363 { ' ', N_("&Configuration..."), 'C', configure_box
},
1364 { ' ', N_("&Layout..."), 'L', layout_cmd
},
1365 { ' ', N_("c&Onfirmation..."), 'O', confirm_box
},
1366 { ' ', N_("&Display bits..."), 'D', display_bits_box
},
1368 { ' ', N_("learn &Keys..."), 'K', learn_keys
},
1369 #endif /* !OS2_NT */
1371 { ' ', N_("&Virtual FS..."), 'V', configure_vfs
},
1372 #endif /* !USE_VFS */
1373 { ' ', "", ' ', 0 },
1374 { ' ', N_("&Save setup"), 'S', save_setup_cmd
}
1377 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
1380 static Menu MenuBarEmpty
[5];
1387 MenuBar
[0] = create_menu ( horizontal_split
? _(" &Above ") : _(" &Left "),
1388 PanelMenu
, menu_entries (PanelMenu
));
1389 MenuBar
[1] = create_menu (_(" &File "), FileMenu
, menu_entries (FileMenu
));
1390 MenuBar
[2] = create_menu (_(" &Command "), CmdMenu
, menu_entries (CmdMenu
));
1391 MenuBar
[3] = create_menu (_(" &Options "), OptMenu
, menu_entries (OptMenu
));
1392 MenuBar
[4] = create_menu (horizontal_split
? _(" &Below ") : _(" &Right "),
1393 RightMenu
, menu_entries (PanelMenu
));
1394 for (i
= 0; i
< 5; i
++)
1395 MenuBarEmpty
[i
] = create_menu (MenuBar
[i
]->name
, 0, 0);
1403 for (i
= 0; i
< 5; i
++){
1404 destroy_menu (MenuBar
[i
]);
1405 destroy_menu (MenuBarEmpty
[i
]);
1410 menu_last_selected_cmd (void)
1412 the_menubar
->active
= 1;
1413 the_menubar
->dropped
= drop_menus
;
1414 the_menubar
->previous_selection
= dlg_item_number (midnight_dlg
);
1415 dlg_select_widget (midnight_dlg
, the_menubar
);
1421 if (the_menubar
->active
)
1424 if (get_current_index () == 0)
1425 the_menubar
->selected
= 0;
1427 the_menubar
->selected
= 4;
1428 menu_last_selected_cmd ();
1430 #endif /* !HAVE_GNOME */
1432 /* Flag toggling functions */
1434 toggle_confirm_delete (void)
1436 confirm_delete
= !confirm_delete
;
1440 toggle_fast_reload (void)
1442 fast_reload
= !fast_reload
;
1443 if (fast_reload_w
== 0 && fast_reload
){
1444 message (0, _(" Information "),
1445 _(" Using the fast reload option may not reflect the exact \n"
1446 " directory contents. In this cases you'll need to do a \n"
1447 " manual reload of the directory. See the man page for \n"
1454 toggle_mix_all_files (void)
1456 mix_all_files
= !mix_all_files
;
1457 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1461 toggle_show_backup (void)
1463 show_backups
= !show_backups
;
1464 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1468 toggle_show_hidden (void)
1470 show_dot_files
= !show_dot_files
;
1471 update_panels (UP_RELOAD
, UP_KEEPSEL
);
1475 toggle_show_mini_status (void)
1477 show_mini_info
= !show_mini_info
;
1478 paint_panel (cpanel
);
1479 if (get_other_type () == view_listing
)
1480 paint_panel (opanel
);
1484 toggle_align_extensions (void)
1486 align_extensions
= !align_extensions
;
1490 * Just a hack for allowing url-like pathnames to be accepted from the
1493 #ifndef PORT_HAS_CREATE_PANELS
1495 translated_mc_chdir (char *dir
)
1499 newdir
= vfs_translate_url (dir
);
1505 create_panels (void)
1511 char original_dir
[1024];
1513 original_dir
[0] = 0;
1515 if (boot_current_is_left
){
1518 current_mode
= startup_left_mode
;
1519 other_mode
= startup_right_mode
;
1523 current_mode
= startup_right_mode
;
1524 other_mode
= startup_left_mode
;
1526 /* Creates the left panel */
1529 /* Ok, user has specified two dirs, save the original one,
1530 * since we may not be able to chdir to the proper
1531 * second directory later
1533 mc_get_current_wd (original_dir
, sizeof (original_dir
)-2);
1535 translated_mc_chdir (this_dir
);
1537 set_display_type (current_index
, current_mode
);
1539 /* The other panel */
1541 if (original_dir
[0])
1542 translated_mc_chdir (original_dir
);
1543 translated_mc_chdir (other_dir
);
1545 set_display_type (other_index
, other_mode
);
1547 if (startup_left_mode
== view_listing
){
1548 current_panel
= left_panel
;
1551 current_panel
= right_panel
;
1553 current_panel
= left_panel
;
1556 /* Create the nice widgets */
1557 cmdline
= command_new (0, 0, 0);
1558 the_prompt
= label_new (0, 0, prompt
, NULL
);
1559 the_prompt
->transparent
= 1;
1560 the_bar
= buttonbar_new (keybar_visible
);
1563 the_hint
= label_new (0, 0, 0, NULL
);
1564 the_hint
->transparent
= 1;
1565 the_hint
->auto_adjust_cols
= 0;
1566 the_hint
->widget
.cols
= COLS
;
1569 the_menubar
= menubar_new (0, 0, COLS
, MenuBar
, 5);
1574 static void copy_current_pathname (void)
1576 if (!command_prompt
)
1579 stuff (input_w (cmdline
), cpanel
->cwd
, 0);
1580 if (cpanel
->cwd
[strlen (cpanel
->cwd
) - 1] != PATH_SEP
)
1581 stuff (input_w (cmdline
), PATH_SEP_STR
, 0);
1584 static void copy_other_pathname (void)
1586 if (get_other_type () != view_listing
)
1589 if (!command_prompt
)
1592 stuff (input_w (cmdline
), opanel
->cwd
, 0);
1593 if (cpanel
->cwd
[strlen (opanel
->cwd
) - 1] != PATH_SEP
)
1594 stuff (input_w (cmdline
), PATH_SEP_STR
, 0);
1596 #endif /* !HAVE_GNOME */
1598 static void copy_readlink (WPanel
*panel
)
1600 if (!command_prompt
)
1602 if (S_ISLNK (selection (panel
)->buf
.st_mode
)) {
1603 char buffer
[MC_MAXPATHLEN
];
1604 char *p
= concat_dir_and_file (panel
->cwd
, selection (panel
)->fname
);
1607 i
= mc_readlink (p
, buffer
, MC_MAXPATHLEN
);
1611 stuff (input_w (cmdline
), buffer
, 0);
1616 static void copy_current_readlink (void)
1618 copy_readlink (cpanel
);
1621 static void copy_other_readlink (void)
1623 if (get_other_type () != view_listing
)
1625 copy_readlink (opanel
);
1628 /* Inserts the selected file name into the input line */
1629 /* Exported so that the command modules uses it */
1630 void copy_prog_name (void)
1633 if (!command_prompt
)
1636 if (get_current_type () == view_tree
){
1637 WTree
*tree
= (WTree
*) get_panel_widget (get_current_index ());
1638 tmp
= name_quote (tree
->selected_ptr
->name
, 1);
1640 tmp
= name_quote (selection (cpanel
)->fname
, 1);
1641 stuff (input_w (cmdline
), tmp
, 1);
1646 static void copy_tagged (WPanel
*panel
)
1650 if (!command_prompt
)
1652 input_disable_update (input_w (cmdline
));
1654 for (i
= 0; i
< panel
->count
; i
++)
1655 if (panel
->dir
.list
[i
].f
.marked
) {
1656 char *tmp
= name_quote (panel
->dir
.list
[i
].fname
, 1);
1657 stuff (input_w (cmdline
), tmp
, 1);
1661 char *tmp
= name_quote (panel
->dir
.list
[panel
->selected
].fname
, 1);
1662 stuff (input_w (cmdline
), tmp
, 1);
1665 input_enable_update (input_w (cmdline
));
1668 static void copy_current_tagged (void)
1670 copy_tagged (cpanel
);
1673 static void copy_other_tagged (void)
1675 if (get_other_type () != view_listing
)
1677 copy_tagged (opanel
);
1680 static void do_suspend_cmd (void)
1684 if (console_flag
&& !use_subshell
)
1689 struct sigaction sigtstp_action
;
1691 /* Make sure that the SIGTSTP below will suspend us directly,
1692 without calling ncurses' SIGTSTP handler; we *don't* want
1693 ncurses to redraw the screen immediately after the SIGCONT */
1694 sigaction (SIGTSTP
, &startup_handler
, &sigtstp_action
);
1696 kill (getpid (), SIGTSTP
);
1698 /* Restore previous SIGTSTP action */
1699 sigaction (SIGTSTP
, &sigtstp_action
, NULL
);
1701 #endif /* SIGTSTP */
1703 if (console_flag
&& !use_subshell
)
1704 handle_console (CONSOLE_SAVE
);
1706 edition_post_exec ();
1714 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1719 init_labels (Widget
*paneletc
)
1721 define_label (midnight_dlg
, paneletc
, 1, _("Help"), help_cmd
);
1722 define_label (midnight_dlg
, paneletc
, 2, _("Menu"), user_file_menu_cmd
);
1723 define_label (midnight_dlg
, paneletc
, 9, _("PullDn"), menu_cmd
);
1724 define_label (midnight_dlg
, paneletc
, 10, _("Quit"), (voidfn
) quit_cmd
);
1726 #endif /* !HAVE_GNOME */
1728 static const key_map ctl_x_map
[] = {
1729 { XCTRL('c'), (callfn
) quit_cmd
},
1730 { 'd', compare_dirs_cmd
},
1733 { 'a', reselect_vfs
},
1734 #endif /* USE_VFS */
1735 { 'p', copy_current_pathname
},
1736 { XCTRL('p'), copy_other_pathname
},
1737 { 't', copy_current_tagged
},
1738 { XCTRL('t'), copy_other_tagged
},
1740 #endif /* !HAVE_GNOME */
1744 #endif /* !HAVE_GNOME */
1746 { XCTRL('l'), other_symlink_cmd
},
1747 { 's', symlink_cmd
},
1748 { XCTRL('s'), edit_symlink_cmd
},
1749 { 'r', copy_current_readlink
},
1750 { XCTRL('r'), copy_other_readlink
},
1751 #endif /* !OS2_NT */
1753 { 'i', info_cmd_no_menu
},
1754 { 'q', quick_cmd_no_menu
},
1755 { 'h', add2hotlist_cmd
},
1756 #endif /* !HAVE_GNOME */
1757 { '!', external_panelize
},
1758 #if defined(WITH_BACKGROUND) && !defined(HAVE_GNOME)
1761 #ifdef HAVE_SETSOCKOPT
1762 { '%', source_routing
},
1767 static int ctl_x_map_enabled
= 0;
1769 static void ctl_x_cmd (int ignore
)
1771 ctl_x_map_enabled
= 1;
1774 static void nothing ()
1778 static const key_map default_map
[] = {
1780 { KEY_F(19), menu_last_selected_cmd
},
1781 { KEY_F(20), (key_callback
) quiet_quit_cmd
},
1783 /* Copy useful information to the command line */
1784 { ALT('\n'), copy_prog_name
},
1785 { ALT('\r'), copy_prog_name
},
1786 { ALT('a'), copy_current_pathname
},
1787 { ALT('A'), copy_other_pathname
},
1789 { ALT('c'), quick_cd_cmd
},
1791 /* To access the directory hotlist */
1792 { XCTRL('\\'), quick_chdir_cmd
},
1795 { XCTRL('z'), suspend_cmd
},
1797 /* The filtered view command */
1798 { ALT('!'), filtered_view_cmd_cpanel
},
1801 { ALT('?'), find_cmd
},
1804 { XCTRL('r'), reread_cmd
},
1806 { ALT('t'), toggle_listing_cmd
},
1810 { XCTRL('u'), swap_cmd
},
1813 { XCTRL('o'), view_other_cmd
},
1816 /* Control-X keybindings */
1817 { XCTRL('x'), ctl_x_cmd
},
1819 /* Trap dlg's exit commands */
1820 { ESC_CHAR
, nothing
},
1821 { XCTRL('c'), nothing
},
1822 { XCTRL('g'), nothing
},
1827 static void setup_sigwinch ()
1829 #if (defined(HAVE_SLANG) || (NCURSES_VERSION_MAJOR >= 4)) && \
1830 !defined(OS2_NT) && defined(SIGWINCH)
1831 struct sigaction act
, oact
;
1832 act
.sa_handler
= flag_winch
;
1833 sigemptyset (&act
.sa_mask
);
1836 act
.sa_flags
|= SA_RESTART
;
1838 sigaction (SIGWINCH
, &act
, &oact
);
1845 /* Call all the inits */
1847 int full_eight_bits
= (display_codepage
!= 0 && display_codepage
!= 1);
1851 meta (stdscr
, eight_bit_clean
);
1853 SLsmg_Display_Eight_Bit
= full_eight_bits
? 128 : 160;
1858 #define setup_sigwinch()
1866 init_uid_gid_cache ();
1869 if (baudrate () < 9600 || slow_terminal
){
1876 midnight_colors
[0] = 0;
1877 midnight_colors
[1] = REVERSE_COLOR
; /* FOCUSC */
1878 midnight_colors
[2] = INPUT_COLOR
; /* HOT_NORMALC */
1879 midnight_colors
[3] = NORMAL_COLOR
; /* HOT_FOCUSC */
1882 static void setup_mc (void)
1893 #ifdef HAVE_SUBSHELL_SUPPORT
1895 add_select_channel (subshell_pty
, load_prompt
, 0);
1901 static void setup_dummy_mc (const char *file
)
1903 char d
[MC_MAXPATHLEN
];
1905 mc_get_current_wd (d
, MC_MAXPATHLEN
);
1909 /* Create a fake current_panel, this is needed because the
1910 * expand_format routine will use current panel.
1912 strcpy (cpanel
->cwd
, d
);
1913 cpanel
->selected
= 0;
1915 cpanel
->dir
.list
[0].fname
= (char *) file
;
1918 static void done_mc ()
1924 * We sync the profiles since the hotlist may have changed, while
1925 * we only change the setup data if we have the auto save feature set
1927 if (auto_save_setup
)
1928 save_setup (); /* does also call save_hotlist */
1932 #endif /* !HAVE_X */
1934 vfs_add_current_stamps ();
1936 if (xterm_flag
&& xterm_hintbar
)
1937 set_hintbar(_("Thank you for using GNU Midnight Commander"));
1938 #endif /* !HAVE_X */
1941 /* This should be called after destroy_dlg since panel widgets
1942 * save their state on the profiles
1944 static void done_mc_profile ()
1946 if (!auto_save_setup
)
1947 profile_forget_profile (profile_name
);
1953 /* This routine only handles cpanel, and opanel, it is easy to
1954 * change to use npanels, just loop over the number of panels
1955 * and use get_panel_widget (i) and make the test done below
1958 make_panels_dirty ()
1961 panel_update_contents (cpanel
);
1963 if ((get_other_type () == view_listing
) && opanel
->dirty
)
1964 panel_update_contents (opanel
);
1967 /* In OS/2 and Windows NT people want to actually type the '\' key frequently */
1969 # define check_key_backslash(x) 0
1971 # define check_key_backslash(x) ((x) == '\\')
1975 midnight_callback (struct Dlg_head
*h
, int id
, int msg
)
1980 /* Speed up routine: now, we just set the */
1982 make_panels_dirty ();
1986 if (ctl_x_map_enabled
){
1987 ctl_x_map_enabled
= 0;
1988 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
1989 if (id
== ctl_x_map
[i
].key_code
){
1990 (*ctl_x_map
[i
].fn
)(id
);
1996 if (id
== KEY_F(10) && !the_menubar
->active
){
2002 free_completions (input_w (cmdline
));
2004 /* On Linux, we can tell the difference */
2005 if (id
== '\n' && ctrl_pressed ()){
2010 if (id
== '\n' && input_w (cmdline
)->buffer
[0]){
2011 send_message_to (h
, (Widget
*) cmdline
, WIDGET_KEY
, id
);
2015 if ((!alternate_plus_minus
|| !(console_flag
|| xterm_flag
)) &&
2016 !quote
&& !cpanel
->searching
) {
2017 if(!only_leading_plus_minus
) {
2018 /* Special treatement, since the input line will eat them */
2024 if (check_key_backslash (id
) || id
== '-'){
2030 reverse_selection_cmd ();
2033 } else if (command_prompt
&& !strlen (input_w (cmdline
)->buffer
)) {
2034 /* Special treatement '+', '-', '\', '*' only when this is
2035 * first char on input line
2043 if (check_key_backslash (id
) || id
== '-') {
2049 reverse_selection_cmd ();
2057 case DLG_HOTKEY_HANDLED
:
2058 if (get_current_type () == view_listing
)
2059 cpanel
->searching
= 0;
2062 case DLG_UNHANDLED_KEY
:
2063 if (command_prompt
){
2066 v
= send_message_to (h
, (Widget
*) cmdline
, WIDGET_KEY
, id
);
2070 if (ctl_x_map_enabled
){
2071 ctl_x_map_enabled
= 0;
2072 for (i
= 0; ctl_x_map
[i
].key_code
; i
++)
2073 if (id
== ctl_x_map
[i
].key_code
){
2074 (*ctl_x_map
[i
].fn
)(id
);
2078 for (i
= 0; default_map
[i
].key_code
; i
++){
2079 if (id
== default_map
[i
].key_code
){
2080 (*default_map
[i
].fn
)(id
);
2085 return MSG_NOT_HANDLED
;
2088 /* We handle the special case of the output lines */
2090 attrset (SELECTED_COLOR
);
2091 if (console_flag
&& output_lines
)
2092 show_console_contents (output_start_y
,
2093 LINES
-output_lines
-keybar_visible
-1,
2094 LINES
-keybar_visible
-1);
2099 return default_dlg_callback (h
, id
, msg
);
2103 /* This should be rewritten in order to support as many panel containers as
2107 widget_data containers
[2];
2108 int containers_no
= 2;
2111 xtoolkit_panel_setup ()
2113 containers
[0] = x_create_panel_container (0);
2114 containers
[1] = x_create_panel_container (1);
2115 input_w (cmdline
)->widget
.wcontainer
= containers
[0];
2116 input_w (cmdline
)->widget
.area
= AREA_BOTTOM
;
2117 the_prompt
->widget
.wcontainer
= containers
[0];
2118 the_prompt
->widget
.area
= AREA_BOTTOM
;
2119 the_bar
->widget
.wcontainer
= containers
[0];
2120 the_bar
->widget
.area
= AREA_TOP
;
2121 get_panel_widget (0)->wcontainer
= containers
[0];
2122 get_panel_widget (0)->area
= AREA_RIGHT
;
2123 get_panel_widget (1)->wcontainer
= containers
[1];
2124 get_panel_widget (1)->area
= AREA_RIGHT
;
2125 the_menubar
->widget
.wcontainer
= (widget_data
) NULL
;
2128 # define xtoolkit_panel_setup()
2132 # define xtoolkit_panel_setup()
2135 #ifndef PORT_HAS_LOAD_HINT
2140 if (!the_hint
->widget
.parent
)
2143 if (!message_visible
&& (!xterm_flag
|| !xterm_hintbar
)){
2144 label_set_text (the_hint
, 0);
2148 if ((hint
= get_random_hint ())){
2153 set_hintbar ("The Midnight Commander " VERSION
2154 " (C) 1995-1997 the Free Software Foundation");
2161 setup_panels_and_run_mc ()
2165 xtoolkit_panel_setup ();
2166 add_widget (midnight_dlg
, the_hint
);
2168 add_widget (midnight_dlg
, cmdline
);
2169 add_widget (midnight_dlg
, the_prompt
);
2170 add_widget (midnight_dlg
, the_bar
);
2172 if (boot_current_is_left
){
2179 add_widget (midnight_dlg
, get_panel_widget (first
));
2180 add_widget (midnight_dlg
, get_panel_widget (second
));
2181 add_widget (midnight_dlg
, the_menubar
);
2183 init_labels (get_panel_widget (0));
2184 init_labels (get_panel_widget (1));
2186 /* Run the Midnight Commander if no file was specified in the command line */
2187 run_dlg (midnight_dlg
);
2189 #endif /* !HAVE_GNOME */
2191 /* result must be free'd (I think this should go in util.c) */
2193 prepend_cwd_on_local (char *filename
)
2198 if (vfs_file_is_local (filename
)){
2199 if (*filename
== PATH_SEP
) /* an absolute pathname */
2200 return g_strdup (filename
);
2201 d
= g_malloc (MC_MAXPATHLEN
+ strlen (filename
) + 2);
2202 mc_get_current_wd (d
, MC_MAXPATHLEN
);
2205 strcpy (d
+ l
, filename
);
2206 return canonicalize_pathname (d
);
2208 return g_strdup (filename
);
2211 #ifdef USE_INTERNAL_EDIT
2214 mc_maybe_editor_or_viewer (void)
2218 if (!(view_one_file
|| edit_one_file
))
2221 /* Invoke the internal view/edit routine with:
2222 * the default processing and forcing the internal viewer/editor
2224 if (view_one_file
) {
2225 path
= prepend_cwd_on_local (view_one_file
);
2226 setup_dummy_mc (path
);
2227 view_file (path
, 0, 1);
2230 path
= prepend_cwd_on_local ("");
2232 setup_dummy_mc (path
);
2234 edit (edit_one_file
, edit_one_file_start_line
);
2241 midnight_shutdown
= 1;
2246 #endif /* USE_INTERNAL_EDIT */
2251 midnight_dlg
= create_dlg (0, 0, LINES
, COLS
, midnight_colors
, midnight_callback
, "[main]", "midnight", 0);
2252 midnight_dlg
->has_menubar
= 1;
2254 #ifdef USE_INTERNAL_EDIT
2255 /* Check if we were invoked as an editor or file viewer */
2256 if (mc_maybe_editor_or_viewer ())
2263 setup_panels_and_run_mc ();
2267 midnight_shutdown
= 1;
2269 /* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
2270 if (print_last_wd
) {
2271 if (!vfs_current_is_local ())
2272 last_wd_string
= g_strdup (".");
2274 last_wd_string
= g_strdup (cpanel
->cwd
);
2279 destroy_dlg (midnight_dlg
);
2285 #if defined (_OS_NT)
2286 /* Windows NT code */
2287 #define CONTROL_FILE "\\mc.%d.control"
2288 char control_file
[sizeof (CONTROL_FILE
) + 8];
2293 SetConsoleTitle ("GNU Midnight Commander");
2295 shell
= getenv ("COMSPEC");
2296 if (!shell
|| !*shell
)
2297 shell
= get_default_shell ();
2299 /* Default opening mode for files is binary, not text (CR/LF translation) */
2304 mc_home
= get_mc_lib_dir ();
2308 sigchld_handler_no_subshell (int sig
)
2318 init_sigfatals (void)
2320 /* Nothing to be done on the OS/2, Windows/NT */
2324 #elif defined (__os2__)
2326 # define CONTROL_FILE "\\mc.%d.control"
2327 char control_file
[sizeof (CONTROL_FILE
) + 8];
2332 /* .ado: This does not work: */
2333 /* DosSMSetTitle ((PSZ) "This is my app"); */
2335 DosSMSetTitle = SESMGR.DOSSMSETTITLE */
2336 shell
= getenv ("COMSPEC");
2337 if (!shell
|| !*shell
)
2338 shell
= get_default_shell ();
2340 mc_home
= get_mc_lib_dir ();
2344 sigchld_handler_no_subshell (int sig
)
2354 init_sigfatals (void)
2356 /* Nothing to be done on the OS/2, Windows/NT */
2361 #define CONTROL_FILE "/tmp/mc.%d.control"
2362 char control_file
[sizeof (CONTROL_FILE
) + 8];
2371 termvalue
= getenv ("TERM");
2372 if (!termvalue
|| !(*termvalue
)){
2373 fprintf (stderr
, _("The TERM environment variable is unset!\n"));
2376 if (force_xterm
|| (strncmp (termvalue
, "xterm", 5) == 0 || strcmp (termvalue
, "dtterm") == 0)){
2377 use_mouse_p
= XTERM_MOUSE
;
2380 printf ("\33]0;GNU Midnight Commander\7");
2383 #endif /* ! HAVE_X */
2384 shell
= getenv ("SHELL");
2385 if (!shell
|| !*shell
)
2386 shell
= g_strdup (getpwuid (geteuid ())->pw_shell
);
2387 if (!shell
|| !*shell
)
2390 g_snprintf (control_file
, sizeof (control_file
), CONTROL_FILE
, getpid ());
2391 my_putenv ("MC_CONTROL_FILE", control_file
);
2393 /* This is the directory, where MC was installed, on Unix this is LIBDIR */
2394 /* and can be overriden by the MC_LIBDIR environment variable */
2395 if ((mc_libdir
= getenv ("MC_LIBDIR")) != NULL
) {
2396 mc_home
= g_strdup (mc_libdir
);
2398 mc_home
= g_strdup (LIBDIR
);
2403 sigchld_handler_no_subshell (int sig
)
2411 /* COMMENT: if it were true that after the call to handle_console(..INIT)
2412 the value of console_flag never changed, we could simply not install
2413 this handler at all if (!console_flag && !use_subshell). */
2415 /* That comment is no longer true. We need to wait() on a sigchld
2416 handler (that's at least what the tarfs code expects currently). */
2419 pid
= waitpid (cons_saver_pid
, &status
, WUNTRACED
| WNOHANG
);
2421 if (pid
== cons_saver_pid
){
2422 /* {{{ Someone has stopped or killed cons.saver; restart it */
2425 if (WIFSTOPPED (status
))
2426 kill (pid
, SIGCONT
);
2430 handle_console (CONSOLE_DONE
);
2431 handle_console (CONSOLE_INIT
);
2435 #endif /* ! SCO_FLAVOR */
2437 /* If we get here, some other child exited; ignore it */
2438 #endif /* ! HAVE_X */
2444 struct sigaction sigchld_action
;
2446 sigchld_action
.sa_handler
=
2447 #ifdef HAVE_SUBSHELL_SUPPORT
2448 use_subshell
? sigchld_handler
:
2450 sigchld_handler_no_subshell
;
2452 sigemptyset (&sigchld_action
.sa_mask
);
2455 sigchld_action
.sa_flags
= SA_RESTART
;
2457 sigchld_action
.sa_flags
= 0;
2460 sigaction (SIGCHLD
, &sigchld_action
, NULL
);
2463 #endif /* _OS_NT, __os2__, UNIX */
2466 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2467 extern int SLtt_Try_Termcap
;
2473 print_mc_usage (void)
2475 const char * const * ptr
;
2476 const char * const usage
[] = {
2479 "mc [flags] [this_dir] [other_panel_dir]\n\n"),
2480 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2481 N_("-a, --stickchars Force use of +, -, | for line drawing.\n"),
2483 N_("-b, --nocolor Force black and white display.\n"),
2484 #ifdef WITH_BACKGROUND
2485 N_("-B, --background [DEVEL-ONLY: Debug the background code]\n"),
2487 N_("-c, --color Force color mode.\n"
2488 "-C, --colors Specify colors (use --help-colors to get a list).\n"
2489 "-d, --nomouse Disable mouse support.\n"),
2490 #ifdef USE_INTERNAL_EDIT
2491 N_("-e, --edit Startup the internal editor.\n"),
2493 N_("-f, --libdir Print configured paths.\n"
2494 "-h, --help Shows this help message.\n"
2495 "-k, --resetsoft Reset softkeys (HP terminals only) to their terminfo/termcap\n"
2498 N_("-l, --ftplog file Log ftpfs commands to the file.\n"),
2501 N_("-M, --memory file [DEVEL-ONLY: Log MAD messages to the file.]\n"),
2503 N_("-P, --printwd At exit, print the last working directory.\n"
2504 "-s, --slow Disables verbose operation (for slow terminals).\n"),
2505 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2506 N_("-t, --termcap Activate support for the TERMCAP variable.\n"),
2508 #if defined(HAVE_SLANG) && defined(OS2_NT)
2509 N_("-S, --createcmdile Create command file to set default directory upon exit.\n"),
2511 #ifdef HAVE_SUBSHELL_SUPPORT
2512 N_("-u, --nosubshell Disable the concurrent subshell mode.\n"
2513 "-U, --subshell Force the concurrent subshell mode.\n"
2514 "-r, --forceexec Force subshell execution.\n"),
2516 N_("-v, --view fname Start up into the viewer mode.\n"
2517 "-V, --version Report version and configuration options.\n"
2518 "-x, --xterm Force xterm mouse support and screen save/restore.\n"
2519 "+number number it is the start line number of file for `mcedit'.\n"),
2520 #ifdef HAVE_SUBSHELL_SUPPORT
2521 N_("-X, --dbgsubshell [DEVEL-ONLY: Debug the subshell].\n"),
2524 "Please send any bug reports (including the output of `mc -V')\n"
2525 "to mc-devel@gnome.org\n"),
2531 for (ptr
= usage
; *ptr
; ptr
++)
2532 fprintf (stderr
, _(*ptr
));
2536 print_color_usage (void)
2539 "--colors KEYWORD={FORE},{BACK}\n\n"
2540 "{FORE} and {BACK} can be ommited, and the default will be used\n"
2543 " Global: errors, reverse, gauge, input\n"
2544 " File display: normal, selected, marked, markselect\n"
2545 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
2546 " Menus: menu, menuhot, menusel, menuhotsel\n"
2547 " Help: helpnormal, helpitalic, helplink, helpslink\n"
2548 " File types: directory, execute, link, device, special, core\n"
2551 " black, gray, red, brightred, green, brightgreen, brown,\n"
2552 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2553 " brightcyan, lightgray and white\n\n"));
2555 #endif /* !HAVE_X */
2558 probably_finish_program (void)
2560 if (finish_program
){
2573 process_args (int c
, const char *option_arg
)
2588 #endif /* !HAVE_X */
2591 fprintf (stderr
, _("Library directory for the Midnight Commander: %s\n"), mc_home
);
2597 ftpfs_set_debug (option_arg
);
2599 /* smbfs_set_debug (option_arg); */
2605 fprintf (stderr
, _("Option -m is obsolete. Please look at Display Bits... in the Option's menu\n"));
2611 mad_set_debug (option_arg
);
2618 batch_file_name
= option_arg
;
2623 use_mouse_p
= NO_MOUSE
;
2626 #ifdef HAVE_SUBSHELL_SUPPORT
2640 force_subshell_execution
= 1;
2642 #endif /* HAVE_SUBSHELL_SUPPORT */
2646 print_color_usage ();
2658 static void parse_an_arg (poptContext state
,
2659 enum poptCallbackReason reason
,
2660 const struct poptOption
*opt
,
2661 const char *arg
, void *data
)
2663 process_args (opt
->shortName
, arg
);
2668 char *cmdline_geometry
= NULL
;
2670 static const struct poptOption argument_table
[] = {
2672 { NULL
, '\0', POPT_ARG_CALLBACK
, parse_an_arg
, 0},
2674 #ifdef WITH_BACKGROUND
2675 { "background", 'B', POPT_ARG_NONE
, &background_wait
, 0,
2676 N_("Use to debug the background code") },
2678 #if defined(HAVE_SLANG) && defined(OS2_NT)
2679 { "createcmdfile", 'S', POPT_ARG_STRING
, NULL
, 'S' },
2681 { "color", 'c', POPT_ARG_NONE
, NULL
, 'c',
2682 N_("Request to run in color mode") },
2683 { "colors", 'C', POPT_ARG_STRING
, &command_line_colors
, 0,
2684 N_("Specifies a color configuration") },
2685 #ifdef HAVE_SUBSHELL_SUPPORT
2686 { "dbgsubshell", 'X', POPT_ARG_NONE
, &debug_subshell
, 0 },
2688 { "edit", 'e', POPT_ARG_STRING
, &edit_one_file
, 0,
2689 N_("Edits one file") },
2692 { "help", 'h', POPT_ARG_NONE
, NULL
, 'h',
2693 N_("Displays this help message") },
2695 { "help-colors", 'H', POPT_ARG_NONE
, NULL
, 'H',
2696 N_("Displays a help screen on how to change the color scheme") },
2698 { "ftplog", 'l', POPT_ARG_STRING
, NULL
, 'l',
2699 N_("Log ftp dialog to specified file") },
2702 { "memory", 'M', POPT_ARG_STRING
, NULL
, 'M', },
2704 { "libdir", 'f', POPT_ARG_NONE
, NULL
, 'f' },
2705 { NULL
, 'm', POPT_ARG_NONE
, NULL
, 'm',
2707 { "nocolor", 'b', POPT_ARG_NONE
, &disable_colors
, 0,
2708 N_("Requests to run in black and white") },
2709 { "nomouse", 'd', POPT_ARG_NONE
, NULL
, 'd',
2710 N_("Disable mouse support in text version") },
2711 #ifdef HAVE_SUBSHELL_SUPPORT
2712 { "nosubshell", 'u', POPT_ARG_NONE
, NULL
, 'u',
2713 N_("Disables subshell support") },
2714 { "forceexec", 'r', POPT_ARG_NONE
, NULL
, 'r' },
2716 { "printwd", 'P', POPT_ARG_NONE
, &print_last_wd
, 0,
2717 N_("Prints working directory at program exit") },
2718 { "resetsoft", 'k', POPT_ARG_NONE
, &reset_hp_softkeys
, 0,
2719 N_("Resets soft keys on HP terminals") },
2720 { "slow", 's', POPT_ARG_NONE
, &slow_terminal
, 0,
2721 N_("To run on slow terminals") },
2722 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2723 { "stickchars", 'a', 0, &force_ugly_line_drawing
, 0,
2724 N_("Use stickchars to draw") },
2726 #ifdef HAVE_SUBSHELL_SUPPORT
2727 { "subshell", 'U', POPT_ARG_NONE
, NULL
, 'U',
2728 N_("Enables subshell support (default)")},
2730 #if !defined(HAVE_X)
2731 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2732 { "termcap", 't', 0, &SLtt_Try_Termcap
, 0,
2733 N_("Tries to use termcap instead of terminfo") },
2736 { "version", 'V', POPT_ARG_NONE
, NULL
, 'V',
2737 N_("Displays the current version") },
2738 { "view", 'v', POPT_ARG_STRING
, &view_one_file
, 0,
2739 N_("Launches the file viewer on a file") },
2740 { "xterm", 'x', POPT_ARG_NONE
, &force_xterm
, 0,
2741 N_("Forces xterm features") },
2743 { "geometry", '\0', POPT_ARG_STRING
, &cmdline_geometry
, 0, N_("Geometry for the window"), N_("GEOMETRY")},
2744 {"nowindows", '\0', POPT_ARG_NONE
, &nowindows
, 0, N_("No windows opened at startup"), NULL
},
2745 {"nodesktop", '\0', POPT_ARG_NONE
, &nodesktop
, 0, N_("No desktop icons"), NULL
},
2746 {"twopanel", '\0', POPT_ARG_NONE
, &twopanel
, 0, N_("Look more like traditional gmc"), NULL
},
2747 {"desktop-linksdir", '\0', POPT_ARG_NONE
, &display_linksdir
, 0,
2748 N_("Display the directory that holds the .links startup files and exit")},
2751 { NULL
, 0, 0, NULL
, 0 }
2754 #if defined(HAVE_CORBA) || defined(HAVE_GNOME)
2755 /* Convenience function to display the desktop initialization directory and exit */
2757 maybe_display_linksdir (void)
2759 if (display_linksdir
) {
2760 puts (DESKTOP_INIT_DIR
);
2767 /* Initializes the ORB and does the initial argument processing */
2769 init_corba_with_args (int *argc
, char **argv
, poptContext
*ctx
)
2771 CORBA_Environment ev
;
2773 CORBA_exception_init (&ev
);
2774 orb
= gnome_CORBA_init_with_popt_table ("gmc", VERSION
, argc
, argv
, argument_table
, 0, ctx
,
2775 GNORBA_INIT_SERVER_FUNC
, &ev
);
2777 maybe_display_linksdir ();
2779 if (ev
._major
!= CORBA_NO_EXCEPTION
) {
2780 CORBA_exception_free (&ev
);
2781 g_warning ("Could not initialize CORBA");
2785 CORBA_exception_free (&ev
);
2787 if (!corba_init_server ()) {
2788 g_warning ("Could not initialize the CORBA server");
2796 corba_activate_server (void)
2802 corba_create_window (char *startup_dir
)
2809 handle_args (int argc
, char *argv
[])
2814 char *option_arg
, *base
;
2816 #endif /* !HAVE_GNOME */
2819 /* special case, handle --desktop-linksdir without initing X */
2821 if (strcmp (argv
[1], "--desktop-linksdir") == 0){
2822 puts (DESKTOP_INIT_DIR
);
2827 init_corba_with_args (&argc
, argv
, &ctx
);
2829 gnome_init_with_popt_table ("gmc", VERSION
, argc
, argv
, argument_table
, 0, &ctx
);
2830 maybe_display_linksdir ();
2833 #ifdef HAVE_GNOME_WINDOW_ICON
2834 gnome_window_icon_set_default_from_file (ICONDIR
"/i-directory.png");
2836 gtk_widget_push_visual (gdk_imlib_get_visual ());
2837 gtk_widget_push_colormap (gdk_imlib_get_colormap ());
2839 /* poptResetContext (ctx); */
2841 ctx
= poptGetContext ("mc", argc
, argv
, argument_table
, 0);
2846 SLtt_Try_Termcap
= 1;
2851 while ((c
= poptGetNextOpt (ctx
)) > 0){
2852 option_arg
= poptGetOptArg (ctx
);
2854 process_args (c
, option_arg
);
2859 fprintf(stderr
, "%s: %s\n",
2860 poptBadOption (ctx
, POPT_BADOPTION_NOALIAS
),
2864 probably_finish_program ();
2865 #endif /* !HAVE_GNOME */
2867 tmp
= poptGetArg (ctx
);
2871 * Check for special invocation names mcedit and mcview,
2872 * if none apply then set the current directory and the other
2873 * directory from the command line arguments
2875 base
= x_basename (argv
[0]);
2876 if (!STRNCOMP (base
, "mce", 3) || !STRCOMP(base
, "vi")) {
2878 edit_one_file_start_line
= 1;
2880 if (*tmp
== '+' && isdigit (tmp
[1])){
2881 int start_line
= atoi (tmp
);
2882 if (start_line
> 0) {
2883 char *file
= poptGetArg (ctx
);
2886 edit_one_file_start_line
= start_line
;
2890 edit_one_file
= g_strdup (tmp
);
2893 if (!STRNCOMP (base
, "mcv", 3) || !STRCOMP(base
, "view")) {
2895 view_one_file
= g_strdup (tmp
);
2897 fprintf (stderr
, "No arguments given to the viewer\n");
2899 probably_finish_program ();
2902 #endif /* !HAVE_GNOME */
2904 /* sets the current dir and the other dir */
2906 char buffer
[MC_MAXPATHLEN
+ 2];
2907 this_dir
= g_strdup (tmp
);
2908 mc_get_current_wd (buffer
, sizeof (buffer
) - 2);
2909 if ((tmp
= poptGetArg (ctx
)))
2910 other_dir
= g_strdup (tmp
);
2914 poptFreeContext (ctx
);
2918 * The compatibility_move_mc_files routine is intended to
2919 * move all of the hidden .mc files into a private ~/.mc
2920 * directory in the home directory, to avoid cluttering the users.
2922 * Previous versions of the program had all of their files in
2923 * the $HOME, we are now putting them in $HOME/.mc
2926 # define compatibility_move_mc_files()
2930 do_mc_filename_rename (char *mc_dir
, char *o_name
, char *n_name
)
2932 char *full_o_name
= concat_dir_and_file (home_dir
, o_name
);
2933 char *full_n_name
= g_strconcat (home_dir
, MC_BASE
, n_name
, NULL
);
2936 move
= 0 == rename (full_o_name
, full_n_name
);
2937 g_free (full_o_name
);
2938 g_free (full_n_name
);
2943 do_compatibility_move (char *mc_dir
)
2948 if (stat (mc_dir
, &s
) == 0)
2950 if (errno
!= ENOENT
)
2953 if (mkdir (mc_dir
, 0777) == -1)
2956 move
= do_mc_filename_rename (mc_dir
, ".mc.ini", "ini");
2957 move
+= do_mc_filename_rename (mc_dir
, ".mc.hot", "hotlist");
2958 move
+= do_mc_filename_rename (mc_dir
, ".mc.ext", "ext");
2959 move
+= do_mc_filename_rename (mc_dir
, ".mc.menu", "menu");
2960 move
+= do_mc_filename_rename (mc_dir
, ".mc.bashrc", "bashrc");
2961 move
+= do_mc_filename_rename (mc_dir
, ".mc.inputrc", "inputrc");
2962 move
+= do_mc_filename_rename (mc_dir
, ".mc.tcshrc", "tcshrc");
2963 move
+= do_mc_filename_rename (mc_dir
, ".mc.tree", "tree");
2968 show_change_notice
= 1;
2972 compatibility_move_mc_files (void)
2974 char *mc_dir
= concat_dir_and_file (home_dir
, ".mc");
2976 do_compatibility_move (mc_dir
);
2982 main (int argc
, char *argv
[])
2984 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2985 setlocale (LC_ALL
, "");
2986 bindtextdomain ("mc", LOCALEDIR
);
2990 /* This is here to debug startup stuff */
2994 printf ("GMC IS WAITING %d\n", getpid ());
3000 /* Initialize list of all user group for timur_clr_mode */
3005 /* This variable is used by the subshell */
3006 home_dir
= getenv ("HOME");
3008 /* mc_home was computed by OS_Setup */
3015 /* NOTE: This call has to be before any our argument handling :) */
3019 char *base
= x_basename (argv
[0]);
3022 if (strcmp (base
, "mcedit") == 0)
3025 if (strcmp (base
, "mcview") == 0)
3030 handle_args(argc
, argv
);
3035 probably_finish_program ();
3038 if (xtoolkit_init (&argc
, argv
) == -1)
3045 SLtt_Ignore_Beep
= 1;
3048 /* NOTE: This has to be called before slang_init or whatever routine
3049 calls any define_sequence */
3052 handle_args (argc
, argv
);
3055 /* Used to report the last working directory at program end */
3058 stdout_fd
= dup (1);
3060 if (open (ttyname (0), O_RDWR
) < 0)
3061 if (open ("/dev/tty", O_RDWR
) < 0) {
3062 /* Try if stderr is not redirected as the last chance */
3063 char *p
= g_strdup (ttyname (0));
3065 if (!strcmp (p
, ttyname (2)))
3069 _("Couldn't open tty line. You have to run mc without the -P flag.\n"
3070 "On some systems you may want to run # `which mc`\n"));
3079 /* This is to avoid subshell trying to restard any child pid
3080 * that happends to have cons_saver_pid (a random startup value).
3081 * and PID 1 is init, unlikely we could be the parent of it.
3083 /* cons_saver_pid = 1; */
3085 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
3086 handle_console (CONSOLE_INIT
);
3089 # ifdef HAVE_SUBSHELL_SUPPORT
3090 subshell_get_console_attributes ();
3093 /* Install the SIGCHLD handler; must be done before init_subshell() */
3096 compatibility_move_mc_files ();
3099 /* We need this, since ncurses endwin () doesn't restore the signals */
3100 /* Very strange comment given that ifdef HAVE_X stands here since
3101 revision 1.1 - Pavel Roskin */
3102 save_stop_handler ();
3106 /* Must be done before init_subshell, to set up the terminal size: */
3107 /* FIXME: Should be removed and LINES and COLS computed on subshell */
3111 /* NOTE: This call has to be after slang_init. It's the small part from
3112 the previous init_key which had to be moved after the call of slang_init */
3113 init_key_input_fd ();
3114 #endif /* !HAVE_X */
3124 #ifdef HAVE_SUBSHELL_SUPPORT
3126 /* Don't use subshell in GNOME and when invoked as a viewer or editor */
3128 if (edit_one_file
|| view_one_file
)
3129 #endif /* !HAVE_GNOME */
3132 /* Done here to ensure that the subshell doesn't */
3133 /* inherit the file descriptors opened below, etc */
3137 #endif /* HAVE_SUBSHELL_SUPPORT */
3140 /* Removing this from the X code let's us type C-c */
3143 /* Also done after init_subshell, to save any shell init file messages */
3145 handle_console (CONSOLE_SAVE
);
3147 if (alternate_plus_minus
)
3148 application_keypad_mode ();
3149 #endif /* !HAVE_X */
3152 gnome_check_super_user ();
3155 if (show_change_notice
){
3156 message (1, _(" Notice "),
3157 _(" The Midnight Commander configuration files \n"
3158 " are now stored in the ~/.mc directory, the \n"
3159 " files have been moved now\n"));
3162 # ifdef HAVE_SUBSHELL_SUPPORT
3164 prompt
= strip_ctrl_codes (subshell_prompt
);
3169 prompt
= (geteuid () == 0) ? "# " : "$ ";
3171 /* Program main loop */
3174 /* Save the tree store */
3177 /* Virtual File System shutdown */
3180 /* Delete list of all user groups*/
3183 flush_extension_file (); /* does only free memory */
3186 /* Miguel, maybe the fix in slang is not required and
3187 * it could be done by removing the slang_done_screen.
3188 * Do I need to call slang_reset_tty then?
3193 if (console_flag
&& !(quit
& SUBSHELL_EXIT
))
3195 if (alternate_plus_minus
)
3196 numeric_keypad_mode ();
3200 signal (SIGCHLD
, SIG_DFL
); /* Disable the SIGCHLD handler */
3205 handle_console (CONSOLE_DONE
);
3206 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
3210 /* On NT, home_dir is malloced */
3214 if (print_last_wd
== 2){
3218 bat_file
= fopen(batch_file_name
, "w");
3219 if (bat_file
!= NULL
){
3220 /* .ado: \r\n for Win95 */
3221 fprintf(bat_file
, "@echo off\r\n");
3222 if (isalpha(last_wd_string
[0]))
3223 fprintf(bat_file
, "%c:\r\n", last_wd_string
[0]);
3224 fprintf(bat_file
, "cd %s\r\n", last_wd_string
);
3229 if (print_last_wd
) {
3230 if (print_last_revert
|| edit_one_file
|| view_one_file
)
3231 write (stdout_fd
, ".", 1);
3233 write (stdout_fd
, last_wd_string
, strlen (last_wd_string
));
3234 g_free (last_wd_string
);
3241 mad_finalize (__FILE__
, __LINE__
);