1 /* Routines invoked by a function key
2 They normally operate on the current panel.
4 Copyright (C) 1994, 1995 Miguel de Icaza
5 Copyright (C) 1994, 1995 Janne Kukonlehto
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include <sys/types.h>
38 # include <sys/mman.h>
42 #include "cmd.h" /* Our definitions */
43 #include "fileopctx.h" /* file_op_context_new() */
44 #include "file.h" /* copy_file_file() */
45 #include "find.h" /* do_find() */
46 #include "hotlist.h" /* hotlist_cmd() */
47 #include "tree.h" /* tree_chdir() */
48 #include "subshell.h" /* use_subshell */
49 #include "cons.saver.h" /* console_flag */
50 #include "tty.h" /* LINES */
51 #include "dlg.h" /* Widget */
52 #include "view.h" /* view() */
53 #include "wtools.h" /* message() */
54 #include "widget.h" /* push_history() */
55 #include "key.h" /* application_keypad_mode() */
56 #include "win.h" /* do_enter_ca_mode() */
57 #include "dialog.h" /* do_refresh() */
58 #include "main.h" /* change_panel() */
59 #include "panel.h" /* cpanel */
60 #include "help.h" /* interactive_display() */
61 #include "user.h" /* MC_GLOBAL_MENU */
62 #include "command.h" /* cmdline */
63 #include "layout.h" /* get_current_type() */
64 #include "ext.h" /* regex_command() */
65 #include "boxes.h" /* cd_dialog() */
66 #include "setup.h" /* save_setup() */
67 #include "profile.h" /* PROFILE_NAME */
73 #ifdef USE_INTERNAL_EDIT
74 # include "../edit/edit.h"
77 /* If set and you don't have subshell support,then C-o will give you a shell */
78 int output_starts_shell
= 0;
80 /* Source routing destination */
83 /* If set, use the builtin editor */
84 int use_internal_edit
= 1;
88 * Execute command on a filename that can be on VFS.
89 * Errors are reported to the user.
92 execute_with_vfs_arg (const char *command
, const char *filename
)
99 /* Simplest case, this file is local */
100 if (!filename
|| vfs_file_is_local (filename
)) {
101 execute_internal (command
, filename
);
105 /* FIXME: Creation of new files on VFS is not supported */
109 localcopy
= mc_getlocalcopy (filename
);
110 if (localcopy
== NULL
) {
111 message (1, MSG_ERROR
, _(" Cannot fetch a local copy of %s "),
117 * filename can be an entry on panel, it can be changed by executing
118 * the command, so make a copy. Smarter VFS code would make the code
121 fn
= g_strdup (filename
);
122 mc_stat (localcopy
, &st
);
124 execute_internal (command
, localcopy
);
125 mc_stat (localcopy
, &st
);
126 mc_ungetlocalcopy (fn
, localcopy
, mtime
!= st
.st_mtime
);
132 view_file_at_line (char *filename
, int plain_view
, int internal
,
135 static char *viewer
= 0;
140 int changed_hex_mode
= 0;
141 int changed_nroff_flag
= 0;
142 int changed_magic_flag
= 0;
144 altered_hex_mode
= 0;
145 altered_nroff_flag
= 0;
146 altered_magic_flag
= 0;
147 if (default_hex_mode
)
148 changed_hex_mode
= 1;
149 if (default_nroff_flag
)
150 changed_nroff_flag
= 1;
151 if (default_magic_flag
)
152 changed_magic_flag
= 1;
153 default_hex_mode
= 0;
154 default_nroff_flag
= 0;
155 default_magic_flag
= 0;
156 view (0, filename
, &move_dir
, start_line
);
157 if (changed_hex_mode
&& !altered_hex_mode
)
158 default_hex_mode
= 1;
159 if (changed_nroff_flag
&& !altered_nroff_flag
)
160 default_nroff_flag
= 1;
161 if (changed_magic_flag
&& !altered_magic_flag
)
162 default_magic_flag
= 1;
167 char view_entry
[BUF_TINY
];
170 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d",
173 strcpy (view_entry
, "View");
175 if (regex_command (filename
, view_entry
, &move_dir
) == 0) {
176 view (0, filename
, &move_dir
, start_line
);
181 viewer
= getenv ("PAGER");
185 execute_with_vfs_arg (viewer
, filename
);
190 /* view_file (filename, plain_view, internal)
193 * filename: The file name to view
194 * plain_view: If set does not do any fancy pre-processing (no filtering) and
195 * always invokes the internal viewer.
196 * internal: If set uses the internal viewer, otherwise an external viewer.
199 view_file (char *filename
, int plain_view
, int internal
)
201 return view_file_at_line (filename
, plain_view
, internal
, 0);
204 /* scan_for_file (panel, idx, direction)
207 * panel: pointer to the panel on which we operate
208 * idx: starting file.
209 * direction: 1, or -1
211 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
213 int i
= idx
+ direction
;
217 i
= panel
->count
- 1;
218 if (i
== panel
->count
)
220 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
228 * Run viewer (internal or external) on the currently selected file.
229 * If normal is 1, force internal viewer and raw mode (used for F13).
232 do_view_cmd (int normal
)
236 /* Directories are viewed by changing to them */
237 if (S_ISDIR (selection (cpanel
)->buf
.st_mode
)
238 || link_isdir (selection (cpanel
))) {
239 if (confirm_view_dir
&& (cpanel
->marked
|| cpanel
->dirs_marked
)) {
241 (_(" Confirmation "), _("Files tagged, want to cd?"), 0, 2,
242 _("&Yes"), _("&No")) != 0) {
246 if (!do_cd (selection (cpanel
)->fname
, cd_exact
))
247 message (1, MSG_ERROR
, _("Cannot change directory"));
253 file_idx
= cpanel
->selected
;
257 filename
= cpanel
->dir
.list
[file_idx
].fname
;
259 dir
= view_file (filename
, normal
, use_internal_view
);
262 file_idx
= scan_for_file (cpanel
, file_idx
, dir
);
266 /* Run user's preferred viewer on the currently selected file */
273 /* Ask for file and run user's preferred viewer on it */
280 input_dialog (_(" View file "), _(" Filename:"),
281 selection (cpanel
)->fname
);
285 view_file (filename
, 0, use_internal_view
);
289 /* Run plain internal viewer on the currently selected file */
291 view_simple_cmd (void)
297 filtered_view_cmd (void)
302 input_dialog (_(" Filtered view "),
303 _(" Filter command and arguments:"),
304 selection (cpanel
)->fname
);
308 view (command
, "", 0, 0);
313 void do_edit_at_line (const char *what
, int start_line
)
315 static char *editor
= 0;
317 #ifdef USE_INTERNAL_EDIT
318 if (use_internal_edit
){
319 edit (what
, start_line
);
320 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
324 #endif /* USE_INTERNAL_EDIT */
326 editor
= getenv ("EDITOR");
328 editor
= get_default_editor ();
330 execute_with_vfs_arg (editor
, what
);
331 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
336 do_edit (const char *what
)
338 do_edit_at_line (what
, 0);
344 if (regex_command (selection (cpanel
)->fname
, "Edit", 0) == 0)
345 do_edit (selection (cpanel
)->fname
);
354 /* Invoked by F5. Copy, default to the other panel. */
359 if (panel_operate (cpanel
, OP_COPY
, NULL
, TRUE
)) {
360 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
365 /* Invoked by F6. Move/rename, default to the other panel. */
369 if (panel_operate (cpanel
, OP_MOVE
, NULL
, TRUE
)){
370 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
375 /* Invoked by F15. Copy, default to the same panel. */
376 void copy_cmd_local (void)
379 if (panel_operate (cpanel
, OP_COPY
, selection (cpanel
)->fname
, TRUE
)){
380 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
385 /* Invoked by F16. Move/rename, default to the same panel. */
386 void ren_cmd_local (void)
389 if (panel_operate (cpanel
, OP_MOVE
, selection (cpanel
)->fname
, TRUE
)){
390 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
402 input_expand_dialog (_("Create a new Directory"),
403 _(" Enter directory name:"), "");
408 if (dir
[0] == '/' || dir
[0] == '~')
409 tempdir
= g_strdup (dir
);
411 tempdir
= concat_dir_and_file (cpanel
->cwd
, dir
);
415 if (my_mkdir (tempdir
, 0777) == 0) {
416 update_panels (UP_OPTIMIZE
, tempdir
);
418 select_item (cpanel
);
423 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
426 void delete_cmd (void)
430 if (panel_operate (cpanel
, OP_DELETE
, NULL
, TRUE
)){
431 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
442 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
448 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
449 p
->filter
= allocated_filter_string
;
451 g_free (allocated_filter_string
);
455 /* Set a given panel filter expression */
457 set_panel_filter (WPanel
*p
)
462 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
464 reg_exp
= input_dialog_help (_(" Filter "),
465 _(" Set expression for filtering filenames"),
469 set_panel_filter_to (p
, reg_exp
);
472 /* Invoked from the left/right menus */
473 void filter_cmd (void)
477 if (!SELECTED_IS_PANEL
)
481 set_panel_filter (p
);
484 void reread_cmd (void)
488 if (get_current_type () == view_listing
&&
489 get_other_type () == view_listing
)
490 flag
= strcmp (cpanel
->cwd
, opanel
->cwd
) ? UP_ONLY_CURRENT
: 0;
492 flag
= UP_ONLY_CURRENT
;
494 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
498 void reverse_selection_cmd (void)
503 for (i
= 0; i
< cpanel
->count
; i
++){
504 file
= &cpanel
->dir
.list
[i
];
505 if (S_ISDIR (file
->buf
.st_mode
))
507 do_file_mark (cpanel
, i
, !file
->f
.marked
);
509 paint_panel (cpanel
);
512 void select_cmd (void)
514 char *reg_exp
, *reg_exp_t
;
519 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
525 /* Check if they specified a directory */
526 if (*reg_exp_t
== PATH_SEP
){
530 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
532 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
535 for (i
= 0; i
< cpanel
->count
; i
++){
536 if (!strcmp (cpanel
->dir
.list
[i
].fname
, ".."))
538 if (S_ISDIR (cpanel
->dir
.list
[i
].buf
.st_mode
)){
545 c
= regexp_match (reg_exp_t
, cpanel
->dir
.list
[i
].fname
, match_file
);
547 message (1, MSG_ERROR
, _(" Malformed regular expression "));
552 do_file_mark (cpanel
, i
, 1);
555 paint_panel (cpanel
);
559 void unselect_cmd (void)
561 char *reg_exp
, *reg_exp_t
;
566 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
572 /* Check if they specified directory matching */
573 if (*reg_exp_t
== PATH_SEP
){
577 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
579 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
581 for (i
= 0; i
< cpanel
->count
; i
++){
582 if (!strcmp (cpanel
->dir
.list
[i
].fname
, ".."))
584 if (S_ISDIR (cpanel
->dir
.list
[i
].buf
.st_mode
)){
591 c
= regexp_match (reg_exp_t
, cpanel
->dir
.list
[i
].fname
, match_file
);
593 message (1, MSG_ERROR
, _(" Malformed regular expression "));
598 do_file_mark (cpanel
, i
, 0);
601 paint_panel (cpanel
);
605 /* Check if the file exists */
606 /* If not copy the default */
608 check_for_default(char *default_file
, char *file
)
615 if (mc_stat (file
, &s
)){
616 if (mc_stat (default_file
, &s
)){
619 ctx
= file_op_context_new ();
620 file_op_context_create_ui (ctx
, OP_COPY
, 0);
621 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
622 file_op_context_destroy (ctx
);
634 if (geteuid () == 0){
635 dir
= query_dialog (_("Extension file edit"),
636 _(" Which extension file you want to edit? "), 0, 2,
637 _("&User"), _("&System Wide"));
639 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
642 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
643 check_for_default (extdir
, buffer
);
650 flush_extension_file ();
653 /* where = 0 - do edit file menu for mc */
654 /* where = 1 - do edit file menu for mcedit */
656 menu_edit_cmd (int where
)
664 _(" Which menu file do you want to edit? "),
665 0, geteuid() ? 2 : 3,
666 _("&Local"), _("&Home"), _("&System Wide")
669 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
673 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
674 check_for_default (menufile
, buffer
);
678 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
679 check_for_default (menufile
, buffer
);
683 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
697 void quick_chdir_cmd (void)
701 target
= hotlist_cmd (LIST_HOTLIST
);
705 if (get_current_type () == view_tree
)
706 tree_chdir (the_tree
, target
);
708 if (!do_cd (target
, cd_exact
))
709 message (1, MSG_ERROR
, _("Cannot change directory") );
713 /* edit file menu for mc */
715 edit_mc_menu_cmd (void)
720 #ifdef USE_INTERNAL_EDIT
721 /* edit file menu for mcedit */
723 edit_user_menu_cmd (void)
728 /* edit syntax file for mcedit */
730 edit_syntax_cmd (void)
736 if (geteuid () == 0) {
738 query_dialog (_("Syntax file edit"),
739 _(" Which syntax file you want to edit? "), 0, 2,
740 _("&User"), _("&System Wide"));
742 extdir
= concat_dir_and_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
745 buffer
= concat_dir_and_file (home_dir
, SYNTAX_FILE
);
746 check_for_default (extdir
, buffer
);
757 void free_vfs_now (void)
762 void reselect_vfs (void)
766 target
= hotlist_cmd (LIST_VFSLIST
);
770 if (!do_cd (target
, cd_exact
))
771 message (1, MSG_ERROR
, _("Cannot change directory") );
776 static int compare_files (char *name1
, char *name2
, off_t size
)
779 int result
= -1; /* Different by default */
781 file1
= open (name1
, O_RDONLY
);
783 file2
= open (name2
, O_RDONLY
);
788 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
789 if (data1
!= (char*) -1){
790 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
791 if (data2
!= (char*) -1){
793 result
= memcmp (data1
, data2
, size
);
794 munmap (data2
, size
);
796 munmap (data1
, size
);
799 /* Don't have mmap() :( Even more ugly :) */
800 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
805 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
806 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
807 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
808 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
809 #endif /* !HAVE_MMAP */
818 compare_quick
, compare_size_only
, compare_thourough
822 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
825 char *src_name
, *dst_name
;
827 /* No marks by default */
830 panel
->dirs_marked
= 0;
832 /* Handle all files in the panel */
833 for (i
= 0; i
< panel
->count
; i
++){
834 file_entry
*source
= &panel
->dir
.list
[i
];
836 /* Default: unmarked */
837 file_mark (panel
, i
, 0);
839 /* Skip directories */
840 if (S_ISDIR (source
->buf
.st_mode
))
843 /* Search the corresponding entry from the other panel */
844 for (j
= 0; j
< other
->count
; j
++){
845 if (strcmp (source
->fname
,
846 other
->dir
.list
[j
].fname
) == 0)
849 if (j
>= other
->count
)
850 /* Not found -> mark */
851 do_file_mark (panel
, i
, 1);
854 file_entry
*target
= &other
->dir
.list
[j
];
856 if (mode
!= compare_size_only
){
857 /* Older version is not marked */
858 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
862 /* Newer version with different size is marked */
863 if (source
->buf
.st_size
!= target
->buf
.st_size
){
864 do_file_mark (panel
, i
, 1);
868 if (mode
== compare_size_only
)
871 if (mode
== compare_quick
){
872 /* Thorough compare off, compare only time stamps */
873 /* Mark newer version, don't mark version with the same date */
874 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
875 do_file_mark (panel
, i
, 1);
880 /* Thorough compare on, do byte-by-byte comparison */
881 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
882 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
883 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
884 do_file_mark (panel
, i
, 1);
892 compare_dirs_cmd (void)
895 enum CompareMode thorough_flag
;
898 query_dialog (_(" Compare directories "),
899 _(" Select compare method: "), 0, 3, _("&Quick"),
900 _("&Size only"), _("&Thorough"), _("&Cancel"));
902 if (choice
< 0 || choice
> 2)
905 thorough_flag
= choice
;
907 if (get_current_type () == view_listing
908 && get_other_type () == view_listing
) {
909 compare_dir (cpanel
, opanel
, thorough_flag
);
910 compare_dir (opanel
, cpanel
, thorough_flag
);
911 paint_panel (cpanel
);
912 paint_panel (opanel
);
914 message (1, MSG_ERROR
,
915 _(" Both panels should be in the "
916 "listing mode to use this command "));
926 if (cmdline
->need_push
) {
927 if (push_history (cmdline
, cmdline
->buffer
) == 2)
928 cmdline
->need_push
= 0;
930 if (!cmdline
->history
) {
931 message (1, MSG_ERROR
, _(" The command history is empty "));
934 current
= g_list_first (cmdline
->history
);
935 listbox
= create_listbox_window (60, 10, _(" Command history "),
938 LISTBOX_APPEND_TEXT (listbox
, 0, (char *) current
->data
, current
);
939 current
= g_list_next(current
);
941 run_dlg (listbox
->dlg
);
942 if (listbox
->dlg
->ret_value
== B_CANCEL
)
945 current
= listbox
->list
->current
->data
;
946 destroy_dlg (listbox
->dlg
);
951 cmdline
->history
= current
;
952 assign_text (cmdline
, (char *) current
->data
);
953 update_input (cmdline
, 1);
964 view_other_cmd (void)
966 static int message_flag
= TRUE
;
967 #ifdef HAVE_SUBSHELL_SUPPORT
968 char *new_dir
= NULL
;
970 #endif /* HAVE_SUBSHELL_SUPPORT */
972 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
974 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
975 " the panels cannot be toggled. "));
976 message_flag
= FALSE
;
980 if (clear_before_exec
)
982 if (alternate_plus_minus
)
983 numeric_keypad_mode ();
985 /* With slang we don't want any of this, since there
986 * is no mc_raw_mode supported
990 #endif /* !HAVE_SLANG */
991 keypad(stdscr
, FALSE
);
998 #ifdef HAVE_SUBSHELL_SUPPORT
1000 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
1001 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
1002 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
1004 #endif /* HAVE_SUBSHELL_SUPPORT */
1006 if (output_starts_shell
){
1008 _("Type `exit' to return to the Midnight Commander"));
1009 fprintf (stderr
, "\n\r\n\r");
1011 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
1016 handle_console (CONSOLE_SAVE
);
1018 do_enter_ca_mode ();
1021 keypad(stdscr
, TRUE
);
1023 /* Prevent screen flash when user did 'exit' or 'logout' within
1030 if (alternate_plus_minus
)
1031 application_keypad_mode ();
1033 #ifdef HAVE_SUBSHELL_SUPPORT
1037 do_possible_cd (new_dir
);
1038 if (console_flag
&& output_lines
)
1039 show_console_contents (output_start_y
,
1040 LINES
-keybar_visible
-output_lines
-1,
1041 LINES
-keybar_visible
-1);
1043 #endif /* HAVE_SUBSHELL_SUPPORT */
1047 update_xterm_title_path ();
1051 #ifndef NATIVE_WIN32
1053 do_link (int symbolic_link
, char *fname
)
1057 if (!symbolic_link
) {
1058 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
1059 dest
= input_expand_dialog (_(" Link "), src
, "");
1068 if (-1 == mc_link (fname
, dest
))
1069 message (1, MSG_ERROR
, _(" link: %s "),
1070 unix_error_string (errno
));
1075 /* suggest the full path for symlink */
1076 s
= concat_dir_and_file (cpanel
->cwd
, fname
);
1078 if (get_other_type () == view_listing
) {
1079 d
= concat_dir_and_file (opanel
->cwd
, fname
);
1081 d
= g_strdup (fname
);
1084 symlink_dialog (s
, d
, &dest
, &src
);
1088 if (!dest
|| !*dest
|| !src
|| !*src
) {
1096 if (-1 == mc_symlink (dest
, src
))
1097 message (1, MSG_ERROR
, _(" symlink: %s "),
1098 unix_error_string (errno
));
1102 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1106 void link_cmd (void)
1108 do_link (0, selection (cpanel
)->fname
);
1111 void symlink_cmd (void)
1113 char *filename
= NULL
;
1114 filename
= selection (cpanel
)->fname
;
1117 do_link (1, filename
);
1121 void edit_symlink_cmd (void)
1123 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1124 char buffer
[MC_MAXPATHLEN
];
1129 p
= selection (cpanel
)->fname
;
1131 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
1133 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1136 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1138 if (*dest
&& strcmp (buffer
, dest
)) {
1140 if (-1 == mc_unlink (p
)){
1141 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
1142 p
, unix_error_string (errno
));
1144 if (-1 == mc_symlink (dest
, p
))
1145 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1146 unix_error_string (errno
));
1148 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1156 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
1157 selection (cpanel
)->fname
);
1160 #endif /* !NATIVE_WIN32 */
1162 void help_cmd (void)
1164 interactive_display (NULL
, "[main]");
1167 /* partly taken from dcigettext.c, returns "" for default locale */
1168 /* value should be freed by calling function g_free() */
1169 char *guess_message_value (void)
1171 static const char * const var
[] = {
1172 /* The highest priority value is the `LANGUAGE' environment
1173 variable. This is a GNU extension. */
1175 /* Setting of LC_ALL overwrites all other. */
1177 /* Next comes the name of the desired category. */
1179 /* Last possibility is the LANG environment variable. */
1181 /* NULL exit loops */
1186 char *locale
= NULL
;
1188 while (var
[i
] != NULL
) {
1189 locale
= getenv (var
[i
]);
1190 if (locale
!= NULL
&& locale
[0] != '\0')
1198 return g_strdup (locale
);
1202 * Return a random hint. If force is not 0, ignore the timeout.
1205 get_random_hint (int force
)
1207 char *data
, *result
, *eol
;
1211 /* Do not change hints more often than one minute */
1218 if (!force
&& (now
- last
) < 60)
1219 return g_strdup ("");
1222 static int last_sec
;
1223 static struct timeval tv
;
1225 gettimeofday (&tv
, NULL
);
1226 if (!force
&& !(tv
.tv_sec
> last_sec
+ 60))
1227 return g_strdup ("");
1228 last_sec
= tv
.tv_sec
;
1229 #endif /* !SCO_FLAVOR */
1231 data
= load_mc_home_file (MC_HINT
, NULL
);
1236 srand ((short) now
);
1239 #endif /* !SCO_FLAVOR */
1240 /* get a random entry */
1241 len
= strlen (data
);
1242 start
= rand () % len
;
1244 for (;start
; start
--){
1245 if (data
[start
] == '\n'){
1250 eol
= strchr (&data
[start
], '\n');
1253 result
= g_strdup (&data
[start
]);
1258 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1260 nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1265 if (!SELECTED_IS_PANEL
)
1268 machine
= input_dialog_help (text
,
1274 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1275 ugly as hell and leads to problems in vfs layer */
1277 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1278 cd_path
= g_strconcat (machine
, to_home
? "/~/" : NULL
, NULL
);
1280 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1282 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1283 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1285 message (1, MSG_ERROR
, _(" Cannot chdir to %s "), cd_path
);
1289 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1294 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1297 void netlink_cmd (void)
1299 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1300 "[Network File System]", "/#mc:", 1);
1302 #endif /* WITH_MCFS */
1304 void ftplink_cmd (void)
1306 nice_cd (_(" FTP to machine "), _(machine_str
),
1307 "[FTP File System]", "/#ftp:", 1);
1310 void fishlink_cmd (void)
1312 nice_cd (_(" Shell link to machine "), _(machine_str
),
1313 "[FIle transfer over SHell filesystem]", "/#sh:", 1);
1317 void smblink_cmd (void)
1319 nice_cd (_(" SMB link to machine "), _(machine_str
),
1320 "[SMB File System]", "/#smb:", 0);
1322 #endif /* WITH_SMBFS */
1324 #ifdef HAVE_SETSOCKOPT
1325 void source_routing (void)
1330 source
= input_dialog (_(" Socket source routing setup "),
1331 _(" Enter host name to use as a source routing hop: "),
1336 hp
= gethostbyname (source
);
1339 message (1, _(" Host name "), _(" Error while looking up IP address "));
1342 source_route
= *((int *)hp
->h_addr
);
1344 #endif /* HAVE_SETSOCKOPT */
1345 #endif /* USE_NETCODE */
1347 #ifdef USE_EXT2FSLIB
1348 void undelete_cmd (void)
1350 nice_cd (_(" Undelete files on an ext2 file system "),
1351 _(" Enter device (without /dev/) to undelete\n "
1352 " files on: (F1 for details)"),
1353 "[Undelete File System]", "/#undel:", 0);
1355 #endif /* USE_EXT2FSLIB */
1357 void quick_cd_cmd (void)
1359 char *p
= cd_dialog ();
1362 char *q
= g_strconcat ("cd ", p
, NULL
);
1374 WPanel
*panel
= cpanel
;
1379 for (i
= 0; i
< panel
->count
; i
++)
1380 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1381 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1382 !panel
->dirs_marked
) &&
1383 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1385 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1386 panel
->dir
.list
[i
].buf
.st_size
= (off_t
) total
;
1387 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1390 recalculate_panel_summary (panel
);
1391 paint_panel (panel
);
1395 save_setup_cmd (void)
1401 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1403 message (0, _(" Setup "), str
);
1408 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1410 p
->user_mini_status
= use_msformat
;
1411 p
->list_type
= view_type
;
1413 if (view_type
== list_user
|| use_msformat
){
1414 g_free (p
->user_format
);
1415 p
->user_format
= user
;
1417 g_free (p
->user_status_format
[view_type
]);
1418 p
->user_status_format
[view_type
] = status
;
1420 set_panel_formats (p
);
1427 set_panel_formats (p
);
1434 info_cmd_no_menu (void)
1436 if (get_display_type (0) == view_info
)
1437 set_display_type (0, view_listing
);
1438 else if (get_display_type (1) == view_info
)
1439 set_display_type (1, view_listing
);
1441 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1445 quick_cmd_no_menu (void)
1447 if (get_display_type (0) == view_quick
)
1448 set_display_type (0, view_listing
);
1449 else if (get_display_type (1) == view_quick
)
1450 set_display_type (1, view_listing
);
1452 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1456 switch_to_listing (int panel_index
)
1458 if (get_display_type (panel_index
) != view_listing
)
1459 set_display_type (panel_index
, view_listing
);
1465 int view_type
, use_msformat
;
1466 char *user
, *status
;
1470 display_type
= get_display_type (MENU_PANEL_IDX
);
1471 if (display_type
== view_listing
)
1472 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1476 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1478 if (view_type
== -1)
1481 switch_to_listing (MENU_PANEL_IDX
);
1483 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1485 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1491 set_display_type (MENU_PANEL_IDX
, view_tree
);
1497 set_display_type (MENU_PANEL_IDX
, view_info
);
1501 quick_view_cmd (void)
1503 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == cpanel
)
1505 set_display_type (MENU_PANEL_IDX
, view_quick
);
1508 /* Handle the tree internal listing modes switching */
1510 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1512 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1514 switch_to_listing (panel_index
);
1515 p
->list_type
= listing_mode
;
1516 if (set_panel_formats (p
))
1525 toggle_listing_cmd (void)
1527 int current
= get_current_index ();
1528 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1529 int list_mode
= p
->list_type
;
1543 if (set_basic_panel_listing_to (current
, m
))
1545 set_basic_panel_listing_to (current
, list_full
);