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 view_file_at_line (char *filename
, int plain_view
, int internal
,
91 static char *viewer
= 0;
96 int changed_hex_mode
= 0;
97 int changed_nroff_flag
= 0;
98 int changed_magic_flag
= 0;
100 altered_hex_mode
= 0;
101 altered_nroff_flag
= 0;
102 altered_magic_flag
= 0;
103 if (default_hex_mode
)
104 changed_hex_mode
= 1;
105 if (default_nroff_flag
)
106 changed_nroff_flag
= 1;
107 if (default_magic_flag
)
108 changed_magic_flag
= 1;
109 default_hex_mode
= 0;
110 default_nroff_flag
= 0;
111 default_magic_flag
= 0;
112 view (0, filename
, &move_dir
, start_line
);
113 if (changed_hex_mode
&& !altered_hex_mode
)
114 default_hex_mode
= 1;
115 if (changed_nroff_flag
&& !altered_nroff_flag
)
116 default_nroff_flag
= 1;
117 if (changed_magic_flag
&& !altered_magic_flag
)
118 default_magic_flag
= 1;
123 char view_entry
[BUF_TINY
];
126 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d",
129 strcpy (view_entry
, "View");
131 if (regex_command (filename
, view_entry
, &move_dir
) == 0) {
132 view (0, filename
, &move_dir
, start_line
);
139 viewer
= getenv ("PAGER");
143 /* The file may be a non local file, get a copy */
144 if (!vfs_file_is_local (filename
)) {
145 localcopy
= mc_getlocalcopy (filename
);
146 if (localcopy
== NULL
) {
147 message (1, MSG_ERROR
,
148 _(" Can not fetch a local copy of %s "),
152 execute_internal (viewer
, localcopy
);
153 mc_ungetlocalcopy (filename
, localcopy
, 0);
155 execute_internal (viewer
, filename
);
160 /* view_file (filename, plain_view, internal)
163 * filename: The file name to view
164 * plain_view: If set does not do any fancy pre-processing (no filtering) and
165 * always invokes the internal viewer.
166 * internal: If set uses the internal viewer, otherwise an external viewer.
169 view_file (char *filename
, int plain_view
, int internal
)
171 return view_file_at_line (filename
, plain_view
, internal
, 0);
174 /* scan_for_file (panel, idx, direction)
177 * panel: pointer to the panel on which we operate
178 * idx: starting file.
179 * direction: 1, or -1
181 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
183 int i
= idx
+ direction
;
187 i
= panel
->count
- 1;
188 if (i
== panel
->count
)
190 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
198 * Run viewer (internal or external) on the currently selected file.
199 * If normal is 1, force internal viewer and raw mode (used for F13).
202 do_view_cmd (int normal
)
206 /* Directories are viewed by changing to them */
207 if (S_ISDIR (selection (cpanel
)->buf
.st_mode
)
208 || link_isdir (selection (cpanel
))) {
209 if (confirm_view_dir
&& (cpanel
->marked
|| cpanel
->dirs_marked
)) {
211 (_(" Confirmation "), _("Files tagged, want to cd?"), 0, 2,
212 _("&Yes"), _("&No")) != 0) {
216 if (!do_cd (selection (cpanel
)->fname
, cd_exact
))
217 message (1, MSG_ERROR
, _("Could not change directory"));
223 file_idx
= cpanel
->selected
;
227 filename
= cpanel
->dir
.list
[file_idx
].fname
;
229 dir
= view_file (filename
, normal
, use_internal_view
);
232 file_idx
= scan_for_file (cpanel
, file_idx
, dir
);
236 /* Run user's preferred viewer on the currently selected file */
243 /* Ask for file and run user's preferred viewer on it */
250 input_dialog (_(" View file "), _(" Filename:"),
251 selection (cpanel
)->fname
);
255 view_file (filename
, 0, use_internal_view
);
259 /* Run plain internal viewer on the currently selected file */
261 view_simple_cmd (void)
267 filtered_view_cmd (void)
272 input_dialog (_(" Filtered view "),
273 _(" Filter command and arguments:"),
274 selection (cpanel
)->fname
);
278 view (command
, "", 0, 0);
283 void do_edit_at_line (const char *what
, int start_line
)
285 static char *editor
= 0;
287 #ifdef USE_INTERNAL_EDIT
288 if (use_internal_edit
){
289 edit (what
, start_line
);
290 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
294 #endif /* USE_INTERNAL_EDIT */
296 editor
= getenv ("EDITOR");
298 editor
= get_default_editor ();
300 execute_internal (editor
, what
);
301 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
306 do_edit (const char *what
)
308 do_edit_at_line (what
, 0);
314 if (regex_command (selection (cpanel
)->fname
, "Edit", 0) == 0)
315 do_edit (selection (cpanel
)->fname
);
324 /* Invoked by F5. Copy, default to the other panel. */
329 if (panel_operate (cpanel
, OP_COPY
, NULL
, TRUE
)) {
330 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
335 /* Invoked by F6. Move/rename, default to the other panel. */
339 if (panel_operate (cpanel
, OP_MOVE
, NULL
, TRUE
)){
340 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
345 /* Invoked by F15. Copy, default to the same panel. */
346 void copy_cmd_local (void)
349 if (panel_operate (cpanel
, OP_COPY
, selection (cpanel
)->fname
, TRUE
)){
350 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
355 /* Invoked by F16. Move/rename, default to the same panel. */
356 void ren_cmd_local (void)
359 if (panel_operate (cpanel
, OP_MOVE
, selection (cpanel
)->fname
, TRUE
)){
360 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
365 void mkdir_cmd (void)
370 dir
= input_expand_dialog (_("Create a new Directory"), _(" Enter directory name:") , "");
375 if (dir
[0] && (dir
[0] == '/' || dir
[0] == '~'))
376 tempdir
= g_strdup (dir
);
378 tempdir
= concat_dir_and_file (cpanel
->cwd
, dir
);
382 if (my_mkdir (tempdir
, 0777) == 0){
383 update_panels (UP_OPTIMIZE
, tempdir
);
385 select_item (cpanel
);
390 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
393 void delete_cmd (void)
397 if (panel_operate (cpanel
, OP_DELETE
, NULL
, TRUE
)){
398 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
409 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
415 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
416 p
->filter
= allocated_filter_string
;
418 g_free (allocated_filter_string
);
422 /* Set a given panel filter expression */
424 set_panel_filter (WPanel
*p
)
429 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
431 reg_exp
= input_dialog_help (_(" Filter "),
432 _(" Set expression for filtering filenames"),
436 set_panel_filter_to (p
, reg_exp
);
439 /* Invoked from the left/right menus */
440 void filter_cmd (void)
444 if (!SELECTED_IS_PANEL
)
448 set_panel_filter (p
);
451 void reread_cmd (void)
455 if (get_current_type () == view_listing
&&
456 get_other_type () == view_listing
)
457 flag
= strcmp (cpanel
->cwd
, opanel
->cwd
) ? UP_ONLY_CURRENT
: 0;
459 flag
= UP_ONLY_CURRENT
;
461 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
465 void reverse_selection_cmd (void)
470 for (i
= 0; i
< cpanel
->count
; i
++){
471 file
= &cpanel
->dir
.list
[i
];
472 if (S_ISDIR (file
->buf
.st_mode
))
474 do_file_mark (cpanel
, i
, !file
->f
.marked
);
476 paint_panel (cpanel
);
479 void select_cmd (void)
481 char *reg_exp
, *reg_exp_t
;
486 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
492 /* Check if they specified a directory */
493 if (*reg_exp_t
== PATH_SEP
){
497 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
499 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
502 for (i
= 0; i
< cpanel
->count
; i
++){
503 if (!strcmp (cpanel
->dir
.list
[i
].fname
, ".."))
505 if (S_ISDIR (cpanel
->dir
.list
[i
].buf
.st_mode
)){
512 c
= regexp_match (reg_exp_t
, cpanel
->dir
.list
[i
].fname
, match_file
);
514 message (1, MSG_ERROR
, _(" Malformed regular expression "));
519 do_file_mark (cpanel
, i
, 1);
522 paint_panel (cpanel
);
526 void unselect_cmd (void)
528 char *reg_exp
, *reg_exp_t
;
533 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
539 /* Check if they specified directory matching */
540 if (*reg_exp_t
== PATH_SEP
){
544 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
546 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
548 for (i
= 0; i
< cpanel
->count
; i
++){
549 if (!strcmp (cpanel
->dir
.list
[i
].fname
, ".."))
551 if (S_ISDIR (cpanel
->dir
.list
[i
].buf
.st_mode
)){
558 c
= regexp_match (reg_exp_t
, cpanel
->dir
.list
[i
].fname
, match_file
);
560 message (1, MSG_ERROR
, _(" Malformed regular expression "));
565 do_file_mark (cpanel
, i
, 0);
568 paint_panel (cpanel
);
572 /* Check if the file exists */
573 /* If not copy the default */
575 check_for_default(char *default_file
, char *file
)
582 if (mc_stat (file
, &s
)){
583 if (mc_stat (default_file
, &s
)){
586 ctx
= file_op_context_new ();
587 file_op_context_create_ui (ctx
, OP_COPY
, 0);
588 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
589 file_op_context_destroy (ctx
);
601 if (geteuid () == 0){
602 dir
= query_dialog (_("Extension file edit"),
603 _(" Which extension file you want to edit? "), 0, 2,
604 _("&User"), _("&System Wide"));
606 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
609 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
610 check_for_default (extdir
, buffer
);
617 flush_extension_file ();
620 /* where = 0 - do edit file menu for mc */
621 /* where = 1 - do edit file menu for mcedit */
623 menu_edit_cmd (int where
)
631 _(" Which menu file do you want to edit? "),
632 0, geteuid() ? 2 : 3,
633 _("&Local"), _("&Home"), _("&System Wide")
636 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
640 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
641 check_for_default (menufile
, buffer
);
645 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
646 check_for_default (menufile
, buffer
);
650 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
664 void quick_chdir_cmd (void)
668 target
= hotlist_cmd (LIST_HOTLIST
);
672 if (get_current_type () == view_tree
)
673 tree_chdir (the_tree
, target
);
675 if (!do_cd (target
, cd_exact
))
676 message (1, MSG_ERROR
, _("Could not change directory") );
680 /* edit file menu for mc */
682 edit_mc_menu_cmd (void)
687 #ifdef USE_INTERNAL_EDIT
688 /* edit file menu for mcedit */
690 edit_user_menu_cmd (void)
695 /* edit syntax file for mcedit */
697 edit_syntax_cmd (void)
703 if (geteuid () == 0) {
705 query_dialog (_("Syntax file edit"),
706 _(" Which syntax file you want to edit? "), 0, 2,
707 _("&User"), _("&System Wide"));
709 extdir
= concat_dir_and_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
712 buffer
= concat_dir_and_file (home_dir
, SYNTAX_FILE
);
713 check_for_default (extdir
, buffer
);
724 void free_vfs_now (void)
729 void reselect_vfs (void)
733 target
= hotlist_cmd (LIST_VFSLIST
);
737 if (!do_cd (target
, cd_exact
))
738 message (1, MSG_ERROR
, _("Could not change directory") );
743 static int compare_files (char *name1
, char *name2
, off_t size
)
746 int result
= -1; /* Different by default */
748 file1
= open (name1
, O_RDONLY
);
750 file2
= open (name2
, O_RDONLY
);
755 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
756 if (data1
!= (char*) -1){
757 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
758 if (data2
!= (char*) -1){
760 result
= memcmp (data1
, data2
, size
);
761 munmap (data2
, size
);
763 munmap (data1
, size
);
766 /* Don't have mmap() :( Even more ugly :) */
767 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
772 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
773 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
774 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
775 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
776 #endif /* !HAVE_MMAP */
785 compare_quick
, compare_size_only
, compare_thourough
789 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
792 char *src_name
, *dst_name
;
794 /* No marks by default */
797 panel
->dirs_marked
= 0;
799 /* Handle all files in the panel */
800 for (i
= 0; i
< panel
->count
; i
++){
801 file_entry
*source
= &panel
->dir
.list
[i
];
803 /* Default: unmarked */
804 file_mark (panel
, i
, 0);
806 /* Skip directories */
807 if (S_ISDIR (source
->buf
.st_mode
))
810 /* Search the corresponding entry from the other panel */
811 for (j
= 0; j
< other
->count
; j
++){
812 if (strcmp (source
->fname
,
813 other
->dir
.list
[j
].fname
) == 0)
816 if (j
>= other
->count
)
817 /* Not found -> mark */
818 do_file_mark (panel
, i
, 1);
821 file_entry
*target
= &other
->dir
.list
[j
];
823 if (mode
!= compare_size_only
){
824 /* Older version is not marked */
825 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
829 /* Newer version with different size is marked */
830 if (source
->buf
.st_size
!= target
->buf
.st_size
){
831 do_file_mark (panel
, i
, 1);
835 if (mode
== compare_size_only
)
838 if (mode
== compare_quick
){
839 /* Thorough compare off, compare only time stamps */
840 /* Mark newer version, don't mark version with the same date */
841 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
842 do_file_mark (panel
, i
, 1);
847 /* Thorough compare on, do byte-by-byte comparison */
848 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
849 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
850 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
851 do_file_mark (panel
, i
, 1);
859 compare_dirs_cmd (void)
862 enum CompareMode thorough_flag
;
865 query_dialog (_(" Compare directories "),
866 _(" Select compare method: "), 0, 3, _("&Quick"),
867 _("&Size only"), _("&Thorough"), _("&Cancel"));
869 if (choice
< 0 || choice
> 2)
872 thorough_flag
= choice
;
874 if (get_current_type () == view_listing
875 && get_other_type () == view_listing
) {
876 compare_dir (cpanel
, opanel
, thorough_flag
);
877 compare_dir (opanel
, cpanel
, thorough_flag
);
878 paint_panel (cpanel
);
879 paint_panel (opanel
);
881 message (1, MSG_ERROR
,
882 _(" Both panels should be in the "
883 "listing mode to use this command "));
893 if (cmdline
->need_push
) {
894 if (push_history (cmdline
, cmdline
->buffer
) == 2)
895 cmdline
->need_push
= 0;
897 if (!cmdline
->history
) {
898 message (1, MSG_ERROR
, _(" The command history is empty "));
901 current
= cmdline
->history
;
902 while (current
->prev
)
903 current
= current
->prev
;
904 listbox
= create_listbox_window (60, 10, _(" Command history "),
907 LISTBOX_APPEND_TEXT (listbox
, 0, current
->text
, current
);
908 current
= current
->next
;
910 run_dlg (listbox
->dlg
);
911 if (listbox
->dlg
->ret_value
== B_CANCEL
)
914 current
= listbox
->list
->current
->data
;
915 destroy_dlg (listbox
->dlg
);
920 cmdline
->history
= current
;
921 assign_text (cmdline
, cmdline
->history
->text
);
922 update_input (cmdline
, 1);
933 view_other_cmd (void)
935 static int message_flag
= TRUE
;
936 #ifdef HAVE_SUBSHELL_SUPPORT
937 char *new_dir
= NULL
;
939 #endif /* HAVE_SUBSHELL_SUPPORT */
941 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
943 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
944 " the panels cannot be toggled. "));
945 message_flag
= FALSE
;
949 if (clear_before_exec
)
951 if (alternate_plus_minus
)
952 numeric_keypad_mode ();
954 /* With slang we don't want any of this, since there
955 * is no mc_raw_mode supported
959 #endif /* !HAVE_SLANG */
960 keypad(stdscr
, FALSE
);
967 #ifdef HAVE_SUBSHELL_SUPPORT
969 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
970 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
971 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
973 #endif /* HAVE_SUBSHELL_SUPPORT */
975 if (output_starts_shell
){
977 _("Type `exit' to return to the Midnight Commander"));
978 fprintf (stderr
, "\n\r\n\r");
980 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
985 handle_console (CONSOLE_SAVE
);
990 keypad(stdscr
, TRUE
);
992 /* Prevent screen flash when user did 'exit' or 'logout' within
999 if (alternate_plus_minus
)
1000 application_keypad_mode ();
1002 #ifdef HAVE_SUBSHELL_SUPPORT
1006 do_possible_cd (new_dir
);
1007 if (console_flag
&& output_lines
)
1008 show_console_contents (output_start_y
,
1009 LINES
-keybar_visible
-output_lines
-1,
1010 LINES
-keybar_visible
-1);
1012 #endif /* HAVE_SUBSHELL_SUPPORT */
1019 #ifndef NATIVE_WIN32
1021 do_link (int symbolic_link
, char *fname
)
1025 if (!symbolic_link
) {
1026 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
1027 dest
= input_expand_dialog (_(" Link "), src
, "");
1036 if (-1 == mc_link (fname
, dest
))
1037 message (1, MSG_ERROR
, _(" link: %s "),
1038 unix_error_string (errno
));
1043 /* suggest the full path for symlink */
1044 s
= concat_dir_and_file (cpanel
->cwd
, fname
);
1046 if (get_other_type () == view_listing
) {
1047 d
= concat_dir_and_file (opanel
->cwd
, fname
);
1049 d
= g_strdup (fname
);
1052 symlink_dialog (s
, d
, &dest
, &src
);
1056 if (!dest
|| !*dest
|| !src
|| !*src
) {
1064 if (-1 == mc_symlink (dest
, src
))
1065 message (1, MSG_ERROR
, _(" symlink: %s "),
1066 unix_error_string (errno
));
1070 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1074 void link_cmd (void)
1076 do_link (0, selection (cpanel
)->fname
);
1079 void symlink_cmd (void)
1081 char *filename
= NULL
;
1082 filename
= selection (cpanel
)->fname
;
1085 do_link (1, filename
);
1089 void edit_symlink_cmd (void)
1091 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1092 char buffer
[MC_MAXPATHLEN
];
1097 p
= selection (cpanel
)->fname
;
1099 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
1101 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1104 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1106 if (*dest
&& strcmp (buffer
, dest
)) {
1108 if (-1 == mc_unlink (p
)){
1109 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
1110 p
, unix_error_string (errno
));
1112 if (-1 == mc_symlink (dest
, p
))
1113 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1114 unix_error_string (errno
));
1116 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1124 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
1125 selection (cpanel
)->fname
);
1128 #endif /* !NATIVE_WIN32 */
1130 void help_cmd (void)
1132 interactive_display (NULL
, "[main]");
1135 /* partly taken from dcigettext.c, returns "" for default locale */
1136 /* value should be freed by calling function g_free() */
1137 char *guess_message_value (void)
1139 static const char * const var
[] = {
1140 /* The highest priority value is the `LANGUAGE' environment
1141 variable. This is a GNU extension. */
1143 /* Setting of LC_ALL overwrites all other. */
1145 /* Next comes the name of the desired category. */
1147 /* Last possibility is the LANG environment variable. */
1149 /* NULL exit loops */
1154 char *locale
= NULL
;
1156 while (var
[i
] != NULL
) {
1157 locale
= getenv (var
[i
]);
1158 if (locale
!= NULL
&& locale
[0] != '\0')
1166 return g_strdup (locale
);
1169 /* Returns a random hint */
1170 char *get_random_hint (void)
1172 char *data
, *result
, *eol
;
1176 /* Do not change hints more often than one minute */
1183 if ((now
- last
) < 60)
1184 return g_strdup ("");
1187 static int last_sec
;
1188 static struct timeval tv
;
1190 gettimeofday (&tv
, NULL
);
1191 if (!(tv
.tv_sec
> last_sec
+60))
1192 return g_strdup ("");
1193 last_sec
= tv
.tv_sec
;
1194 #endif /* !SCO_FLAVOR */
1196 data
= load_mc_home_file (MC_HINT
, NULL
);
1201 srand ((short) now
);
1204 #endif /* !SCO_FLAVOR */
1205 /* get a random entry */
1206 len
= strlen (data
);
1207 start
= rand () % len
;
1209 for (;start
; start
--){
1210 if (data
[start
] == '\n'){
1215 eol
= strchr (&data
[start
], '\n');
1218 result
= g_strdup (&data
[start
]);
1223 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1225 nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1230 if (!SELECTED_IS_PANEL
)
1233 machine
= input_dialog_help (text
,
1239 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1240 ugly as hell and leads to problems in vfs layer */
1242 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1243 cd_path
= g_strconcat (machine
, to_home
? "/~/" : NULL
, NULL
);
1245 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1247 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1248 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1250 message (1, MSG_ERROR
, _(" Could not chdir to %s "), cd_path
);
1254 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1259 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1262 void netlink_cmd (void)
1264 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1265 "[Network File System]", "/#mc:", 1);
1267 #endif /* WITH_MCFS */
1269 void ftplink_cmd (void)
1271 nice_cd (_(" FTP to machine "), _(machine_str
),
1272 "[FTP File System]", "/#ftp:", 1);
1275 void fishlink_cmd (void)
1277 nice_cd (_(" Shell link to machine "), _(machine_str
),
1278 "[FIle transfer over SHell filesystem]", "/#sh:", 1);
1282 void smblink_cmd (void)
1284 nice_cd (_(" SMB link to machine "), _(machine_str
),
1285 "[SMB File System]", "/#smb:", 0);
1287 #endif /* WITH_SMBFS */
1289 #ifdef HAVE_SETSOCKOPT
1290 void source_routing (void)
1295 source
= input_dialog (_(" Socket source routing setup "),
1296 _(" Enter host name to use as a source routing hop: "),
1301 hp
= gethostbyname (source
);
1304 message (1, _(" Host name "), _(" Error while looking up IP address "));
1307 source_route
= *((int *)hp
->h_addr
);
1309 #endif /* HAVE_SETSOCKOPT */
1310 #endif /* USE_NETCODE */
1312 #ifdef USE_EXT2FSLIB
1313 void undelete_cmd (void)
1315 nice_cd (_(" Undelete files on an ext2 file system "),
1316 _(" Enter device (without /dev/) to undelete\n "
1317 " files on: (F1 for details)"),
1318 "[Undelete File System]", "/#undel:", 0);
1320 #endif /* USE_EXT2FSLIB */
1322 void quick_cd_cmd (void)
1324 char *p
= cd_dialog ();
1327 char *q
= g_strconcat ("cd ", p
, NULL
);
1339 WPanel
*panel
= cpanel
;
1344 for (i
= 0; i
< panel
->count
; i
++)
1345 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1346 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1347 !panel
->dirs_marked
) &&
1348 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1350 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1351 panel
->dir
.list
[i
].buf
.st_size
= (off_t
) total
;
1352 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1355 recalculate_panel_summary (panel
);
1356 paint_panel (panel
);
1360 save_setup_cmd (void)
1366 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1368 message (0, _(" Setup "), str
);
1373 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1375 p
->user_mini_status
= use_msformat
;
1376 p
->list_type
= view_type
;
1378 if (view_type
== list_user
|| use_msformat
){
1379 g_free (p
->user_format
);
1380 p
->user_format
= user
;
1382 g_free (p
->user_status_format
[view_type
]);
1383 p
->user_status_format
[view_type
] = status
;
1385 set_panel_formats (p
);
1392 set_panel_formats (p
);
1399 info_cmd_no_menu (void)
1401 if (get_display_type (0) == view_info
)
1402 set_display_type (0, view_listing
);
1403 else if (get_display_type (1) == view_info
)
1404 set_display_type (1, view_listing
);
1406 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1410 quick_cmd_no_menu (void)
1412 if (get_display_type (0) == view_quick
)
1413 set_display_type (0, view_listing
);
1414 else if (get_display_type (1) == view_quick
)
1415 set_display_type (1, view_listing
);
1417 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1421 switch_to_listing (int panel_index
)
1423 if (get_display_type (panel_index
) != view_listing
)
1424 set_display_type (panel_index
, view_listing
);
1430 int view_type
, use_msformat
;
1431 char *user
, *status
;
1435 display_type
= get_display_type (MENU_PANEL_IDX
);
1436 if (display_type
== view_listing
)
1437 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1441 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1443 if (view_type
== -1)
1446 switch_to_listing (MENU_PANEL_IDX
);
1448 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1450 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1456 set_display_type (MENU_PANEL_IDX
, view_tree
);
1462 set_display_type (MENU_PANEL_IDX
, view_info
);
1466 quick_view_cmd (void)
1468 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == cpanel
)
1470 set_display_type (MENU_PANEL_IDX
, view_quick
);
1473 /* Handle the tree internal listing modes switching */
1475 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1477 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1479 switch_to_listing (panel_index
);
1480 p
->list_type
= listing_mode
;
1481 if (set_panel_formats (p
))
1490 toggle_listing_cmd (void)
1492 int current
= get_current_index ();
1493 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1494 int list_mode
= p
->list_type
;
1508 if (set_basic_panel_listing_to (current
, m
))
1510 set_basic_panel_listing_to (current
, list_full
);